Device handling cleanups
v3 cover Device handling cleanups
This is version 3 of the udev handling cleanups.
Changes since v2:
* Addressed comments from Denis
Changes since v1:
* Reworked patch 1/5 (was 11/15) to handle 'legacy' devices in a simpler manner.
* Addressed comments from Denis
Original blurb follows:
This is a series of incremental cleanups to the libudev device handling code.
- the early patches in the series are all good cleanups that can be taken irregardless of whether the last patches are desired
- the last patches are more intrusive as they attempt to move the functionality of udev.c into udevng.c
Somebody with access to old hardware really needs to take a look at this series to see if the migration to udevng works properly. I do not have any such hardware, myself. I suspect that there's not many such devices in circulation; my hope is that this legacy code works for now and can be ripped out in time.
In any case, if someone has such old hardware, hopefully these changes are sufficiently correct that the last bugs can shake themselves out easily... we'll see.
Jonas Bonn (5):
udevng: add serial device handling functions
udevng: match on the hsi subsystem for legacy devices
udevng: hook up legacy devices
udevng: get properties from interface
plugins: remove udev module
Makefile.am | 2 - plugins/udev.c | 431 ------------------------------------------------------- plugins/udevng.c | 292 ++++++++++++++++++++++++++++++++++--- 3 files changed, 272 insertions(+), 453 deletions(-) delete mode 100644 plugins/udev.c
Signature · 1 line
2.9.3
PATCH v3 1/5 udevng: add serial device handling functions
This adds, but does not hook up, support for simple serial modems. These modems generally have only a single device node so are simpler than the USB devices which generally have different device nodes for different functions. These modems are currently handled by udev.c, but this functionality will allow to remove that module completely in a later patch.
- A new "device_info" type is created called serial_device_info
- the function add_serial_device sets up a modem_info structure and a serial_device_info for the device
- A reference to the device's udev node is saved in the device info
- The device driver is retrieved from the OFONO_DRIVER environment variable which needs to be set up by some udev rule
- Setup functions are added for these types of devices: a common function setup_serial_modem covers the generic (simple) case, whereas modems with special requirements are given their own setup functions to handle the special bits
- Modem destroy needs to know the "device_info" type in order to clean up properly, so a 'type' value is set on the modem_info structure to guide selection of the proper cleanup function
--- plugins/udevng.c | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 249 insertions(+), 16 deletions(-)
plugins/udevng.c +249 -16
@@ -37,13 +37,22 @@#include <ofono/modem.h> #include <ofono/log.h> +typedef enum { +MODEM_TYPE_USB , +MODEM_TYPE_SERIAL , +}ModemType ; +struct modem_info {char *syspath;char *devname;char *driver;char *vendor;char *model; -GSList *devices; +ModemType type; +union { +GSList *devices; +struct serial_device_info * serial; + };struct ofono_modem *modem;const char *sysattr; };
@@ -58,6 +67,14 @@ struct device_info {char *subsystem; }; +struct serial_device_info { +char *devpath; +char *devnode; +char *subsystem; +struct udev_device * dev; +}; + +static gboolean setup_isi (struct modem_info *modem) {const char *node =NULL ;
@@ -867,6 +884,100 @@ static gboolean setup_quectel(struct modem_info *modem)return TRUE; } +static gboolean setup_serial_modem (struct modem_info * modem) +{ +struct serial_device_info * info; + + info = modem->serial; + +ofono_modem_set_string (modem->modem,"Device" , info->devnode); + +return TRUE; +} + +static gboolean setup_tc65 (struct modem_info * modem) +{ +ofono_modem_set_driver (modem->modem,"cinterion" ); + +return setup_serial_modem (modem); +} + +static gboolean setup_ehs6 (struct modem_info * modem) +{ +ofono_modem_set_driver (modem->modem,"cinterion" ); + +return setup_serial_modem (modem); +} + +static gboolean setup_ifx (struct modem_info * modem) +{ +struct serial_device_info * info; +const char *value; + + info = modem->serial; + + value =udev_device_get_property_value (info->dev,"OFONO_IFX_LDISC" ); +if (value) +ofono_modem_set_string (modem->modem,"LineDiscipline" , value); + + value =udev_device_get_property_value (info->dev,"OFONO_IFX_AUDIO" ); +if (value) +ofono_modem_set_string (modem->modem,"AudioSetting" , value); + + value =udev_device_get_property_value (info->dev,"OFONO_IFX_LOOPBACK" ); +if (value) +ofono_modem_set_string (modem->modem,"AudioLoopback" , value); + +ofono_modem_set_string (modem->modem,"Device" , info->devnode); + +return TRUE; +} + +static gboolean setup_wavecom (struct modem_info * modem) +{ +struct serial_device_info * info; +const char *value; + + info = modem->serial; + + value =udev_device_get_property_value (info->dev, +"OFONO_WAVECOM_MODEL" ); +if (value) +ofono_modem_set_string (modem->modem,"Model" , value); + +ofono_modem_set_string (modem->modem,"Device" , info->devnode); + +return TRUE; +} + +static gboolean setup_isi_serial (struct modem_info * modem) +{ +struct serial_device_info * info; +const char *value; + + info = modem->serial; + +if (g_strcmp0 (udev_device_get_subsystem (info->dev),"net" ) !=0 ) +return FALSE; + + value =udev_device_get_sysattr_value (info->dev,"type" ); +if (g_strcmp0 (value,"820" ) !=0 ) +return FALSE; + +/* OK, we want this device to be a modem */ + value =udev_device_get_sysname (info->dev); +if (value) +ofono_modem_set_string (modem->modem,"Interface" , value); + + value =udev_device_get_property_value (info->dev,"OFONO_ISI_ADDRESS" ); +if (value) +ofono_modem_set_integer (modem->modem,"Address" ,atoi (value)); + +ofono_modem_set_string (modem->modem,"Device" , info->devnode); + +return TRUE; +} +static gboolean setup_ublox (struct modem_info *modem) {const char *aux =NULL , *mdm =NULL , *net =NULL ;
@@ -997,6 +1108,17 @@ static struct { { "quectel", setup_quectel }, { "ublox", setup_ublox }, { "gemalto", setup_gemalto }, +/* Following are non-USB modems */ + { "ifx", setup_ifx }, + { "u8500", setup_isi_serial }, + { "n900", setup_isi_serial }, + { "calypso", setup_serial_modem }, + { "cinterion", setup_serial_modem }, + { "nokiacdma", setup_serial_modem }, + { "sim900", setup_serial_modem }, + { "wavecom", setup_wavecom }, + { "tc65", setup_tc65 }, + { "ehs6", setup_ehs6 }, { } };
@@ -1014,6 +1136,27 @@ static const char *get_sysattr(const char *driver)return NULL ; } +static void device_info_free (struct device_info * info) +{ +g_free (info->devpath); +g_free (info->devnode); +g_free (info->interface); +g_free (info->number); +g_free (info->label); +g_free (info->sysattr); +g_free (info->subsystem); +g_free (info); +} + +static void serial_device_info_free (struct serial_device_info * info) +{ +g_free (info->devpath); +g_free (info->devnode); +g_free (info->subsystem); +udev_device_unref (info->dev); +g_free (info); +} +static void destroy_modem (gpointer data) {struct modem_info *modem = data;
@@ -1023,25 +1166,22 @@ static void destroy_modem(gpointer data)ofono_modem_remove (modem->modem); -for (list = modem->devices; list; list = list->next) { -struct device_info *info = list->data; - -DBG ("%s" , info->devnode); +switch (modem->type) { +case MODEM_TYPE_USB : +for (list = modem->devices; list; list = list->next) { +struct device_info *info = list->data; -g_free (info->devpath); -g_free (info->devnode); -g_free (info->interface); -g_free (info->number); -g_free (info->label); -g_free (info->sysattr); -g_free (info->subsystem); -g_free (info); +DBG ("%s" , info->devnode); +device_info_free (info); + } - list->data =NULL ; +g_slist_free (modem->devices); +break ; +case MODEM_TYPE_SERIAL : +serial_device_info_free (modem->serial); +break ; } -g_slist_free (modem->devices); -g_free (modem->syspath);g_free (modem->devname);g_free (modem->driver);
@@ -1088,6 +1228,98 @@ static gint compare_device(gconstpointer a, gconstpointer b)return g_strcmp0 (info1->number, info2->number); } +/* +* Here we try to find the "modem device". +* +* In this variant we identify the "modem device" as simply the device +* that has the OFONO_DRIVER property. If the device node doesn't +* have this property itself, then we do a brute force search for it +* through the device hierarchy. +* +*/ +static struct udev_device *get_serial_modem_device (struct udev_device *dev) +{ +const char * driver; + +while (dev) { + driver =udev_device_get_property_value (dev,"OFONO_DRIVER" ); +if (driver) +return dev; + + dev =udev_device_get_parent (dev); + } + +return NULL ; +} + +/* +* Add 'legacy' device +* +* The term legacy is a bit misleading, but this adds devices according +* to the original ofono model. +* +* - We cannot assume that these are USB devices +* - The modem consists of only a single interface +* - The device must have an OFONO_DRIVER property from udev +*/ +static void add_serial_device (struct udev_device *dev) +{ +const char *syspath, *devpath, *devname, *devnode; +struct modem_info *modem; +struct serial_device_info *info; +const char *subsystem; +struct udev_device * mdev; +const char * driver; + + mdev =get_serial_modem_device (dev); +if (!mdev) { +DBG ("Device is missing required OFONO_DRIVER property" ); +return ; + } + + driver =udev_device_get_property_value (mdev,"OFONO_DRIVER" ); + + syspath =udev_device_get_syspath (mdev); + devname =udev_device_get_devnode (mdev); + devpath =udev_device_get_devpath (mdev); + + devnode =udev_device_get_devnode (dev); + +if (!syspath || !devname || !devpath || !devnode) +return ; + + 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_SERIAL ; + modem->syspath =g_strdup (syspath); + modem->devname =g_strdup (devname); + modem->driver =g_strdup ("legacy" ); + +g_hash_table_replace (modem_list, modem->syspath, modem); + } + + subsystem =udev_device_get_subsystem (dev); + +DBG ("%s" , syspath); +DBG ("%s" , devpath); +DBG ("%s (%s)" , devnode, driver); + + info = g_try_new0(struct serial_device_info, 1); +if (info ==NULL ) +return ; + + info->devpath =g_strdup (devpath); + info->devnode =g_strdup (devnode); + info->subsystem =g_strdup (subsystem); + info->dev =udev_device_ref (dev); + + modem->devices =g_slist_append (modem->devices, info); +} +static void add_device (const char *syspath,const char *devname,const char *driver,const char *vendor,const char *model,struct udev_device *device)
@@ -1121,6 +1353,7 @@ static void add_device(const char *syspath, const char *devname,if (modem ==NULL )return ; + modem->type =MODEM_TYPE_USB ; modem->syspath =g_strdup (syspath); modem->devname =g_strdup (devname); modem->driver =g_strdup (driver);
Signature · 1 line
2.9.3
PATCH v3 2/5 udevng: match on the hsi subsystem for legacy devices
In reply to Jonas Bonn--- plugins/udevng.c | 2 ++ 1 file changed, 2 insertions(+)
plugins/udevng.c +2 -0
@@ -1613,6 +1613,7 @@ static void enumerate_devices(struct udev *context)udev_enumerate_add_match_subsystem (enumerate,"usb" );udev_enumerate_add_match_subsystem (enumerate,"usbmisc" );udev_enumerate_add_match_subsystem (enumerate,"net" ); +udev_enumerate_add_match_subsystem (enumerate,"hsi" );udev_enumerate_scan_devices (enumerate);
@@ -1737,6 +1738,7 @@ static int detect_init(void)udev_monitor_filter_add_match_subsystem_devtype (udev_mon,"usbmisc" ,NULL );udev_monitor_filter_add_match_subsystem_devtype (udev_mon,"net" ,NULL ); +udev_monitor_filter_add_match_subsystem_devtype (udev_mon,"hsi" ,NULL );udev_monitor_filter_update (udev_mon);
Signature · 1 line
2.9.3
PATCH v3 3/5 udevng: hook up legacy devices
In reply to Jonas Bonn...and disable old udev code by shorting it out in it's init() function.
The check_device function is augmented to differentiate between USB and serial devices:
- if the device sits on a USB bus, the device is handled as before
- if not, an attempt is made to handle the device as a serial device
--- plugins/udev.c | 2 ++ plugins/udevng.c | 3 +++ 2 files changed, 5 insertions(+)
plugins/udev.c +2 -0
@@ -365,6 +365,8 @@ static void udev_start(void)static int udev_init (void ) { +return 0 ; + devpath_list =g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);if (devpath_list ==NULL ) {
plugins/udevng.c +3 -0
@@ -1563,6 +1563,9 @@ 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 +add_serial_device (device); + }static gboolean create_modem (gpointer key,gpointer value,gpointer user_data)
Signature · 1 line
2.9.3
PATCH v3 4/5 udevng: get properties from interface
In reply to Jonas BonnDevice properties are generally on the device, on the USB interface descriptor, or the on the USB device descriptor.
--- plugins/udevng.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
plugins/udevng.c +18 -4
@@ -1324,7 +1324,7 @@ static void add_device(const char *syspath, const char *devname, const char *driver, const char *vendor, const char *model, struct udev_device *device) { - struct udev_device *intf; + struct udev_device *usb_interface;const char *devpath, *devnode, *interface, *number;const char *label, *sysattr, *subsystem;struct modem_info *modem;
@@ -1342,9 +1342,9 @@ static void add_device(const char *syspath, const char *devname,return ; } - intf =udev_device_get_parent_with_subsystem_devtype (device, + usb_interface =udev_device_get_parent_with_subsystem_devtype (device,"usb" ,"usb_interface" ); -if (intf ==NULL ) +if (usb_interface ==NULL )return ; modem =g_hash_table_lookup (modem_list, syspath);
@@ -1365,7 +1365,7 @@ static void add_device(const char *syspath, const char *devname,g_hash_table_replace (modem_list, modem->syspath, modem); } - interface =udev_device_get_property_value (intf,"INTERFACE" ); + interface =udev_device_get_property_value (usb_interface,"INTERFACE" ); number =udev_device_get_property_value (device,"ID_USB_INTERFACE_NUM" );/* If environment variable is not set, get value from attributes (or parent's ones) */
@@ -1381,6 +1381,10 @@ static void add_device(const char *syspath, const char *devname, } label =udev_device_get_property_value (device,"OFONO_LABEL" ); +if (!label) + label =udev_device_get_property_value (usb_interface, +"OFONO_LABEL" ); + subsystem =udev_device_get_subsystem (device);if (modem->sysattr !=NULL )
@@ -1502,6 +1506,16 @@ static void check_usb_device(struct udev_device *device) model =udev_device_get_property_value (usb_device,"ID_MODEL_ID" ); driver =udev_device_get_property_value (usb_device,"OFONO_DRIVER" ); +if (!driver) { +struct udev_device *usb_interface = +udev_device_get_parent_with_subsystem_devtype ( + device,"usb" ,"usb_interface" ); + +if (usb_interface) + driver =udev_device_get_property_value ( + usb_interface,"OFONO_DRIVER" ); + } +if (driver ==NULL ) {const char *drv;unsigned int i;
Signature · 1 line
2.9.3
PATCH v3 5/5 plugins: remove udev module
In reply to Jonas BonnThis functionality has been moved into the udevng module and was already disabled in an earlier patch.
--- Makefile.am | 2 - plugins/udev.c | 433 --------------------------------------------------------- 2 files changed, 435 deletions(-) delete mode 100644 plugins/udev.c
Makefile.am +0 -2
@@ -106,8 +106,6 @@ gril_sources = gril/gril.h gril/gril.c \ btio_sources = btio/btio.h btio/btio.c if UDEV -builtin_modules += udev -builtin_sources += plugins/udev.c builtin_cflags += @UDEV_CFLAGS@ builtin_libadd += @UDEV_LIBS@
plugins/udev.c deleted +0 -433
433 lines not on this page · raw message
Signature · 1 line
2.9.3
v3 cover Device handling cleanups
In reply to Jonas BonnThis is version 3 of the udev handling cleanups.
Changes since v2:
* Addressed comments from Denis
Changes since v1:
* Reworked patch 1/5 (was 11/15) to handle 'legacy' devices in a simpler manner.
* Addressed comments from Denis
Original blurb follows:
This is a series of incremental cleanups to the libudev device handling code.
- the early patches in the series are all good cleanups that can be taken irregardless of whether the last patches are desired
- the last patches are more intrusive as they attempt to move the functionality of udev.c into udevng.c
Somebody with access to old hardware really needs to take a look at this series to see if the migration to udevng works properly. I do not have any such hardware, myself. I suspect that there's not many such devices in circulation; my hope is that this legacy code works for now and can be ripped out in time.
In any case, if someone has such old hardware, hopefully these changes are sufficiently correct that the last bugs can shake themselves out easily... we'll see.
Jonas Bonn (5):
udevng: add serial device handling functions
udevng: match on the hsi subsystem for legacy devices
udevng: hook up legacy devices
udevng: get properties from interface
plugins: remove udev module
Makefile.am | 2 - plugins/udev.c | 431 ------------------------------------------------------- plugins/udevng.c | 292 ++++++++++++++++++++++++++++++++++--- 3 files changed, 272 insertions(+), 453 deletions(-) delete mode 100644 plugins/udev.c
Signature · 1 line
2.9.3
Hi Jonas,
Quoted 39 lines · Jonas Bonn
This is version 3 of the udev handling cleanups.
Changes since v2:
* Addressed comments from Denis
Changes since v1:
* Reworked patch 1/5 (was 11/15) to handle 'legacy' devices in a simpler manner.
* Addressed comments from DenisOriginal blurb follows:
This is a series of incremental cleanups to the libudev device handling code.
- the early patches in the series are all good cleanups that can be taken irregardless of whether the last patches are desired
- the last patches are more intrusive as they attempt to move the functionality ofudev.cintoudevng.cSomebody with access to old hardware really needs to take a look at this series to see if the migration to udevng works properly. I do not have any such hardware, myself. I suspect that there's not many such devices in circulation; my hope is that this legacy code works for now and can be ripped out in time.
In any case, if someone has such old hardware, hopefully these changes are sufficiently correct that the last bugs can shake themselves out easily... we'll see.
Jonas Bonn (5):
udevng: add serial device handling functions
udevng: match on the hsi subsystem for legacy devices
udevng: hook up legacy devices
udevng: get properties from interface
plugins: remove udev module
Quoted 6 lines
Makefile.am | 2 - plugins/udev.c | 431 ------------------------------------------------------- plugins/udevng.c | 292 ++++++++++++++++++++++++++++++++++--- 3 files changed, 272 insertions(+), 453 deletions(-) delete mode 100644 plugins/udev.c
This version looked good, so I went ahead and applied all 5 of these. I tweaked patch 1 slightly to modify the enum type. We generally don't use typedefs for enums.
Thanks!
Regards,
-Denis