RemoveProvider argument is an object path
[framework/connectivity/connman.git] / src / manager.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  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 <gdbus.h>
27
28 #include "connman.h"
29
30 static DBusMessage *get_properties(DBusConnection *conn,
31                                         DBusMessage *msg, void *data)
32 {
33         DBusMessage *reply;
34         DBusMessageIter array, dict;
35         connman_bool_t offlinemode, tethering;
36         const char *str;
37
38         DBG("conn %p", conn);
39
40         reply = dbus_message_new_method_return(msg);
41         if (reply == NULL)
42                 return NULL;
43
44         dbus_message_iter_init_append(reply, &array);
45
46         connman_dbus_dict_open(&array, &dict);
47
48         str = __connman_profile_active_path();
49         if (str != NULL)
50                 connman_dbus_dict_append_basic(&dict, "ActiveProfile",
51                                                 DBUS_TYPE_OBJECT_PATH, &str);
52
53         connman_dbus_dict_append_array(&dict, "Profiles",
54                         DBUS_TYPE_OBJECT_PATH, __connman_profile_list, NULL);
55         connman_dbus_dict_append_array(&dict, "Services",
56                         DBUS_TYPE_OBJECT_PATH, __connman_service_list, NULL);
57         connman_dbus_dict_append_array(&dict, "Technologies",
58                         DBUS_TYPE_OBJECT_PATH, __connman_technology_list, NULL);
59
60         str = __connman_notifier_get_state();
61         connman_dbus_dict_append_basic(&dict, "State",
62                                                 DBUS_TYPE_STRING, &str);
63
64         offlinemode = __connman_profile_get_offlinemode();
65         connman_dbus_dict_append_basic(&dict, "OfflineMode",
66                                         DBUS_TYPE_BOOLEAN, &offlinemode);
67
68         tethering = __connman_tethering_get_status();
69         connman_dbus_dict_append_basic(&dict, "Tethering",
70                                         DBUS_TYPE_BOOLEAN, &tethering);
71
72         connman_dbus_dict_append_array(&dict, "AvailableTechnologies",
73                 DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL);
74         connman_dbus_dict_append_array(&dict, "EnabledTechnologies",
75                 DBUS_TYPE_STRING, __connman_notifier_list_enabled, NULL);
76         connman_dbus_dict_append_array(&dict, "ConnectedTechnologies",
77                 DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
78
79         str = __connman_service_default();
80         if (str != NULL)
81                 connman_dbus_dict_append_basic(&dict, "DefaultTechnology",
82                                                 DBUS_TYPE_STRING, &str);
83
84         connman_dbus_dict_append_array(&dict, "AvailableDebugs",
85                         DBUS_TYPE_STRING, __connman_debug_list_available, NULL);
86         connman_dbus_dict_append_array(&dict, "EnabledDebugs",
87                         DBUS_TYPE_STRING, __connman_debug_list_enabled, NULL);
88
89         connman_dbus_dict_close(&array, &dict);
90
91         return reply;
92 }
93
94 static DBusMessage *set_property(DBusConnection *conn,
95                                         DBusMessage *msg, void *data)
96 {
97         DBusMessageIter iter, value;
98         const char *name;
99         int type;
100
101         DBG("conn %p", conn);
102
103         if (dbus_message_iter_init(msg, &iter) == FALSE)
104                 return __connman_error_invalid_arguments(msg);
105
106         dbus_message_iter_get_basic(&iter, &name);
107         dbus_message_iter_next(&iter);
108         dbus_message_iter_recurse(&iter, &value);
109
110         type = dbus_message_iter_get_arg_type(&value);
111
112         if (g_str_equal(name, "OfflineMode") == TRUE) {
113                 connman_bool_t offlinemode;
114
115                 if (type != DBUS_TYPE_BOOLEAN)
116                         return __connman_error_invalid_arguments(msg);
117
118                 dbus_message_iter_get_basic(&value, &offlinemode);
119
120                 __connman_profile_set_offlinemode(offlinemode, TRUE);
121
122                 __connman_profile_save_default();
123         } else if (g_str_equal(name, "Tethering") == TRUE) {
124                 connman_bool_t tethering;
125
126                 if (type != DBUS_TYPE_BOOLEAN)
127                         return __connman_error_invalid_arguments(msg);
128
129                 dbus_message_iter_get_basic(&value, &tethering);
130
131                 if (__connman_tethering_set_status(tethering) < 0)
132                         return __connman_error_invalid_arguments(msg);
133
134                 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
135                                         CONNMAN_MANAGER_INTERFACE, "Tethering",
136                                                 DBUS_TYPE_BOOLEAN, &tethering);
137         } else if (g_str_equal(name, "ActiveProfile") == TRUE) {
138                 const char *str;
139
140                 dbus_message_iter_get_basic(&value, &str);
141
142                 return __connman_error_not_supported(msg);
143         } else
144                 return __connman_error_invalid_property(msg);
145
146         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
147 }
148
149 static DBusMessage *get_state(DBusConnection *conn,
150                                         DBusMessage *msg, void *data)
151 {
152         const char *str;
153
154         DBG("conn %p", conn);
155
156         str = __connman_notifier_get_state();
157
158         return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &str,
159                                                 DBUS_TYPE_INVALID);
160 }
161
162 static DBusMessage *create_profile(DBusConnection *conn,
163                                         DBusMessage *msg, void *data)
164 {
165         const char *name, *path;
166         int err;
167
168         DBG("conn %p", conn);
169
170         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
171                                                         DBUS_TYPE_INVALID);
172
173         err = __connman_profile_create(name, &path);
174         if (err < 0)
175                 return __connman_error_failed(msg, -err);
176
177         return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path,
178                                                         DBUS_TYPE_INVALID);
179 }
180
181 static DBusMessage *remove_profile(DBusConnection *conn,
182                                         DBusMessage *msg, void *data)
183 {
184         const char *path;
185         int err;
186
187         DBG("conn %p", conn);
188
189         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
190                                                         DBUS_TYPE_INVALID);
191
192         err = __connman_profile_remove(path);
193         if (err < 0)
194                 return __connman_error_failed(msg, -err);
195
196         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
197 }
198
199 static DBusMessage *remove_provider(DBusConnection *conn,
200                                     DBusMessage *msg, void *data)
201 {
202         const char *path;
203         int err;
204
205         DBG("conn %p", conn);
206
207         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
208                                                         DBUS_TYPE_INVALID);
209
210         err = __connman_provider_remove(path);
211         if (err < 0)
212                 return __connman_error_failed(msg, -err);
213
214         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
215 }
216
217 static DBusMessage *request_scan(DBusConnection *conn,
218                                         DBusMessage *msg, void *data)
219 {
220         enum connman_service_type type;
221         const char *str;
222         int err;
223
224         DBG("conn %p", conn);
225
226         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
227                                                         DBUS_TYPE_INVALID);
228
229         if (g_strcmp0(str, "") == 0)
230                 type = CONNMAN_SERVICE_TYPE_UNKNOWN;
231         else if (g_strcmp0(str, "wifi") == 0)
232                 type = CONNMAN_SERVICE_TYPE_WIFI;
233         else if (g_strcmp0(str, "wimax") == 0)
234                 type = CONNMAN_SERVICE_TYPE_WIMAX;
235         else
236                 return __connman_error_invalid_arguments(msg);
237
238         err = __connman_element_request_scan(type);
239         if (err < 0) {
240                 if (err == -EINPROGRESS) {
241                         connman_error("Invalid return code from scan");
242                         err = -EINVAL;
243                 }
244
245                 return __connman_error_failed(msg, -err);
246         }
247
248         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
249 }
250
251 static DBusConnection *connection = NULL;
252
253 static enum connman_service_type technology_type;
254 static connman_bool_t technology_enabled;
255 static DBusMessage *technology_pending = NULL;
256 static guint technology_timeout = 0;
257
258 static void technology_reply(int error)
259 {
260         DBG("");
261
262         if (technology_timeout > 0) {
263                 g_source_remove(technology_timeout);
264                 technology_timeout = 0;
265         }
266
267         if (technology_pending != NULL) {
268                 if (error > 0) {
269                         DBusMessage *reply;
270
271                         reply = __connman_error_failed(technology_pending,
272                                                                 error);
273                         if (reply != NULL)
274                                 g_dbus_send_message(connection, reply);
275                 } else
276                         g_dbus_send_reply(connection, technology_pending,
277                                                         DBUS_TYPE_INVALID);
278
279                 dbus_message_unref(technology_pending);
280                 technology_pending = NULL;
281         }
282
283         technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
284 }
285
286 static gboolean technology_abort(gpointer user_data)
287 {
288         DBG("");
289
290         technology_timeout = 0;
291
292         technology_reply(ETIMEDOUT);
293
294         return FALSE;
295 }
296
297 static void technology_notify(enum connman_service_type type,
298                                                 connman_bool_t enabled)
299 {
300         DBG("type %d enabled %d", type, enabled);
301
302         if (type == technology_type && enabled == technology_enabled)
303                 technology_reply(0);
304 }
305
306 static struct connman_notifier technology_notifier = {
307         .name           = "manager",
308         .priority       = CONNMAN_NOTIFIER_PRIORITY_HIGH,
309         .service_enabled= technology_notify,
310 };
311
312 static DBusMessage *enable_technology(DBusConnection *conn,
313                                         DBusMessage *msg, void *data)
314 {
315         enum connman_service_type type;
316         const char *str;
317         int err;
318
319         DBG("conn %p", conn);
320
321         if (technology_pending != NULL)
322                 return __connman_error_in_progress(msg);
323
324         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
325                                                         DBUS_TYPE_INVALID);
326
327         if (g_strcmp0(str, "ethernet") == 0)
328                 type = CONNMAN_SERVICE_TYPE_ETHERNET;
329         else if (g_strcmp0(str, "wifi") == 0)
330                 type = CONNMAN_SERVICE_TYPE_WIFI;
331         else if (g_strcmp0(str, "wimax") == 0)
332                 type = CONNMAN_SERVICE_TYPE_WIMAX;
333         else if (g_strcmp0(str, "bluetooth") == 0)
334                 type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
335         else if (g_strcmp0(str, "cellular") == 0)
336                 type = CONNMAN_SERVICE_TYPE_CELLULAR;
337         else
338                 return __connman_error_invalid_arguments(msg);
339
340         if (__connman_notifier_is_registered(type) == FALSE)
341                 return __connman_error_not_registered(msg);
342
343         if (__connman_notifier_is_enabled(type) == TRUE)
344                 return __connman_error_already_enabled(msg);
345
346         technology_type = type;
347         technology_enabled = TRUE;
348         technology_pending = dbus_message_ref(msg);
349
350         err = __connman_element_enable_technology(type);
351         if (err < 0 && err != -EINPROGRESS)
352                 technology_reply(-err);
353         else
354                 technology_timeout = g_timeout_add_seconds(15,
355                                                 technology_abort, NULL);
356
357         return NULL;
358 }
359
360 static DBusMessage *disable_technology(DBusConnection *conn,
361                                         DBusMessage *msg, void *data)
362 {
363         enum connman_service_type type;
364         const char *str;
365         int err;
366
367         DBG("conn %p", conn);
368
369         if (technology_pending != NULL)
370                 return __connman_error_in_progress(msg);
371
372         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
373                                                         DBUS_TYPE_INVALID);
374
375         if (g_strcmp0(str, "ethernet") == 0)
376                 type = CONNMAN_SERVICE_TYPE_ETHERNET;
377         else if (g_strcmp0(str, "wifi") == 0)
378                 type = CONNMAN_SERVICE_TYPE_WIFI;
379         else if (g_strcmp0(str, "wimax") == 0)
380                 type = CONNMAN_SERVICE_TYPE_WIMAX;
381         else if (g_strcmp0(str, "bluetooth") == 0)
382                 type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
383         else if (g_strcmp0(str, "cellular") == 0)
384                 type = CONNMAN_SERVICE_TYPE_CELLULAR;
385         else
386                 return __connman_error_invalid_arguments(msg);
387
388         if (__connman_notifier_is_registered(type) == FALSE)
389                 return __connman_error_not_registered(msg);
390
391         if (__connman_notifier_is_enabled(type) == FALSE)
392                 return __connman_error_already_disabled(msg);
393
394         technology_type = type;
395         technology_enabled = FALSE;
396         technology_pending = dbus_message_ref(msg);
397
398         err = __connman_element_disable_technology(type);
399         if (err < 0 && err != -EINPROGRESS)
400                 technology_reply(-err);
401         else
402                 technology_timeout = g_timeout_add_seconds(10,
403                                                 technology_abort, NULL);
404
405         return NULL;
406 }
407
408 static DBusMessage *get_services(DBusConnection *conn,
409                                         DBusMessage *msg, void *data)
410 {
411         DBusMessage *reply;
412         DBusMessageIter iter, array;
413
414         reply = dbus_message_new_method_return(msg);
415         if (reply == NULL)
416                 return NULL;
417
418         dbus_message_iter_init_append(reply, &iter);
419
420         dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
421                         DBUS_STRUCT_BEGIN_CHAR_AS_STRING
422                         DBUS_TYPE_OBJECT_PATH_AS_STRING
423                         DBUS_TYPE_ARRAY_AS_STRING
424                                 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
425                                         DBUS_TYPE_STRING_AS_STRING
426                                         DBUS_TYPE_VARIANT_AS_STRING
427                                 DBUS_DICT_ENTRY_END_CHAR_AS_STRING
428                         DBUS_STRUCT_END_CHAR_AS_STRING, &array);
429
430         __connman_service_list_struct(&array);
431
432         dbus_message_iter_close_container(&iter, &array);
433
434         return reply;
435 }
436
437 static DBusMessage *lookup_service(DBusConnection *conn,
438                                         DBusMessage *msg, void *data)
439 {
440         const char *pattern, *path;
441         int err;
442
443         DBG("conn %p", conn);
444
445         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
446                                                         DBUS_TYPE_INVALID);
447
448         err = __connman_service_lookup(pattern, &path);
449         if (err < 0)
450                 return __connman_error_failed(msg, -err);
451
452         return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path,
453                                                         DBUS_TYPE_INVALID);
454 }
455
456 static DBusMessage *connect_service(DBusConnection *conn,
457                                         DBusMessage *msg, void *data)
458 {
459         int err;
460
461         DBG("conn %p", conn);
462
463         err = __connman_service_create_and_connect(msg);
464         if (err < 0) {
465                 if (err == -EINPROGRESS) {
466                         connman_error("Invalid return code from connect");
467                         err = -EINVAL;
468                 }
469
470                 return __connman_error_failed(msg, -err);
471         }
472
473         return NULL;
474 }
475
476
477 static DBusMessage *connect_provider(DBusConnection *conn,
478                                         DBusMessage *msg, void *data)
479 {
480         int err;
481
482         DBG("conn %p", conn);
483
484         err = __connman_provider_create_and_connect(msg);
485         if (err < 0) {
486                 if (err == -EINPROGRESS) {
487                         connman_error("Invalid return code from connect");
488                         err = -EINVAL;
489                 }
490
491                 return __connman_error_failed(msg, -err);
492         }
493
494         return NULL;
495 }
496
497 static DBusMessage *register_agent(DBusConnection *conn,
498                                         DBusMessage *msg, void *data)
499 {
500         const char *sender, *path;
501         int err;
502
503         DBG("conn %p", conn);
504
505         sender = dbus_message_get_sender(msg);
506
507         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
508                                                         DBUS_TYPE_INVALID);
509
510         err = __connman_agent_register(sender, path);
511         if (err < 0)
512                 return __connman_error_failed(msg, -err);
513
514         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
515 }
516
517 static DBusMessage *unregister_agent(DBusConnection *conn,
518                                         DBusMessage *msg, void *data)
519 {
520         const char *sender, *path;
521         int err;
522
523         DBG("conn %p", conn);
524
525         sender = dbus_message_get_sender(msg);
526
527         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
528                                                         DBUS_TYPE_INVALID);
529
530         err = __connman_agent_unregister(sender, path);
531         if (err < 0)
532                 return __connman_error_failed(msg, -err);
533
534         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
535 }
536
537 static DBusMessage *register_counter(DBusConnection *conn,
538                                         DBusMessage *msg, void *data)
539 {
540         const char *sender, *path;
541         unsigned int accuracy, period;
542         int err;
543
544         DBG("conn %p", conn);
545
546         sender = dbus_message_get_sender(msg);
547
548         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
549                                                 DBUS_TYPE_UINT32, &accuracy,
550                                                 DBUS_TYPE_UINT32, &period,
551                                                         DBUS_TYPE_INVALID);
552
553         /* FIXME: add handling of accuracy parameter */
554
555         err = __connman_counter_register(sender, path, period);
556         if (err < 0)
557                 return __connman_error_failed(msg, -err);
558
559         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
560 }
561
562 static DBusMessage *unregister_counter(DBusConnection *conn,
563                                         DBusMessage *msg, void *data)
564 {
565         const char *sender, *path;
566         int err;
567
568         DBG("conn %p", conn);
569
570         sender = dbus_message_get_sender(msg);
571
572         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
573                                                         DBUS_TYPE_INVALID);
574
575         err = __connman_counter_unregister(sender, path);
576         if (err < 0)
577                 return __connman_error_failed(msg, -err);
578
579         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
580 }
581
582 static DBusMessage *request_session(DBusConnection *conn,
583                                         DBusMessage *msg, void *data)
584 {
585         const char *bearer, *sender, *service_path;
586         struct connman_service *service;
587
588         DBG("conn %p", conn);
589
590         sender = dbus_message_get_sender(msg);
591
592         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &bearer,
593                                                         DBUS_TYPE_INVALID);
594
595         service = __connman_session_request(bearer, sender);
596         if (service == NULL)
597                 return __connman_error_failed(msg, EINVAL);
598
599         service_path = __connman_service_get_path(service);
600
601         return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &service_path,
602                                                 DBUS_TYPE_INVALID);
603 }
604
605 static DBusMessage *release_session(DBusConnection *conn,
606                                         DBusMessage *msg, void *data)
607 {
608         const char *sender;
609         int err;
610
611         DBG("conn %p", conn);
612
613         sender = dbus_message_get_sender(msg);
614
615         err = __connman_session_release(sender);
616         if (err < 0)
617                 return __connman_error_failed(msg, -err);
618
619         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
620 }
621
622 static GDBusMethodTable manager_methods[] = {
623         { "GetProperties",     "",      "a{sv}", get_properties     },
624         { "SetProperty",       "sv",    "",      set_property       },
625         { "GetState",          "",      "s",     get_state          },
626         { "CreateProfile",     "s",     "o",     create_profile     },
627         { "RemoveProfile",     "o",     "",      remove_profile     },
628         { "RemoveProvider",    "o",     "",      remove_provider    },
629         { "RequestScan",       "s",     "",      request_scan       },
630         { "EnableTechnology",  "s",     "",      enable_technology,
631                                                 G_DBUS_METHOD_FLAG_ASYNC },
632         { "DisableTechnology", "s",     "",      disable_technology,
633                                                 G_DBUS_METHOD_FLAG_ASYNC },
634         { "GetServices",       "",      "a(oa{sv})", get_services   },
635         { "LookupService",     "s",     "o",     lookup_service,    },
636         { "ConnectService",    "a{sv}", "o",     connect_service,
637                                                 G_DBUS_METHOD_FLAG_ASYNC },
638         { "ConnectProvider",   "a{sv}", "o",     connect_provider,
639                                                 G_DBUS_METHOD_FLAG_ASYNC },
640         { "RegisterAgent",     "o",     "",      register_agent     },
641         { "UnregisterAgent",   "o",     "",      unregister_agent   },
642         { "RegisterCounter",   "ouu",   "",      register_counter   },
643         { "UnregisterCounter", "o",     "",      unregister_counter },
644         { "RequestSession",    "s",     "o",     request_session    },
645         { "ReleaseSession",    "s",     "",      release_session    },
646         { },
647 };
648
649 static GDBusSignalTable manager_signals[] = {
650         { "PropertyChanged", "sv" },
651         { "StateChanged",    "s"  },
652         { },
653 };
654
655 static DBusMessage *nm_sleep(DBusConnection *conn,
656                                         DBusMessage *msg, void *data)
657 {
658         DBusMessage *reply;
659
660         DBG("conn %p", conn);
661
662         reply = dbus_message_new_method_return(msg);
663         if (reply == NULL)
664                 return NULL;
665
666         dbus_message_append_args(reply, DBUS_TYPE_INVALID);
667
668         return reply;
669 }
670
671 static DBusMessage *nm_wake(DBusConnection *conn,
672                                         DBusMessage *msg, void *data)
673 {
674         DBusMessage *reply;
675
676         DBG("conn %p", conn);
677
678         reply = dbus_message_new_method_return(msg);
679         if (reply == NULL)
680                 return NULL;
681
682         dbus_message_append_args(reply, DBUS_TYPE_INVALID);
683
684         return reply;
685 }
686
687 enum {
688         NM_STATE_UNKNOWN = 0,
689         NM_STATE_ASLEEP,
690         NM_STATE_CONNECTING,
691         NM_STATE_CONNECTED,
692         NM_STATE_DISCONNECTED
693 };
694
695 static DBusMessage *nm_state(DBusConnection *conn,
696                                         DBusMessage *msg, void *data)
697 {
698         DBusMessage *reply;
699         dbus_uint32_t state;
700
701         DBG("conn %p", conn);
702
703         reply = dbus_message_new_method_return(msg);
704         if (reply == NULL)
705                 return NULL;
706
707         if (__connman_notifier_count_connected() > 0)
708                 state = NM_STATE_CONNECTED;
709         else
710                 state = NM_STATE_DISCONNECTED;
711
712         dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
713                                                         DBUS_TYPE_INVALID);
714
715         return reply;
716 }
717
718 static GDBusMethodTable nm_methods[] = {
719         { "sleep", "",  "",   nm_sleep        },
720         { "wake",  "",  "",   nm_wake         },
721         { "state", "",  "u",  nm_state        },
722         { },
723 };
724
725 static gboolean nm_compat = FALSE;
726
727 int __connman_manager_init(gboolean compat)
728 {
729         DBG("");
730
731         connection = connman_dbus_get_connection();
732         if (connection == NULL)
733                 return -1;
734
735         if (connman_notifier_register(&technology_notifier) < 0)
736                 connman_error("Failed to register technology notifier");
737
738         g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
739                                         CONNMAN_MANAGER_INTERFACE,
740                                         manager_methods,
741                                         manager_signals, NULL, NULL, NULL);
742
743         if (compat == TRUE) {
744                 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
745                                         nm_methods, NULL, NULL, NULL, NULL);
746
747                 nm_compat = TRUE;
748         }
749
750         return 0;
751 }
752
753 void __connman_manager_cleanup(void)
754 {
755         DBG("");
756
757         connman_notifier_unregister(&technology_notifier);
758
759         if (connection == NULL)
760                 return;
761
762         if (nm_compat == TRUE) {
763                 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
764         }
765
766         g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
767                                                 CONNMAN_MANAGER_INTERFACE);
768
769         dbus_connection_unref(connection);
770 }