udev: Adding PCIe as a subsystem in udev
PATCH 1/1 udev: Adding PCIe as a subsystem in udev
Adding support for enumerating PCIe types of modems in ofono
--- plugins/udevng.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 21 deletions(-)
plugins/udevng.c +174 -21
@@ -41,6 +41,7 @@enum modem_type {MODEM_TYPE_USB ,MODEM_TYPE_SERIAL , +MODEM_TYPE_PCIE , };struct modem_info {
@@ -1229,26 +1230,43 @@ static gboolean setup_xmm7xxx(struct modem_info *modem) info->interface, info->number, info->label, info->sysattr, info->subsystem); -if (g_strcmp0 (modem->model,"095a" ) ==0 ) { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"06" ) ==0 ) - net = info->devnode; -if (g_strcmp0 (info->number,"08" ) ==0 ) - net2 = info->devnode; -if (g_strcmp0 (info->number,"0a" ) ==0 ) - net3 = info->devnode; +if (g_strcmp0 (info->subsystem,"pci" ) ==0 ) { +if ((g_strcmp0 (modem->vendor,"0x8086" ) ==0 ) && + (g_strcmp0 (modem->model,"0x7560" ) ==0 )) { + mdm ="/dev/iat" ; + net ="inm0" ; + net2 ="inm1" ; + net3 ="inm2" ; +ofono_modem_set_string (modem->modem, +"CtrlPath" ,"/PCIE/IOSM/CTRL/1" ); +ofono_modem_set_string (modem->modem,"DataPath" , +"/PCIE/IOSM/IPS/" ); } - }else { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"02" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - net = info->devnode; + }else {/* For USB */ +if (g_strcmp0 (modem->model,"095a" ) ==0 ) { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"06" ) ==0 ) + net = info->devnode; +if (g_strcmp0 (info->number,"08" ) ==0 ) + net2 = info->devnode; +if (g_strcmp0 (info->number,"0a" ) ==0 ) + net3 = info->devnode; + } + }else { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { +if (g_strcmp0 (info->number,"02" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + net = info->devnode; + } } + +ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); +ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" ); } }
@@ -1266,9 +1284,6 @@ static gboolean setup_xmm7xxx(struct modem_info *modem)if (net3)ofono_modem_set_string (modem->modem,"NetworkInterface3" , net3); -ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); -ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" ); -return TRUE; }
@@ -1437,6 +1452,7 @@ static void destroy_modem(gpointer data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;
@@ -1467,6 +1483,7 @@ static gboolean check_remove(gpointer key, gpointer value, gpointer user_data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;
@@ -1597,6 +1614,91 @@ static void add_serial_device(struct udev_device *dev) modem->serial = info; } +static void add_pci_device (const char *syspath,const char *devname, +const char *driver,const char *vendor, +const char *model,struct udev_device *device) +{ +const char *devpath, *devnode, *interface, *number; +const char *label, *sysattr, *subsystem; +struct modem_info *modem; +struct device_info *info; +struct udev_device *parent; + + devpath =udev_device_get_syspath (device); + +if (devpath ==NULL ) +return ; + + devnode =udev_device_get_devnode (device); + +if (devnode ==NULL ) { + devnode =udev_device_get_property_value (device,"INTERFACE" ); +DBG ("devnode = %s" , devnode); + } + + modem =g_hash_table_lookup (modem_list, syspath); + +if (modem ==NULL ) { + modem = g_try_new0(struct modem_info, 1); + +if (modem ==NULL ) +return ; + + modem->type =MODEM_TYPE_PCIE ; + modem->syspath =g_strdup (syspath); + modem->devname =g_strdup (devname); + modem->driver =g_strdup (driver); + modem->vendor =g_strdup (vendor); + modem->model =g_strdup (model); + modem->sysattr =get_sysattr (driver); + +g_hash_table_replace (modem_list, modem->syspath, modem); + } + + interface =udev_device_get_property_value (device,"INTERFACE" ); + +/* +* If environment variable is not set, get value from attributes +* (or parent's ones) +*/ + number =udev_device_get_sysattr_value (device,"bInterfaceNumber" ); + +if (number ==NULL ) { + parent =udev_device_get_parent (device); + number =udev_device_get_sysattr_value (parent,"bInterfaceNumber" ); + } + + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + +if (!label) + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + + subsystem =udev_device_get_subsystem (device); + +if (modem->sysattr !=NULL ) + sysattr =udev_device_get_sysattr_value (device, modem->sysattr); +else + sysattr =NULL ; + +DBG ("%s (%s) %s [%s] ==> %s %s" , devnode, driver, + interface, number, label, sysattr); + info = g_try_new0(struct device_info, 1); + +if (info ==NULL ) +return ; + + info->devpath =g_strdup (devpath); + info->devnode =g_strdup (devnode); + info->interface =g_strdup (interface); + info->number =g_strdup (number); + info->label =g_strdup (label); + info->sysattr =g_strdup (sysattr); + info->subsystem =g_strdup (subsystem); + + modem->devices =g_slist_insert_sorted (modem->devices, info, + compare_device); +} +static void add_device (const char *syspath,const char *devname,const char *driver,const char *vendor,const char *model,struct udev_device *device)
@@ -1625,8 +1727,10 @@ static void add_device(const char *syspath, const char *devname,return ; modem =g_hash_table_lookup (modem_list, syspath); +if (modem ==NULL ) { modem = g_try_new0(struct modem_info, 1); +if (modem ==NULL )return ;
@@ -1772,6 +1876,7 @@ static struct { { "telit", "cdc_acm", "1bc7", "0036" }, { "xmm7xxx", "cdc_acm", "8087" }, { "xmm7xxx", "cdc_ncm", "8087" }, + { "xmm7xxx", "imc_ipc", "0x8086", "0x7560"}, { } };
@@ -1858,6 +1963,51 @@ static void check_usb_device(struct udev_device *device)add_device (syspath, devname, driver, vendor, model, device); } +static void check_pci_device (struct udev_device *device) +{ +const char *syspath, *devname, *driver; +const char *vendor =NULL , *model =NULL , *drv =NULL ; +unsigned int i; + + syspath =udev_device_get_syspath (device); + +if (syspath ==NULL ) +return ; + + devname =udev_device_get_devnode (device); + vendor =udev_device_get_sysattr_value (device,"vendor" ); + model =udev_device_get_sysattr_value (device,"device" ); + driver =udev_device_get_property_value (device,"OFONO_DRIVER" ); + drv =udev_device_get_property_value (device,"DRIVER" ); +DBG ("%s [%s:%s]" , drv, vendor, model); + +if (vendor ==NULL || model ==NULL ) +return ; + +for (i =0 ; vendor_list[i].driver; i++) { +if ((drv !=NULL ) && (g_str_equal (vendor_list[i].drv, drv) == TRUE)) +DBG ("vendor_list[%d].drv = %s" , i, vendor_list[i].drv); +else +continue ; + +if (vendor_list[i].vid) { +if (!g_str_equal (vendor_list[i].vid, vendor)) +continue ; + } + +if (vendor_list[i].pid) { +if (!g_str_equal (vendor_list[i].pid, model)) +continue ; + } + + driver = vendor_list[i].driver; + } + +if (driver ==NULL ) +return ; + +add_pci_device (syspath, devname, driver, vendor, model, device); +}static void check_device (struct udev_device *device) {const char *bus;
@@ -1872,6 +2022,8 @@ static void check_device(struct udev_device *device)if ((g_str_equal (bus,"usb" ) == TRUE) || (g_str_equal (bus,"usbmisc" ) == TRUE))check_usb_device (device); +else if (g_str_equal (bus,"pci" ) == TRUE) +check_pci_device (device);else add_serial_device (device);
@@ -1932,6 +2084,7 @@ static void enumerate_devices(struct udev *context)udev_enumerate_add_match_subsystem (enumerate,"usbmisc" );udev_enumerate_add_match_subsystem (enumerate,"net" );udev_enumerate_add_match_subsystem (enumerate,"hsi" ); +udev_enumerate_add_match_subsystem (enumerate,"pci" );udev_enumerate_scan_devices (enumerate);
Signature · 1 line
1.9.1
Hi Antara,
Quoted 66 lines · Antara Borwankar
Adding support for enumerating PCIe types of modems in ofono
--- plugins/udevng.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 21 deletions(-)plugins/udevng.c +27
-18@@ -41,6 +41,7 @@enum modem_type {MODEM_TYPE_USB ,MODEM_TYPE_SERIAL , +MODEM_TYPE_PCIE , };struct modem_info {@@ -1229,26 +1230,43 @@ static gboolean setup_xmm7xxx(struct modem_info *modem) info->interface, info->number, info->label, info->sysattr, info->subsystem); -if (g_strcmp0 (modem->model,"095a" ) ==0 ) { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"06" ) ==0 ) - net = info->devnode; -if (g_strcmp0 (info->number,"08" ) ==0 ) - net2 = info->devnode; -if (g_strcmp0 (info->number,"0a" ) ==0 ) - net3 = info->devnode; +if (g_strcmp0 (info->subsystem,"pci" ) ==0 ) { +if ((g_strcmp0 (modem->vendor,"0x8086" ) ==0 ) && + (g_strcmp0 (modem->model,"0x7560" ) ==0 )) { + mdm ="/dev/iat" ; + net ="inm0" ; + net2 ="inm1" ; + net3 ="inm2" ; +ofono_modem_set_string (modem->modem, +"CtrlPath" ,"/PCIE/IOSM/CTRL/1" ); +ofono_modem_set_string (modem->modem,"DataPath" , +"/PCIE/IOSM/IPS/" ); } - }else { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"02" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - net = info->devnode; + }else {/* For USB */ +if (g_strcmp0 (modem->model,"095a" ) ==0 ) { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"06" ) ==0 ) + net = info->devnode; +if (g_strcmp0 (info->number,"08" ) ==0 ) + net2 = info->devnode; +if (g_strcmp0 (info->number,"0a" ) ==0 ) + net3 = info->devnode; + } + }else { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) {
plugins/udevng.c static gboolean setup_xmm7xxx(struct modem_info *modem) · line 1269
Quoted 10 lines
plugins/udevng.c +9
-0+if (g_strcmp0 (info->number,"02" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + net = info->devnode; + } } + +ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); +ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" );
Lines > 80 characters, please see doc/coding-style.txt
Quoted 106 lines
plugins/udevng.c +75
-3} }@@ -1266,9 +1284,6 @@ static gboolean setup_xmm7xxx(struct modem_info *modem)if (net3)ofono_modem_set_string (modem->modem,"NetworkInterface3" , net3); -ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); -ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" ); -return TRUE; }@@ -1437,6 +1452,7 @@ static void destroy_modem(gpointer data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;@@ -1467,6 +1483,7 @@ static gboolean check_remove(gpointer key, gpointer value, gpointer user_data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;@@ -1597,6 +1614,91 @@ static void add_serial_device(struct udev_device *dev) modem->serial = info; } +static void add_pci_device (const char *syspath,const char *devname, +const char *driver,const char *vendor, +const char *model,struct udev_device *device) +{ +const char *devpath, *devnode, *interface, *number; +const char *label, *sysattr, *subsystem; +struct modem_info *modem; +struct device_info *info; +struct udev_device *parent; + + devpath =udev_device_get_syspath (device); + +if (devpath ==NULL ) +return ; + + devnode =udev_device_get_devnode (device); + +if (devnode ==NULL ) { + devnode =udev_device_get_property_value (device,"INTERFACE" ); +DBG ("devnode = %s" , devnode); + } + + modem =g_hash_table_lookup (modem_list, syspath); + +if (modem ==NULL ) { + modem = g_try_new0(struct modem_info, 1); + +if (modem ==NULL ) +return ; + + modem->type =MODEM_TYPE_PCIE ; + modem->syspath =g_strdup (syspath); + modem->devname =g_strdup (devname); + modem->driver =g_strdup (driver); + modem->vendor =g_strdup (vendor); + modem->model =g_strdup (model); + modem->sysattr =get_sysattr (driver); + +g_hash_table_replace (modem_list, modem->syspath, modem); + } + + interface =udev_device_get_property_value (device,"INTERFACE" ); + +/* +* If environment variable is not set, get value from attributes +* (or parent's ones) +*/ + number =udev_device_get_sysattr_value (device,"bInterfaceNumber" ); + +if (number ==NULL ) { + parent =udev_device_get_parent (device); + number =udev_device_get_sysattr_value (parent,"bInterfaceNumber" ); + } + + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + +if (!label) + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + + subsystem =udev_device_get_subsystem (device); + +if (modem->sysattr !=NULL ) + sysattr =udev_device_get_sysattr_value (device, modem->sysattr); +else + sysattr =NULL ; + +DBG ("%s (%s) %s [%s] ==> %s %s" , devnode, driver, + interface, number, label, sysattr); + info = g_try_new0(struct device_info, 1); + +if (info ==NULL ) +return ; +
plugins/udevng.c static void add_serial_device(struct udev_device *dev) · line 1699
Quoted 10 lines
plugins/udevng.c +10
-0+ info->devpath =g_strdup (devpath); + info->devnode =g_strdup (devnode); + info->interface =g_strdup (interface); + info->number =g_strdup (number); + info->label =g_strdup (label); + info->sysattr =g_strdup (sysattr); + info->subsystem =g_strdup (subsystem); + + modem->devices =g_slist_insert_sorted (modem->devices, info, + compare_device);
This seems to be an almost verbatim copy-paste of add_device. Can you not use that instead with some modifications? Or factor out the common operations into a separate function?
Quoted 6 lines
plugins/udevng.c +2
-0+} +static void add_device (const char *syspath,const char *devname,const char *driver,const char *vendor,const char *model,struct udev_device *device)
plugins/udevng.c static void add_device(const char *syspath, const char *devname, · line 1736
Quoted 10 lines
plugins/udevng.c +2
-0@@ -1625,8 +1727,10 @@ static void add_device(const char *syspath, const char *devname,return ; modem =g_hash_table_lookup (modem_list, syspath); +if (modem ==NULL ) { modem = g_try_new0(struct modem_info, 1); +if (modem ==NULL )return ;
These changes seem to be superfluous and unrelated to this patch?
plugins/udevng.c static struct { · line 1879
Quoted 5 lines
plugins/udevng.c +1
-0@@ -1772,6 +1876,7 @@ static struct { { "telit", "cdc_acm", "1bc7", "0036" }, { "xmm7xxx", "cdc_acm", "8087" }, { "xmm7xxx", "cdc_ncm", "8087" }, + { "xmm7xxx", "imc_ipc", "0x8086", "0x7560"},
Can you tell me why this new addition uses vid/pid with a 0x prefix while the rest of the table does not? It seems weird & inconsistent.
Quoted 17 lines
plugins/udevng.c +10
-0{ } };@@ -1858,6 +1963,51 @@ static void check_usb_device(struct udev_device *device)add_device (syspath, devname, driver, vendor, model, device); } +static void check_pci_device (struct udev_device *device) +{ +const char *syspath, *devname, *driver; +const char *vendor =NULL , *model =NULL , *drv =NULL ; +unsigned int i; + + syspath =udev_device_get_syspath (device); + +if (syspath ==NULL ) +return ;
plugins/udevng.c static void check_usb_device(struct udev_device *device) · line 1985
Quoted 10 lines
plugins/udevng.c +10
-0+ + devname =udev_device_get_devnode (device); + vendor =udev_device_get_sysattr_value (device,"vendor" ); + model =udev_device_get_sysattr_value (device,"device" ); + driver =udev_device_get_property_value (device,"OFONO_DRIVER" ); + drv =udev_device_get_property_value (device,"DRIVER" ); +DBG ("%s [%s:%s]" , drv, vendor, model); + +if (vendor ==NULL || model ==NULL ) +return ;
So should you be adding drv == NULL check above as well?
plugins/udevng.c static void check_usb_device(struct udev_device *device) · line 1988
Quoted 3 lines
plugins/udevng.c +3
-0+ +for (i =0 ; vendor_list[i].driver; i++) { +if ((drv !=NULL ) && (g_str_equal (vendor_list[i].drv, drv) == TRUE))
That way you can avoid looping here and simplify your logic considerably
plugins/udevng.c static void check_usb_device(struct udev_device *device) · line 1989
Quoted 1 line
plugins/udevng.c +1
-0+DBG ("vendor_list[%d].drv = %s" , i, vendor_list[i].drv);
Did you intend to leave this DBG in here?
Quoted 35 lines
plugins/udevng.c +23
-0+else +continue ; + +if (vendor_list[i].vid) { +if (!g_str_equal (vendor_list[i].vid, vendor)) +continue ; + } + +if (vendor_list[i].pid) { +if (!g_str_equal (vendor_list[i].pid, model)) +continue ; + } + + driver = vendor_list[i].driver; + } + +if (driver ==NULL ) +return ; + +add_pci_device (syspath, devname, driver, vendor, model, device); +}static void check_device (struct udev_device *device) {const char *bus;@@ -1872,6 +2022,8 @@ static void check_device(struct udev_device *device)if ((g_str_equal (bus,"usb" ) == TRUE) || (g_str_equal (bus,"usbmisc" ) == TRUE))check_usb_device (device); +else if (g_str_equal (bus,"pci" ) == TRUE) +check_pci_device (device);else add_serial_device (device);
plugins/udevng.c static void enumerate_devices(struct udev *context) · line 2090
Quoted 7 lines
plugins/udevng.c +1
-0@@ -1932,6 +2084,7 @@ static void enumerate_devices(struct udev *context)udev_enumerate_add_match_subsystem (enumerate,"usbmisc" );udev_enumerate_add_match_subsystem (enumerate,"net" );udev_enumerate_add_match_subsystem (enumerate,"hsi" ); +udev_enumerate_add_match_subsystem (enumerate,"pci" );udev_enumerate_scan_devices (enumerate);
Regards,
-Denis
Borwankar
Hi Denis,
Regarding your below query
- Can you tell me why this new addition uses vid/pid with a 0x prefix while the rest of the table does not? It seems weird & inconsistent.
Actually in case of pci device vendor and device id read using libudev API is returning as "0x8086" and "0x7560" strings respectively. So I have added the same values in vendor_list table. In case of usb device the vendor and device strings returned by same libudev API does not have "0x" prefix. I don’t have any idea why it is so.
If you insist I can remove this prefix 0x from vendor_list table and change the implementation of check_pci_device() function to handle comparison of vendor and model strings with vid, pid form vendor_list.
Regards
Antara
-----Original Message-----
From: Denis Kenzior [mailto:denkenz(a)gmail.com]
Sent: Thursday, September 26, 2019 7:55 AM
To: Borwankar, Antara <[email protected]>; ofono(a)ofono.org
Subject: Re: [PATCH] udev: Adding PCIe as a subsystem in udev
Hi Antara,
Quoted 66 lines · Antara Borwankar
Adding support for enumerating PCIe types of modems in ofono
--- plugins/udevng.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 21 deletions(-)plugins/udevng.c index renamed from plugins/udevng.c +0
-01b54b4a..bebbc2d 100644
plugins/udevng.c +27
-18@@ -41,6 +41,7 @@enum modem_type {MODEM_TYPE_USB ,MODEM_TYPE_SERIAL , +MODEM_TYPE_PCIE , };struct modem_info {@@ -1229,26 +1230,43 @@ static gboolean setup_xmm7xxx(struct modem_info *modem) info->interface, info->number, info->label, info->sysattr, info->subsystem); -if (g_strcmp0 (modem->model,"095a" ) ==0 ) { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"06" ) ==0 ) - net = info->devnode; -if (g_strcmp0 (info->number,"08" ) ==0 ) - net2 = info->devnode; -if (g_strcmp0 (info->number,"0a" ) ==0 ) - net3 = info->devnode; +if (g_strcmp0 (info->subsystem,"pci" ) ==0 ) { +if ((g_strcmp0 (modem->vendor,"0x8086" ) ==0 ) && + (g_strcmp0 (modem->model,"0x7560" ) ==0 )) { + mdm ="/dev/iat" ; + net ="inm0" ; + net2 ="inm1" ; + net3 ="inm2" ; +ofono_modem_set_string (modem->modem, +"CtrlPath" ,"/PCIE/IOSM/CTRL/1" ); +ofono_modem_set_string (modem->modem,"DataPath" , +"/PCIE/IOSM/IPS/" ); } - }else { -if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { -if (g_strcmp0 (info->number,"02" ) ==0 ) - mdm = info->devnode; - }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { -if (g_strcmp0 (info->number,"00" ) ==0 ) - net = info->devnode; + }else {/* For USB */ +if (g_strcmp0 (modem->model,"095a" ) ==0 ) { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"06" ) ==0 ) + net = info->devnode; +if (g_strcmp0 (info->number,"08" ) ==0 ) + net2 = info->devnode; +if (g_strcmp0 (info->number,"0a" ) ==0 ) + net3 = info->devnode; + } + }else { +if (g_strcmp0 (info->subsystem,"tty" ) ==0 ) {
plugins/udevng.c static gboolean setup_xmm7xxx(struct modem_info *modem) · line 1269
Quoted 10 lines
plugins/udevng.c +9
-0+if (g_strcmp0 (info->number,"02" ) ==0 ) + mdm = info->devnode; + }else if (g_strcmp0 (info->subsystem,"net" ) ==0 ) { +if (g_strcmp0 (info->number,"00" ) ==0 ) + net = info->devnode; + } } + +ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); +ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" );
Lines > 80 characters, please see doc/coding-style.txt
Quoted 106 lines
plugins/udevng.c +74
-3} }@@ -1266,9 +1284,6 @@ static gboolean setup_xmm7xxx(struct modem_info *modem)if (net3)ofono_modem_set_string (modem->modem,"NetworkInterface3" , net3); -ofono_modem_set_string (modem->modem,"CtrlPath" ,"/USBCDC/0" ); -ofono_modem_set_string (modem->modem,"DataPath" ,"/USBHS/NCM/" ); -return TRUE; }@@ -1437,6 +1452,7 @@ static void destroy_modem(gpointer data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;@@ -1467,6 +1483,7 @@ static gboolean check_remove(gpointer key, gpointer value, gpointer user_data)switch (modem->type) {case MODEM_TYPE_USB : +case MODEM_TYPE_PCIE :for (list = modem->devices; list; list = list->next) {struct device_info *info = list->data;@@ -1597,6 +1614,91 @@ static void add_serial_device(struct udev_device *dev) modem->serial = info; } +static void add_pci_device (const char *syspath,const char *devname, +const char *driver,const char *vendor, +const char *model,struct udev_device *device) { +const char *devpath, *devnode, *interface, *number; +const char *label, *sysattr, *subsystem; +struct modem_info *modem; +struct device_info *info; +struct udev_device *parent; + + devpath =udev_device_get_syspath (device); + +if (devpath ==NULL ) +return ; + + devnode =udev_device_get_devnode (device); + +if (devnode ==NULL ) { + devnode =udev_device_get_property_value (device,"INTERFACE" ); +DBG ("devnode = %s" , devnode); + } + + modem =g_hash_table_lookup (modem_list, syspath); + +if (modem ==NULL ) { + modem = g_try_new0(struct modem_info, 1); + +if (modem ==NULL ) +return ; + + modem->type =MODEM_TYPE_PCIE ; + modem->syspath =g_strdup (syspath); + modem->devname =g_strdup (devname); + modem->driver =g_strdup (driver); + modem->vendor =g_strdup (vendor); + modem->model =g_strdup (model); + modem->sysattr =get_sysattr (driver); + +g_hash_table_replace (modem_list, modem->syspath, modem); + } + + interface =udev_device_get_property_value (device,"INTERFACE" ); + +/* +* If environment variable is not set, get value from attributes +* (or parent's ones) +*/ + number =udev_device_get_sysattr_value (device,"bInterfaceNumber" ); + +if (number ==NULL ) { + parent =udev_device_get_parent (device); + number =udev_device_get_sysattr_value (parent,"bInterfaceNumber" ); + } + + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + +if (!label) + label =udev_device_get_property_value (device,"OFONO_LABEL" ); + + subsystem =udev_device_get_subsystem (device); + +if (modem->sysattr !=NULL ) + sysattr =udev_device_get_sysattr_value (device, modem->sysattr); +else + sysattr =NULL ; + +DBG ("%s (%s) %s [%s] ==> %s %s" , devnode, driver, + interface, number, label, sysattr); + info = g_try_new0(struct device_info, 1); + +if (info ==NULL ) +return ; +
plugins/udevng.c static void add_serial_device(struct udev_device *dev) · line 1698
Quoted 10 lines
plugins/udevng.c +10
-0+ info->devpath =g_strdup (devpath); + info->devnode =g_strdup (devnode); + info->interface =g_strdup (interface); + info->number =g_strdup (number); + info->label =g_strdup (label); + info->sysattr =g_strdup (sysattr); + info->subsystem =g_strdup (subsystem); + + modem->devices =g_slist_insert_sorted (modem->devices, info, + compare_device);
This seems to be an almost verbatim copy-paste of add_device. Can you not use that instead with some modifications? Or factor out the common operations into a separate function?
Quoted 10 lines
plugins/udevng.c +3
-0+} +static void add_device (const char *syspath,const char *devname,const char *driver,const char *vendor, const char *model, struct udev_device *device) @@ -1625,8 +1727,10 @@ static void add_device(const char *syspath, const char *devname,return;
modem = g_hash_table_lookup(modem_list, syspath);
plugins/udevng.c static void add_device(const char *syspath, const char *devname, · line 1735
Quoted 6 lines
plugins/udevng.c +2
-0+if (modem ==NULL ) { modem = g_try_new0(struct modem_info, 1); +if (modem ==NULL )return ;
These changes seem to be superfluous and unrelated to this patch?
plugins/udevng.c static struct { · line 1879
Quoted 5 lines
plugins/udevng.c +1
-0@@ -1772,6 +1876,7 @@ static struct { { "telit", "cdc_acm", "1bc7", "0036" }, { "xmm7xxx", "cdc_acm", "8087" }, { "xmm7xxx", "cdc_ncm", "8087" }, + { "xmm7xxx", "imc_ipc", "0x8086", "0x7560"},
Can you tell me why this new addition uses vid/pid with a 0x prefix while the rest of the table does not? It seems weird & inconsistent.
Quoted 16 lines
plugins/udevng.c +9
-0{ } };@@ -1858,6 +1963,51 @@ static void check_usb_device(struct udev_device *device)add_device (syspath, devname, driver, vendor, model, device); } +static void check_pci_device (struct udev_device *device) { +const char *syspath, *devname, *driver; +const char *vendor =NULL , *model =NULL , *drv =NULL ; +unsigned int i; + + syspath =udev_device_get_syspath (device); + +if (syspath ==NULL ) +return ;
plugins/udevng.c static void check_usb_device(struct udev_device *device) · line 1984
Quoted 10 lines
plugins/udevng.c +10
-0+ + devname =udev_device_get_devnode (device); + vendor =udev_device_get_sysattr_value (device,"vendor" ); + model =udev_device_get_sysattr_value (device,"device" ); + driver =udev_device_get_property_value (device,"OFONO_DRIVER" ); + drv =udev_device_get_property_value (device,"DRIVER" ); +DBG ("%s [%s:%s]" , drv, vendor, model); + +if (vendor ==NULL || model ==NULL ) +return ;
So should you be adding drv == NULL check above as well?
plugins/udevng.c static void check_usb_device(struct udev_device *device)
Quoted 4 lines
plugins/udevng.c +4
-0+ +for (i =0 ; vendor_list[i].driver; i++) { +if ((drv !=NULL ) && (g_str_equal (vendor_list[i].drv, drv) == +TRUE))
That way you can avoid looping here and simplify your logic considerably
plugins/udevng.c static void check_usb_device(struct udev_device *device) · line 1989
Quoted 1 line
plugins/udevng.c +1
-0+DBG ("vendor_list[%d].drv = %s" , i, vendor_list[i].drv);
Did you intend to leave this DBG in here?
Quoted 34 lines
plugins/udevng.c +22
-0+else +continue ; + +if (vendor_list[i].vid) { +if (!g_str_equal (vendor_list[i].vid, vendor)) +continue ; + } + +if (vendor_list[i].pid) { +if (!g_str_equal (vendor_list[i].pid, model)) +continue ; + } + + driver = vendor_list[i].driver; + } + +if (driver ==NULL ) +return ; + +add_pci_device (syspath, devname, driver, vendor, model, device); }static void check_device (struct udev_device *device) {const char *bus;@@ -1872,6 +2022,8 @@ static void check_device(struct udev_device *device)if ((g_str_equal (bus,"usb" ) == TRUE) || (g_str_equal (bus,"usbmisc" ) == TRUE))check_usb_device (device); +else if (g_str_equal (bus,"pci" ) == TRUE) +check_pci_device (device);else add_serial_device (device);
plugins/udevng.c static void enumerate_devices(struct udev *context) · line 2090
Quoted 7 lines
plugins/udevng.c +1
-0@@ -1932,6 +2084,7 @@ static void enumerate_devices(struct udev *context)udev_enumerate_add_match_subsystem (enumerate,"usbmisc" );udev_enumerate_add_match_subsystem (enumerate,"net" );udev_enumerate_add_match_subsystem (enumerate,"hsi" ); +udev_enumerate_add_match_subsystem (enumerate,"pci" );udev_enumerate_scan_devices (enumerate);
Regards,
-Denis
Hi Antara,
Quoted 6 lines · Antara
Hi Denis,
Regarding your below query
- Can you tell me why this new addition uses vid/pid with a 0x prefix while the rest of the table does not? It seems weird & inconsistent.
Actually in case of pci device vendor and device id read using libudev API is returning as "0x8086" and "0x7560" strings respectively. So I have added the same values invendor_listtable.
That is strange. Okay, so maybe we should just add a different look-up table to handle this. Perhaps pci_driver_list[] and use vids/pids with 0x prefixes there.
Quoted 3 lines
In case of usb device the vendor and device strings returned by same libudev API does not have "0x" prefix. I don’t have any idea why it is so.
If you insist I can remove this prefix 0x from
vendor_listtable and change the implementation ofcheck_pci_device()function to handle comparison of vendor and model strings with vid, pid formvendor_list.
Yep, that might be another alternative. I'd be fine with either. Having some entries with 0x and some without will confuse people and lead to bugs.
Regards,
-Denis