583b2ad19458f6ee623af120db5312d029b804fe
[platform/upstream/connman.git] / src / manager.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2013  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 #include <connman/agent.h>
31
32 #include "connman.h"
33
34 static bool connman_state_idle;
35 static dbus_bool_t sessionmode;
36
37 static DBusMessage *get_properties(DBusConnection *conn,
38                                         DBusMessage *msg, void *data)
39 {
40         DBusMessage *reply;
41         DBusMessageIter array, dict;
42         dbus_bool_t offlinemode;
43         const char *str;
44 #if defined TIZEN_EXT
45         dbus_bool_t autoconnectmode;
46 #endif
47
48         DBG("conn %p", conn);
49
50         reply = dbus_message_new_method_return(msg);
51         if (!reply)
52                 return NULL;
53
54         dbus_message_iter_init_append(reply, &array);
55
56         connman_dbus_dict_open(&array, &dict);
57
58         str = __connman_notifier_get_state();
59         connman_dbus_dict_append_basic(&dict, "State",
60                                                 DBUS_TYPE_STRING, &str);
61
62         offlinemode = __connman_technology_get_offlinemode();
63         connman_dbus_dict_append_basic(&dict, "OfflineMode",
64                                         DBUS_TYPE_BOOLEAN, &offlinemode);
65
66         connman_dbus_dict_append_basic(&dict, "SessionMode",
67                                         DBUS_TYPE_BOOLEAN,
68                                         &sessionmode);
69 #if defined TIZEN_EXT
70         autoconnectmode = __connman_service_get_auto_connect_mode();
71         connman_dbus_dict_append_basic(&dict, "AutoConnectMode",
72                                         DBUS_TYPE_BOOLEAN,
73                                         &autoconnectmode);
74 #endif
75
76         connman_dbus_dict_close(&array, &dict);
77
78         return reply;
79 }
80
81 static DBusMessage *set_property(DBusConnection *conn,
82                                         DBusMessage *msg, void *data)
83 {
84         DBusMessageIter iter, value;
85         const char *name;
86         int type;
87
88         DBG("conn %p", conn);
89
90         if (!dbus_message_iter_init(msg, &iter))
91                 return __connman_error_invalid_arguments(msg);
92
93         if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
94                 return __connman_error_invalid_arguments(msg);
95
96         dbus_message_iter_get_basic(&iter, &name);
97         dbus_message_iter_next(&iter);
98
99         if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
100                 return __connman_error_invalid_arguments(msg);
101
102         dbus_message_iter_recurse(&iter, &value);
103
104         type = dbus_message_iter_get_arg_type(&value);
105
106         if (g_str_equal(name, "OfflineMode")) {
107                 dbus_bool_t offlinemode;
108
109                 if (type != DBUS_TYPE_BOOLEAN)
110                         return __connman_error_invalid_arguments(msg);
111
112                 dbus_message_iter_get_basic(&value, &offlinemode);
113
114                 __connman_technology_set_offlinemode(offlinemode);
115         } else if (g_str_equal(name, "SessionMode")) {
116
117                 if (type != DBUS_TYPE_BOOLEAN)
118                         return __connman_error_invalid_arguments(msg);
119
120                 dbus_message_iter_get_basic(&value, &sessionmode);
121 #if defined TIZEN_EXT
122         } else if (g_str_equal(name, "AutoConnectMode") == TRUE) {
123                 bool automode;
124
125                 if (type != DBUS_TYPE_BOOLEAN)
126                         return __connman_error_invalid_arguments(msg);
127
128                 dbus_message_iter_get_basic(&value, &automode);
129
130                 __connman_service_set_auto_connect_mode(automode);
131 #endif
132         } else
133                 return __connman_error_invalid_property(msg);
134
135         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
136 }
137
138 static void append_technology_structs(DBusMessageIter *iter, void *user_data)
139 {
140         __connman_technology_list_struct(iter);
141 }
142
143 static DBusMessage *get_technologies(DBusConnection *conn,
144                 DBusMessage *msg, void *data)
145 {
146         DBusMessage *reply;
147
148 #if !defined TIZEN_EXT
149         DBG("");
150 #endif
151
152         reply = dbus_message_new_method_return(msg);
153         if (!reply)
154                 return NULL;
155
156         __connman_dbus_append_objpath_dict_array(reply,
157                         append_technology_structs, NULL);
158
159         return reply;
160 }
161
162 static DBusMessage *remove_provider(DBusConnection *conn,
163                                     DBusMessage *msg, void *data)
164 {
165         const char *path;
166         int err;
167
168         DBG("conn %p", conn);
169
170         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
171                                                         DBUS_TYPE_INVALID);
172
173         err = __connman_provider_remove_by_path(path);
174         if (err < 0)
175                 return __connman_error_failed(msg, -err);
176
177         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
178 }
179
180 static DBusConnection *connection = NULL;
181
182 static void idle_state(bool idle)
183 {
184
185         DBG("idle %d", idle);
186
187         connman_state_idle = idle;
188
189         if (!connman_state_idle)
190                 return;
191 }
192
193 static const struct connman_notifier technology_notifier = {
194         .name           = "manager",
195         .priority       = CONNMAN_NOTIFIER_PRIORITY_HIGH,
196         .idle_state     = idle_state,
197 };
198
199 static void append_service_structs(DBusMessageIter *iter, void *user_data)
200 {
201         __connman_service_list_struct(iter);
202 }
203
204 static DBusMessage *get_services(DBusConnection *conn,
205                                         DBusMessage *msg, void *data)
206 {
207         DBusMessage *reply;
208
209         reply = dbus_message_new_method_return(msg);
210         if (!reply)
211                 return NULL;
212
213         __connman_dbus_append_objpath_dict_array(reply,
214                         append_service_structs, NULL);
215
216         return reply;
217 }
218
219 static void append_peer_structs(DBusMessageIter *iter, void *user_data)
220 {
221         __connman_peer_list_struct(iter);
222 }
223
224 static DBusMessage *get_peers(DBusConnection *conn,
225                                         DBusMessage *msg, void *data)
226 {
227         DBusMessage *reply;
228
229         reply = dbus_message_new_method_return(msg);
230         if (!reply)
231                 return NULL;
232
233         __connman_dbus_append_objpath_dict_array(reply,
234                                         append_peer_structs, NULL);
235         return reply;
236 }
237
238 static DBusMessage *get_tethering_clients(DBusConnection *conn,
239                                         DBusMessage *msg, void *data)
240 {
241         DBusMessage *reply;
242         DBusMessageIter iter, array;
243
244         reply = dbus_message_new_method_return(msg);
245         if (!reply)
246                 return NULL;
247
248         dbus_message_iter_init_append(reply, &iter);
249
250         dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
251                                 DBUS_TYPE_STRING_AS_STRING, &array);
252
253         __connman_tethering_list_clients(&array);
254
255         dbus_message_iter_close_container(&iter, &array);
256         return reply;
257 }
258
259 static DBusMessage *connect_provider(DBusConnection *conn,
260                                         DBusMessage *msg, void *data)
261 {
262         int err;
263
264         DBG("conn %p", conn);
265
266         err = __connman_provider_create_and_connect(msg);
267         if (err < 0)
268                 return __connman_error_failed(msg, -err);
269
270         return NULL;
271 }
272
273 static DBusMessage *register_agent(DBusConnection *conn,
274                                         DBusMessage *msg, void *data)
275 {
276         const char *sender, *path;
277         int err;
278
279         DBG("conn %p", conn);
280
281         sender = dbus_message_get_sender(msg);
282
283         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
284                                                         DBUS_TYPE_INVALID);
285
286         err = connman_agent_register(sender, path);
287         if (err < 0)
288                 return __connman_error_failed(msg, -err);
289
290         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
291 }
292
293 static DBusMessage *unregister_agent(DBusConnection *conn,
294                                         DBusMessage *msg, void *data)
295 {
296         const char *sender, *path;
297         int err;
298
299         DBG("conn %p", conn);
300
301         sender = dbus_message_get_sender(msg);
302
303         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
304                                                         DBUS_TYPE_INVALID);
305
306         err = connman_agent_unregister(sender, path);
307         if (err < 0)
308                 return __connman_error_failed(msg, -err);
309
310         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
311 }
312
313 static DBusMessage *register_counter(DBusConnection *conn,
314                                         DBusMessage *msg, void *data)
315 {
316         const char *sender, *path;
317         unsigned int accuracy, period;
318         int err;
319
320         DBG("conn %p", conn);
321
322         sender = dbus_message_get_sender(msg);
323
324         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
325                                                 DBUS_TYPE_UINT32, &accuracy,
326                                                 DBUS_TYPE_UINT32, &period,
327                                                         DBUS_TYPE_INVALID);
328
329         /* FIXME: add handling of accuracy parameter */
330
331         err = __connman_counter_register(sender, path, period);
332         if (err < 0)
333                 return __connman_error_failed(msg, -err);
334
335         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
336 }
337
338 static DBusMessage *unregister_counter(DBusConnection *conn,
339                                         DBusMessage *msg, void *data)
340 {
341         const char *sender, *path;
342         int err;
343
344         DBG("conn %p", conn);
345
346         sender = dbus_message_get_sender(msg);
347
348         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
349                                                         DBUS_TYPE_INVALID);
350
351         err = __connman_counter_unregister(sender, path);
352         if (err < 0)
353                 return __connman_error_failed(msg, -err);
354
355         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
356 }
357
358 static DBusMessage *create_session(DBusConnection *conn,
359                                         DBusMessage *msg, void *data)
360 {
361         int err;
362
363         DBG("conn %p", conn);
364
365         err = __connman_session_create(msg);
366         if (err < 0) {
367                 if (err == -EINPROGRESS)
368                         return NULL;
369
370                 return __connman_error_failed(msg, -err);
371         }
372
373         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
374 }
375
376 static DBusMessage *destroy_session(DBusConnection *conn,
377                                         DBusMessage *msg, void *data)
378 {
379         int err;
380
381         DBG("conn %p", conn);
382
383         err = __connman_session_destroy(msg);
384         if (err < 0)
385                 return __connman_error_failed(msg, -err);
386
387         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
388 }
389
390 static DBusMessage *request_private_network(DBusConnection *conn,
391                                         DBusMessage *msg, void *data)
392 {
393         const char *sender;
394         int  err;
395
396         DBG("conn %p", conn);
397
398         sender = dbus_message_get_sender(msg);
399
400         err = __connman_private_network_request(msg, sender);
401         if (err < 0)
402                 return __connman_error_failed(msg, -err);
403
404         return NULL;
405 }
406
407 static DBusMessage *release_private_network(DBusConnection *conn,
408                                         DBusMessage *msg, void *data)
409 {
410         const char *path;
411         int err;
412
413         DBG("conn %p", conn);
414
415         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
416                                                         DBUS_TYPE_INVALID);
417
418         err = __connman_private_network_release(path);
419         if (err < 0)
420                 return __connman_error_failed(msg, -err);
421
422         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
423 }
424
425 static int parse_peers_service_specs(DBusMessageIter *array,
426                         const unsigned char **spec, int *spec_len,
427                         const unsigned char **query, int *query_len,
428                         int *version)
429 {
430         *spec = *query = NULL;
431         *spec_len = *query_len = *version = 0;
432
433         while (dbus_message_iter_get_arg_type(array) ==
434                                                         DBUS_TYPE_DICT_ENTRY) {
435                 DBusMessageIter entry, inter, value;
436                 const char *key;
437
438                 dbus_message_iter_recurse(array, &entry);
439                 dbus_message_iter_get_basic(&entry, &key);
440
441                 dbus_message_iter_next(&entry);
442
443                 dbus_message_iter_recurse(&entry, &inter);
444
445                 if  (!g_strcmp0(key, "BonjourResponse")) {
446                         dbus_message_iter_recurse(&inter, &value);
447                         dbus_message_iter_get_fixed_array(&value,
448                                                         spec, spec_len);
449                 } else if (!g_strcmp0(key, "BonjourQuery")) {
450                         dbus_message_iter_recurse(&inter, &value);
451                         dbus_message_iter_get_fixed_array(&value,
452                                                         query, query_len);
453                 } else if (!g_strcmp0(key, "UpnpService")) {
454                         dbus_message_iter_get_basic(&inter, spec);
455                         *spec_len = strlen((const char *)*spec)+1;
456                 } else if (!g_strcmp0(key, "UpnpVersion")) {
457                         dbus_message_iter_get_basic(&inter, version);
458                 } else if (!g_strcmp0(key, "WiFiDisplayIEs")) {
459                         if (*spec || *query)
460                                 return -EINVAL;
461
462                         dbus_message_iter_recurse(&inter, &value);
463                         dbus_message_iter_get_fixed_array(&value,
464                                                         spec, spec_len);
465                 } else
466                         return -EINVAL;
467
468                 dbus_message_iter_next(array);
469         }
470
471         if ((*query && !*spec && !*version) ||
472                                 (!*spec && !*query) || (!*spec && *version))
473                 return -EINVAL;
474
475         return 0;
476 }
477
478 static DBusMessage *register_peer_service(DBusConnection *conn,
479                                                 DBusMessage *msg, void *data)
480 {
481         const unsigned char *spec, *query;
482         DBusMessageIter iter, array;
483         int spec_len, query_len;
484         dbus_bool_t master;
485         const char *owner;
486         int version;
487         int ret;
488
489         DBG("");
490
491         owner = dbus_message_get_sender(msg);
492
493         dbus_message_iter_init(msg, &iter);
494         dbus_message_iter_recurse(&iter, &array);
495
496         ret = parse_peers_service_specs(&array, &spec, &spec_len,
497                                                 &query, &query_len, &version);
498         if (ret)
499                 goto error;
500
501         dbus_message_iter_next(&iter);
502         dbus_message_iter_get_basic(&iter, &master);
503
504         ret = __connman_peer_service_register(owner, msg, spec, spec_len,
505                                         query, query_len, version,master);
506         if (!ret)
507                 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
508         if (ret == -EINPROGRESS)
509                 return NULL;
510 error:
511         return __connman_error_failed(msg, -ret);
512 }
513
514 static DBusMessage *unregister_peer_service(DBusConnection *conn,
515                                                 DBusMessage *msg, void *data)
516 {
517         const unsigned char *spec, *query;
518         DBusMessageIter iter, array;
519         int spec_len, query_len;
520         const char *owner;
521         int version;
522         int ret;
523
524         DBG("");
525
526         owner = dbus_message_get_sender(msg);
527
528         dbus_message_iter_init(msg, &iter);
529         dbus_message_iter_recurse(&iter, &array);
530
531         ret = parse_peers_service_specs(&array, &spec, &spec_len,
532                                                 &query, &query_len, &version);
533         if (ret)
534                 goto error;
535
536         ret = __connman_peer_service_unregister(owner, spec, spec_len,
537                                                 query, query_len, version);
538         if (!ret)
539                 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
540 error:
541         return __connman_error_failed(msg, -ret);
542
543 }
544
545 #if defined TIZEN_EXT_WIFI_MESH
546 static void append_mesh_peer_structs(DBusMessageIter *iter, void *user_data)
547 {
548         __connman_mesh_peer_list_struct(iter);
549 }
550
551 static DBusMessage *get_mesh_peers(DBusConnection *conn,
552                                         DBusMessage *msg, void *data)
553 {
554         DBusMessage *reply;
555
556         reply = dbus_message_new_method_return(msg);
557         if (!reply)
558                 return NULL;
559
560         __connman_dbus_append_objpath_dict_array(reply,
561                                         append_mesh_peer_structs, NULL);
562         return reply;
563 }
564
565 static DBusMessage *get_connected_mesh_peers(DBusConnection *conn,
566                                         DBusMessage *msg, void *data)
567 {
568         DBusMessage *reply;
569         DBusMessageIter iter, array;
570
571         reply = dbus_message_new_method_return(msg);
572         if (!reply)
573                 return NULL;
574
575         dbus_message_iter_init_append(reply, &iter);
576         dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
577                         DBUS_STRUCT_BEGIN_CHAR_AS_STRING
578                         DBUS_TYPE_ARRAY_AS_STRING
579                                 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
580                                         DBUS_TYPE_STRING_AS_STRING
581                                         DBUS_TYPE_VARIANT_AS_STRING
582                                 DBUS_DICT_ENTRY_END_CHAR_AS_STRING
583                         DBUS_STRUCT_END_CHAR_AS_STRING, &array);
584
585         __connman_mesh_connected_peer_list_struct(&array);
586         dbus_message_iter_close_container(&iter, &array);
587         return reply;
588 }
589
590 static DBusMessage *get_disconnected_mesh_peers(DBusConnection *conn,
591                                         DBusMessage *msg, void *data)
592 {
593         DBusMessage *reply;
594         DBusMessageIter iter, array;
595
596         reply = dbus_message_new_method_return(msg);
597         if (!reply)
598                 return NULL;
599
600         dbus_message_iter_init_append(reply, &iter);
601         dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
602                         DBUS_STRUCT_BEGIN_CHAR_AS_STRING
603                         DBUS_TYPE_ARRAY_AS_STRING
604                                 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
605                                         DBUS_TYPE_STRING_AS_STRING
606                                         DBUS_TYPE_VARIANT_AS_STRING
607                                 DBUS_DICT_ENTRY_END_CHAR_AS_STRING
608                         DBUS_STRUCT_END_CHAR_AS_STRING, &array);
609
610         __connman_mesh_disconnected_peer_list_struct(&array);
611         dbus_message_iter_close_container(&iter, &array);
612         return reply;
613 }
614
615 static DBusMessage *mesh_add_peer(DBusConnection *conn,
616                                         DBusMessage *msg, void *user_data)
617 {
618         const char *addr;
619         int err;
620
621         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr,
622                                                         DBUS_TYPE_INVALID);
623
624         DBG("Address %s", addr);
625
626         err = __connman_mesh_change_peer_status(msg, addr, CONNMAN_MESH_PEER_ADD);
627         if (err < 0)
628                 return __connman_error_failed(msg, -err);
629
630         return NULL;
631 }
632
633 static DBusMessage *mesh_remove_peer(DBusConnection *conn,
634                                         DBusMessage *msg, void *user_data)
635 {
636         const char *addr;
637         int err;
638
639         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr,
640                                                         DBUS_TYPE_INVALID);
641
642         DBG("Address %s", addr);
643
644         err = __connman_mesh_change_peer_status(msg, addr,
645                                                                                 CONNMAN_MESH_PEER_REMOVE);
646         if (err < 0)
647                 return __connman_error_failed(msg, -err);
648
649         return NULL;
650 }
651 #endif
652
653 static const GDBusMethodTable manager_methods[] = {
654         { GDBUS_METHOD("GetProperties",
655                         NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
656                         get_properties) },
657         { GDBUS_ASYNC_METHOD("SetProperty",
658                         GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
659                         NULL, set_property) },
660         { GDBUS_METHOD("GetTechnologies",
661                         NULL, GDBUS_ARGS({ "technologies", "a(oa{sv})" }),
662                         get_technologies) },
663         { GDBUS_DEPRECATED_METHOD("RemoveProvider",
664                         GDBUS_ARGS({ "provider", "o" }), NULL,
665                         remove_provider) },
666         { GDBUS_METHOD("GetServices",
667                         NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
668                         get_services) },
669         { GDBUS_METHOD("GetPeers",
670                         NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
671                         get_peers) },
672         { GDBUS_METHOD("GetTetheringClients",
673                         NULL, GDBUS_ARGS({ "tethering_clients", "as" }),
674                         get_tethering_clients) },
675         { GDBUS_DEPRECATED_ASYNC_METHOD("ConnectProvider",
676                               GDBUS_ARGS({ "provider", "a{sv}" }),
677                               GDBUS_ARGS({ "path", "o" }),
678                               connect_provider) },
679         { GDBUS_METHOD("RegisterAgent",
680                         GDBUS_ARGS({ "path", "o" }), NULL,
681                         register_agent) },
682         { GDBUS_METHOD("UnregisterAgent",
683                         GDBUS_ARGS({ "path", "o" }), NULL,
684                         unregister_agent) },
685         { GDBUS_METHOD("RegisterCounter",
686                         GDBUS_ARGS({ "path", "o" }, { "accuracy", "u" },
687                                         { "period", "u" }),
688                         NULL, register_counter) },
689         { GDBUS_METHOD("UnregisterCounter",
690                         GDBUS_ARGS({ "path", "o" }), NULL,
691                         unregister_counter) },
692         { GDBUS_ASYNC_METHOD("CreateSession",
693                         GDBUS_ARGS({ "settings", "a{sv}" },
694                                                 { "notifier", "o" }),
695                         GDBUS_ARGS({ "session", "o" }),
696                         create_session) },
697         { GDBUS_METHOD("DestroySession",
698                         GDBUS_ARGS({ "session", "o" }), NULL,
699                         destroy_session) },
700         { GDBUS_ASYNC_METHOD("RequestPrivateNetwork",
701                               NULL, GDBUS_ARGS({ "path", "o" },
702                                                { "settings", "a{sv}" },
703                                                { "socket", "h" }),
704                               request_private_network) },
705         { GDBUS_METHOD("ReleasePrivateNetwork",
706                         GDBUS_ARGS({ "path", "o" }), NULL,
707                         release_private_network) },
708         { GDBUS_ASYNC_METHOD("RegisterPeerService",
709                         GDBUS_ARGS({ "specification", "a{sv}" },
710                                    { "master", "b" }), NULL,
711                         register_peer_service) },
712         { GDBUS_METHOD("UnregisterPeerService",
713                         GDBUS_ARGS({ "specification", "a{sv}" }), NULL,
714                         unregister_peer_service) },
715 #if defined TIZEN_EXT_WIFI_MESH
716         { GDBUS_METHOD("GetMeshPeers",
717                         NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
718                         get_mesh_peers) },
719         { GDBUS_METHOD("GetConnectedMeshPeers",
720                         NULL, GDBUS_ARGS({ "peers", "a(a{sv})" }),
721                         get_connected_mesh_peers) },
722         { GDBUS_METHOD("GetDisconnectedMeshPeers",
723                         NULL, GDBUS_ARGS({ "peers", "a(a{sv})" }),
724                         get_disconnected_mesh_peers) },
725         { GDBUS_ASYNC_METHOD("MeshAddPeer", GDBUS_ARGS({ "address", "s" }), NULL,
726                                    mesh_add_peer) },
727         { GDBUS_ASYNC_METHOD("MeshRemovePeer", GDBUS_ARGS({ "address", "s" }), NULL,
728                                    mesh_remove_peer) },
729 #endif
730         { },
731 };
732
733 static const GDBusSignalTable manager_signals[] = {
734         { GDBUS_SIGNAL("PropertyChanged",
735                         GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
736         { GDBUS_SIGNAL("TechnologyAdded",
737                         GDBUS_ARGS({ "path", "o" },
738                                    { "properties", "a{sv}" })) },
739         { GDBUS_SIGNAL("TechnologyRemoved",
740                         GDBUS_ARGS({ "path", "o" })) },
741         { GDBUS_SIGNAL("ServicesChanged",
742                         GDBUS_ARGS({ "changed", "a(oa{sv})" },
743                                         { "removed", "ao" })) },
744         { GDBUS_SIGNAL("PeersChanged",
745                         GDBUS_ARGS({ "changed", "a(oa{sv})" },
746                                         { "removed", "ao" })) },
747         { },
748 };
749
750 int __connman_manager_init(void)
751 {
752         DBG("");
753
754         connection = connman_dbus_get_connection();
755         if (!connection)
756                 return -1;
757
758         if (connman_notifier_register(&technology_notifier) < 0)
759                 connman_error("Failed to register technology notifier");
760
761         g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
762                                         CONNMAN_MANAGER_INTERFACE,
763                                         manager_methods,
764                                         manager_signals, NULL, NULL, NULL);
765
766         connman_state_idle = true;
767
768         return 0;
769 }
770
771 void __connman_manager_cleanup(void)
772 {
773         DBG("");
774
775         if (!connection)
776                 return;
777
778         connman_notifier_unregister(&technology_notifier);
779
780         g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
781                                                 CONNMAN_MANAGER_INTERFACE);
782
783         dbus_connection_unref(connection);
784 }