Serial port access for private repository

Hello, We have private repository (internethandel-electron-cme) and We need serial port access to support various devices.

I am not even sure why private repositories doesn’t have more relaxed rules.

If it is not possible, We would need to move from snapcraft.io or from snap package format altogether.

Hi, whilst your snap is marked as private it is uploaded to the global snap store and so needs to be treated as a publicly accessible snap (since you could easily mark it as public in the future).

So then looking at your snap - I notice your snap declares a large number of serial-port slots - however application snaps are not allowed to declare this since they don’t actually provide the serial-port at all - instead only gadget snaps can declare a slot of this type.

Instead I suspect you want your snap to be able to interact with whatever serial-ports are connected - in that case you likely want to use serial-port via hotplug - please see Hotplug support in that case.

Otherwise, please provide more details on what your snap is trying to accomplish by slotting serial-port currently and we can try to help you achieve this in a more correct manner.

@radomirpolach ping, were you able to look into using hotplug with serial-port as suggested above?

I will be looking into this during the week. I will inform you as soon as I am done testing it.

@alexmurray I am looking at that, but I am not really sure what I need to do for devices to appear within the snap.

I enabled hotplug support and connected serial device.

There is a lot of implementation details here: Developing hotplug interfaces

But I don’t rally see any guiding how to configure my snap to allow for serial devices.

I basically need for specific device (either defined by PID/VID or name to appear within my snap).

$ sudo snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - internethandel-electron-cme

So, I have nice plug in my snap.

$ lsusb
...
Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics CH340 serial converter
...

I have a device connected to my system, but no connections:

$ snap connections system | grep serial

did you enable hotplug support on the machine ?

If you mean this:

sudo snap set system experimental.hotplug=true

Then yes. I also restart snapd (and rebooted as well).

@alexmurray Any ideas what I have to do?

@radomirpolach what device does this USB-Serial converter show up as on your host system? Also can you confirm that sudo snap get system experimental.hotplug outputs true? When testing this locally with a different USB-Serial converter:

$ lsusb | grep Keyspan
Bus 005 Device 009: ID 06cd:0121 Keyspan USA-19hs serial adapter

It works for me:

$ sudo snap get system experimental.hotplug
true
$ sudo dmesg | grep ttyUSB
[43658.826363] usb 5-2.2: Keyspan 1 port adapter converter now attached to ttyUSB0
$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
slots:
  - snapd:keyspanusa-19h (allows accessing a specific serial port)
          -                                                              :keyspanusa-19h            -

what do you see in dmesg when plugging in the USB/serial adapter … it should look similar to the stuff below:

$ sudo dmesg -w
[...]
[268760.901758] audit: type=1420 audit(1654174808.483:1290): subj_apparmor=unconfined
[268868.859996] usb 1-1: new full-speed USB device number 4 using xhci_hcd
[268869.013021] usb 1-1: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
[268869.013028] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[268869.013030] usb 1-1: Product: USB-Serial Controller
[268869.013033] usb 1-1: Manufacturer: Prolific Technology Inc.
[268869.126420] usbcore: registered new interface driver usbserial_generic
[268869.126461] usbserial: USB Serial support registered for generic
[268869.128788] usbcore: registered new interface driver pl2303
[268869.128827] usbserial: USB Serial support registered for pl2303
[268869.128866] pl2303 1-1:1.0: pl2303 converter detected
[268869.129541] usb 1-1: pl2303 converter now attached to ttyUSB0
[...]

you should then see a slot:

$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - arduino
  - esptool
  - pcsc-daemon
slots:
  - snapd:pl2303serialportmobi (allows accessing a specific serial port)

does the kernel actually detect the device and assign a ttyUSB* port for it in the first step above ?

$  sudo snap get system experimental.hotplug
true
$  sudo dmesg | grep ttyUSB
[  425.300597] usb 1-4: ch341-uart converter now attached to ttyUSB0
[  426.010761] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
$  snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - internethandel-electron-cme
$  snap connections system | grep serial

Complete dmesg from connecting the device:

[  581.148236] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[  581.301054] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.54
[  581.301059] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[  581.301060] usb 1-1: Product: USB2.0-Serial
[  581.302426] ch341 1-1:1.0: ch341-uart converter detected
[  581.302772] usb 1-1: ch341-uart converter now attached to ttyUSB0
[  581.843558] audit: type=1400 audit(1654176321.477:217): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  581.881687] audit: type=1400 audit(1654176321.517:218): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  582.415955] input: BRLTTY 6.4 Linux Screen Driver Keyboard as /devices/virtual/input/input30
[  582.541536] usb 1-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
[  582.542318] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[  582.542380] ch341 1-1:1.0: device disconnected

that looks like:

(not actually snap related at all)

Ah good find @ogra - so it looks like you may be able to resolve this @radomirpolach by removing the brltty package.

@radomirpolach ping can you confirm if removing the brltty package is sufficient to get serial-port with hotplug working? If so, we can then look at granting the required snap declaration to allow this to occur automatically when your snap is installed. Thanks.

@radomirpolach - ping, have you had a chance to test removing the brltty package to get this working?