RE: usb device implemented with functionfs - must app run as root?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Suggestion from GKH is to write a udev rule to change ownership, group, permissions of the functionfs created endpoint files: 
   /dev/usbffs/ep1
   /dev/usbffs/ep2
   /dev/usbffs/ep3

I tried all morning to create a udev rule, but no success. 
My attempts are documented below.

I don't know what else to try. 

Am I doing something wrong?

My theory is that udev is not wired up to usb functionfs properly and is not seeing the creation events for ep1, ep2, ep3. 
Note that the system did not create /dev/usbffs. My startup script creates this file. 




###
### Try 1 ... at this point, /dev/usbffs/ep0 already exists on the device 
### 
$ udevadm info -a -p /dev/usbffs/ep0
RESULT: syspath not found

###
### Try 2
### 
$ udevadm info -a -p /dev/usbffs/
RESULT: syspath not found

###
### Try 3 ... maybe udevadm requires the path to be under /sys 
### 
$ udevadm info -a -p /sys/class/udc/e1100000.usbd     <== this is path to the low-level usb-device driver in the kernel 
RESULT: 
    KERNEL=="e1100000.usbd"
    SUBSYSTEM=="udc"
    DRIVER==""
    ATTR{a_alt_hnp_support}=="0"
    ATTR{a_hnp_support}=="0"
    ATTR{b_hnp_enable}=="0"
    ATTR{current_speed}=="UNKNOWN"
    ATTR{function}==""
    ATTR{is_a_peripheral}=="0"
    ATTR{is_otg}=="0"
    ATTR{is_selfpowered}=="0"
    ATTR{maximum_speed}=="high-speed"
    ATTR{state}=="not attached"

  looking at parent device '/devices/platform/ahb/e1100000.usbd':
    KERNELS=="e1100000.usbd"
    SUBSYSTEMS=="platform"
    DRIVERS=="designware-udc"
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform/ahb':
    KERNELS=="ahb"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"

set rule KERNEL=="e1100000.usbd", SUBSYSTEM=="udc", SUBSYSTEMS=="platform", ACTION=="add",  RUN+="/etc/udev/scripts/usb488setup.sh"
reboot, attempt to start usb-device 
RESULT: Script usb488setup.sh does not run. If it runs, it attempts to create /tmp/junk.txt 
Maybe this is no surprise - there is no e1100000.usbd driver added when I attempt to start the application. 
Kernel has already loaded it. 
... test using udevadm 
$ udevadm test /sys/class/udc/e1100000.usbd 2>&1 | grep usb488setup
run: '/etc/udev/scripts/usb488setup.sh'

###
### Try 4
###
$ udevadm info -a -p /sys/kernel/config/usb_gadget
RESULT: 
    KERNEL=="usb_gadget"
    SUBSYSTEM==""
    DRIVER==""

  looking at parent device '/kernel/config':
    KERNELS=="config"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel':
    KERNELS=="kernel"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{fscaps}=="1"
    ATTRS{rcu_expedited}=="0"
    ATTRS{rcu_normal}=="0"
    ATTRS{uevent_seqnum}=="1115"

set rule KERNEL=="usb_gadget", KERNELS=="config", ACTION=="add",  RUN+="/etc/udev/scripts/usb488setup.sh"
reboot, attempt to start usb-device 
RESULT: script not run 
... test using udevadm.
udevadm test /sys/kernel/config/usb_gadget 2>&1 | grep usb488
no output ? 


###
### Try 5
###
$ udevadm info -a -p /sys/kernel/config/usb_gadget/g1
RESULT: returns 
    KERNEL=="g1"
    SUBSYSTEM==""
    DRIVER==""
    ATTR{UDC}==""
    ATTR{bDeviceClass}=="0x00"
    ATTR{bDeviceProtocol}=="0x00"
    ATTR{bDeviceSubClass}=="0x00"
    ATTR{bMaxPacketSize0}=="0x00"
    ATTR{bcdDevice}=="0x0414"
    ATTR{bcdUSB}=="0x0000"
    ATTR{idProduct}=="0x0000"
    ATTR{idVendor}=="0x0000"

  looking at parent device '/kernel/config/usb_gadget':
    KERNELS=="usb_gadget"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel/config':
    KERNELS=="config"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel':
    KERNELS=="kernel"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{fscaps}=="1"
    ATTRS{rcu_expedited}=="0"
    ATTRS{rcu_normal}=="0"
    ATTRS{uevent_seqnum}=="1115"

