diff options
-rw-r--r-- | plugins/Makefile.am | 19 | ||||
-rw-r--r-- | plugins/mm-modem-moto-c-gsm.c | 158 | ||||
-rw-r--r-- | plugins/mm-modem-moto-c-gsm.h | 43 | ||||
-rw-r--r-- | plugins/mm-plugin-moto-c.c | 309 | ||||
-rw-r--r-- | plugins/mm-plugin-moto-c.h | 42 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 86 | ||||
-rw-r--r-- | src/mm-generic-gsm.h | 18 |
7 files changed, 669 insertions, 6 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 10b0ca25..a164b4c2 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,5 +1,6 @@ pkglib_LTLIBRARIES = \ libmm-plugin-generic.la \ + libmm-plugin-moto-c.la \ libmm-plugin-huawei.la \ libmm-plugin-hso.la \ libmm-plugin-mbm.la \ @@ -25,6 +26,24 @@ libmm_plugin_generic_la_LDFLAGS = \ -module \ -avoid-version +# Motorola C-series phones + +libmm_plugin_moto_c_la_SOURCES = \ + mm-plugin-moto-c.c \ + mm-plugin-moto-c.h \ + mm-modem-moto-c-gsm.c \ + mm-modem-moto-c-gsm.h + +libmm_plugin_moto_c_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_moto_c_la_LDFLAGS = \ + $(GUDEV_LDFLAGS) \ + -module \ + -avoid-version + # Huawei libmm_plugin_huawei_la_SOURCES = \ diff --git a/plugins/mm-modem-moto-c-gsm.c b/plugins/mm-modem-moto-c-gsm.c new file mode 100644 index 00000000..cba7b920 --- /dev/null +++ b/plugins/mm-modem-moto-c-gsm.c @@ -0,0 +1,158 @@ +/* -*- 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 <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include "mm-modem-moto-c-gsm.h" +#include "mm-errors.h" +#include "mm-callback-info.h" +#include "mm-modem-gsm-card.h" + +static gpointer mm_modem_moto_c_gsm_parent_class = NULL; + +MMModem * +mm_modem_moto_c_gsm_new (const char *device, + const char *driver, + const char *plugin) +{ + 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_MOTO_C_GSM, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + NULL)); +} + +/*****************************************************************************/ + +static void +modem_init (MMModem *modem_class) +{ +} + +/*****************************************************************************/ + +static void +get_imei (MMModemGsmCard *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED, + "Operation not supported"); + mm_callback_info_schedule (info); +} + +static void +modem_gsm_card_init (MMModemGsmCard *class) +{ + class->get_imei = get_imei; +} + +/*****************************************************************************/ + +static void +mm_modem_moto_c_gsm_init (MMModemMotoCGsm *self) +{ +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + + /* These devices just don't implement AT+CFUN */ + + switch (prop_id) { + case MM_GENERIC_GSM_PROP_POWER_UP_CMD: + g_value_set_string (value, ""); + break; + case MM_GENERIC_GSM_PROP_POWER_DOWN_CMD: + g_value_set_string (value, ""); + break; + default: + break; + } +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ +} + +static void +mm_modem_moto_c_gsm_class_init (MMModemMotoCGsmClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + mm_modem_moto_c_gsm_parent_class = g_type_class_peek_parent (klass); + + object_class->get_property = get_property; + object_class->set_property = set_property; + + g_object_class_override_property (object_class, + MM_GENERIC_GSM_PROP_POWER_UP_CMD, + MM_GENERIC_GSM_POWER_UP_CMD); + + g_object_class_override_property (object_class, + MM_GENERIC_GSM_PROP_POWER_DOWN_CMD, + MM_GENERIC_GSM_POWER_DOWN_CMD); +} + +GType +mm_modem_moto_c_gsm_get_type (void) +{ + static GType modem_moto_c_gsm_type = 0; + + if (G_UNLIKELY (modem_moto_c_gsm_type == 0)) { + static const GTypeInfo modem_moto_c_gsm_type_info = { + sizeof (MMModemMotoCGsmClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mm_modem_moto_c_gsm_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (MMModemMotoCGsm), + 0, /* n_preallocs */ + (GInstanceInitFunc) mm_modem_moto_c_gsm_init, + }; + + static const GInterfaceInfo modem_iface_info = { + (GInterfaceInitFunc) modem_init + }; + + static const GInterfaceInfo modem_gsm_card_info = { + (GInterfaceInitFunc) modem_gsm_card_init + }; + + modem_moto_c_gsm_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemMotoCGsm", + &modem_moto_c_gsm_type_info, 0); + + g_type_add_interface_static (modem_moto_c_gsm_type, MM_TYPE_MODEM, &modem_iface_info); + g_type_add_interface_static (modem_moto_c_gsm_type, MM_TYPE_MODEM_GSM_CARD, &modem_gsm_card_info); + } + + return modem_moto_c_gsm_type; +} diff --git a/plugins/mm-modem-moto-c-gsm.h b/plugins/mm-modem-moto-c-gsm.h new file mode 100644 index 00000000..eb1dad12 --- /dev/null +++ b/plugins/mm-modem-moto-c-gsm.h @@ -0,0 +1,43 @@ +/* -*- 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_MOTO_C_GSM_H +#define MM_MODEM_MOTO_C_GSM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_MOTO_C_GSM (mm_modem_moto_c_gsm_get_type ()) +#define MM_MODEM_MOTO_C_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_MOTO_C_GSM, MMModemMotoCGsm)) +#define MM_MODEM_MOTO_C_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_MOTO_C_GSM, MMModemMotoCGsmClass)) +#define MM_IS_MODEM_MOTO_C_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_MOTO_C_GSM)) +#define MM_IS_MODEM_MOTO_C_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_MOTO_C_GSM)) +#define MM_MODEM_MOTO_C_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_MOTO_C_GSM, MMModemMotoCGsmClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemMotoCGsm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemMotoCGsmClass; + +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); + +#endif /* MM_MODEM_MOTO_C_GSM_H */ diff --git a/plugins/mm-plugin-moto-c.c b/plugins/mm-plugin-moto-c.c new file mode 100644 index 00000000..25337776 --- /dev/null +++ b/plugins/mm-plugin-moto-c.c @@ -0,0 +1,309 @@ +/* -*- 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 <string.h> +#include <gmodule.h> +#define G_UDEV_API_IS_SUBJECT_TO_CHANGE +#include <gudev/gudev.h> + +#include "mm-plugin-moto-c.h" +#include "mm-modem-moto-c-gsm.h" + +static void plugin_init (MMPlugin *plugin_class); + +G_DEFINE_TYPE_EXTENDED (MMPluginMotoC, mm_plugin_moto_c, G_TYPE_OBJECT, + 0, G_IMPLEMENT_INTERFACE (MM_TYPE_PLUGIN, plugin_init)) + +int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; +int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; + +#define MM_PLUGIN_MOTO_C_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_MOTO_C, MMPluginMotoCPrivate)) + +typedef struct { + GUdevClient *client; + GHashTable *modems; +} MMPluginMotoCPrivate; + + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_MOTO_C, NULL)); +} + +/*****************************************************************************/ + +static char * +get_driver_name (GUdevDevice *device) +{ + GUdevDevice *parent = NULL; + const char *driver; + char *ret; + + driver = g_udev_device_get_driver (device); + if (!driver) { + parent = g_udev_device_get_parent (device); + if (parent) + driver = g_udev_device_get_driver (parent); + } + + if (driver) + ret = g_strdup (driver); + if (parent) + g_object_unref (parent); + + return ret; +} + +static GUdevDevice * +find_physical_device (GUdevDevice *child) +{ + GUdevDevice *iter, *old = NULL; + const char *bus, *type; + + g_return_val_if_fail (child != NULL, NULL); + + bus = g_udev_device_get_property (child, "ID_BUS"); + if (!bus) + return NULL; + + if (strcmp (bus, "usb")) + return NULL; + + /* Walk the parents to find the 'usb_device' for this device. */ + iter = g_object_ref (child); + while (iter) { + type = g_udev_device_get_devtype (iter); + if (type && !strcmp (type, "usb_device")) + return iter; + + old = iter; + iter = g_udev_device_get_parent (old); + g_object_unref (old); + } + g_object_unref (child); + + return NULL; +} + +#define PROP_GSM "ID_MM_MODEM_GSM" + +static guint32 +supports_port (MMPlugin *plugin, + const char *subsys, + const char *name) +{ + MMPluginMotoCPrivate *priv = MM_PLUGIN_MOTO_C_GET_PRIVATE (plugin); + GUdevDevice *device, *physdev = NULL; + guint32 level = 0; + const char *tmp; + + g_return_val_if_fail (plugin != NULL, 0); + g_return_val_if_fail (MM_IS_PLUGIN (plugin), 0); + g_return_val_if_fail (subsys != NULL, 0); + g_return_val_if_fail (name != NULL, 0); + + /* Can't do anything with non-serial ports */ + if (strcmp (subsys, "tty")) + return 0; + + device = g_udev_client_query_by_subsystem_and_name (priv->client, subsys, name); + if (!device) + return 0; + + tmp = g_udev_device_get_property (device, "ID_BUS"); + if (!tmp || strcmp (tmp, "usb")) + goto out; + + tmp = g_udev_device_get_property (device, "ID_VENDOR_ID"); + if (!tmp || strcmp (tmp, "22b8")) + goto out; + + tmp = g_udev_device_get_property (device, "ID_MODEL_ID"); + if (!tmp || strcmp (tmp, "3802")) + goto out; + + if (!g_udev_device_get_property_as_boolean (device, PROP_GSM)) + goto out; + + physdev = find_physical_device (device); + if (!physdev) + goto out; + g_object_unref (physdev); + level = 10; + +out: + g_object_unref (device); + return level; +} + +typedef struct { + char *key; + gpointer modem; +} FindInfo; + +static void +find_modem (gpointer key, gpointer data, gpointer user_data) +{ + FindInfo *info = user_data; + + if (!info->key && data == info->modem) + info->key = g_strdup ((const char *) key); +} + +static void +modem_destroyed (gpointer data, GObject *modem) +{ + MMPluginMotoC *self = MM_PLUGIN_MOTO_C (data); + MMPluginMotoCPrivate *priv = MM_PLUGIN_MOTO_C_GET_PRIVATE (self); + FindInfo info = { NULL, modem }; + + g_hash_table_foreach (priv->modems, find_modem, &info); + if (info.key) + g_hash_table_remove (priv->modems, info.key); + g_free (info.key); +} + +static MMModem * +grab_port (MMPlugin *plugin, + const char *subsys, + const char *name, + GError **error) +{ + MMPluginMotoC *self = MM_PLUGIN_MOTO_C (plugin); + MMPluginMotoCPrivate *priv = MM_PLUGIN_MOTO_C_GET_PRIVATE (plugin); + GUdevDevice *device = NULL, *physdev = NULL; + const char *devfile, *sysfs_path; + char *driver = NULL; + MMModem *modem = NULL; + + g_return_val_if_fail (subsys != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + /* Can't do anything with non-serial ports */ + if (strcmp (subsys, "tty")) + return NULL; + + device = g_udev_client_query_by_subsystem_and_name (priv->client, subsys, name); + if (!device) { + g_set_error (error, 0, 0, "Could not get port's udev device."); + return NULL; + } + + if (!g_udev_device_get_property_as_boolean (device, PROP_GSM)) { + g_set_error (error, 0, 0, "Modem unsupported (not GSM)."); + goto out; + } + + physdev = find_physical_device (device); + if (!physdev) { + g_set_error (error, 0, 0, "Could not get ports's physical device."); + goto out; + } + + devfile = g_udev_device_get_device_file (device); + if (!devfile) { + g_set_error (error, 0, 0, "Could not get port's sysfs file."); + goto out; + } + + driver = get_driver_name (device); + if (!driver) { + g_set_error (error, 0, 0, "Could not get port's driver name."); + goto out; + } + + sysfs_path = g_udev_device_get_sysfs_path (physdev); + if (!devfile) { + g_set_error (error, 0, 0, "Could not get port's physical device sysfs path."); + goto out; + } + + modem = g_hash_table_lookup (priv->modems, sysfs_path); + if (!modem) { + modem = mm_modem_moto_c_gsm_new (sysfs_path, + driver, + mm_plugin_get_name (plugin)); + + if (modem) { + if (!mm_modem_grab_port (modem, subsys, name, error)) { + g_object_unref (modem); + modem = NULL; + } + } + + if (modem) { + g_object_weak_ref (G_OBJECT (modem), modem_destroyed, self); + g_hash_table_insert (priv->modems, g_strdup (sysfs_path), modem); + } + } else { + if (!mm_modem_grab_port (modem, subsys, name, error)) + modem = NULL; + } + +out: + g_free (driver); + g_object_unref (device); + g_object_unref (physdev); + return modem; +} + +static const char * +get_name (MMPlugin *plugin) +{ + return "MotoC"; +} + +/*****************************************************************************/ + +static void +plugin_init (MMPlugin *plugin_class) +{ + /* interface implementation */ + plugin_class->get_name = get_name; + plugin_class->supports_port = supports_port; + plugin_class->grab_port = grab_port; +} + +static void +mm_plugin_moto_c_init (MMPluginMotoC *self) +{ + MMPluginMotoCPrivate *priv = MM_PLUGIN_MOTO_C_GET_PRIVATE (self); + const char *subsys[2] = { "tty", NULL }; + + priv->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + + priv->client = g_udev_client_new (subsys); +} + +static void +dispose (GObject *object) +{ + MMPluginMotoCPrivate *priv = MM_PLUGIN_MOTO_C_GET_PRIVATE (object); + + g_hash_table_destroy (priv->modems); + g_object_unref (priv->client); +} + +static void +mm_plugin_moto_c_class_init (MMPluginMotoCClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (MMPluginMotoCPrivate)); + + object_class->dispose = dispose; +} diff --git a/plugins/mm-plugin-moto-c.h b/plugins/mm-plugin-moto-c.h new file mode 100644 index 00000000..effd2e4f --- /dev/null +++ b/plugins/mm-plugin-moto-c.h @@ -0,0 +1,42 @@ +/* -*- 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_MOTO_C_H +#define MM_PLUGIN_MOTO_C_H + +#include "mm-plugin.h" +#include "mm-generic-gsm.h" + +#define MM_TYPE_PLUGIN_MOTO_C (mm_plugin_moto_c_get_type ()) +#define MM_PLUGIN_MOTO_C(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_MOTO_C, MMPluginMotoC)) +#define MM_PLUGIN_MOTO_C_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_MOTO_C, MMPluginMotoCClass)) +#define MM_IS_PLUGIN_MOTO_C(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_MOTO_C)) +#define MM_IS_PLUGIN_MOTO_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_MOTO_C)) +#define MM_PLUGIN_MOTO_C_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_MOTO_C, MMPluginMotoCClass)) + +typedef struct { + GObject parent; +} MMPluginMotoC; + +typedef struct { + GObjectClass parent; +} MMPluginMotoCClass; + +GType mm_plugin_moto_c_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_MOTO_C_H */ diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 3cf8ab8c..0397614c 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -295,6 +295,7 @@ init_done (MMSerialPort *port, gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; + char *cmd = NULL; if (error) { info->error = g_error_copy (error); @@ -305,14 +306,24 @@ init_done (MMSerialPort *port, else mm_serial_port_queue_command (port, "+CREG=0", 5, NULL, NULL); - mm_serial_port_queue_command (port, "+CFUN=1", 5, enable_done, user_data); + g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_POWER_UP_CMD, &cmd, NULL); + if (cmd && strlen (cmd)) + mm_serial_port_queue_command (port, cmd, 5, enable_done, user_data); + else + enable_done (port, NULL, NULL, user_data); + g_free (cmd); } } static void enable_flash_done (MMSerialPort *port, gpointer user_data) { - mm_serial_port_queue_command (port, "Z E0 V1 X4 &C1 +CMEE=1", 3, init_done, user_data); + MMCallbackInfo *info = user_data; + char *cmd = NULL; + + g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_INIT_CMD, &cmd, NULL); + mm_serial_port_queue_command (port, cmd, 3, init_done, user_data); + g_free (cmd); } static void @@ -328,7 +339,15 @@ disable_done (MMSerialPort *port, static void disable_flash_done (MMSerialPort *port, gpointer user_data) { - mm_serial_port_queue_command (port, "+CFUN=0", 5, disable_done, user_data); + MMCallbackInfo *info = user_data; + char *cmd = NULL; + + g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_POWER_UP_CMD, &cmd, NULL); + if (cmd && strlen (cmd)) + mm_serial_port_queue_command (port, cmd, 5, disable_done, user_data); + else + disable_done (port, NULL, NULL, user_data); + g_free (cmd); } static void @@ -1018,22 +1037,27 @@ scan_done (MMSerialPort *port, if (error) info->error = g_error_copy (error); - else if (!strncmp (reply, "+COPS: ", 7)) { + else if (strstr (reply, "+COPS: ")) { /* Got valid reply */ GPtrArray *results; GRegex *r; GMatchInfo *match_info; GError *err = NULL; - reply += 7; + reply = strstr (reply, "+COPS: ") + 7; /* Pattern without crazy escaping using | for matching: (|\d|,"|.+|","|.+|","|.+|"\)?,|\d|) */ /* Quirk: Sony-Ericsson TM-506 sometimes includes a stray ')' like so: * * +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0) + * + * Quirk: Motorola C-series (BUSlink SCWi275u) don't include the operator + * number, like so: + * + * +COPS: (2,"T-Mobile","","310260"),(0,"Cingular Wireless","","310410") */ - r = g_regex_new ("\\((\\d),\"(.*)\",\"(.*)\",\"(.*)\"\\)?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &err); + r = g_regex_new ("\\((\\d),\"(.*)\",\"(.*)\",\"(.*)\"\\)?[,]?[(\\d)]?\\)", G_REGEX_UNGREEDY, 0, &err); if (err) { g_error ("Invalid regular expression: %s", err->message); g_error_free (err); @@ -1370,6 +1394,21 @@ sms_send (MMModemGsmSms *modem, g_free (command); } +MMSerialPort * +mm_generic_gsm_get_port (MMGenericGsm *modem, + MMSerialPortType ptype) +{ + g_return_val_if_fail (MM_IS_GENERIC_GSM (modem), NULL); + g_return_val_if_fail (ptype != MM_SERIAL_PORT_TYPE_UNKNOWN, NULL); + + if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) + return MM_GENERIC_GSM_GET_PRIVATE (modem)->primary; + else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY) + return MM_GENERIC_GSM_GET_PRIVATE (modem)->secondary; + + return NULL; +} + /*****************************************************************************/ /* MMModemSimple interface */ @@ -1689,6 +1728,8 @@ set_property (GObject *object, guint prop_id, break; case MM_MODEM_PROP_TYPE: case MM_MODEM_PROP_VALID: + case MM_GENERIC_GSM_PROP_POWER_UP_CMD: + case MM_GENERIC_GSM_PROP_POWER_DOWN_CMD: break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1727,6 +1768,15 @@ get_property (GObject *object, guint prop_id, case MM_MODEM_PROP_VALID: g_value_set_boolean (value, priv->valid); break; + case MM_GENERIC_GSM_PROP_POWER_UP_CMD: + g_value_set_string (value, "+CFUN=1"); + break; + case MM_GENERIC_GSM_PROP_POWER_DOWN_CMD: + g_value_set_string (value, "+CFUN=0"); + break; + case MM_GENERIC_GSM_PROP_INIT_CMD: + g_value_set_string (value, "Z E0 V1 X4 &C1 +CMEE=1"); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1789,6 +1839,30 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass) g_object_class_override_property (object_class, MM_MODEM_PROP_VALID, MM_MODEM_VALID); + + g_object_class_install_property + (object_class, MM_GENERIC_GSM_PROP_POWER_UP_CMD, + g_param_spec_string (MM_GENERIC_GSM_POWER_UP_CMD, + "PowerUpCommand", + "Power up command", + "+CFUN=1", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property + (object_class, MM_GENERIC_GSM_PROP_POWER_DOWN_CMD, + g_param_spec_string (MM_GENERIC_GSM_POWER_DOWN_CMD, + "PowerDownCommand", + "Power down command", + "+CFUN=0", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property + (object_class, MM_GENERIC_GSM_PROP_INIT_CMD, + g_param_spec_string (MM_GENERIC_GSM_INIT_CMD, + "InitCommand", + "Initialization command", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } GType diff --git a/src/mm-generic-gsm.h b/src/mm-generic-gsm.h index a98afefa..4178ef1d 100644 --- a/src/mm-generic-gsm.h +++ b/src/mm-generic-gsm.h @@ -13,6 +13,21 @@ #define MM_IS_GENERIC_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_GENERIC_GSM)) #define MM_GENERIC_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsmClass)) +#define MM_GENERIC_GSM_POWER_UP_CMD "power-up-cmd" +#define MM_GENERIC_GSM_POWER_DOWN_CMD "power-down-cmd" +#define MM_GENERIC_GSM_INIT_CMD "init-cmd" + +typedef enum { + MM_GENERIC_GSM_PROP_FIRST = 0x2000, + + MM_GENERIC_GSM_PROP_POWER_UP_CMD, + MM_GENERIC_GSM_PROP_POWER_DOWN_CMD, + MM_GENERIC_GSM_PROP_INIT_CMD, + + MM_GENERIC_GSM_LAST_PROP = MM_GENERIC_GSM_PROP_POWER_DOWN_CMD +} MMGenericGsmProp; + + typedef struct { MMSerial parent; } MMGenericGsm; @@ -43,4 +58,7 @@ void mm_generic_gsm_check_pin (MMGenericGsm *modem, MMModemFn callback, gpointer user_data); +MMSerialPort *mm_generic_gsm_get_port (MMGenericGsm *modem, + MMSerialPortType ptype); + #endif /* MM_GENERIC_GSM_H */ |