From 19e4dc97c1518d6b545a6c90f1dba94e45a9cdd2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 6 Aug 2011 13:08:33 +0200 Subject: [PATCH] udev: Add support for default driver assignments If devices are not tagged with OFONO_DRIVER, then the driver will be figured out based on kernel module name, vendor and/or product IDs. Of course the manual tagging with OFONO_DRIVER as part of an udev rule can always overwrite the default assignment. --- plugins/ofono.rules | 19 ---------------- plugins/udevng.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/plugins/ofono.rules b/plugins/ofono.rules index d781e78..555125a 100644 --- a/plugins/ofono.rules +++ b/plugins/ofono.rules @@ -65,25 +65,6 @@ ENV{DEVTYPE}!="usb_device", GOTO="ofono_end" # Ignore fake serial number ATTRS{serial}=="1234567890ABCDEF", ENV{ID_SERIAL_SHORT}="" -# Novatel Wireless -ATTRS{idVendor}=="1410", ENV{OFONO_DRIVER}="novatel" - -# Sierra Wireless -ATTRS{idVendor}=="1199", ENV{OFONO_DRIVER}="sierra" - -# HUAWEI Technology -ATTRS{idVendor}=="12d1", ENV{OFONO_DRIVER}="huawei" -ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="140b", ENV{OFONO_DRIVER}="huaweicdma" - -# Olive -ATTRS{idVendor}=="201e", ENV{OFONO_DRIVER}="huaweicdma" - -# Qualcomm Incorporated -ATTRS{idVendor}=="05c6", ENV{OFONO_DRIVER}="gobi" - -# ZTE Incorporated -ATTRS{idVendor}=="19d2", ENV{OFONO_DRIVER}="zte" - # Alcatel X220L ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017", ENV{OFONO_DRIVER}="alcatel" diff --git a/plugins/udevng.c b/plugins/udevng.c index b02399e..d125ff1 100644 --- a/plugins/udevng.c +++ b/plugins/udevng.c @@ -385,6 +385,22 @@ static void add_device(const char *syspath, const char *devname, compare_device); } +static struct { + const char *driver; + const char *drv; + const char *vid; + const char *pid; +} vendor_list[] = { + { "gobi", "qcserial" }, + { "sierra", "sierra" }, + { "huawei", "option", "12d1" }, + { "huaweicdma", "option", "12d1", "140b" }, + { "huaweicdma", "option", "201e" }, + { "novatel", "option", "1410" }, + { "zte", "option", "19d2" }, + { } +}; + static void check_device(struct udev_device *device) { struct udev_device *usb_device; @@ -411,8 +427,50 @@ static void check_device(struct udev_device *device) return; driver = udev_device_get_property_value(usb_device, "OFONO_DRIVER"); - if (driver == NULL) - return; + if (driver == NULL) { + const char *drv, *vid, *pid; + unsigned int i; + + drv = udev_device_get_property_value(device, "ID_USB_DRIVER"); + if (drv == NULL) + return; + + vid = udev_device_get_property_value(device, "ID_VENDOR_ID"); + if (vid == NULL) + return; + + pid = udev_device_get_property_value(device, "ID_MODEL_ID"); + if (pid == NULL) + return; + + DBG("%s [%s:%s]", drv, vid, pid); + + for (i = 0; vendor_list[i].driver; i++) { + if (g_str_equal(vendor_list[i].drv, drv) == FALSE) + continue; + + if (vendor_list[i].vid == NULL) { + driver = vendor_list[i].driver; + break; + } + + if (g_str_equal(vendor_list[i].vid, vid) == TRUE) { + if (vendor_list[i].pid == NULL) { + if (driver == NULL) + driver = vendor_list[i].driver; + continue; + } + + if (g_strcmp0(vendor_list[i].pid, pid) == 0) { + driver = vendor_list[i].driver; + break; + } + } + } + + if (driver == NULL) + return; + } add_device(syspath, devname, driver, device); } @@ -430,6 +488,7 @@ static void create_modem(gpointer key, gpointer value, gpointer user_data) return; DBG("%s", syspath); + DBG("driver=%s", modem->driver); modem->modem = ofono_modem_create(NULL, modem->driver); if (modem->modem == NULL) -- 2.7.4