--- modemmanager-0.3/plugins/Makefile.am 2010-01-21 00:51:42.000000000 +0900 +++ modemmanager-0.3-m1/plugins/Makefile.am 2010-06-21 16:39:45.000000000 +0900 @@ -239,7 +239,9 @@ mm-plugin-anydata.c \ mm-plugin-anydata.h \ mm-modem-anydata-cdma.c \ - mm-modem-anydata-cdma.h + mm-modem-anydata-cdma.h \ + mm-modem-anydata-gsm.c \ + mm-modem-anydata-gsm.h libmm_plugin_anydata_la_CPPFLAGS = \ $(MM_CFLAGS) \ --- /dev/null 2010-06-22 21:58:35.035342748 +0900 +++ modemmanager-0.3-m1/plugins/mm-modem-anydata-gsm.c 2010-06-22 12:38:04.000000000 +0900 @@ -0,0 +1,183 @@ +/* -*- 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. + * Copyright (C) 2010 Hiroshi Miura + * + * many come from huawei plugin + */ + +#include +#include +#include + +#define G_UDEV_API_IS_SUBJECT_TO_CHANGE +#include + +#include "mm-modem-anydata-gsm.h" +#include "mm-modem-gsm-network.h" +#include "mm-errors.h" +#include "mm-callback-info.h" +#include "mm-serial-port.h" +#include "mm-serial-parsers.h" + +static void modem_init (MMModem *modem_class); +static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class); + +G_DEFINE_TYPE_EXTENDED (MMModemAnydataGsm, mm_modem_anydata_gsm, MM_TYPE_GENERIC_GSM, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_GSM_NETWORK, modem_gsm_network_init)) + + +MMModem * +mm_modem_anydata_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_ANYDATA_GSM, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + 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; + const char *sys[] = { "tty", NULL }; + GUdevClient *client; + GUdevDevice *device = NULL; + MMPort *port = NULL; + int usbif; + + client = g_udev_client_new (sys); + if (!client) { + g_set_error (error, 0, 0, "Could not get udev client."); + return FALSE; + } + + device = g_udev_client_query_by_subsystem_and_name (client, subsys, name); + if (!device) { + g_set_error (error, 0, 0, "Could not get udev device."); + goto out; + } + + usbif = g_udev_device_get_property_as_int (device, "ID_USB_INTERFACE_NUM"); + if (usbif < 0) { + g_set_error (error, 0, 0, "Could not get USB device interface number."); + goto out; + } + + if (usbif == 0) { + if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_PRIMARY)) + ptype = MM_PORT_TYPE_PRIMARY; + } else if (suggested_type == MM_PORT_TYPE_SECONDARY) { + if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_SECONDARY)) + ptype = MM_PORT_TYPE_SECONDARY; + } + + port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error); + + if (port && MM_IS_SERIAL_PORT (port)) { + g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL); + } +out: + if (device) + g_object_unref (device); + g_object_unref (client); + return !!port; +} + +/*****************************************************************************/ +static void +anydata_reg_info_invoke (MMCallbackInfo *info) +{ + MMModemGsmNetworkRegInfoFn callback = (MMModemGsmNetworkRegInfoFn) info->callback; + + callback (MM_MODEM_GSM_NETWORK (info->modem), + MM_MODEM_GSM_NETWORK_REG_STATUS_HOME, + NULL, + NULL, + info->error, + info->user_data); +} + +static void +get_registration_info (MMModemGsmNetwork *self, + MMModemGsmNetworkRegInfoFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = mm_callback_info_new_full (MM_MODEM (self), + anydata_reg_info_invoke, + G_CALLBACK (callback), + user_data); + /* Registration info updates are handled internally either by unsolicited + * updates or by polling. Thus just return the cached registration state. + */ + mm_callback_info_schedule (info); +} + +static void +do_register (MMModemGsmNetwork *modem, + const char *network_id, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + /* Clear any previous registration */ + mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (modem)); + + info = mm_callback_info_new (MM_MODEM (modem), callback, user_data); + mm_callback_info_schedule (info); +} +/*****************************************************************************/ + +static void +modem_init (MMModem *modem_class) +{ + modem_class->grab_port = grab_port; +} + +static void +modem_gsm_network_init (MMModemGsmNetwork *class) +{ + class->do_register = do_register; + class->get_registration_info = get_registration_info; +} + +static void +mm_modem_anydata_gsm_init (MMModemAnydataGsm *self) +{ +} + +static void +mm_modem_anydata_gsm_class_init (MMModemAnydataGsmClass *klass) +{ + mm_modem_anydata_gsm_parent_class = g_type_class_peek_parent (klass); +} --- /dev/null 2010-06-22 21:58:35.035342748 +0900 +++ modemmanager-0.3-m1/plugins/mm-modem-anydata-gsm.h 2010-06-21 16:54:02.000000000 +0900 @@ -0,0 +1,51 @@ +/* -*- 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_ANYDATA_GSM_H +#define MM_MODEM_ANYDATA_GSM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_ANYDATA_GSM (mm_modem_anydata_gsm_get_type ()) +#define MM_MODEM_ANYDATA_GSM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), MM_TYPE_MODEM_ANYDATA_GSM, \ + MMModemAnydataGsm)) +#define MM_MODEM_ANYDATA_GSM_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_ANYDATA_GSM,\ + MMModemAnydataGsmClass)) +#define MM_IS_MODEM_ANYDATA_GSM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ANYDATA_GSM)) +#define MM_IS_MODEM_ANYDATA_GSM_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_ANYDATA_GSM)) +#define MM_MODEM_ANYDATA_GSM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_ANYDATA_GSM, \ + MMModemAnydataGsmClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemAnydataGsm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemAnydataGsmClass; + +GType mm_modem_anydata_gsm_get_type (void); + +MMModem *mm_modem_anydata_gsm_new (const char *device, + const char *driver, + const char *plugin); + +#endif /* MM_MODEM_ANYDATA_GSM_H */ --- modemmanager-0.3/plugins/mm-plugin-anydata.c 2010-01-21 00:51:42.000000000 +0900 +++ modemmanager-0.3-m1/plugins/mm-plugin-anydata.c 2010-06-21 16:41:39.000000000 +0900 @@ -18,6 +18,7 @@ #include #include "mm-plugin-anydata.h" #include "mm-modem-anydata-cdma.h" +#include "mm-modem-anydata-gsm.h" G_DEFINE_TYPE (MMPluginAnydata, mm_plugin_anydata, MM_TYPE_PLUGIN_BASE) @@ -42,9 +43,11 @@ static guint32 get_level_for_capabilities (guint32 capabilities) { - /* Only CDMA for now */ if (capabilities & CAP_CDMA) return 10; + if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) + return 10; + return 0; } @@ -130,12 +133,12 @@ name = g_udev_device_get_name (port); caps = mm_plugin_base_supports_task_get_probed_capabilities (task); - if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { - g_set_error (error, 0, 0, "Only CDMA modems are currently supported by this plugin."); - return NULL; - } - if (!existing) { + if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { + modem = mm_modem_anydata_gsm_new (sysfs_path, + mm_plugin_base_supports_task_get_driver(task), + mm_plugin_get_name (MM_PLUGIN (base))); + } if (caps & CAP_CDMA) { modem = mm_modem_anydata_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task),