I'm currently trying to setup a linux system with a USB OTG Port in device mode. When enabling the NCM gadget with the precomposed configuration, I already could load the gadget driver and a host attached to the OTG port recognized the NCM gadget. Two interfaces with several endpoints where listed under /sys/bus/usb/devices/3-1/. Now, I would like to modify the interfaces (and endpoints) offered to the host.
From my research, I assume, that libcomposite and configfs is the way to go for this. I therefore enabled NCM configurable through configfs in buildroot.
For configuration, I try to follow the kernel documentation about configuring gadgets through the configfs: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
I loaded the libcomposite.ko and mounted the configfs. I could create a folder under /sys/kernel/config/usb_gadget/. When entering the folder, it contains the expected files and subfolders:
total 0
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 UDC
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bDeviceClass
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bDeviceProtocol
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bDeviceSubClass
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bMaxPacketSize0
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bcdDevice
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 bcdUSB
drwxr-xr-x 2 root root 0 Feb 16 14:43 configs
drwxr-xr-x 2 root root 0 Feb 16 14:43 functions
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 idProduct
-rw-r--r-- 1 root root 4.0K Feb 16 15:15 idVendor
drwxr-xr-x 2 root root 0 Feb 16 14:43 os_desc
drwxr-xr-x 2 root root 0 Feb 16 14:43 strings
mkdir functions/ncm.usb3
mkdir: can't create directory 'functions/ncm.usb3': No such file or directory
However, under /lib/modules/4.14.78-linux-v4.14-BSP0112/kernel/drivers/usb/gadget/function/ a file usb_f_ncm.ko does exist!
I have tried several names (e.g. usb0, usb, u1,...), other gadgets (like the mass storage gadget) all without success. I can create configurations under ./configs and also subfolders under ./strings... What piece in the puzzle am I missing here? Any help is appreciated
Side info: A this is an embedded system, modprobe is not available, only insmod...
Update I could solve the problem from above. Previously, I had the libcomposite and ncm as modules (M) in buildroot. When directly including them into the kernel (*) I could add the ncm functionality. This probably is related to the missing modprobe functionality.. However, only four configuration files appear in the created function folder:
total 0
-rw-r--r-- 1 root root 4.0K Feb 16 16:30 dev_addr
-rw-r--r-- 1 root root 4.0K Feb 16 16:30 host_addr
-r--r--r-- 1 root root 4.0K Feb 16 16:30 ifname
-rw-r--r-- 1 root root 4.0K Feb 16 16:30 qmult
How can I specify further attributes of this interface? E.g. Endpoints?