How to get device path and mount path using usbdi callbacks

Hi,

I am in the progress of implementing a service which will detect usb plugin/removal using usbdi callback functions. Callback function has a parameter “usbd_device_instance_t * usbInstance” from which i can get device vendor id,product id and the device class information. But how do i get a mount point in case of a mass storage device and a device path in case of a HID device?

Hi,

You can’t get mount point or device path from usbdi API.
This is because USB DDK is not aware of these informations.

Depending on your OS version, you can use usblauncher to get device information through PPS.

notes :

Thank you for your response. Is there any other way to do that without using usb_launcher service?

usblauncher does more than publishing information. It also manages the plug&play when USB devices are connected.
The rules file associated with USB launcher allows to launch a specific driver with/without specific options when a USB device is connected.
That’s the case for mass storage.

For HID devices, this is different. io-hid is in charge of their management. io-hid connects to the USB stack.
However, some HID devices are still managed by usb-launcher to launch a specific driver (iPod).

How are the USB devices mounted in your system ?

Yes. In my case, my application should handle all the USB Devices plugin/removal activities (which you described that usb launcher and io-hid takes care in qnx). My application should take the control over all the USB devices attached to the system(USB detection, loading a driver, mounting usb mass storage, etc). Is it possible to do all those things?

Why not using usblauncher ?

In case of using usb launcher, How to identify the device object of the device connected? is it requires directory scanning ?

PPS files are created/removed dynamically when connecting/unconnecting USB devices.

You can subscribe to a PPS directory.
With fd_usb_device = open("/pps/qnx/device/.all?wait,delta", O_RDONLY); your code gets notified when a device is connected/unconnected.

When reading the opened file, you immediately receive :

@usb_ctrl

When a device is connected, you get (just an example) :

+@usb-0.2 @usb-0.2 bus::USB busno::0x00 devno::0x02 vendor_id::0xXXX product_id::0xXXX configurations::1 configuration::1 device_class::0xef device_subclass::0x02 device_protocol::0x01 max_packet_size0::64 manufacturer::XXXXXXXXXX product::XXXXXXXXXX upstream_device_address::1 upstream_host_controller::0 upstream_port::3 upstream_port_speed::Full topology::(1,3),(0,1) drivers_matched::0 drivers_running::0

When the device is unconnected, you get :

*@usb-0.2 -@usb-0.2

You can try with cat /pps/qnx/device/.all?wait,delta in a terminal (while usblauncher is running).

This one Makes sense. One more idea stroked in my mind. Is it possible to identify the device object of the connected/disconnected device with the details returned by usbdi callback function?

When USB devices are connected, other files are published in other directories.

An example, with a mass storage device :

/ #cat /pps/qnx/device/usb-0.2
[n]@usb-0.2
bus::USB
busno::0x00
configuration::1
configurations::1
device_class::0x00
devno::0x02
drivers_matched::1
drivers_running::1
max_packet_size0::64
product::USB Mass Storage Device
product_id::0xba01
serial_number::03AD0000000471
topology::(1,3),(0,1)
upstream_device_address::1
upstream_host_controller::0
upstream_port::3
upstream_port_speed::High
vendor_id::0x4146

/ #cat /pps/qnx/driver/1536016
[n]@1536016
PPS_DEVICE_ID::/pps/qnx/device/usb-0.2
arguments::cam quiet blk cache=1m,vnode=384,auto=none,delwri=2:2,rmvto=none,noatime disk name=hd_usb cdrom name=cd_usb umass priority=21,vid=0x4146,did=0xba01,bu
sno=0,devno=0x2,iface=0,ign_remove
interface::0
interface_class::0x08
interface_protocol::0x50
interface_subclass::0x06
name::devb-umass
pid::1536016

/ #cat /pps/qnx/mount/hd_usb0
[n]@hd_usb0
PPS_DRIVER_ID::/pps/qnx/driver/1536016
blocks_size::512
blocks_total::8323072
mnt_status::0 (No error)
partition_count::1
raw::/dev/hd_usb0

/ #cat /pps/qnx/mount/hd_usb0.0
[n]@hd_usb0.0
PPS_DRIVER_ID::/pps/qnx/driver/1536016
PPS_RAWMOUNT_ID::/pps/qnx/mount/hd_usb0
blocks_size::512
blocks_total::511968
fs_type::dos (fat32)
label::TEST
mnt_status::0 (No error)
mount::/mnt/usb0
partition::/dev/hd_usb0t11
partition_order::0
raw::/dev/hd_usb0
read_only::0

How to identify the PID of the device object? so that i will be able identify the driver object belongs to the device object. How the device object, driver object and mount objects are related? Is there any way to identify the driver object and mount object of a device object without reading each file inside it?