5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #define CONNMAN_API_SUBJECT_TO_CHANGE
33 #include <connman/plugin.h>
34 #include <connman/device.h>
35 #include <connman/resolver.h>
36 #include <connman/log.h>
42 struct modem_data *modem;
45 static void owandata_callback(const char *buf, void *user_data)
47 //struct hso_data *data = user_data;
48 char *str, ip[16], nm[16], ns1[16], ns2[16], ns3[16], ns4[16], val[20];
51 str = g_strrstr(buf, "_OWANDATA");
52 if (str == NULL || strstr(buf, "ERROR") != NULL)
55 err = sscanf(str, "_OWANDATA: %d, %[^,], %[^,], "
56 "%[^,], %[^,], %[^,], %[^,], %s",
57 &num, ip, nm, ns1, ns2, ns3, ns4, val);
60 DBG("parsed %d arguments", err);
64 DBG("ip %s dns %s %s val %s", ip, ns1, ns2, val);
66 //connman_resolver_append(data->iface, NULL, ns1);
67 //connman_resolver_append(data->iface, NULL, ns2);
70 static void owancall_callback(const char *buf, void *user_data)
72 struct hso_data *data = user_data;
76 if (g_strrstr(buf, "_OWANCALL: 1, 3") != NULL) {
78 //modem_command(modem, owancall_callback, data,
79 // "_OWANCALL", "%d,%d,%d", 1, 1, 1);
82 if (g_strrstr(buf, "_OWANCALL: 1, 1") != NULL) {
84 modem_command(data->modem, owandata_callback, data,
85 "_OWANDATA", "%d", 1);
88 if (g_strrstr(buf, "\r\nOK\r\n") != NULL) {
89 modem_command(data->modem, owandata_callback, data,
90 "_OWANDATA", "%d", 1);
94 static int network_probe(struct connman_network *network)
96 DBG("network %p", network);
101 static void network_remove(struct connman_network *network)
103 DBG("network %p", network);
106 static int network_connect(struct connman_network *network)
108 DBG("network %p", network);
113 static int network_disconnect(struct connman_network *network)
115 DBG("network %p", network);
120 static struct connman_network_driver network_driver = {
121 .name = "hso-network",
122 .type = CONNMAN_NETWORK_TYPE_HSO,
123 .probe = network_probe,
124 .remove = network_remove,
125 .connect = network_connect,
126 .disconnect = network_disconnect,
129 static int hso_probe(struct connman_device *device)
131 struct hso_data *data;
133 DBG("device %p", device);
135 data = g_try_new0(struct hso_data, 1);
139 data->index = connman_device_get_index(device);
141 data->modem = modem_create("/dev/ttyHS0");
142 if (data->modem == NULL) {
147 connman_device_set_data(device, data);
149 modem_add_callback(data->modem, "_OWANCALL",
150 owancall_callback, data);
155 static void hso_remove(struct connman_device *device)
157 struct hso_data *data = connman_device_get_data(device);
159 DBG("device %p", device);
161 connman_device_set_data(device, NULL);
163 modem_destroy(data->modem);
168 static int hso_enable(struct connman_device *device)
170 struct hso_data *data = connman_device_get_data(device);
171 struct connman_network *network;
174 DBG("device %p", device);
176 err = modem_open(data->modem);
180 connman_device_set_powered(device, TRUE);
182 modem_command(data->modem, NULL, NULL, "Z", NULL);
183 modem_command(data->modem, NULL, NULL, "I", NULL);
185 modem_command(data->modem, owancall_callback, data,
186 "_OWANCALL", "%d,%d,%d", 1, 1, 1);
188 network = connman_network_create("internet", CONNMAN_NETWORK_TYPE_HSO);
189 connman_device_add_network(device, network);
194 static int hso_disable(struct connman_device *device)
196 struct hso_data *data = connman_device_get_data(device);
197 //const char *iface = connman_device_get_interface(device);
199 DBG("device %p", device);
201 //connman_resolver_remove_all(iface);
203 modem_command(data->modem, owancall_callback, data,
204 "_OWANCALL", "%d,%d,%d", 1, 0, 0);
206 connman_device_set_powered(device, FALSE);
208 modem_close(data->modem);
213 static struct connman_device_driver hso_driver = {
215 .type = CONNMAN_DEVICE_TYPE_HSO,
217 .remove = hso_remove,
218 .enable = hso_enable,
219 .disable = hso_disable,
222 static int hso_init(void)
226 err = connman_network_driver_register(&network_driver);
230 err = connman_device_driver_register(&hso_driver);
232 connman_network_driver_unregister(&network_driver);
239 static void hso_exit(void)
241 connman_device_driver_unregister(&hso_driver);
242 connman_network_driver_register(&network_driver);
245 CONNMAN_PLUGIN_DEFINE(hso, "Option HSO device plugin", VERSION,
246 CONNMAN_PLUGIN_PRIORITY_DEFAULT, hso_init, hso_exit)