From 7fbee6ce27176bfc7ae9b34a4de9452cf5f6fa43 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Wed, 5 Feb 2014 08:38:23 +0100 Subject: Imported Upstream version 0.4+git.20110124t203624.00b6cce --- plugins/77-mm-ericsson-mbm.rules | 33 ++ plugins/77-mm-x22x-port-types.rules | 30 ++ plugins/77-mm-zte-port-types.rules | 57 +++ plugins/Makefile.am | 71 +++- plugins/mm-modem-anydata-cdma.c | 34 +- plugins/mm-modem-anydata-cdma.h | 4 +- plugins/mm-modem-gobi-gsm.c | 6 +- plugins/mm-modem-gobi-gsm.h | 4 +- plugins/mm-modem-hso.c | 8 +- plugins/mm-modem-hso.h | 4 +- plugins/mm-modem-huawei-cdma.c | 13 +- plugins/mm-modem-huawei-cdma.h | 4 +- plugins/mm-modem-huawei-gsm.c | 88 ++-- plugins/mm-modem-huawei-gsm.h | 4 +- plugins/mm-modem-icera.c | 794 ++++++++++++++++++++++++++++++++++++ plugins/mm-modem-icera.h | 89 ++++ plugins/mm-modem-linktop.c | 208 ++++++++++ plugins/mm-modem-linktop.h | 45 ++ plugins/mm-modem-longcheer-gsm.c | 6 +- plugins/mm-modem-longcheer-gsm.h | 4 +- plugins/mm-modem-mbm.c | 79 ++-- plugins/mm-modem-mbm.h | 4 +- plugins/mm-modem-moto-c-gsm.c | 6 +- plugins/mm-modem-moto-c-gsm.h | 4 +- plugins/mm-modem-nokia.c | 10 +- plugins/mm-modem-nokia.h | 4 +- plugins/mm-modem-novatel-cdma.c | 148 ++++++- plugins/mm-modem-novatel-cdma.h | 4 +- plugins/mm-modem-novatel-gsm.c | 6 +- plugins/mm-modem-novatel-gsm.h | 4 +- plugins/mm-modem-option.c | 6 +- plugins/mm-modem-option.h | 4 +- plugins/mm-modem-sierra-cdma.c | 6 +- plugins/mm-modem-sierra-cdma.h | 4 +- plugins/mm-modem-sierra-gsm.c | 318 ++++++++++++++- plugins/mm-modem-sierra-gsm.h | 4 +- plugins/mm-modem-simtech-gsm.c | 6 +- plugins/mm-modem-simtech-gsm.h | 4 +- plugins/mm-modem-x22x-gsm.c | 209 ++++++++++ plugins/mm-modem-x22x-gsm.h | 45 ++ plugins/mm-modem-zte.c | 206 +++++++++- plugins/mm-modem-zte.h | 4 +- plugins/mm-plugin-anydata.c | 10 +- plugins/mm-plugin-generic.c | 33 +- plugins/mm-plugin-gobi.c | 14 +- plugins/mm-plugin-hso.c | 10 +- plugins/mm-plugin-huawei.c | 29 +- plugins/mm-plugin-linktop.c | 164 ++++++++ plugins/mm-plugin-linktop.h | 41 ++ plugins/mm-plugin-longcheer.c | 14 +- plugins/mm-plugin-mbm.c | 12 +- plugins/mm-plugin-moto-c.c | 10 +- plugins/mm-plugin-nokia.c | 14 +- plugins/mm-plugin-novatel.c | 14 +- plugins/mm-plugin-option.c | 10 +- plugins/mm-plugin-sierra.c | 50 ++- plugins/mm-plugin-simtech.c | 14 +- plugins/mm-plugin-x22x.c | 192 +++++++++ plugins/mm-plugin-x22x.h | 41 ++ plugins/mm-plugin-zte.c | 35 +- 60 files changed, 3088 insertions(+), 210 deletions(-) create mode 100644 plugins/77-mm-x22x-port-types.rules create mode 100644 plugins/mm-modem-icera.c create mode 100644 plugins/mm-modem-icera.h create mode 100644 plugins/mm-modem-linktop.c create mode 100644 plugins/mm-modem-linktop.h create mode 100644 plugins/mm-modem-x22x-gsm.c create mode 100644 plugins/mm-modem-x22x-gsm.h create mode 100644 plugins/mm-plugin-linktop.c create mode 100644 plugins/mm-plugin-linktop.h create mode 100644 plugins/mm-plugin-x22x.c create mode 100644 plugins/mm-plugin-x22x.h (limited to 'plugins') diff --git a/plugins/77-mm-ericsson-mbm.rules b/plugins/77-mm-ericsson-mbm.rules index 8804036..51cc06f 100644 --- a/plugins/77-mm-ericsson-mbm.rules +++ b/plugins/77-mm-ericsson-mbm.rules @@ -17,18 +17,30 @@ ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1906", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="190a", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1909", ENV{ID_MM_ERICSSON_MBM}="1" +# Ericsson F3307 R2 +ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1914", ENV{ID_MM_ERICSSON_MBM}="1" + # Ericsson C3607w ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1049", ENV{ID_MM_ERICSSON_MBM}="1" # Ericsson C3607w v2 ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="190b", ENV{ID_MM_ERICSSON_MBM}="1" +# Ericsson F5521gw +ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="190d", ENV{ID_MM_ERICSSON_MBM}="1" + # Sony-Ericsson MD300 ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="d0cf", ENV{ID_MM_ERICSSON_MBM}="1" # Sony-Ericsson MD400 ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="d0e1", ENV{ID_MM_ERICSSON_MBM}="1" +# Sony-Ericsson MD400G +ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="d103", ENV{ID_MM_ERICSSON_MBM}="1" + +# Dell 5550 +ATTRS{idVendor}=="413c", ATTRS{idProduct}=="818d", ENV{ID_MM_ERICSSON_MBM}="1" + # Dell 5530 HSDPA ATTRS{idVendor}=="413c", ATTRS{idProduct}=="8147", ENV{ID_MM_ERICSSON_MBM}="1" @@ -40,6 +52,18 @@ ATTRS{idVendor}=="413c", ATTRS{idProduct}=="8184", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="413c", ATTRS{idProduct}=="818b", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="413c", ATTRS{idProduct}=="818c", ENV{ID_MM_ERICSSON_MBM}="1" +# HP hs2330 Mobile Broadband Module +ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="271d", ENV{ID_MM_ERICSSON_MBM}="1" + +# HP hs2320 Mobile Broadband Module +ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="261d", ENV{ID_MM_ERICSSON_MBM}="1" + +# HP lc2000 Mobile Broadband Module +ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="301d", ENV{ID_MM_ERICSSON_MBM}="1" + +# HP lc2010 Mobile Broadband Module +ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="2f1d", ENV{ID_MM_ERICSSON_MBM}="1" + # Toshiba ATTRS{idVendor}=="0930", ATTRS{idProduct}=="130b", ENV{ID_MM_ERICSSON_MBM}="1" @@ -47,5 +71,14 @@ ATTRS{idVendor}=="0930", ATTRS{idProduct}=="130b", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="0930", ATTRS{idProduct}=="130c", ENV{ID_MM_ERICSSON_MBM}="1" ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1311", ENV{ID_MM_ERICSSON_MBM}="1" +# Toshiba F3307 +ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1315", ENV{ID_MM_ERICSSON_MBM}="1" +ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1316", ENV{ID_MM_ERICSSON_MBM}="1" +ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1317", ENV{ID_MM_ERICSSON_MBM}="1" + +# Toshiba F5521gw +ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1313", ENV{ID_MM_ERICSSON_MBM}="1" +ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1314", ENV{ID_MM_ERICSSON_MBM}="1" + LABEL="mm_mbm_end" diff --git a/plugins/77-mm-x22x-port-types.rules b/plugins/77-mm-x22x-port-types.rules new file mode 100644 index 0000000..0f870a4 --- /dev/null +++ b/plugins/77-mm-x22x-port-types.rules @@ -0,0 +1,30 @@ +# do not edit this file, it will be overwritten on update + +# Alcatel One Touch X220D +# +# These values were scraped from the X220D's Windows .inf files. jrdmdm.inf +# lists the actual command and data (ie PPP) ports, while jrdser.inf lists the +# aux ports that may be either AT-capable or not but cannot be used for PPP. + + +ACTION!="add|change", GOTO="mm_x22x_port_types_end" +SUBSYSTEM!="tty", GOTO="mm_x22x_port_types_end" + +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1bbb", GOTO="mm_x22x_vendorcheck" +GOTO="mm_x22x_port_types_end" + +LABEL="mm_x22x_vendorcheck" +SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}" + +ATTRS{idProduct}=="0017", ENV{.MM_USBIFNUM}=="05", ENV{ID_MM_X22X_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0017", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_X22X_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0017", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_X22X_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0017", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_X22X_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0017", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_X22X_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0017", ENV{ID_MM_X22X_TAGGED}="1" + +GOTO="mm_x22x_port_types_end" + + +LABEL="mm_x22x_port_types_end" + diff --git a/plugins/77-mm-zte-port-types.rules b/plugins/77-mm-zte-port-types.rules index 9d64aa9..072154c 100644 --- a/plugins/77-mm-zte-port-types.rules +++ b/plugins/77-mm-zte-port-types.rules @@ -78,6 +78,9 @@ ATTRS{idProduct}=="0033", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}= ATTRS{idProduct}=="0037", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0037", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0039", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0039", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + ATTRS{idProduct}=="0042", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0042", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" @@ -93,9 +96,15 @@ ATTRS{idProduct}=="0049", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_ZTE_PORT_TYPE_AUX}= ATTRS{idProduct}=="0052", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0052", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0054", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0054", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + ATTRS{idProduct}=="0055", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0055", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0057", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0057", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" @@ -108,8 +117,56 @@ ATTRS{idProduct}=="0064", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_ZTE_PORT_TYPE_AUX}= ATTRS{idProduct}=="0066", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="0066", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="0082", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0082", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0108", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0108", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0113", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0113", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0117", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0117", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0118", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0118", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0121", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0121", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0123", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0123", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0124", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0124", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="05", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0126", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0126", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="0128", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="0128", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="1007", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="1007", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="1008", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="1008", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + +ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + ATTRS{idProduct}=="2002", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" ATTRS{idProduct}=="2002", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" +ATTRS{idProduct}=="2003", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_ZTE_PORT_TYPE_MODEM}="1" +ATTRS{idProduct}=="2003", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_ZTE_PORT_TYPE_AUX}="1" + LABEL="mm_zte_port_types_end" diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 8192653..dd58b94 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,3 +1,24 @@ + +########################## +# Icera-specific support # +########################## + +noinst_LTLIBRARIES = libicera-utils.la + +libicera_utils_la_SOURCES = \ + mm-modem-icera.c \ + mm-modem-icera.h + +libicera_utils_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libicera_utils_la_LIBADD = \ + $(GUDEV_LDFLAGS) + +######################################## + pkglib_LTLIBRARIES = \ libmm-plugin-generic.la \ libmm-plugin-moto-c.la \ @@ -12,7 +33,9 @@ pkglib_LTLIBRARIES = \ libmm-plugin-mbm.la \ libmm-plugin-longcheer.la \ libmm-plugin-anydata.la \ - libmm-plugin-simtech.la + libmm-plugin-simtech.la \ + libmm-plugin-x22x.la \ + libmm-plugin-linktop.la # Generic @@ -95,8 +118,8 @@ libmm_plugin_hso_la_SOURCES = \ mm-modem-hso.c \ mm-modem-hso.h -mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-hso.xml - dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $< +mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.Modem.Gsm.Hso.xml + $(AM_V_GEN) dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $< libmm_plugin_hso_la_CPPFLAGS = \ $(MM_CFLAGS) \ @@ -177,7 +200,8 @@ libmm_plugin_novatel_la_SOURCES = \ libmm_plugin_novatel_la_CPPFLAGS = \ $(MM_CFLAGS) \ $(GUDEV_CFLAGS) \ - -I$(top_srcdir)/src + -I$(top_srcdir)/src \ + -I$(top_srcdir) libmm_plugin_novatel_la_LDFLAGS = \ $(GUDEV_LDFLAGS) \ @@ -217,6 +241,7 @@ libmm_plugin_zte_la_CPPFLAGS = \ libmm_plugin_zte_la_LDFLAGS = \ $(GUDEV_LDFLAGS) \ + $(builddir)/libicera-utils.la \ -module \ -avoid-version @@ -274,13 +299,49 @@ libmm_plugin_simtech_la_LDFLAGS = \ -module \ -avoid-version +# Alcatel/TCT/JRD x220D and possibly others + +libmm_plugin_x22x_la_SOURCES = \ + mm-plugin-x22x.c \ + mm-plugin-x22x.h \ + mm-modem-x22x-gsm.c \ + mm-modem-x22x-gsm.h + +libmm_plugin_x22x_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_x22x_la_LDFLAGS = \ + $(GUDEV_LDFLAGS) \ + -module \ + -avoid-version + +# Linktop + +libmm_plugin_linktop_la_SOURCES = \ + mm-plugin-linktop.c \ + mm-plugin-linktop.h \ + mm-modem-linktop.c \ + mm-modem-linktop.h + +libmm_plugin_linktop_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_linktop_la_LDFLAGS = \ + $(GUDEV_LDFLAGS) \ + -module \ + -avoid-version udevrulesdir = $(UDEV_BASE_DIR)/rules.d udevrules_DATA = \ 77-mm-ericsson-mbm.rules \ 77-mm-zte-port-types.rules \ 77-mm-longcheer-port-types.rules \ - 77-mm-simtech-port-types.rules + 77-mm-simtech-port-types.rules \ + 77-mm-x22x-port-types.rules BUILT_SOURCES = \ mm-modem-gsm-hso-glue.h diff --git a/plugins/mm-modem-anydata-cdma.c b/plugins/mm-modem-anydata-cdma.c index c7cca46..0e7e65c 100644 --- a/plugins/mm-modem-anydata-cdma.c +++ b/plugins/mm-modem-anydata-cdma.c @@ -28,6 +28,7 @@ #include "mm-callback-info.h" #include "mm-serial-port.h" #include "mm-serial-parsers.h" +#include "mm-log.h" static void modem_init (MMModem *modem_class); @@ -39,7 +40,9 @@ mm_modem_anydata_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA) + gboolean evdo_revA, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -52,6 +55,8 @@ mm_modem_anydata_cdma_new (const char *device, MM_GENERIC_CDMA_EVDO_REV0, evdo_rev0, MM_GENERIC_CDMA_EVDO_REVA, evdo_revA, MM_GENERIC_CDMA_REGISTRATION_TRY_CSS, FALSE, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -136,7 +141,7 @@ evdo_state_done (MMAtSerialPort *port, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); if (!r) { /* Parse error; warn about it and assume EVDO is not available */ - g_warning ("AnyDATA(%s): *HSTATE parse regex creation failed.", __func__); + mm_warn ("ANYDATA: *HSTATE parse regex creation failed."); goto done; } @@ -163,7 +168,7 @@ evdo_state_done (MMAtSerialPort *port, reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; break; default: - g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val); + mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val); /* fall through */ case 0: /* NO SERVICE */ case 1: /* ACQUISITION */ @@ -202,7 +207,7 @@ state_done (MMAtSerialPort *port, r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); if (!r) { - g_warning ("AnyDATA(%s): *STATE parse regex creation failed.", __func__); + mm_warn ("ANYDATA: *STATE parse regex creation failed."); mm_callback_info_schedule (info); return; } @@ -231,7 +236,7 @@ state_done (MMAtSerialPort *port, reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; break; default: - g_warning ("ANYDATA: unknown *STATE (%d); assuming no service.", val); + mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val); /* fall through */ case 0: /* NO SERVICE */ break; @@ -268,6 +273,24 @@ query_registration_state (MMGenericCdma *cdma, /*****************************************************************************/ +static void +reset (MMModem *modem, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + info = mm_callback_info_new (MM_MODEM (modem), callback, user_data); + + /* Ensure we have a usable port to use for the command */ + port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error); + if (port) + mm_at_serial_port_queue_command (port, "*RESET", 3, NULL, NULL); + + mm_callback_info_schedule (info); +} + static gboolean grab_port (MMModem *modem, const char *subsys, @@ -329,6 +352,7 @@ static void modem_init (MMModem *modem_class) { modem_class->grab_port = grab_port; + modem_class->reset = reset; } static void diff --git a/plugins/mm-modem-anydata-cdma.h b/plugins/mm-modem-anydata-cdma.h index d2695d5..5a9fc4b 100644 --- a/plugins/mm-modem-anydata-cdma.h +++ b/plugins/mm-modem-anydata-cdma.h @@ -40,6 +40,8 @@ MMModem *mm_modem_anydata_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA); + gboolean evdo_revA, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_ANYDATA_CDMA_H */ diff --git a/plugins/mm-modem-gobi-gsm.c b/plugins/mm-modem-gobi-gsm.c index 3b9e9ec..7e2fa4c 100644 --- a/plugins/mm-modem-gobi-gsm.c +++ b/plugins/mm-modem-gobi-gsm.c @@ -36,7 +36,9 @@ G_DEFINE_TYPE_EXTENDED (MMModemGobiGsm, mm_modem_gobi_gsm, MM_TYPE_GENERIC_GSM, MMModem * mm_modem_gobi_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -46,6 +48,8 @@ mm_modem_gobi_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-gobi-gsm.h b/plugins/mm-modem-gobi-gsm.h index 4bd262f..b1af164 100644 --- a/plugins/mm-modem-gobi-gsm.h +++ b/plugins/mm-modem-gobi-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_gobi_gsm_get_type (void); MMModem *mm_modem_gobi_gsm_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_GOBI_GSM_H */ diff --git a/plugins/mm-modem-hso.c b/plugins/mm-modem-hso.c index 1fd4633..ff0264a 100644 --- a/plugins/mm-modem-hso.c +++ b/plugins/mm-modem-hso.c @@ -74,7 +74,9 @@ typedef struct { MMModem * mm_modem_hso_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -85,6 +87,8 @@ mm_modem_hso_new (const char *device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -427,7 +431,7 @@ unsolicited_disable_done (MMModem *modem, } /* Otherwise, kill any existing connection */ - if (mm_generic_gsm_get_cid (MM_GENERIC_GSM (modem)) >= 0) + if (hso_get_cid (MM_MODEM_HSO (modem)) >= 0) hso_call_control (MM_MODEM_HSO (modem), FALSE, TRUE, disable_done, info); else disable_done (modem, NULL, info); diff --git a/plugins/mm-modem-hso.h b/plugins/mm-modem-hso.h index e2d7623..7e79886 100644 --- a/plugins/mm-modem-hso.h +++ b/plugins/mm-modem-hso.h @@ -38,7 +38,9 @@ GType mm_modem_hso_get_type (void); MMModem *mm_modem_hso_new (const char *device, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); void mm_hso_modem_authenticate (MMModemHso *self, const char *username, diff --git a/plugins/mm-modem-huawei-cdma.c b/plugins/mm-modem-huawei-cdma.c index 523578f..3aec470 100644 --- a/plugins/mm-modem-huawei-cdma.c +++ b/plugins/mm-modem-huawei-cdma.c @@ -27,6 +27,7 @@ #include "mm-callback-info.h" #include "mm-serial-port.h" #include "mm-serial-parsers.h" +#include "mm-log.h" static void modem_init (MMModem *modem_class); @@ -39,7 +40,9 @@ mm_modem_huawei_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA) + gboolean evdo_revA, + guint32 vendor, + guint32 product) { gboolean try_css = TRUE; @@ -61,6 +64,8 @@ mm_modem_huawei_cdma_new (const char *device, MM_GENERIC_CDMA_EVDO_REV0, evdo_rev0, MM_GENERIC_CDMA_EVDO_REVA, evdo_revA, MM_GENERIC_CDMA_REGISTRATION_TRY_CSS, try_css, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -75,7 +80,7 @@ parse_quality (const char *str, const char *detail) quality = strtol (str, NULL, 10); if (errno == 0) { quality = CLAMP (quality, 0, 100); - g_debug ("%s: %ld", detail, quality); + mm_dbg ("%s: %ld", detail, quality); return (gint) quality; } return -1; @@ -173,7 +178,7 @@ sysinfo_done (MMAtSerialPort *port, r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); if (!r) { - g_warning ("Huawei(%s): ^SYSINFO parse regex creation failed.", __func__); + mm_warn ("Huawei: ^SYSINFO parse regex creation failed."); goto done; } @@ -214,7 +219,7 @@ sysinfo_done (MMAtSerialPort *port, mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state); } } else - g_warning ("Huawei(%s): failed to parse ^SYSINFO response.", __func__); + mm_warn ("Huawei: failed to parse ^SYSINFO response."); g_match_info_free (match_info); g_regex_unref (r); diff --git a/plugins/mm-modem-huawei-cdma.h b/plugins/mm-modem-huawei-cdma.h index 738f2d9..88b425c 100644 --- a/plugins/mm-modem-huawei-cdma.h +++ b/plugins/mm-modem-huawei-cdma.h @@ -40,6 +40,8 @@ MMModem *mm_modem_huawei_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA); + gboolean evdo_revA, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_HUAWEI_CDMA_H */ diff --git a/plugins/mm-modem-huawei-gsm.c b/plugins/mm-modem-huawei-gsm.c index 5123e7f..3fc9ae2 100644 --- a/plugins/mm-modem-huawei-gsm.c +++ b/plugins/mm-modem-huawei-gsm.c @@ -29,6 +29,7 @@ #include "mm-callback-info.h" #include "mm-at-serial-port.h" #include "mm-serial-parsers.h" +#include "mm-log.h" static void modem_init (MMModem *modem_class); static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class); @@ -50,7 +51,9 @@ typedef struct { MMModem * mm_modem_huawei_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -60,6 +63,8 @@ mm_modem_huawei_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -362,6 +367,35 @@ get_band (MMModemGsmNetwork *modem, mm_at_serial_port_queue_command (port, "AT^SYSCFG?", 3, get_band_done, info); } +static MMModemGsmAccessTech +huawei_sysinfo_to_act (int huawei) +{ + switch (huawei) { + case 1: + return MM_MODEM_GSM_ACCESS_TECH_GSM; + case 2: + return MM_MODEM_GSM_ACCESS_TECH_GPRS; + case 3: + return MM_MODEM_GSM_ACCESS_TECH_EDGE; + case 4: + return MM_MODEM_GSM_ACCESS_TECH_UMTS; + case 5: + return MM_MODEM_GSM_ACCESS_TECH_HSDPA; + case 6: + return MM_MODEM_GSM_ACCESS_TECH_HSUPA; + case 7: + return MM_MODEM_GSM_ACCESS_TECH_HSPA; + case 9: + return MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS; + case 8: + /* TD-SCDMA */ + default: + break; + } + + return MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; +} + static void get_act_request_done (MMAtSerialPort *port, GString *response, @@ -404,22 +438,8 @@ get_act_request_done (MMAtSerialPort *port, if (srv_stat != 0) { /* Valid service */ str = g_match_info_fetch (match_info, 7); - if (str && strlen (str)) { - if (str[0] == '1') - act = MM_MODEM_GSM_ACCESS_TECH_GSM; - else if (str[0] == '2') - act = MM_MODEM_GSM_ACCESS_TECH_GPRS; - else if (str[0] == '3') - act = MM_MODEM_GSM_ACCESS_TECH_EDGE; - else if (str[0] == '4') - act = MM_MODEM_GSM_ACCESS_TECH_UMTS; - else if (str[0] == '5') - act = MM_MODEM_GSM_ACCESS_TECH_HSDPA; - else if (str[0] == '6') - act = MM_MODEM_GSM_ACCESS_TECH_HSUPA; - else if (str[0] == '7') - act = MM_MODEM_GSM_ACCESS_TECH_HSPA; - } + if (str && strlen (str)) + act = huawei_sysinfo_to_act (atoi (str)); g_free (str); } @@ -514,7 +534,7 @@ send_huawei_cpin_done (MMAtSerialPort *port, else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PIN2)) num = 5; else { - g_debug ("%s: unhandled pin type '%s'", __func__, pin_type); + mm_dbg ("unhandled pin type '%s'", pin_type); info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type"); } @@ -556,7 +576,7 @@ get_unlock_retries (MMModemGsmCard *modem, char *command; MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); - g_debug ("%s: pin type '%s'", __func__, pin_type); + mm_dbg ("pin type '%s'", pin_type); /* Ensure we have a usable port to use for the command */ port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); @@ -622,40 +642,30 @@ handle_mode_change (MMAtSerialPort *port, MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; char *str; int a; - int b; str = g_match_info_fetch (match_info, 1); a = atoi (str); g_free (str); str = g_match_info_fetch (match_info, 2); - b = atoi (str); + act = huawei_sysinfo_to_act (atoi (str)); g_free (str); if (a == 3) { /* GSM/GPRS mode */ - if (b == 1) - act = MM_MODEM_GSM_ACCESS_TECH_GSM; - else if (b == 2) - act = MM_MODEM_GSM_ACCESS_TECH_GPRS; - else if (b == 3) - act = MM_MODEM_GSM_ACCESS_TECH_EDGE; + if (act > MM_MODEM_GSM_ACCESS_TECH_EDGE) + act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; } else if (a == 5) { /* WCDMA mode */ - if (b == 4) - act = MM_MODEM_GSM_ACCESS_TECH_UMTS; - else if (b == 5) - act = MM_MODEM_GSM_ACCESS_TECH_HSDPA; - else if (b == 6) - act = MM_MODEM_GSM_ACCESS_TECH_HSUPA; - else if (b == 7) - act = MM_MODEM_GSM_ACCESS_TECH_HSPA; + if (act < MM_MODEM_GSM_ACCESS_TECH_UMTS) + act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; } else if (a == 0) act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; else { - g_warning ("Couldn't parse mode change value: '%s'", str); + mm_warn ("Couldn't parse mode change value: '%s'", str); return; } - g_debug ("Access Technology: %d", act); + mm_dbg ("Access Technology: %d", act); + mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act); } @@ -669,8 +679,8 @@ handle_status_change (MMAtSerialPort *port, str = g_match_info_fetch (match_info, 1); if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) { - g_debug ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n", - n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024); + mm_dbg ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n", + n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024); } g_free (str); } diff --git a/plugins/mm-modem-huawei-gsm.h b/plugins/mm-modem-huawei-gsm.h index 9c2ec34..05f1f29 100644 --- a/plugins/mm-modem-huawei-gsm.h +++ b/plugins/mm-modem-huawei-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_huawei_gsm_get_type (void); MMModem *mm_modem_huawei_gsm_new (const char *device, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_HUAWEI_GSM_H */ diff --git a/plugins/mm-modem-icera.c b/plugins/mm-modem-icera.c new file mode 100644 index 0000000..3f71c5b --- /dev/null +++ b/plugins/mm-modem-icera.c @@ -0,0 +1,794 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2010 Red Hat, Inc. + */ + +/****************************************** + * Generic utilities for Icera-based modems + ******************************************/ + +#include +#include +#include +#include +#include +#include + +#include "mm-modem-icera.h" + +#include "mm-modem.h" +#include "mm-errors.h" +#include "mm-callback-info.h" +#include "mm-at-serial-port.h" +#include "mm-generic-gsm.h" +#include "mm-modem-helpers.h" +#include "mm-log.h" + +struct _MMModemIceraPrivate { + /* Pending connection attempt */ + MMCallbackInfo *connect_pending_data; + guint connect_pending_id; + + char *username; + char *password; + + MMModemGsmAccessTech last_act; +}; + +#define MM_MODEM_ICERA_GET_PRIVATE(m) (MM_MODEM_ICERA_GET_INTERFACE(m)->priv) + +static void +get_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + gboolean parsed = FALSE; + + if (error) + info->error = g_error_copy (error); + else if (!g_str_has_prefix (response->str, "%IPSYS: ")) { + int a, b; + + if (sscanf (response->str + 8, "%d,%d", &a, &b)) { + MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; + + switch (a) { + case 0: + mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY; + break; + case 1: + mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY; + break; + case 2: + mode = MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED; + break; + case 3: + mode = MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED; + break; + default: + break; + } + + mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL); + parsed = TRUE; + } + } + + if (!error && !parsed) + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Could not parse allowed mode results"); + + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_get_allowed_mode (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + mm_at_serial_port_queue_command (port, "%IPSYS?", 3, get_allowed_mode_done, info); +} + +static void +set_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) + info->error = g_error_copy (error); + + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_set_allowed_mode (MMModemIcera *self, + MMModemGsmAllowedMode mode, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + char *command; + int i; + + info = mm_callback_info_new (MM_MODEM (self), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + switch (mode) { + case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY: + i = 0; + break; + case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY: + i = 1; + break; + case MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED: + i = 2; + break; + case MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED: + i = 3; + break; + case MM_MODEM_GSM_ALLOWED_MODE_ANY: + default: + i = 5; + break; + } + + command = g_strdup_printf ("%%IPSYS=%d", i); + mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info); + g_free (command); +} + +static MMModemGsmAccessTech +nwstate_to_act (const char *str) +{ + /* small 'g' means CS, big 'G' means PS */ + if (!strcmp (str, "2G-GPRS")) + return MM_MODEM_GSM_ACCESS_TECH_GPRS; + else if (!strcmp (str, "2G-EDGE")) + return MM_MODEM_GSM_ACCESS_TECH_EDGE; + else if (!strcmp (str, "3G")) + return MM_MODEM_GSM_ACCESS_TECH_UMTS; + else if (!strcmp (str, "3G-HSDPA")) + return MM_MODEM_GSM_ACCESS_TECH_HSDPA; + else if (!strcmp (str, "3G-HSUPA")) + return MM_MODEM_GSM_ACCESS_TECH_HSUPA; + else if (!strcmp (str, "3G-HSDPA-HSUPA")) + return MM_MODEM_GSM_ACCESS_TECH_HSPA; + + return MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; +} + +static void +nwstate_changed (MMAtSerialPort *port, + GMatchInfo *info, + gpointer user_data) +{ + MMModemIcera *self = MM_MODEM_ICERA (user_data); + MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; + char *str; + int rssi = -1; + + str = g_match_info_fetch (info, 1); + if (str) { + rssi = atoi (str); + rssi = CLAMP (rssi, -1, 5); + g_free (str); + } + + str = g_match_info_fetch (info, 3); + if (str) { + act = nwstate_to_act (str); + g_free (str); + } + + MM_MODEM_ICERA_GET_PRIVATE (self)->last_act = act; + mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act); +} + +static void +pacsp_received (MMAtSerialPort *port, + GMatchInfo *info, + gpointer user_data) +{ + return; +} + +static void +get_nwstate_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + + info->error = mm_modem_check_removed (info->modem, error); + if (!info->error) { + MMModemIcera *self = MM_MODEM_ICERA (info->modem); + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + + /* The unsolicited message handler will already have run and + * removed the NWSTATE response, so we have to work around that. + */ + mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->last_act), NULL); + priv->last_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; + } + + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_get_access_technology (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data) +{ + MMAtSerialPort *port; + MMCallbackInfo *info; + + info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + mm_at_serial_port_queue_command (port, "%NWSTATE=1", 3, get_nwstate_done, info); +} + +/****************************************************************/ + +static void +disconnect_ipdpact_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + mm_callback_info_schedule ((MMCallbackInfo *) user_data); +} + +void +mm_modem_icera_do_disconnect (MMGenericGsm *gsm, + gint cid, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *primary; + char *command; + + info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); + + primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + command = g_strdup_printf ("%%IPDPACT=%d,0", cid); + mm_at_serial_port_queue_command (primary, command, 3, disconnect_ipdpact_done, info); + g_free (command); +} + +/*****************************************************************************/ + +static void +connect_pending_done (MMModemIcera *self) +{ + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + GError *error = NULL; + + if (priv->connect_pending_data) { + if (priv->connect_pending_data->error) { + error = priv->connect_pending_data->error; + priv->connect_pending_data->error = NULL; + } + + /* Complete the connect */ + mm_generic_gsm_connect_complete (MM_GENERIC_GSM (self), error, priv->connect_pending_data); + priv->connect_pending_data = NULL; + } + + if (priv->connect_pending_id) { + g_source_remove (priv->connect_pending_id); + priv->connect_pending_id = 0; + } +} + +static void +icera_disconnect_done (MMModem *modem, + GError *error, + gpointer user_data) +{ + mm_info ("Modem signaled disconnection from the network"); +} + +static void +connection_enabled (MMAtSerialPort *port, + GMatchInfo *match_info, + gpointer user_data) +{ + MMModemIcera *self = MM_MODEM_ICERA (user_data); + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + MMCallbackInfo *info = priv->connect_pending_data; + char *str; + int status, cid, tmp; + + cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)); + if (cid < 0) + return; + + str = g_match_info_fetch (match_info, 1); + g_return_if_fail (str != NULL); + tmp = atoi (str); + g_free (str); + + /* Make sure the unsolicited message's CID matches the current CID */ + if (tmp != cid) + return; + + str = g_match_info_fetch (match_info, 2); + g_return_if_fail (str != NULL); + status = atoi (str); + g_free (str); + + switch (status) { + case 0: + /* Disconnected */ + if (mm_modem_get_state (MM_MODEM (self)) >= MM_MODEM_STATE_CONNECTED) + mm_modem_disconnect (MM_MODEM (self), icera_disconnect_done, NULL); + break; + case 1: + /* Connected */ + connect_pending_done (self); + break; + case 2: + /* Connecting */ + break; + case 3: + /* Call setup failure? */ + if (info) { + info->error = g_error_new_literal (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Call setup failed"); + } + connect_pending_done (self); + break; + default: + mm_warn ("Unknown Icera connect status %d", status); + break; + } +} + +/****************************************************************/ + +static gint +_get_cid (MMModemIcera *self) +{ + gint cid; + + cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)); + if (cid < 0) { + g_warn_if_fail (cid >= 0); + cid = 0; + } + return cid; +} + +static void +icera_call_control (MMModemIcera *self, + gboolean activate, + MMAtSerialResponseFn callback, + gpointer user_data) +{ + char *command; + MMAtSerialPort *primary; + + primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + command = g_strdup_printf ("%%IPDPACT=%d,%d", _get_cid (self), activate ? 1 : 0); + mm_at_serial_port_queue_command (primary, command, 3, callback, user_data); + g_free (command); +} + +static void +timeout_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + connect_pending_done (MM_MODEM_ICERA (user_data)); +} + +static gboolean +icera_connect_timed_out (gpointer data) +{ + MMModemIcera *self = MM_MODEM_ICERA (data); + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + MMCallbackInfo *info = priv->connect_pending_data; + + priv->connect_pending_id = 0; + + if (info) { + info->error = g_error_new_literal (MM_SERIAL_ERROR, + MM_SERIAL_ERROR_RESPONSE_TIMEOUT, + "Connection timed out"); + } + + icera_call_control (self, FALSE, timeout_done, self); + return FALSE; +} + +static void +icera_enabled (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) { + mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info); + } else { + MMModemIcera *self = MM_MODEM_ICERA (info->modem); + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + + g_warn_if_fail (priv->connect_pending_id == 0); + if (priv->connect_pending_id) + g_source_remove (priv->connect_pending_id); + + priv->connect_pending_data = info; + priv->connect_pending_id = g_timeout_add_seconds (30, icera_connect_timed_out, self); + } +} + +static void +old_context_clear_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + /* Activate the PDP context and start the data session */ + icera_call_control (MM_MODEM_ICERA (info->modem), TRUE, icera_enabled, info); +} + +static void +auth_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) + mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info); + else { + /* Ensure the PDP context is deactivated */ + icera_call_control (MM_MODEM_ICERA (info->modem), FALSE, old_context_clear_done, info); + } +} + +void +mm_modem_icera_do_connect (MMModemIcera *self, + const char *number, + MMModemFn callback, + gpointer user_data) +{ + MMModem *modem = MM_MODEM (self); + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + MMCallbackInfo *info; + MMAtSerialPort *primary; + gint cid; + char *command; + + mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE); + + info = mm_callback_info_new (modem, callback, user_data); + + primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + cid = _get_cid (self); + + + /* Both user and password are required; otherwise firmware returns an error */ + if (!priv->username || !priv->password) + command = g_strdup_printf ("%%IPDPCFG=%d,0,0,\"\",\"\"", cid); + else { + command = g_strdup_printf ("%%IPDPCFG=%d,0,1,\"%s\",\"%s\"", + cid, + priv->password ? priv->password : "", + priv->username ? priv->username : ""); + + } + + mm_at_serial_port_queue_command (primary, command, 3, auth_done, info); + g_free (command); +} + +/****************************************************************/ + + +static void +free_dns_array (gpointer data) +{ + g_array_free ((GArray *) data, TRUE); +} + +static void +ip4_config_invoke (MMCallbackInfo *info) +{ + MMModemIp4Fn callback = (MMModemIp4Fn) info->callback; + + callback (info->modem, + GPOINTER_TO_UINT (mm_callback_info_get_data (info, "ip4-address")), + (GArray *) mm_callback_info_get_data (info, "ip4-dns"), + info->error, info->user_data); +} + +#define IPDPADDR_TAG "%IPDPADDR: " + +static void +get_ip4_config_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + char **items, **iter; + GArray *dns_array; + int i; + guint32 tmp; + gint cid; + + if (error) { + info->error = g_error_copy (error); + goto out; + } else if (!g_str_has_prefix (response->str, IPDPADDR_TAG)) { + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Retrieving failed: invalid response."); + goto out; + } + + cid = _get_cid (MM_MODEM_ICERA (info->modem)); + dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2); + + /* %IPDPADDR: ,,,,[,,] */ + items = g_strsplit (response->str + strlen (IPDPADDR_TAG), ", ", 0); + + for (iter = items, i = 0; *iter; iter++, i++) { + if (i == 0) { /* CID */ + long int num; + + errno = 0; + num = strtol (*iter, NULL, 10); + if (errno != 0 || num < 0 || (gint) num != cid) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Unknown CID in IPDPADDR response (" + "got %d, expected %d)", (guint) num, cid); + break; + } + } else if (i == 1) { /* IP address */ + if (inet_pton (AF_INET, *iter, &tmp) > 0) + mm_callback_info_set_data (info, "ip4-address", GUINT_TO_POINTER (tmp), NULL); + } else if (i == 3) { /* DNS 1 */ + if (inet_pton (AF_INET, *iter, &tmp) > 0) + g_array_append_val (dns_array, tmp); + } else if (i == 4) { /* DNS 2 */ + if (inet_pton (AF_INET, *iter, &tmp) > 0) + g_array_append_val (dns_array, tmp); + } + } + + g_strfreev (items); + mm_callback_info_set_data (info, "ip4-dns", dns_array, free_dns_array); + + out: + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_get_ip4_config (MMModemIcera *self, + MMModemIp4Fn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + char *command; + MMAtSerialPort *primary; + + info = mm_callback_info_new_full (MM_MODEM (self), + ip4_config_invoke, + G_CALLBACK (callback), + user_data); + + primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + command = g_strdup_printf ("%%IPDPADDR=%d", _get_cid (self)); + mm_at_serial_port_queue_command (primary, command, 3, get_ip4_config_done, info); + g_free (command); +} + +/****************************************************************/ + +static const char * +get_string_property (GHashTable *properties, const char *name) +{ + GValue *value; + + value = (GValue *) g_hash_table_lookup (properties, name); + if (value && G_VALUE_HOLDS_STRING (value)) + return g_value_get_string (value); + return NULL; +} + +void +mm_modem_icera_simple_connect (MMModemIcera *self, GHashTable *properties) +{ + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + + g_free (priv->username); + priv->username = g_strdup (get_string_property (properties, "username")); + g_free (priv->password); + priv->password = g_strdup (get_string_property (properties, "password")); +} + +/****************************************************************/ + +void +mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self, + MMAtSerialPort *port) +{ + GRegex *regex; + + /* %NWSTATE: ,,,, */ + regex = g_regex_new ("\\r\\n%NWSTATE:\\s*(\\d+),(\\d+),([^,]*),([^,]*),(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + mm_at_serial_port_add_unsolicited_msg_handler (port, regex, nwstate_changed, self, NULL); + g_regex_unref (regex); + + regex = g_regex_new ("\\r\\n\\+PACSP(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + mm_at_serial_port_add_unsolicited_msg_handler (port, regex, pacsp_received, self, NULL); + g_regex_unref (regex); + + /* %IPDPACT: ,,0 */ + regex = g_regex_new ("\\r\\n%IPDPACT:\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + mm_at_serial_port_add_unsolicited_msg_handler (port, regex, connection_enabled, self, NULL); + g_regex_unref (regex); +} + +void +mm_modem_icera_change_unsolicited_messages (MMModemIcera *self, gboolean enabled) +{ + MMAtSerialPort *primary; + + primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + mm_at_serial_port_queue_command (primary, enabled ? "%NWSTATE=1" : "%NWSTATE=0", 3, NULL, NULL); +} + +/****************************************************************/ + +static void +is_icera_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + + info->error = mm_modem_check_removed (info->modem, error); + if (!info->error) + mm_callback_info_set_result (info, GUINT_TO_POINTER (TRUE), NULL); + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_is_icera (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data) +{ + MMAtSerialPort *port; + MMCallbackInfo *info; + + info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + mm_at_serial_port_queue_command (port, "%IPSYS?", 5, is_icera_done, info); +} + +/****************************************************************/ + +void +mm_modem_icera_prepare (MMModemIcera *self) +{ + self->priv = g_malloc0 (sizeof (MMModemIceraPrivate)); +} + +void +mm_modem_icera_cleanup (MMModemIcera *self) +{ + MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self); + + /* Clear the pending connection if necessary */ + connect_pending_done (self); + + g_free (priv->username); + g_free (priv->password); + + memset (priv, 0, sizeof (MMModemIceraPrivate)); + g_free (priv); +} + +static void +mm_modem_icera_init (gpointer g_iface) +{ + static gboolean initialized = FALSE; + + if (!initialized) { + initialized = TRUE; + } +} + +GType +mm_modem_icera_get_type (void) +{ + static GType icera_type = 0; + + if (!G_UNLIKELY (icera_type)) { + const GTypeInfo icera_info = { + sizeof (MMModemIcera), /* class_size */ + mm_modem_icera_init, /* base_init */ + NULL, /* base_finalize */ + NULL, + NULL, /* class_finalize */ + NULL, /* class_data */ + 0, + 0, /* n_preallocs */ + NULL + }; + + icera_type = g_type_register_static (G_TYPE_INTERFACE, + "MMModemIcera", + &icera_info, 0); + + g_type_interface_add_prerequisite (icera_type, MM_TYPE_MODEM); + } + + return icera_type; +} + diff --git a/plugins/mm-modem-icera.h b/plugins/mm-modem-icera.h new file mode 100644 index 0000000..71258d2 --- /dev/null +++ b/plugins/mm-modem-icera.h @@ -0,0 +1,89 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2010 Red Hat, Inc. + */ + +/****************************************** + * Generic utilities for Icera-based modems + ******************************************/ + +#ifndef MM_MODEM_ICERA_H +#define MM_MODEM_ICERA_H + +#include + +#include "mm-modem-gsm.h" +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_ICERA (mm_modem_icera_get_type ()) +#define MM_MODEM_ICERA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_ICERA, MMModemIcera)) +#define MM_IS_MODEM_ICERA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ICERA)) +#define MM_MODEM_ICERA_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_ICERA, MMModemIcera)) + +typedef struct _MMModemIceraPrivate MMModemIceraPrivate; + +typedef struct _MMModemIcera MMModemIcera; + +struct _MMModemIcera { + GTypeInterface g_iface; + + MMModemIceraPrivate *priv; +}; + +GType mm_modem_icera_get_type (void); + +void mm_modem_icera_prepare (MMModemIcera *self); + +void mm_modem_icera_cleanup (MMModemIcera *self); + +void mm_modem_icera_get_allowed_mode (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data); + +void mm_modem_icera_set_allowed_mode (MMModemIcera *self, + MMModemGsmAllowedMode mode, + MMModemFn callback, + gpointer user_data); + +void mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self, + MMAtSerialPort *port); + +void mm_modem_icera_change_unsolicited_messages (MMModemIcera *self, + gboolean enabled); + +void mm_modem_icera_get_access_technology (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data); + +void mm_modem_icera_is_icera (MMModemIcera *self, + MMModemUIntFn callback, + gpointer user_data); + +void mm_modem_icera_do_disconnect (MMGenericGsm *gsm, + gint cid, + MMModemFn callback, + gpointer user_data); + +void mm_modem_icera_simple_connect (MMModemIcera *self, GHashTable *properties); + +void mm_modem_icera_do_connect (MMModemIcera *self, + const char *number, + MMModemFn callback, + gpointer user_data); + +void mm_modem_icera_get_ip4_config (MMModemIcera *self, + MMModemIp4Fn callback, + gpointer user_data); + +#endif /* MM_MODEM_ICERA_H */ + diff --git a/plugins/mm-modem-linktop.c b/plugins/mm-modem-linktop.c new file mode 100644 index 0000000..923c219 --- /dev/null +++ b/plugins/mm-modem-linktop.c @@ -0,0 +1,208 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include "mm-modem-linktop.h" +#include "mm-serial-parsers.h" +#include "mm-errors.h" + +#define LINKTOP_NETWORK_MODE_ANY 1 +#define LINKTOP_NETWORK_MODE_2G 5 +#define LINKTOP_NETWORK_MODE_3G 6 + +static void modem_init (MMModem *modem_class); + +G_DEFINE_TYPE_EXTENDED (MMModemLinktop, mm_modem_linktop, MM_TYPE_GENERIC_GSM, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)) + + +MMModem * +mm_modem_linktop_new (const char *device, + const char *driver, + const char *plugin, + guint32 vendor, + guint32 product) +{ + g_return_val_if_fail (device != NULL, NULL); + g_return_val_if_fail (driver != NULL, NULL); + g_return_val_if_fail (plugin != NULL, NULL); + + return MM_MODEM (g_object_new (MM_TYPE_MODEM_LINKTOP, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, + NULL)); +} + +static gboolean +grab_port (MMModem *modem, + const char *subsys, + const char *name, + MMPortType suggested_type, + gpointer user_data, + GError **error) +{ + MMGenericGsm *gsm = MM_GENERIC_GSM (modem); + MMPortType ptype = MM_PORT_TYPE_IGNORED; + MMPort *port = NULL; + + if (suggested_type == MM_PORT_TYPE_UNKNOWN) { + if (!mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY)) + ptype = MM_PORT_TYPE_PRIMARY; + else if (!mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_SECONDARY)) + ptype = MM_PORT_TYPE_SECONDARY; + } else + ptype = suggested_type; + + port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error); + if (port && MM_IS_AT_SERIAL_PORT (port)) { + mm_at_serial_port_set_response_parser (MM_AT_SERIAL_PORT (port), + mm_serial_parser_v1_e1_parse, + mm_serial_parser_v1_e1_new (), + mm_serial_parser_v1_e1_destroy); + } + + return !!port; +} + +static int +linktop_parse_allowed_mode (MMModemGsmAllowedMode network_mode) +{ + switch (network_mode) { + case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY: + return LINKTOP_NETWORK_MODE_2G; + case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY: + return LINKTOP_NETWORK_MODE_3G; + default: + return LINKTOP_NETWORK_MODE_ANY; + } +} + +static void +linktop_set_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) + info->error = g_error_copy (error); + + mm_callback_info_schedule (info); +} + +static void +set_allowed_mode (MMGenericGsm *gsm, + MMModemGsmAllowedMode mode, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + char *command; + MMAtSerialPort *port; + + info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (gsm, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + command = g_strdup_printf ("+CFUN=%d", linktop_parse_allowed_mode (mode)); + mm_at_serial_port_queue_command (port, command, 3, linktop_set_allowed_mode_done, info); + g_free (command); +} + +static void +get_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + gboolean parsed = FALSE; + + if (error) + info->error = g_error_copy (error); + else if (!g_str_has_prefix (response->str, "CFUN: ")) { + MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; + int a; + + a = atoi (response->str + 6); + if (a == LINKTOP_NETWORK_MODE_2G) + mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY; + else if (a == LINKTOP_NETWORK_MODE_3G) + mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY; + + mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL); + parsed = TRUE; + } + + if (!error && !parsed) + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Could not parse allowed mode results"); + + mm_callback_info_schedule (info); +} + +static void +get_allowed_mode (MMGenericGsm *gsm, + MMModemUIntFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (gsm, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + mm_at_serial_port_queue_command (port, "+CFUN?", 3, get_allowed_mode_done, info); +} + +/*****************************************************************************/ + +static void +modem_init (MMModem *modem_class) +{ + modem_class->grab_port = grab_port; +} + +static void +mm_modem_linktop_init (MMModemLinktop *self) +{ +} + +static void +mm_modem_linktop_class_init (MMModemLinktopClass *klass) +{ + MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass); + + gsm_class->get_allowed_mode = get_allowed_mode; + gsm_class->set_allowed_mode = set_allowed_mode; +} + diff --git a/plugins/mm-modem-linktop.h b/plugins/mm-modem-linktop.h new file mode 100644 index 0000000..4b7153e --- /dev/null +++ b/plugins/mm-modem-linktop.h @@ -0,0 +1,45 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 Red Hat, Inc. + */ + +#ifndef MM_MODEM_LINKTOP_H +#define MM_MODEM_LINKTOP_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_LINKTOP (mm_modem_linktop_get_type ()) +#define MM_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_LINKTOP, MMModemLinktop)) +#define MM_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_LINKTOP, MMModemLinktopClass)) +#define MM_IS_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_LINKTOP)) +#define MM_IS_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_LINKTOP)) +#define MM_MODEM_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_LINKTOP, MMModemLinktopClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemLinktop; + +typedef struct { + MMGenericGsmClass parent; +} MMModemLinktopClass; + +GType mm_modem_linktop_get_type (void); + +MMModem *mm_modem_linktop_new (const char *data, + const char *driver, + const char *plugin, + guint32 vendor, + guint32 product); + +#endif /* MM_MODEM_LINKTOP_H */ diff --git a/plugins/mm-modem-longcheer-gsm.c b/plugins/mm-modem-longcheer-gsm.c index 62980f7..33763e2 100644 --- a/plugins/mm-modem-longcheer-gsm.c +++ b/plugins/mm-modem-longcheer-gsm.c @@ -30,7 +30,9 @@ G_DEFINE_TYPE (MMModemLongcheerGsm, mm_modem_longcheer_gsm, MM_TYPE_GENERIC_GSM) MMModem * mm_modem_longcheer_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -40,6 +42,8 @@ mm_modem_longcheer_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-longcheer-gsm.h b/plugins/mm-modem-longcheer-gsm.h index 5383c52..e9abfbe 100644 --- a/plugins/mm-modem-longcheer-gsm.h +++ b/plugins/mm-modem-longcheer-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_longcheer_gsm_get_type (void); MMModem *mm_modem_longcheer_gsm_new (const char *device, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_LONGCHEER_H */ diff --git a/plugins/mm-modem-mbm.c b/plugins/mm-modem-mbm.c index 7f6bc9c..9303453 100644 --- a/plugins/mm-modem-mbm.c +++ b/plugins/mm-modem-mbm.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2008 - 2010 Ericsson AB - * Copyright (C) 2009 - 2010 Red Hat, Inc. + * Copyright (C) 2009 - 2011 Red Hat, Inc. * * Author: Per Hallsmark * Bjorn Runaker @@ -31,6 +31,7 @@ #include "mm-modem-gsm-card.h" #include "mm-errors.h" #include "mm-callback-info.h" +#include "mm-log.h" static void modem_init (MMModem *modem_class); static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class); @@ -49,8 +50,6 @@ G_DEFINE_TYPE_EXTENDED (MMModemMbm, mm_modem_mbm, MM_TYPE_GENERIC_GSM, 0, #define MBM_E2NAP_CONNECTED 1 #define MBM_E2NAP_CONNECTING 2 -#define MBM_SIGNAL_INDICATOR 2 - #define MBM_NETWORK_MODE_ANY 1 #define MBM_NETWORK_MODE_2G 5 #define MBM_NETWORK_MODE_3G 6 @@ -82,7 +81,9 @@ mbm_modem_authenticate (MMModemMbm *self, MMModem * mm_modem_mbm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -93,6 +94,8 @@ mm_modem_mbm_new (const char *device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_DHCP, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -349,7 +352,6 @@ mbm_enable_done (MMAtSerialPort *port, MMCallbackInfo *info = (MMCallbackInfo *) user_data; /* Start unsolicited signal strength and access technology responses */ - mm_at_serial_port_queue_command (port, "+CMER=3,0,0,1", 3, NULL, NULL); mm_at_serial_port_queue_command (port, "*ERINFO=1", 3, NULL, NULL); mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info); @@ -409,7 +411,7 @@ mbm_emrdy_done (MMAtSerialPort *port, MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem); if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) - g_warning ("%s: timed out waiting for EMRDY response.", __func__); + mm_warn ("timed out waiting for EMRDY response."); else priv->have_emrdy = TRUE; @@ -473,7 +475,7 @@ disable (MMModem *modem, g_assert (primary); /* Turn off unsolicited responses */ - mm_at_serial_port_queue_command (primary, "+CMER=0;*ERINFO=0", 5, disable_unsolicited_done, info); + mm_at_serial_port_queue_command (primary, "*ERINFO=0", 5, disable_unsolicited_done, info); } static void @@ -508,6 +510,24 @@ do_disconnect (MMGenericGsm *gsm, MM_GENERIC_GSM_CLASS (mm_modem_mbm_parent_class)->do_disconnect (gsm, cid, callback, user_data); } +static void +reset (MMModem *modem, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + info = mm_callback_info_new (MM_MODEM (modem), callback, user_data); + + /* Ensure we have a usable port to use for the command */ + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); + if (port) + mm_at_serial_port_queue_command (port, "*E2RESET", 3, NULL, NULL); + + mm_callback_info_schedule (info); +} + static void factory_reset_done (MMAtSerialPort *port, GString *response, @@ -579,29 +599,6 @@ mbm_pacsp_received (MMAtSerialPort *port, return; } -static void -mbm_ciev_received (MMAtSerialPort *port, - GMatchInfo *info, - gpointer user_data) -{ - int quality = 0, ind = 0; - char *str; - - str = g_match_info_fetch (info, 1); - if (str) - ind = atoi (str); - g_free (str); - - if (ind == MBM_SIGNAL_INDICATOR) { - str = g_match_info_fetch (info, 2); - if (str) { - quality = atoi (str); - mm_generic_gsm_update_signal_quality (MM_GENERIC_GSM (user_data), quality * 20); - } - g_free (str); - } -} - static void mbm_do_connect_done (MMModemMbm *self, gboolean success) { @@ -636,16 +633,16 @@ mbm_e2nap_received (MMAtSerialPort *port, g_free (str); if (MBM_E2NAP_DISCONNECTED == state) { - g_debug ("%s: disconnected", __func__); + mm_dbg ("disconnected"); mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE); } else if (MBM_E2NAP_CONNECTED == state) { - g_debug ("%s: connected", __func__); + mm_dbg ("connected"); mbm_do_connect_done (MM_MODEM_MBM (user_data), TRUE); } else if (MBM_E2NAP_CONNECTING == state) - g_debug("%s: connecting", __func__); + mm_dbg ("connecting"); else { /* Should not happen */ - g_debug("%s: unhandled E2NAP state %d", __func__, state); + mm_dbg ("unhandled E2NAP state %d", state); mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE); } } @@ -724,18 +721,15 @@ mbm_auth_done (MMSerialPort *port, MMCallbackInfo *info = (MMCallbackInfo *) user_data; MMGenericGsm *modem = MM_GENERIC_GSM (info->modem); char *command; - guint32 cid; if (error) { mm_generic_gsm_connect_complete (modem, error, info); return; } - cid = mm_generic_gsm_get_cid (modem); - mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port), "AT*E2NAP=1", 3, NULL, NULL); - command = g_strdup_printf ("AT*ENAP=1,%d", cid); + command = g_strdup_printf ("AT*ENAP=1,%d", mm_generic_gsm_get_cid (modem)); mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port), command, 3, enap_done, user_data); g_free (command); } @@ -818,7 +812,7 @@ send_epin_done (MMAtSerialPort *port, else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PUK2)) sscanf (response->str, "*EPIN: %*d, %*d, %*d, %d", &attempts_left); else { - g_debug ("%s: unhandled pin type '%s'", __func__, pin_type); + mm_dbg ("unhandled pin type '%s'", pin_type); info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type"); } @@ -845,7 +839,7 @@ mbm_get_unlock_retries (MMModemGsmCard *modem, char *command; MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); - g_debug ("%s: pin type '%s'", __func__, pin_type); + mm_dbg ("pin type '%s'", pin_type); /* Ensure we have a usable port to use for the command */ port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); @@ -922,10 +916,6 @@ grab_port (MMModem *modem, mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, mbm_pacsp_received, modem, NULL); g_regex_unref (regex); - regex = g_regex_new ("\\r\\n\\+CIEV: (\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, mbm_ciev_received, modem, NULL); - g_regex_unref (regex); - /* also consume unsolicited mbm messages we are not interested in them - see LP: #416418 */ regex = g_regex_new ("\\R\\*ESTKSMENU:.*\\R", G_REGEX_RAW | G_REGEX_OPTIMIZE | G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, G_REGEX_MATCH_NEWLINE_CRLF, NULL); mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); @@ -969,6 +959,7 @@ modem_init (MMModem *modem_class) modem_class->grab_port = grab_port; modem_class->disable = disable; modem_class->connect = do_connect; + modem_class->reset = reset; modem_class->factory_reset = factory_reset; } diff --git a/plugins/mm-modem-mbm.h b/plugins/mm-modem-mbm.h index db0f627..bb1c2ff 100644 --- a/plugins/mm-modem-mbm.h +++ b/plugins/mm-modem-mbm.h @@ -43,6 +43,8 @@ GType mm_modem_mbm_get_type (void); MMModem *mm_modem_mbm_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_MBM_H */ diff --git a/plugins/mm-modem-moto-c-gsm.c b/plugins/mm-modem-moto-c-gsm.c index 5910ff2..cd7b4ed 100644 --- a/plugins/mm-modem-moto-c-gsm.c +++ b/plugins/mm-modem-moto-c-gsm.c @@ -35,7 +35,9 @@ G_DEFINE_TYPE_EXTENDED (MMModemMotoCGsm, mm_modem_moto_c_gsm, MM_TYPE_GENERIC_GS MMModem * mm_modem_moto_c_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -45,6 +47,8 @@ mm_modem_moto_c_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-moto-c-gsm.h b/plugins/mm-modem-moto-c-gsm.h index eb1dad1..a8ddd6d 100644 --- a/plugins/mm-modem-moto-c-gsm.h +++ b/plugins/mm-modem-moto-c-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_moto_c_gsm_get_type (void); MMModem *mm_modem_moto_c_gsm_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_MOTO_C_GSM_H */ diff --git a/plugins/mm-modem-nokia.c b/plugins/mm-modem-nokia.c index eb90287..56b8c91 100644 --- a/plugins/mm-modem-nokia.c +++ b/plugins/mm-modem-nokia.c @@ -30,7 +30,9 @@ G_DEFINE_TYPE_EXTENDED (MMModemNokia, mm_modem_nokia, MM_TYPE_GENERIC_GSM, 0, MMModem * mm_modem_nokia_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -40,6 +42,8 @@ mm_modem_nokia_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -54,6 +58,7 @@ grab_port (MMModem *modem, MMGenericGsm *gsm = MM_GENERIC_GSM (modem); MMPortType ptype = MM_PORT_TYPE_IGNORED; MMPort *port = NULL; + gulong send_delay = 5000; if (suggested_type == MM_PORT_TYPE_UNKNOWN) { if (!mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY)) @@ -71,6 +76,9 @@ grab_port (MMModem *modem, mm_serial_parser_v1_e1_destroy); } + /* N900 appears to need longer delay between port bytes */ + g_object_set (G_OBJECT (port), MM_SERIAL_PORT_SEND_DELAY, send_delay, NULL); + return !!port; } diff --git a/plugins/mm-modem-nokia.h b/plugins/mm-modem-nokia.h index 0e24619..0873d2d 100644 --- a/plugins/mm-modem-nokia.h +++ b/plugins/mm-modem-nokia.h @@ -38,6 +38,8 @@ GType mm_modem_nokia_get_type (void); MMModem *mm_modem_nokia_new (const char *data, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_NOKIA_H */ diff --git a/plugins/mm-modem-novatel-cdma.c b/plugins/mm-modem-novatel-cdma.c index 64ee15f..6b8c4aa 100644 --- a/plugins/mm-modem-novatel-cdma.c +++ b/plugins/mm-modem-novatel-cdma.c @@ -21,6 +21,8 @@ #include #include "mm-modem-novatel-cdma.h" +#include "mm-modem-helpers.h" +#include "libqcdm/src/commands.h" #include "mm-errors.h" #include "mm-callback-info.h" @@ -35,7 +37,9 @@ mm_modem_novatel_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA) + gboolean evdo_revA, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -72,6 +76,8 @@ get_one_qual (const char *reply, const char *tag) { int qual = -1; const char *p; + long int dbm; + gboolean success = FALSE; p = strstr (reply, tag); if (!p) @@ -83,17 +89,26 @@ get_one_qual (const char *reply, const char *tag) /* Skip spaces */ while (isspace (*p)) p++; - if (*p == '-') { - long int dbm; - - errno = 0; - dbm = strtol (p, NULL, 10); - if (dbm < 0 && errno == 0) { - dbm = CLAMP (dbm, -113, -51); - qual = 100 - ((dbm + 51) * 100 / (-113 + 51)); + + errno = 0; + dbm = strtol (p, NULL, 10); + if (errno == 0) { + if (*p == '-') { + /* Some cards appear to use RX0/RX1 and output RSSI in negative dBm */ + if (dbm < 0) + success = TRUE; + } else if (isdigit (*p) && (dbm > 0) && (dbm < 115)) { + /* S720 appears to use "1x RSSI" and print RSSI in dBm without '-' */ + dbm *= -1; + success = TRUE; } } + if (success) { + dbm = CLAMP (dbm, -113, -51); + qual = 100 - ((dbm + 51) * 100 / (-113 + 51)); + } + return qual; } @@ -122,6 +137,8 @@ get_rssi_done (MMAtSerialPort *port, /* Parse the signal quality */ qual = get_one_qual (response->str, "RX0="); + if (qual < 0) + qual = get_one_qual (response->str, "1x RSSI="); if (qual < 0) qual = get_one_qual (response->str, "RX1="); @@ -164,6 +181,115 @@ get_signal_quality (MMModemCdma *modem, /*****************************************************************************/ +static void +parse_modem_snapshot (MMCallbackInfo *info, QCDMResult *result) +{ + MMModemCdmaRegistrationState evdo_state, cdma1x_state, new_state; + guint8 eri = 0; + + g_return_if_fail (info != NULL); + g_return_if_fail (result != NULL); + + evdo_state = mm_generic_cdma_query_reg_state_get_callback_evdo_state (info); + cdma1x_state = mm_generic_cdma_query_reg_state_get_callback_1x_state (info); + + /* Roaming? */ + if (qcdm_result_get_uint8 (result, QCDM_CMD_NW_SUBSYS_MODEM_SNAPSHOT_CDMA_ITEM_ERI, &eri)) { + char *str; + gboolean roaming = FALSE; + + str = g_strdup_printf ("%u", eri); + if (mm_cdma_parse_eri (str, &roaming, NULL, NULL)) { + new_state = roaming ? MM_MODEM_CDMA_REGISTRATION_STATE_HOME : MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; + if (cdma1x_state != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) + mm_generic_cdma_query_reg_state_set_callback_1x_state (info, new_state); + if (evdo_state != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) + mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, new_state); + } + g_free (str); + } +} + +static void +reg_nwsnap_6500_cb (MMQcdmSerialPort *port, + GByteArray *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + QCDMResult *result; + + if (!error) { + result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, NULL); + if (result) { + parse_modem_snapshot (info, result); + qcdm_result_unref (result); + } + } + mm_callback_info_schedule (info); +} + +static void +reg_nwsnap_6800_cb (MMQcdmSerialPort *port, + GByteArray *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + QCDMResult *result; + GByteArray *nwsnap; + + if (error) + goto done; + + /* Parse the response */ + result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, &info->error); + if (!result) { + g_clear_error (&info->error); + + /* Try for MSM6500 */ + nwsnap = g_byte_array_sized_new (25); + nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6500, NULL); + g_assert (nwsnap->len); + mm_qcdm_serial_port_queue_command (port, nwsnap, 3, reg_nwsnap_6500_cb, info); + return; + } + + parse_modem_snapshot (info, result); + qcdm_result_unref (result); + +done: + mm_callback_info_schedule (info); +} + +static void +query_registration_state (MMGenericCdma *cdma, + MMModemCdmaRegistrationState cur_cdma_state, + MMModemCdmaRegistrationState cur_evdo_state, + MMModemCdmaRegistrationStateFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMQcdmSerialPort *port; + GByteArray *nwsnap; + + info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, cur_cdma_state, cur_evdo_state, callback, user_data); + + port = mm_generic_cdma_get_best_qcdm_port (cdma, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + /* Try MSM6800 first since newer cards use that */ + nwsnap = g_byte_array_sized_new (25); + nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6800, NULL); + g_assert (nwsnap->len); + mm_qcdm_serial_port_queue_command (port, nwsnap, 3, reg_nwsnap_6800_cb, info); +} + +/*****************************************************************************/ + static void modem_cdma_init (MMModemCdma *cdma_class) { @@ -178,6 +304,10 @@ mm_modem_novatel_cdma_init (MMModemNovatelCdma *self) static void mm_modem_novatel_cdma_class_init (MMModemNovatelCdmaClass *klass) { + MMGenericCdmaClass *generic_class = MM_GENERIC_CDMA_CLASS (klass); + mm_modem_novatel_cdma_parent_class = g_type_class_peek_parent (klass); + + generic_class->query_registration_state = query_registration_state; } diff --git a/plugins/mm-modem-novatel-cdma.h b/plugins/mm-modem-novatel-cdma.h index 4d38d8e..c2319ef 100644 --- a/plugins/mm-modem-novatel-cdma.h +++ b/plugins/mm-modem-novatel-cdma.h @@ -40,6 +40,8 @@ MMModem *mm_modem_novatel_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA); + gboolean evdo_revA, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_NOVATEL_CDMA_H */ diff --git a/plugins/mm-modem-novatel-gsm.c b/plugins/mm-modem-novatel-gsm.c index 584156f..64a81bd 100644 --- a/plugins/mm-modem-novatel-gsm.c +++ b/plugins/mm-modem-novatel-gsm.c @@ -33,7 +33,9 @@ G_DEFINE_TYPE_EXTENDED (MMModemNovatelGsm, mm_modem_novatel_gsm, MM_TYPE_GENERIC MMModem * mm_modem_novatel_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -43,6 +45,8 @@ mm_modem_novatel_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-novatel-gsm.h b/plugins/mm-modem-novatel-gsm.h index c2e1138..12b0060 100644 --- a/plugins/mm-modem-novatel-gsm.h +++ b/plugins/mm-modem-novatel-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_novatel_gsm_get_type (void); MMModem *mm_modem_novatel_gsm_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_NOVATEL_GSM_H */ diff --git a/plugins/mm-modem-option.c b/plugins/mm-modem-option.c index ac04b0b..b15e704 100644 --- a/plugins/mm-modem-option.c +++ b/plugins/mm-modem-option.c @@ -36,7 +36,9 @@ typedef struct { MMModem * mm_modem_option_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -46,6 +48,8 @@ mm_modem_option_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-option.h b/plugins/mm-modem-option.h index 4e88607..3af9b1e 100644 --- a/plugins/mm-modem-option.h +++ b/plugins/mm-modem-option.h @@ -38,6 +38,8 @@ GType mm_modem_option_get_type (void); MMModem *mm_modem_option_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_OPTION_H */ diff --git a/plugins/mm-modem-sierra-cdma.c b/plugins/mm-modem-sierra-cdma.c index fc62bf6..1168c83 100644 --- a/plugins/mm-modem-sierra-cdma.c +++ b/plugins/mm-modem-sierra-cdma.c @@ -51,7 +51,9 @@ mm_modem_sierra_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA) + gboolean evdo_revA, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -63,6 +65,8 @@ mm_modem_sierra_cdma_new (const char *device, MM_MODEM_PLUGIN, plugin, MM_GENERIC_CDMA_EVDO_REV0, evdo_rev0, MM_GENERIC_CDMA_EVDO_REVA, evdo_revA, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-sierra-cdma.h b/plugins/mm-modem-sierra-cdma.h index 9111b73..a33b1bc 100644 --- a/plugins/mm-modem-sierra-cdma.h +++ b/plugins/mm-modem-sierra-cdma.h @@ -40,6 +40,8 @@ MMModem *mm_modem_sierra_cdma_new (const char *device, const char *driver, const char *plugin, gboolean evdo_rev0, - gboolean evdo_revA); + gboolean evdo_revA, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_SIERRA_CDMA_H */ diff --git a/plugins/mm-modem-sierra-gsm.c b/plugins/mm-modem-sierra-gsm.c index bf5df31..d4636d7 100644 --- a/plugins/mm-modem-sierra-gsm.c +++ b/plugins/mm-modem-sierra-gsm.c @@ -15,30 +15,39 @@ */ #include +#include #include #include #include #include #include "mm-modem-sierra-gsm.h" #include "mm-errors.h" +#include "mm-modem-simple.h" #include "mm-callback-info.h" #include "mm-modem-helpers.h" static void modem_init (MMModem *modem_class); +static void modem_simple_init (MMModemSimple *class); G_DEFINE_TYPE_EXTENDED (MMModemSierraGsm, mm_modem_sierra_gsm, MM_TYPE_GENERIC_GSM, 0, - G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_SIMPLE, modem_simple_init)) #define MM_MODEM_SIERRA_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_SIERRA_GSM, MMModemSierraGsmPrivate)) typedef struct { guint enable_wait_id; + gboolean has_net; + char *username; + char *password; } MMModemSierraGsmPrivate; MMModem * mm_modem_sierra_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -48,6 +57,8 @@ mm_modem_sierra_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -238,6 +249,85 @@ get_access_technology (MMGenericGsm *modem, mm_at_serial_port_queue_command (port, "*CNTI=0", 3, get_act_request_done, info); } +static void +get_sim_iccid_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + const char *p; + char buf[21]; + int i; + + if (error) { + info->error = g_error_copy (error); + goto done; + } + + p = mm_strip_tag (response->str, "!ICCID:"); + if (!p) { + info->error = g_error_new_literal (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Failed to parse !ICCID response"); + goto done; + } + + memset (buf, 0, sizeof (buf)); + for (i = 0; i < 20; i++) { + if (!isdigit (p[i]) && (p[i] != 'F') && (p[i] == 'f')) { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "CRSM ICCID response contained invalid character '%c'", + p[i]); + goto done; + } + if (p[i] == 'F' || p[i] == 'f') { + buf[i] = 0; + break; + } + buf[i] = p[i]; + } + + if (i == 19 || i == 20) + mm_callback_info_set_result (info, g_strdup (buf), g_free); + else { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Invalid +CRSM ICCID response size (was %d, expected 19 or 20)", + i); + } + +done: + mm_serial_port_close (MM_SERIAL_PORT (port)); + mm_callback_info_schedule (info); +} + +static void +get_sim_iccid (MMGenericGsm *modem, + MMModemStringFn callback, + gpointer callback_data) +{ + MMAtSerialPort *port; + MMCallbackInfo *info; + GError *error = NULL; + + port = mm_generic_gsm_get_best_at_port (modem, &error); + if (!port) + goto error; + + if (!mm_serial_port_open (MM_SERIAL_PORT (port), &error)) + goto error; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, callback_data); + mm_at_serial_port_queue_command (port, "!ICCID?", 3, get_sim_iccid_done, info); + return; + +error: + callback (MM_MODEM (modem), NULL, error, callback_data); + g_clear_error (&error); +} + /*****************************************************************************/ /* Modem class override functions */ /*****************************************************************************/ @@ -302,25 +392,233 @@ grab_port (MMModem *modem, port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error); - if (port && MM_IS_AT_SERIAL_PORT (port)) { - GRegex *regex; + if (port) { + if (MM_IS_AT_SERIAL_PORT (port)) { + GRegex *regex; - g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL); + g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL); - regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); - g_regex_unref (regex); + regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); + g_regex_unref (regex); + } else if (mm_port_get_subsys (port) == MM_PORT_SUBSYS_NET) { + MM_MODEM_SIERRA_GSM_GET_PRIVATE (gsm)->has_net = TRUE; + g_object_set (G_OBJECT (gsm), MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_DHCP, NULL); + } } return !!port; } +static void +ppp_connect_done (MMModem *modem, GError *error, gpointer user_data) +{ + MMCallbackInfo *info = user_data; + + info->error = mm_modem_check_removed (modem, error); + mm_callback_info_schedule (info); +} + +static void +net_activate_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info); +} + + +static void +auth_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + gint cid; + char *command; + + if (error) { + info->error = g_error_copy (error); + mm_callback_info_schedule (info); + return; + } + + cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (info->modem)); + g_warn_if_fail (cid >= 0); + + /* Activate data on the net port */ + command = g_strdup_printf ("!SCACT=1,%d", cid); + mm_at_serial_port_queue_command (port, command, 3, net_activate_done, info); + g_free (command); +} + +static void +ps_attach_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + MMModemSierraGsmPrivate *priv; + MMModem *parent_modem_iface; + const char *number; + + if (error) { + info->error = g_error_copy (error); + mm_callback_info_schedule (info); + return; + } + + priv = MM_MODEM_SIERRA_GSM_GET_PRIVATE (info->modem); + if (priv->has_net) { + gint cid; + char *command; + + /* If we have a net interface, we don't do PPP */ + + cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (info->modem)); + g_warn_if_fail (cid >= 0); + + if (!priv->username || !priv->password) + command = g_strdup_printf ("$QCPDPP=%d,0", cid); + else { + command = g_strdup_printf ("$QCPDPP=%d,1,\"%s\",\"%s\"", + cid, + priv->password ? priv->password : "", + priv->username ? priv->username : ""); + + } + + mm_at_serial_port_queue_command (port, command, 3, auth_done, info); + g_free (command); + } else { + /* We've got a PS attach, chain up to parent for the connect */ + number = mm_callback_info_get_data (info, "number"); + parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem)); + parent_modem_iface->connect (info->modem, number, ppp_connect_done, info); + } +} + +static void +do_connect (MMModem *modem, + const char *number, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE); + + info = mm_callback_info_new (modem, callback, user_data); + mm_callback_info_set_data (info, "number", g_strdup (number), g_free); + + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + /* Try to initiate a PS attach. Some Sierra modems can get into a + * state where if there is no PS attach when dialing, the next time + * the modem tries to connect it won't ever register with the network. + */ + mm_at_serial_port_queue_command (port, "+CGATT=1", 10, ps_attach_done, info); +} + +static void +clear_user_pass (MMModemSierraGsm *self) +{ + MMModemSierraGsmPrivate *priv = MM_MODEM_SIERRA_GSM_GET_PRIVATE (self); + + g_free (priv->username); + priv->username = NULL; + g_free (priv->password); + priv->username = NULL; +} + +static void +do_disconnect (MMGenericGsm *gsm, + gint cid, + MMModemFn callback, + gpointer user_data) +{ + clear_user_pass (MM_MODEM_SIERRA_GSM (gsm)); + + if (MM_MODEM_SIERRA_GSM_GET_PRIVATE (gsm)->has_net) { + MMAtSerialPort *primary; + char *command; + + primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + /* If we have a net interface, deactivate it */ + command = g_strdup_printf ("!SCACT=0,%d", cid); + mm_at_serial_port_queue_command (primary, command, 3, NULL, NULL); + g_free (command); + } + + MM_GENERIC_GSM_CLASS (mm_modem_sierra_gsm_parent_class)->do_disconnect (gsm, cid, callback, user_data); +} + +/*****************************************************************************/ +/* Simple Modem class override functions */ +/*****************************************************************************/ + +static char * +simple_dup_string_property (GHashTable *properties, const char *name, GError **error) +{ + GValue *value; + + value = (GValue *) g_hash_table_lookup (properties, name); + if (!value) + return NULL; + + if (G_VALUE_HOLDS_STRING (value)) + return g_value_dup_string (value); + + g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Invalid property type for '%s': %s (string expected)", + name, G_VALUE_TYPE_NAME (value)); + + return NULL; +} + +static void +simple_connect (MMModemSimple *simple, + GHashTable *properties, + MMModemFn callback, + gpointer user_data) +{ + MMModemSierraGsmPrivate *priv = MM_MODEM_SIERRA_GSM_GET_PRIVATE (simple); + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemSimple *parent_iface; + + clear_user_pass (MM_MODEM_SIERRA_GSM (simple)); + priv->username = simple_dup_string_property (properties, "username", &info->error); + priv->password = simple_dup_string_property (properties, "password", &info->error); + + parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple)); + parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info); +} + /*****************************************************************************/ static void modem_init (MMModem *modem_class) { modem_class->grab_port = grab_port; + modem_class->connect = do_connect; +} + +static void +modem_simple_init (MMModemSimple *class) +{ + class->connect = simple_connect; } static void @@ -335,6 +633,8 @@ dispose (GObject *object) if (priv->enable_wait_id) g_source_remove (priv->enable_wait_id); + + clear_user_pass (MM_MODEM_SIERRA_GSM (object)); } static void @@ -351,5 +651,7 @@ mm_modem_sierra_gsm_class_init (MMModemSierraGsmClass *klass) gsm_class->set_allowed_mode = set_allowed_mode; gsm_class->get_allowed_mode = get_allowed_mode; gsm_class->get_access_technology = get_access_technology; + gsm_class->get_sim_iccid = get_sim_iccid; + gsm_class->do_disconnect = do_disconnect; } diff --git a/plugins/mm-modem-sierra-gsm.h b/plugins/mm-modem-sierra-gsm.h index dd84b30..8f2391d 100644 --- a/plugins/mm-modem-sierra-gsm.h +++ b/plugins/mm-modem-sierra-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_sierra_gsm_get_type (void); MMModem *mm_modem_sierra_gsm_new (const char *device, const char *driver, - const char *plugin_name); + const char *plugin_name, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_SIERRA_GSM_H */ diff --git a/plugins/mm-modem-simtech-gsm.c b/plugins/mm-modem-simtech-gsm.c index 07820b3..4a62694 100644 --- a/plugins/mm-modem-simtech-gsm.c +++ b/plugins/mm-modem-simtech-gsm.c @@ -34,7 +34,9 @@ G_DEFINE_TYPE_EXTENDED (MMModemSimtechGsm, mm_modem_simtech_gsm, MM_TYPE_GENERIC MMModem * mm_modem_simtech_gsm_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -44,6 +46,8 @@ mm_modem_simtech_gsm_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } diff --git a/plugins/mm-modem-simtech-gsm.h b/plugins/mm-modem-simtech-gsm.h index 0ba3c43..85e421c 100644 --- a/plugins/mm-modem-simtech-gsm.h +++ b/plugins/mm-modem-simtech-gsm.h @@ -38,6 +38,8 @@ GType mm_modem_simtech_gsm_get_type (void); MMModem *mm_modem_simtech_gsm_new (const char *device, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_SIMTECH_H */ diff --git a/plugins/mm-modem-x22x-gsm.c b/plugins/mm-modem-x22x-gsm.c new file mode 100644 index 0000000..ff23297 --- /dev/null +++ b/plugins/mm-modem-x22x-gsm.c @@ -0,0 +1,209 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2010 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include "mm-modem-x22x-gsm.h" +#include "mm-at-serial-port.h" +#include "mm-errors.h" +#include "mm-callback-info.h" +#include "mm-modem-helpers.h" + +G_DEFINE_TYPE (MMModemX22xGsm, mm_modem_x22x_gsm, MM_TYPE_GENERIC_GSM) + +MMModem * +mm_modem_x22x_gsm_new (const char *device, + const char *driver, + const char *plugin, + guint32 vendor, + guint32 product) +{ + g_return_val_if_fail (device != NULL, NULL); + g_return_val_if_fail (driver != NULL, NULL); + g_return_val_if_fail (plugin != NULL, NULL); + + return MM_MODEM (g_object_new (MM_TYPE_MODEM_X22X_GSM, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, + NULL)); +} + +/*****************************************************************************/ + +static gboolean +parse_syssel_response (GString *response, + MMModemGsmAllowedMode *out_mode, + GError **error) +{ + GRegex *r; + GMatchInfo *match_info; + char *str; + gint mode = -1; + gboolean success = FALSE; + + g_return_val_if_fail (response != NULL, FALSE); + g_return_val_if_fail (out_mode != NULL, FALSE); + + r = g_regex_new ("\\+SYSSEL:\\s*(\\d),(\\d),(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL); + if (!r) { + g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Internal error parsing mode/tech response"); + return FALSE; + } + + if (!g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, NULL)) { + g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Failed to parse mode/tech response"); + goto out; + } + + str = g_match_info_fetch (match_info, 3); + mode = atoi (str); + g_free (str); + + g_match_info_free (match_info); + + if (mode < 0 || mode > 2) { + g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Failed to parse mode/tech response"); + goto out; + } + + if (out_mode) { + if (mode == 0) + *out_mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; + else if (mode == 1) + *out_mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY; + else if (mode == 2) + *out_mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY; + else + *out_mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; + } + success = TRUE; + +out: + g_regex_unref (r); + return success; +} + +static void +get_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; + + info->error = mm_modem_check_removed (info->modem, error); + if (!info->error) { + parse_syssel_response (response, &mode, &info->error); + mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL); + } + + mm_callback_info_schedule (info); +} + +static void +get_allowed_mode (MMGenericGsm *gsm, + MMModemUIntFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + + info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (gsm, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + mm_at_serial_port_queue_command (port, "+SYSSEL?", 3, get_allowed_mode_done, info); +} + +static void +set_allowed_mode_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + info->error = mm_modem_check_removed (info->modem, error); + mm_callback_info_schedule (info); +} + +static void +set_allowed_mode (MMGenericGsm *gsm, + MMModemGsmAllowedMode mode, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + MMAtSerialPort *port; + char *command = NULL; + + info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (gsm, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + switch (mode) { + case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY: + command = "+SYSSEL=,1,0"; + break; + case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY: + command = "+SYSSEL=,2,0"; + break; + case MM_MODEM_GSM_ALLOWED_MODE_ANY: + default: + command = "+SYSSEL=,0,0"; + break; + } + + mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info); +} + +/*****************************************************************************/ + +static void +mm_modem_x22x_gsm_init (MMModemX22xGsm *self) +{ +} + +static void +mm_modem_x22x_gsm_class_init (MMModemX22xGsmClass *klass) +{ + MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass); + + mm_modem_x22x_gsm_parent_class = g_type_class_peek_parent (klass); + + gsm_class->set_allowed_mode = set_allowed_mode; + gsm_class->get_allowed_mode = get_allowed_mode; +} + diff --git a/plugins/mm-modem-x22x-gsm.h b/plugins/mm-modem-x22x-gsm.h new file mode 100644 index 0000000..61cc14d --- /dev/null +++ b/plugins/mm-modem-x22x-gsm.h @@ -0,0 +1,45 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2010 Red Hat, Inc. + */ + +#ifndef MM_MODEM_X22X_GSM_H +#define MM_MODEM_X22X_GSM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_X22X_GSM (mm_modem_x22x_gsm_get_type ()) +#define MM_MODEM_X22X_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_X22X_GSM, MMModemX22xGsm)) +#define MM_MODEM_X22X_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_X22X_GSM, MMModemX22xGsmClass)) +#define MM_IS_MODEM_X22X_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_X22X_GSM)) +#define MM_IS_MODEM_X22X_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_X22X_GSM)) +#define MM_MODEM_X22X_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_X22X_GSM, MMModemX22xGsmClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemX22xGsm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemX22xGsmClass; + +GType mm_modem_x22x_gsm_get_type (void); + +MMModem *mm_modem_x22x_gsm_new (const char *device, + const char *driver, + const char *plugin, + guint32 vendor, + guint32 product); + +#endif /* MM_MODEM_X22X_H */ diff --git a/plugins/mm-modem-zte.c b/plugins/mm-modem-zte.c index ba8a1db..c447c58 100644 --- a/plugins/mm-modem-zte.c +++ b/plugins/mm-modem-zte.c @@ -24,11 +24,17 @@ #include "mm-errors.h" #include "mm-callback-info.h" #include "mm-modem-helpers.h" +#include "mm-modem-simple.h" +#include "mm-modem-icera.h" static void modem_init (MMModem *modem_class); +static void modem_icera_init (MMModemIcera *icera_class); +static void modem_simple_init (MMModemSimple *simple_class); G_DEFINE_TYPE_EXTENDED (MMModemZte, mm_modem_zte, MM_TYPE_GENERIC_GSM, 0, - G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_ICERA, modem_icera_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_SIMPLE, modem_simple_init)) #define MM_MODEM_ZTE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_ZTE, MMModemZtePrivate)) @@ -36,12 +42,15 @@ typedef struct { gboolean init_retried; guint32 cpms_tries; guint cpms_timeout; + gboolean is_icera; } MMModemZtePrivate; MMModem * mm_modem_zte_new (const char *device, const char *driver, - const char *plugin) + const char *plugin, + guint32 vendor, + guint32 product) { g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); @@ -51,6 +60,8 @@ mm_modem_zte_new (const char *device, MM_MODEM_MASTER_DEVICE, device, MM_MODEM_DRIVER, driver, MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, NULL)); } @@ -145,9 +156,15 @@ get_allowed_mode (MMGenericGsm *gsm, MMModemUIntFn callback, gpointer user_data) { + MMModemZte *self = MM_MODEM_ZTE (gsm); MMCallbackInfo *info; MMAtSerialPort *port; + if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) { + mm_modem_icera_get_allowed_mode (MM_MODEM_ICERA (self), callback, user_data); + return; + } + info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data); port = mm_generic_gsm_get_best_at_port (gsm, &info->error); @@ -179,11 +196,17 @@ set_allowed_mode (MMGenericGsm *gsm, MMModemFn callback, gpointer user_data) { + MMModemZte *self = MM_MODEM_ZTE (gsm); MMCallbackInfo *info; MMAtSerialPort *port; char *command; int cm_mode = 0, pref_acq = 0; + if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) { + mm_modem_icera_set_allowed_mode (MM_MODEM_ICERA (self), mode, callback, user_data); + return; + } + info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); port = mm_generic_gsm_get_best_at_port (gsm, &info->error); @@ -244,16 +267,22 @@ get_act_request_done (MMAtSerialPort *port, } static void -get_access_technology (MMGenericGsm *modem, +get_access_technology (MMGenericGsm *gsm, MMModemUIntFn callback, gpointer user_data) { + MMModemZte *self = MM_MODEM_ZTE (gsm); MMAtSerialPort *port; MMCallbackInfo *info; - info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); + if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) { + mm_modem_icera_get_access_technology (MM_MODEM_ICERA (self), callback, user_data); + return; + } - port = mm_generic_gsm_get_best_at_port (modem, &info->error); + info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (gsm, &info->error); if (!port) { mm_callback_info_schedule (info); return; @@ -262,6 +291,21 @@ get_access_technology (MMGenericGsm *modem, mm_at_serial_port_queue_command (port, "+ZPAS?", 3, get_act_request_done, info); } +static void +do_disconnect (MMGenericGsm *gsm, + gint cid, + MMModemFn callback, + gpointer user_data) +{ + MMModemZte *self = MM_MODEM_ZTE (gsm); + MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (self); + + if (priv->is_icera) + mm_modem_icera_do_disconnect (gsm, cid, callback, user_data); + else + MM_GENERIC_GSM_CLASS (mm_modem_zte_parent_class)->do_disconnect (gsm, cid, callback, user_data); +} + /*****************************************************************************/ /* Modem class override functions */ /*****************************************************************************/ @@ -310,6 +354,10 @@ cpms_try_done (MMAtSerialPort *port, } } + /* Turn on unsolicited network state messages */ + if (priv->is_icera) + mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (info->modem), TRUE); + mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info); } @@ -321,6 +369,8 @@ init_modem_done (MMAtSerialPort *port, { MMCallbackInfo *info = (MMCallbackInfo *) user_data; + mm_at_serial_port_queue_command (port, "E0", 5, NULL, NULL); + /* Attempt to disable floods of "+ZUSIMR:2" unsolicited responses that * eventually fill up the device's buffers and make it crash. Normally * done during probing, but if the device has a PIN enabled it won't @@ -333,6 +383,25 @@ static void enable_flash_done (MMSerialPort *port, GError *error, gpointer user_data); +static void +icera_check_cb (MMModem *modem, + guint32 result, + GError *error, + gpointer user_data) +{ + if (!error) { + MMModemZte *self = MM_MODEM_ZTE (user_data); + MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (self); + + if (result) { + priv->is_icera = TRUE; + g_object_set (G_OBJECT (modem), + MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC, + NULL); + } + } +} + static void pre_init_done (MMAtSerialPort *port, GString *response, @@ -340,7 +409,8 @@ pre_init_done (MMAtSerialPort *port, gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (info->modem); + MMModemZte *self = MM_MODEM_ZTE (info->modem); + MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (self); if (error) { /* Retry the init string one more time; the modem sometimes throws it away */ @@ -349,9 +419,10 @@ pre_init_done (MMAtSerialPort *port, priv->init_retried = TRUE; enable_flash_done (MM_SERIAL_PORT (port), NULL, user_data); } else - mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info); + mm_generic_gsm_enable_complete (MM_GENERIC_GSM (self), error, info); } else { /* Finish the initialization */ + mm_modem_icera_is_icera (MM_MODEM_ICERA (self), icera_check_cb, self); mm_at_serial_port_queue_command (port, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info); } } @@ -383,21 +454,112 @@ do_enable (MMGenericGsm *modem, MMModemFn callback, gpointer user_data) mm_serial_port_flash (MM_SERIAL_PORT (primary), 100, FALSE, enable_flash_done, info); } +/*****************************************************************************/ + +typedef struct { + MMModem *modem; + MMModemFn callback; + gpointer user_data; +} DisableInfo; + +static void +disable_unsolicited_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) + +{ + MMModem *parent_modem_iface; + DisableInfo *info = user_data; + + parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem)); + parent_modem_iface->disable (info->modem, info->callback, info->user_data); + g_free (info); +} + static void disable (MMModem *modem, MMModemFn callback, gpointer user_data) { MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (modem); - MMModem *parent_modem_iface; + MMAtSerialPort *primary; + DisableInfo *info; priv->init_retried = FALSE; - /* Do the normal disable stuff */ - parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem)); - parent_modem_iface->disable (modem, callback, user_data); + info = g_malloc0 (sizeof (DisableInfo)); + info->callback = callback; + info->user_data = user_data; + info->modem = modem; + + primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY); + g_assert (primary); + + /* Turn off unsolicited responses */ + if (priv->is_icera) { + mm_modem_icera_cleanup (MM_MODEM_ICERA (modem)); + mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (modem), FALSE); + } + + /* Random command to ensure unsolicited message disable completes */ + mm_at_serial_port_queue_command (primary, "E0", 5, disable_unsolicited_done, info); +} + +/*****************************************************************************/ + +static void +do_connect (MMModem *modem, + const char *number, + MMModemFn callback, + gpointer user_data) +{ + MMModem *parent_iface; + + if (MM_MODEM_ZTE_GET_PRIVATE (modem)->is_icera) + mm_modem_icera_do_connect (MM_MODEM_ICERA (modem), number, callback, user_data); + else { + parent_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem)); + parent_iface->connect (MM_MODEM (modem), number, callback, user_data); + } +} + +static void +get_ip4_config (MMModem *modem, + MMModemIp4Fn callback, + gpointer user_data) +{ + MMModem *parent_iface; + + if (MM_MODEM_ZTE_GET_PRIVATE (modem)->is_icera) { + mm_modem_icera_get_ip4_config (MM_MODEM_ICERA (modem), callback, user_data); + } else { + parent_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem)); + parent_iface->get_ip4_config (MM_MODEM (modem), callback, user_data); + } +} + +/*****************************************************************************/ + +static void +simple_connect (MMModemSimple *simple, + GHashTable *properties, + MMModemFn callback, + gpointer user_data) +{ + MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (simple); + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemSimple *parent_iface; + + if (priv->is_icera) + mm_modem_icera_simple_connect (MM_MODEM_ICERA (simple), properties); + + parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple)); + parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info); } +/*****************************************************************************/ + static gboolean grab_port (MMModem *modem, const char *subsys, @@ -447,6 +609,9 @@ grab_port (MMModem *modem, regex = g_regex_new ("\\r\\n\\+ZEND\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); g_regex_unref (regex); + + /* Add Icera-specific handlers */ + mm_modem_icera_register_unsolicted_handlers (MM_MODEM_ICERA (gsm), MM_AT_SERIAL_PORT (port)); } return !!port; @@ -458,9 +623,23 @@ static void modem_init (MMModem *modem_class) { modem_class->disable = disable; + modem_class->connect = do_connect; + modem_class->get_ip4_config = get_ip4_config; modem_class->grab_port = grab_port; } +static void +modem_icera_init (MMModemIcera *icera_class) +{ + mm_modem_icera_prepare (icera_class); +} + +static void +modem_simple_init (MMModemSimple *class) +{ + class->connect = simple_connect; +} + static void mm_modem_zte_init (MMModemZte *self) { @@ -474,6 +653,10 @@ dispose (GObject *object) if (priv->cpms_timeout) g_source_remove (priv->cpms_timeout); + + mm_modem_icera_cleanup (MM_MODEM_ICERA (self)); + + G_OBJECT_CLASS (mm_modem_zte_parent_class)->dispose (object); } static void @@ -487,6 +670,7 @@ mm_modem_zte_class_init (MMModemZteClass *klass) object_class->dispose = dispose; gsm_class->do_enable = do_enable; + gsm_class->do_disconnect = do_disconnect; gsm_class->set_allowed_mode = set_allowed_mode; gsm_class->get_allowed_mode = get_allowed_mode; gsm_class->get_access_technology = get_access_technology; diff --git a/plugins/mm-modem-zte.h b/plugins/mm-modem-zte.h index 112bae0..f2f068b 100644 --- a/plugins/mm-modem-zte.h +++ b/plugins/mm-modem-zte.h @@ -38,6 +38,8 @@ GType mm_modem_zte_get_type (void); MMModem *mm_modem_zte_new (const char *device, const char *driver, - const char *plugin); + const char *plugin, + guint32 vendor, + guint32 product); #endif /* MM_MODEM_ZTE_H */ diff --git a/plugins/mm-plugin-anydata.c b/plugins/mm-plugin-anydata.c index 94f4f10..76df673 100644 --- a/plugins/mm-plugin-anydata.c +++ b/plugins/mm-plugin-anydata.c @@ -110,6 +110,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -129,6 +130,11 @@ grab_port (MMPluginBase *base, return NULL; } + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & CAP_CDMA) { @@ -136,7 +142,9 @@ grab_port (MMPluginBase *base, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-generic.c b/plugins/mm-plugin-generic.c index cdf2c66..a27704b 100644 --- a/plugins/mm-plugin-generic.c +++ b/plugins/mm-plugin-generic.c @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2008 - 2009 Dan Williams + * Copyright (C) 2008 - 2010 Dan Williams */ #include @@ -31,6 +31,7 @@ #include "mm-generic-cdma.h" #include "mm-errors.h" #include "mm-serial-parsers.h" +#include "mm-log.h" G_DEFINE_TYPE (MMPluginGeneric, mm_plugin_generic, MM_TYPE_PLUGIN_BASE) @@ -112,6 +113,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path, *driver; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -126,26 +128,35 @@ grab_port (MMPluginBase *base, g_set_error (error, 0, 0, "Could not get port's sysfs file."); return NULL; } else { - g_message ("%s: (%s/%s) WARNING: missing udev 'device' file", - mm_plugin_get_name (MM_PLUGIN (base)), - subsys, - name); + mm_warn ("%s: (%s/%s) WARNING: missing udev 'device' file", + mm_plugin_get_name (MM_PLUGIN (base)), + subsys, + name); } } + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { - if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { - modem = mm_generic_gsm_new (sysfs_path, - mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); - } else if (caps & CAP_CDMA) { + if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); + } else if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { + modem = mm_generic_gsm_new (sysfs_path, + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-gobi.c b/plugins/mm-plugin-gobi.c index fbe3878..36771d1 100644 --- a/plugins/mm-plugin-gobi.c +++ b/plugins/mm-plugin-gobi.c @@ -106,6 +106,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *sysfs_path; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -113,19 +114,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_gobi_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-hso.c b/plugins/mm-plugin-hso.c index dc0a8fc..7b71932 100644 --- a/plugins/mm-plugin-hso.c +++ b/plugins/mm-plugin-hso.c @@ -105,6 +105,7 @@ grab_port (MMPluginBase *base, const char *name, *subsys, *sysfs_path; char *devfile; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -112,6 +113,11 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + devfile = g_strdup (g_udev_device_get_device_file (port)); if (!devfile) { if (!strcmp (subsys, "net")) { @@ -139,7 +145,9 @@ grab_port (MMPluginBase *base, if (!existing) { modem = mm_modem_hso_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); if (modem) { if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) { g_object_unref (modem); diff --git a/plugins/mm-plugin-huawei.c b/plugins/mm-plugin-huawei.c index 2993689..f1590ca 100644 --- a/plugins/mm-plugin-huawei.c +++ b/plugins/mm-plugin-huawei.c @@ -27,6 +27,7 @@ #include "mm-modem-huawei-cdma.h" #include "mm-serial-parsers.h" #include "mm-at-serial-port.h" +#include "mm-log.h" G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN_BASE) @@ -239,19 +240,19 @@ supports_port (MMPluginBase *base, info->id = g_timeout_add_seconds (7, probe_secondary_timeout, task); - g_object_set_data_full (G_OBJECT (task), TAG_SUPPORTS_INFO, - info, huawei_supports_info_destroy); - if (!mm_serial_port_open (MM_SERIAL_PORT (info->serial), &error)) { - g_warning ("%s: (Huawei) %s: couldn't open serial port: (%d) %s", - __func__, name, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + mm_warn ("(Huawei) %s: couldn't open serial port: (%d) %s", + name, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); g_clear_error (&error); huawei_supports_info_destroy (info); return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } + g_object_set_data_full (G_OBJECT (task), TAG_SUPPORTS_INFO, + info, huawei_supports_info_destroy); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } @@ -268,7 +269,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; - guint16 product = 0; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -282,7 +283,7 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); - if (!mm_plugin_base_get_device_ids (base, subsys, name, NULL, &product)) { + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { g_set_error (error, 0, 0, "Could not get modem product ID."); return NULL; } @@ -292,14 +293,18 @@ grab_port (MMPluginBase *base, if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_huawei_gsm_new (sysfs_path, - mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_modem_huawei_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-linktop.c b/plugins/mm-plugin-linktop.c new file mode 100644 index 0000000..411f9cc --- /dev/null +++ b/plugins/mm-plugin-linktop.c @@ -0,0 +1,164 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 Red Hat, Inc. + */ + +#include +#include +#include "mm-plugin-linktop.h" +#include "mm-modem-linktop.h" + +G_DEFINE_TYPE (MMPluginLinktop, mm_plugin_linktop, MM_TYPE_PLUGIN_BASE) + +int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; +int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_LINKTOP, + MM_PLUGIN_BASE_NAME, "Linktop", + NULL)); +} + +/*****************************************************************************/ + +static guint32 +get_level_for_capabilities (guint32 capabilities) +{ + if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) + return 10; + return 0; +} + +static void +probe_result (MMPluginBase *base, + MMPluginBaseSupportsTask *task, + guint32 capabilities, + gpointer user_data) +{ + mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities)); +} + +static MMPluginSupportsResult +supports_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task) +{ + GUdevDevice *port; + guint32 cached = 0, level; + const char *subsys, *name; + guint16 vendor = 0; + + /* Can't do anything with non-serial ports */ + port = mm_plugin_base_supports_task_get_port (task); + if (strcmp (g_udev_device_get_subsystem (port), "tty")) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + if (vendor != 0x230d) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { + level = get_level_for_capabilities (cached); + if (level) { + mm_plugin_base_supports_task_complete (task, level); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + } + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + } + + /* Otherwise kick off a probe */ + if (mm_plugin_base_probe_port (base, task, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; +} + +static MMModem * +grab_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task, + GError **error) +{ + GUdevDevice *port = NULL; + MMModem *modem = NULL; + const char *name, *subsys, *devfile, *sysfs_path; + guint32 caps; + guint16 vendor = 0, product = 0; + + port = mm_plugin_base_supports_task_get_port (task); + g_assert (port); + + devfile = g_udev_device_get_device_file (port); + if (!devfile) { + g_set_error (error, 0, 0, "Could not get port's sysfs file."); + return NULL; + } + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); + if (!existing) { + if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { + modem = mm_modem_linktop_new (sysfs_path, + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); + } + + if (modem) { + if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) { + g_object_unref (modem); + return NULL; + } + } + } else if (get_level_for_capabilities (caps)) { + modem = existing; + if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) + return NULL; + } + + return modem; +} + +/*****************************************************************************/ + +static void +mm_plugin_linktop_init (MMPluginLinktop *self) +{ + g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); +} + +static void +mm_plugin_linktop_class_init (MMPluginLinktopClass *klass) +{ + MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); + + pb_class->supports_port = supports_port; + pb_class->grab_port = grab_port; +} diff --git a/plugins/mm-plugin-linktop.h b/plugins/mm-plugin-linktop.h new file mode 100644 index 0000000..b904725 --- /dev/null +++ b/plugins/mm-plugin-linktop.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 Red Hat, Inc. + */ + +#ifndef MM_PLUGIN_LINKTOP_H +#define MM_PLUGIN_LINKTOP_H + +#include "mm-plugin-base.h" + +#define MM_TYPE_PLUGIN_LINKTOP (mm_plugin_linktop_get_type ()) +#define MM_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktop)) +#define MM_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass)) +#define MM_IS_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_LINKTOP)) +#define MM_IS_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_LINKTOP)) +#define MM_PLUGIN_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass)) + +typedef struct { + MMPluginBase parent; +} MMPluginLinktop; + +typedef struct { + MMPluginBaseClass parent; +} MMPluginLinktopClass; + +GType mm_plugin_linktop_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_LINKTOP_H */ diff --git a/plugins/mm-plugin-longcheer.c b/plugins/mm-plugin-longcheer.c index dbbe186..e63ff4e 100644 --- a/plugins/mm-plugin-longcheer.c +++ b/plugins/mm-plugin-longcheer.c @@ -114,6 +114,7 @@ grab_port (MMPluginBase *base, const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -138,19 +139,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_longcheer_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-mbm.c b/plugins/mm-plugin-mbm.c index 5554d84..6684ff9 100644 --- a/plugins/mm-plugin-mbm.c +++ b/plugins/mm-plugin-mbm.c @@ -84,7 +84,7 @@ supports_port (MMPluginBase *base, client = g_udev_client_new (sys); if (!client) { - g_warning ("mbm: could not get udev client."); + g_warn_if_fail (client != NULL); return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } @@ -132,6 +132,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *sysfs_path; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -143,11 +144,18 @@ grab_port (MMPluginBase *base, if (!(caps & MM_PLUGIN_BASE_PORT_CAP_GSM) && strcmp (subsys, "net")) return NULL; + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { modem = mm_modem_mbm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); if (modem) { if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) { g_object_unref (modem); diff --git a/plugins/mm-plugin-moto-c.c b/plugins/mm-plugin-moto-c.c index d798af4..21b737e 100644 --- a/plugins/mm-plugin-moto-c.c +++ b/plugins/mm-plugin-moto-c.c @@ -105,6 +105,7 @@ grab_port (MMPluginBase *base, GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -118,11 +119,18 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { modem = mm_modem_moto_c_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); if (modem) { if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) { diff --git a/plugins/mm-plugin-nokia.c b/plugins/mm-plugin-nokia.c index 2d0d6af..938f8c5 100644 --- a/plugins/mm-plugin-nokia.c +++ b/plugins/mm-plugin-nokia.c @@ -109,6 +109,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -122,19 +123,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_nokia_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-novatel.c b/plugins/mm-plugin-novatel.c index a968836..5384456 100644 --- a/plugins/mm-plugin-novatel.c +++ b/plugins/mm-plugin-novatel.c @@ -115,6 +115,7 @@ grab_port (MMPluginBase *base, MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -128,19 +129,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_novatel_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_modem_novatel_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-option.c b/plugins/mm-plugin-option.c index 101f9bd..ab2bd3d 100644 --- a/plugins/mm-plugin-option.c +++ b/plugins/mm-plugin-option.c @@ -107,6 +107,7 @@ grab_port (MMPluginBase *base, guint32 caps; int usbif; MMPortType ptype = MM_PORT_TYPE_SECONDARY; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -129,13 +130,20 @@ grab_port (MMPluginBase *base, if (usbif == 0) ptype = MM_PORT_TYPE_PRIMARY; + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_option_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-sierra.c b/plugins/mm-plugin-sierra.c index 8ace653..b7367ab 100644 --- a/plugins/mm-plugin-sierra.c +++ b/plugins/mm-plugin-sierra.c @@ -90,17 +90,28 @@ supports_port (MMPluginBase *base, { GUdevDevice *port; guint32 cached = 0, level; - const char *driver; + const char *driver, *subsys; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); - if (strcmp (g_udev_device_get_subsystem (port), "tty")) + if (!port) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; driver = mm_plugin_base_supports_task_get_driver (task); - if (!driver || strcmp (driver, "sierra")) + if (!driver || (strcmp (driver, "sierra") && strcmp (driver, "sierra_net"))) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + subsys = g_udev_device_get_subsystem (port); + g_assert (subsys); + if (!strcmp (subsys, "net")) { + /* Can't grab the net port until we know whether this is a CDMA or GSM device */ + if (!existing) + return MM_PLUGIN_SUPPORTS_PORT_DEFER; + + mm_plugin_base_supports_task_complete (task, 10); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + } + if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { level = get_level_for_capabilities (cached); if (level) { @@ -125,19 +136,14 @@ grab_port (MMPluginBase *base, { GUdevDevice *port = NULL; MMModem *modem = NULL; - const char *name, *subsys, *devfile, *sysfs_path; + const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); - devfile = g_udev_device_get_device_file (port); - if (!devfile) { - g_set_error (error, 0, 0, "Could not get port's sysfs file."); - return NULL; - } - subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); @@ -145,19 +151,28 @@ grab_port (MMPluginBase *base, if (g_object_get_data (G_OBJECT (task), TAG_SIERRA_SECONDARY_PORT)) ptype = MM_PORT_TYPE_SECONDARY; + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if ((caps & MM_PLUGIN_BASE_PORT_CAP_GSM) || (ptype != MM_PORT_TYPE_UNKNOWN)) { modem = mm_modem_sierra_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_modem_sierra_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { @@ -166,7 +181,16 @@ grab_port (MMPluginBase *base, return NULL; } } - } else if (get_level_for_capabilities (caps) || (ptype != MM_PORT_TYPE_UNKNOWN)) { + } else if ( get_level_for_capabilities (caps) + || (ptype != MM_PORT_TYPE_UNKNOWN) + || (strcmp (subsys, "net") == 0)) { + + /* FIXME: we don't yet know how to activate IP on CDMA devices using + * pseudo-ethernet ports. + */ + if (strcmp (subsys, "net") == 0 && MM_IS_MODEM_SIERRA_CDMA (modem)) + return modem; + modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) return NULL; diff --git a/plugins/mm-plugin-simtech.c b/plugins/mm-plugin-simtech.c index 3c44873..611d2d2 100644 --- a/plugins/mm-plugin-simtech.c +++ b/plugins/mm-plugin-simtech.c @@ -114,6 +114,7 @@ grab_port (MMPluginBase *base, const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -138,19 +139,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_simtech_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { diff --git a/plugins/mm-plugin-x22x.c b/plugins/mm-plugin-x22x.c new file mode 100644 index 0000000..5a8253f --- /dev/null +++ b/plugins/mm-plugin-x22x.c @@ -0,0 +1,192 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2010 Red Hat, Inc. + */ + +#include +#include +#include "mm-plugin-x22x.h" +#include "mm-modem-x22x-gsm.h" +#include "mm-generic-gsm.h" + +G_DEFINE_TYPE (MMPluginX22x, mm_plugin_x22x, MM_TYPE_PLUGIN_BASE) + +int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; +int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_X22X, + MM_PLUGIN_BASE_NAME, "X22X", + NULL)); +} + +/*****************************************************************************/ + +static guint32 +get_level_for_capabilities (guint32 capabilities) +{ + /* These modems have the same vendor ID as a few of the other + * Alcatel/TCT/T&A modems, and the longcheer plugin will try to claim them + * too. So we provide a higher support level here to make sure this + * plugin tries to grab it's supported devices first. + */ + if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) + return 20; + if (capabilities & MM_PLUGIN_BASE_PORT_CAP_QCDM) + return 20; + return 0; +} + +static void +probe_result (MMPluginBase *base, + MMPluginBaseSupportsTask *task, + guint32 capabilities, + gpointer user_data) +{ + mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities)); +} + +static MMPluginSupportsResult +supports_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task) +{ + GUdevDevice *port; + guint32 cached = 0, level; + guint16 vendor = 0; + const char *subsys, *name; + + /* Can't do anything with non-serial ports */ + port = mm_plugin_base_supports_task_get_port (task); + if (strcmp (g_udev_device_get_subsystem (port), "tty")) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + /* Only TCT/T&A for now */ + if (vendor != 0x1bbb) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + /* If the port wasn't tagged, we don't support it */ + if (!g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_TAGGED")) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { + level = get_level_for_capabilities (cached); + if (level) { + mm_plugin_base_supports_task_complete (task, level); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + } + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + } + + /* Otherwise kick off a probe */ + if (mm_plugin_base_probe_port (base, task, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; +} + +static MMModem * +grab_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task, + GError **error) +{ + GUdevDevice *port = NULL; + MMModem *modem = NULL; + const char *name, *subsys, *sysfs_path; + guint32 caps; + MMPortType ptype = MM_PORT_TYPE_UNKNOWN; + guint16 vendor = 0, product = 0; + + port = mm_plugin_base_supports_task_get_port (task); + g_assert (port); + + /* Look for port type hints; just probing can't distinguish which port should + * be the data/primary port on these devices. We have to tag them based on + * what the Windows .INF files say the port layout should be. + */ + if (g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_PORT_TYPE_MODEM")) + ptype = MM_PORT_TYPE_PRIMARY; + else if (g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_PORT_TYPE_AUX")) + ptype = MM_PORT_TYPE_SECONDARY; + + /* If the device was tagged by the udev rules, then ignore any other ports + * to guard against race conditions if a device just happens to show up + * with more than two AT-capable ports. + */ + if ( (ptype == MM_PORT_TYPE_UNKNOWN) + && g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_TAGGED")) + ptype = MM_PORT_TYPE_IGNORED; + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); + if (!existing) { + if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { + modem = mm_modem_x22x_gsm_new (sysfs_path, + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); + } + + if (modem) { + if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) { + g_object_unref (modem); + return NULL; + } + } + } else if (get_level_for_capabilities (caps)) { + if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM) + ptype = MM_PORT_TYPE_QCDM; + + modem = existing; + if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) + return NULL; + } + + return modem; +} + +/*****************************************************************************/ + +static void +mm_plugin_x22x_init (MMPluginX22x *self) +{ + g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); +} + +static void +mm_plugin_x22x_class_init (MMPluginX22xClass *klass) +{ + MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); + + pb_class->supports_port = supports_port; + pb_class->grab_port = grab_port; +} diff --git a/plugins/mm-plugin-x22x.h b/plugins/mm-plugin-x22x.h new file mode 100644 index 0000000..227511d --- /dev/null +++ b/plugins/mm-plugin-x22x.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2010 Red Hat, Inc. + */ + +#ifndef MM_PLUGIN_X22X_H +#define MM_PLUGIN_X22X_H + +#include "mm-plugin-base.h" + +#define MM_TYPE_PLUGIN_X22X (mm_plugin_x22x_get_type ()) +#define MM_PLUGIN_X22X(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_X22X, MMPluginX22x)) +#define MM_PLUGIN_X22X_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_X22X, MMPluginX22xClass)) +#define MM_IS_PLUGIN_X22X(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_X22X)) +#define MM_IS_PLUGIN_X22X_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_X22X)) +#define MM_PLUGIN_X22X_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_X22X, MMPluginX22xClass)) + +typedef struct { + MMPluginBase parent; +} MMPluginX22x; + +typedef struct { + MMPluginBaseClass parent; +} MMPluginX22xClass; + +GType mm_plugin_x22x_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_X22X_H */ diff --git a/plugins/mm-plugin-zte.c b/plugins/mm-plugin-zte.c index e943bbf..bb2ee17 100644 --- a/plugins/mm-plugin-zte.c +++ b/plugins/mm-plugin-zte.c @@ -11,7 +11,7 @@ * GNU General Public License for more details: * * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. + * Copyright (C) 2009 - 2010 Red Hat, Inc. */ #include @@ -73,9 +73,6 @@ supports_port (MMPluginBase *base, /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); - if (strcmp (g_udev_device_get_subsystem (port), "tty")) - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); @@ -85,6 +82,20 @@ supports_port (MMPluginBase *base, if (vendor != 0x19d2) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + if (!strcmp (subsys, "net")) { + /* If we don't know the modem's type yet, defer grabbing the port + * until we know the type. + */ + if (!existing) + return MM_PLUGIN_SUPPORTS_PORT_DEFER; + + mm_plugin_base_supports_task_complete (task, 10); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + } + + if (strcmp (subsys, "tty")) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { level = get_level_for_capabilities (cached); if (level) { @@ -121,6 +132,7 @@ grab_port (MMPluginBase *base, const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; + guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); @@ -134,19 +146,28 @@ grab_port (MMPluginBase *base, subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_zte_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base))); + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), + vendor, + product); } if (modem) { @@ -155,7 +176,7 @@ grab_port (MMPluginBase *base, return NULL; } } - } else if (get_level_for_capabilities (caps)) { + } else if (get_level_for_capabilities (caps) || (!strcmp (subsys, "net"))) { if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM) ptype = MM_PORT_TYPE_QCDM; -- cgit v1.2.3