From: Pekka Pessi <[email protected]>

The usbpnmodem is a stop gap solution until we get udev to support
isimodems. Currently it does the basic configuration of the phonet
interface.
---
 plugins/usbpnmodem.c |   54 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/plugins/usbpnmodem.c b/plugins/usbpnmodem.c
index 68beb6f..d9e39ce 100644
--- a/plugins/usbpnmodem.c
+++ b/plugins/usbpnmodem.c
@@ -39,9 +39,21 @@
 
 static GPhonetNetlink *link = NULL;
 
+static int match_ifname(char const *name, char const *ifname)
+{
+       size_t namelen = strlen(name);
+
+       if (strncmp(name, ifname, namelen) != 0)
+               return FALSE;
+
+       if (ifname[namelen + strspn(ifname + namelen, "0123456789")] != '\0')
+               return FALSE;
+
+       return TRUE;
+}
+
 /*
- * Add or remove isimodems
- * when usbpn* phonet interfaces are added/removed
+ * Add or remove isi modems when phonet interfaces are added/removed
  */
 static void usbpn_status_cb(GIsiModem *idx,
                                GPhonetLinkState st,
@@ -49,37 +61,41 @@ static void usbpn_status_cb(GIsiModem *idx,
                                void *data)
 {
        struct ofono_modem *modem;
-       int error;
+       char *name;
+       char *driver;
+       int address;
+
+       if (g_pn_netlink_by_modem(idx))
+               /* Modem already exists, be quiet */
+               return;
 
        DBG("Phonet link %s (%u) is %s",
                ifname, g_isi_modem_index(idx),
                st == PN_LINK_REMOVED ? "removed" :
                st == PN_LINK_DOWN ? "down" : "up");
 
-       /* Expect phonet interface name usbpn<idx> */
-       if (strncmp(ifname, "usbpn", 5) ||
-               ifname[5 + strspn(ifname + 5, "0123456789")])
-               return;
-
        if (st == PN_LINK_REMOVED)
                return;
 
-       if (g_pn_netlink_by_modem(idx)) {
-               DBG("Modem for interface %s already exists", ifname);
-               return;
-       }
-
-       error = g_pn_netlink_set_address(idx, PN_DEV_PC);
-       if (error && error != -EEXIST) {
-               DBG("g_pn_netlink_set_address: %s\n", strerror(-error));
+       if (match_ifname("usbpn", ifname)) {
+               /* ISI modem connected via usb */
+               name = NULL;
+               driver = "isigen";
+               address = PN_DEV_PC;
+       } else if (!strcmp("phonet0", ifname)) {
+               /* N900 modem connected via internal hsi link */
+               name = "n900";
+               driver = "n900";
+               address = PN_DEV_SOS;
+       } else
                return;
-       }
 
-       modem = ofono_modem_create(NULL, "isimodem");
+       modem = ofono_modem_create(name, driver);
        if (!modem)
                return;
 
        ofono_modem_set_string(modem, "Interface", ifname);
+       ofono_modem_set_integer(modem, "Address", address);
 
        if (ofono_modem_register(modem) == 0)
                DBG("Done regging modem %s", ofono_modem_get_path(modem));
@@ -99,6 +115,6 @@ static void usbpn_exit(void)
        link = NULL;
 }
 
-OFONO_PLUGIN_DEFINE(usbpnmodem, "Hotplug driver for USB Phonet modems", 
VERSION,
+OFONO_PLUGIN_DEFINE(usbpnmodem, "Hotplug driver for Phonet modems", VERSION,
                        OFONO_PLUGIN_PRIORITY_DEFAULT,
                        usbpn_init, usbpn_exit)
-- 
1.7.0.4

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to