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