Check that hostname and domainname is valid
[connman] / plugins / modemmgr.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27
28 #include <gdbus.h>
29
30 #define CONNMAN_API_SUBJECT_TO_CHANGE
31 #include <connman/plugin.h>
32 #include <connman/dbus.h>
33 #include <connman/log.h>
34
35 #define MODEMMGR_SERVICE        "org.freedesktop.ModemManager"
36 #define MODEMMGR_INTERFACE      MODEMMGR_SERVICE
37
38 #define ENUMERATE_DEVICES       "EnumerateDevices"
39
40 #define TIMEOUT 5000
41
42 static void enumerate_devices_reply(DBusPendingCall *call, void *user_data)
43 {
44         DBusMessage *reply;
45
46         DBG("");
47
48         reply = dbus_pending_call_steal_reply(call);
49
50         dbus_message_unref(reply);
51 }
52
53 static void modemmgr_connect(DBusConnection *connection, void *user_data)
54 {
55         DBusMessage *message;
56         DBusPendingCall *call;
57
58         DBG("connection %p", connection);
59
60         message = dbus_message_new_method_call(MODEMMGR_SERVICE, "/",
61                                 MODEMMGR_INTERFACE, ENUMERATE_DEVICES);
62         if (message == NULL)
63                 return;
64
65         if (dbus_connection_send_with_reply(connection, message,
66                                                 &call, TIMEOUT) == FALSE) {
67                 connman_error("Failed to get modem devices");
68                 goto done;
69         }
70
71         if (call == NULL) {
72                 connman_error("D-Bus connection not available");
73                 goto done;
74         }
75
76         dbus_pending_call_set_notify(call, enumerate_devices_reply,
77                                                         NULL, NULL);
78
79 done:
80         dbus_message_unref(message);
81 }
82
83 static void modemmgr_disconnect(DBusConnection *connection, void *user_data)
84 {
85         DBG("connection %p", connection);
86 }
87
88 static DBusConnection *connection;
89 static guint watch;
90
91 static int modemmgr_init(void)
92 {
93         connection = connman_dbus_get_connection();
94         if (connection == NULL)
95                 return -EIO;
96
97         watch = g_dbus_add_service_watch(connection, MODEMMGR_SERVICE,
98                         modemmgr_connect, modemmgr_disconnect, NULL, NULL);
99         if (watch == 0) {
100                 dbus_connection_unref(connection);
101                 return -EIO;
102         }
103
104         return 0;
105 }
106
107 static void modemmgr_exit(void)
108 {
109         g_dbus_remove_watch(connection, watch);
110
111         dbus_connection_unref(connection);
112 }
113
114 CONNMAN_PLUGIN_DEFINE(modemmgr, "Modem Manager plugin", VERSION,
115                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, modemmgr_init, modemmgr_exit)