set rule KERNEL=="g1", KERNELS=="usb_gadget", ACTION=="add",   RUN+="/etc/udev/scripts/usb488setup.sh"
reboot, attempt to start usb-device 
RESULT: script not run 
... test using udevadm.
udevadm test /sys/kernel/config/usb_gadget/g1  2>&1 | grep usb488
no output ?

###
### Try 6
###
$ udevadm info -a -p  /sys/kernel/config/usb_gadget/g1/configs/c.1/ffs.usb488
RESULT: returns info
    KERNEL=="ffs.usb488"
    SUBSYSTEM==""
    DRIVER==""

  looking at parent device '/kernel/config/usb_gadget/g1/functions':
    KERNELS=="functions"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel/config/usb_gadget/g1':
    KERNELS=="g1"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{UDC}==""
    ATTRS{bDeviceClass}=="0x00"
    ATTRS{bDeviceProtocol}=="0x00"
    ATTRS{bDeviceSubClass}=="0x00"
    ATTRS{bMaxPacketSize0}=="0x00"
    ATTRS{bcdDevice}=="0x0414"
    ATTRS{bcdUSB}=="0x0000"
    ATTRS{idProduct}=="0x0000"
    ATTRS{idVendor}=="0x0000"

  looking at parent device '/kernel/config/usb_gadget':
    KERNELS=="usb_gadget"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel/config':
    KERNELS=="config"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel':
    KERNELS=="kernel"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{fscaps}=="1"
    ATTRS{rcu_expedited}=="0"
    ATTRS{rcu_normal}=="0"
    ATTRS{uevent_seqnum}=="1115"

set rule KERNEL=="ffs.usb488", KERNELS=="functions", ACTION=="add",   RUN+="/etc/udev/scripts/usb488setup.sh"
reboot, attempt to start usb-device 
RESULT: script not run
... test using udevadm.
udevadm test /sys/kernel/config/usb_gadget/g1  2>&1 | grep usb488
$ udevadm test /sys/kernel/config/usb_gadget/g1/configs/c.1/ffs.usb488  2>&1 | grep usb488
DEVPATH=/kernel/config/usb_gadget/g1/functions/ffs.usb488   <==== No "run" line 


Andy Purcell





> -----Original Message-----
> From: Greg KH [mailto:gregkh@xxxxxxxxxxxxxxxxxxx]
> Sent: Tuesday, December 5, 2017 11:27 PM
> To: PURCELL,ANDY (K-Loveland,ex1) <andy_purcell@xxxxxxxxxxxx>
> Cc: linux-usb@xxxxxxxxxxxxxxx
> Subject: Re: usb device implemented with functionfs - must app run as root?
> 
> On Tue, Dec 05, 2017 at 10:09:35PM +0000, andy_purcell@xxxxxxxxxxxx wrote:
> > I have implemented a USB device using functionfs.
> > A colleague now says our app must run as a normal user, not as root.
> >
> > I tried it and it does not work.
> > The problem is this - the endpoint files created by the OS are owned by root.
> > These ep files are created after I write the descriptors and strings to the
> /dev/usbffs/ep0 file.
> >
> > $ ls -l /dev/usbffs/
> > total 0
> > -rw-rw-rw- 1 xyzuser xyzgrp 0 Dec  5 21:36 ep0
> > -rw------- 1 root    root   0 Dec  5 21:39 ep1
> > -rw------- 1 root    root   0 Dec  5 21:39 ep2
> > -rw------- 1 root    root   0 Dec  5 21:39 ep3
> >
> > A normal user-space app cannot open, write, read, these ep files.
> >
> > Is there a remedy for this?
> 
> Write a udev rule to change the owners of those files :)
> 
> You must have done that already for the ep0 file, right?
> 
> thanks,
> 
> greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux