OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 /* |
| 3 * This program is free software; you can redistribute it and/or modify |
| 4 * it under the terms of the GNU General Public License as published by |
| 5 * the Free Software Foundation; either version 2 of the License, or |
| 6 * (at your option) any later version. |
| 7 * |
| 8 * This program is distributed in the hope that it will be useful, |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 * GNU General Public License for more details: |
| 12 * |
| 13 * Copyright (C) 2008 - 2009 Novell, Inc. |
| 14 * Copyright (C) 2009 Red Hat, Inc. |
| 15 * Copyright 2011 by Samsung Electronics, Inc., |
| 16 */ |
| 17 |
| 18 #include <string.h> |
| 19 #include <gmodule.h> |
| 20 #define G_UDEV_API_IS_SUBJECT_TO_CHANGE |
| 21 #include <gudev/gudev.h> |
| 22 |
| 23 #include "mm-plugin-samsung.h" |
| 24 #include "mm-modem-samsung-gsm.h" |
| 25 |
| 26 G_DEFINE_TYPE (MMPluginSamsung, mm_plugin_samsung, MM_TYPE_PLUGIN_BASE) |
| 27 |
| 28 int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; |
| 29 int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; |
| 30 |
| 31 G_MODULE_EXPORT MMPlugin * |
| 32 mm_plugin_create (void) |
| 33 { |
| 34 return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_SAMSUNG, |
| 35 MM_PLUGIN_BASE_NAME, "Samsung", |
| 36 NULL)); |
| 37 } |
| 38 |
| 39 static guint32 |
| 40 get_level_for_capabilities (guint32 capabilities) |
| 41 { |
| 42 if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) |
| 43 return 10; |
| 44 return 0; |
| 45 } |
| 46 |
| 47 static void |
| 48 probe_result (MMPluginBase *base, |
| 49 MMPluginBaseSupportsTask *task, |
| 50 guint32 capabilities, |
| 51 gpointer user_data) |
| 52 { |
| 53 mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (cap
abilities)); |
| 54 } |
| 55 |
| 56 static MMPluginSupportsResult |
| 57 supports_port (MMPluginBase *base, |
| 58 MMModem *existing, |
| 59 MMPluginBaseSupportsTask *task) |
| 60 { |
| 61 GUdevDevice *port; |
| 62 const char *tmp; |
| 63 guint32 level; |
| 64 |
| 65 /* Can't do anything with non-serial ports */ |
| 66 port = mm_plugin_base_supports_task_get_port (task); |
| 67 |
| 68 if(!g_str_has_prefix(g_udev_device_get_subsystem(port), "tty")) |
| 69 { |
| 70 if(g_str_has_prefix(g_udev_device_get_name(port), "usb")) |
| 71 { |
| 72 goto done; |
| 73 } |
| 74 else |
| 75 { |
| 76 return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; |
| 77 } |
| 78 } |
| 79 else |
| 80 { |
| 81 tmp = g_udev_device_get_property (port, "ID_BUS"); |
| 82 |
| 83 if(g_strcmp0(tmp, "usb")) |
| 84 return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; |
| 85 |
| 86 tmp = g_udev_device_get_property (port, "ID_VENDOR_ID"); |
| 87 |
| 88 if (g_strcmp0(tmp, "04e8") && g_strcmp0(tmp, "1983")) |
| 89 { |
| 90 return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; |
| 91 } |
| 92 } |
| 93 |
| 94 done: |
| 95 |
| 96 if (g_str_has_prefix(g_udev_device_get_name (port), "usb")) { |
| 97 level = get_level_for_capabilities (1); |
| 98 if (level) { |
| 99 mm_plugin_base_supports_task_complete (task, 10); |
| 100 return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; |
| 101 } |
| 102 return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; |
| 103 } |
| 104 |
| 105 mm_plugin_base_supports_task_set_custom_init_command (task, "+CFUN=1", 10, 4
, FALSE); |
| 106 |
| 107 /* Otherwise kick off a probe */ |
| 108 if (mm_plugin_base_probe_port (base, task, NULL)) |
| 109 { |
| 110 return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; |
| 111 } |
| 112 return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; |
| 113 } |
| 114 |
| 115 static MMModem * |
| 116 grab_port (MMPluginBase *base, |
| 117 MMModem *existing, |
| 118 MMPluginBaseSupportsTask *task, |
| 119 GError **error) |
| 120 { |
| 121 GUdevDevice *port = NULL; |
| 122 MMModem *modem = NULL; |
| 123 const char *name, *subsys, *sysfs_path; |
| 124 |
| 125 port = mm_plugin_base_supports_task_get_port (task); |
| 126 g_assert (port); |
| 127 |
| 128 subsys = g_udev_device_get_subsystem (port); |
| 129 name = g_udev_device_get_name (port); |
| 130 |
| 131 sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); |
| 132 if (!existing) { |
| 133 modem = mm_modem_samsung_gsm_new (sysfs_path, |
| 134 mm_plugin_base_supports_task_get_driver
(task), |
| 135 mm_plugin_get_name (MM_PLUGIN (base))); |
| 136 |
| 137 if (modem) { |
| 138 if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN,
NULL, error)) { |
| 139 g_object_unref (modem); |
| 140 return NULL; |
| 141 } |
| 142 } |
| 143 } else { |
| 144 modem = existing; |
| 145 if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL
, error)) |
| 146 return NULL; |
| 147 } |
| 148 |
| 149 return modem; |
| 150 } |
| 151 |
| 152 static void |
| 153 mm_plugin_samsung_init (MMPluginSamsung *self) |
| 154 { |
| 155 g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); |
| 156 } |
| 157 |
| 158 static void |
| 159 mm_plugin_samsung_class_init (MMPluginSamsungClass *klass) |
| 160 { |
| 161 MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); |
| 162 |
| 163 pb_class->supports_port = supports_port; |
| 164 pb_class->grab_port = grab_port; |
| 165 } |
| 166 |
OLD | NEW |