Remove unused __connman_detect_get_blocked function
[framework/connectivity/connman.git] / src / device.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 <errno.h>
27 #include <string.h>
28
29 #include <gdbus.h>
30
31 #include "connman.h"
32
33 static DBusConnection *connection = NULL;
34
35 struct connman_device {
36         struct connman_element element;
37         enum connman_device_type type;
38         enum connman_device_mode mode;
39         connman_bool_t offlinemode;
40         connman_bool_t blocked;
41         connman_bool_t powered;
42         connman_bool_t powered_pending;
43         connman_bool_t powered_persistent;
44         connman_bool_t scanning;
45         connman_bool_t disconnected;
46         connman_bool_t reconnect;
47         connman_uint16_t scan_interval;
48         char *name;
49         char *node;
50         char *address;
51         char *interface;
52         char *control;
53         char *ident;
54         int phyindex;
55         unsigned int connections;
56         guint scan_timeout;
57
58         struct connman_device_driver *driver;
59         void *driver_data;
60
61         connman_bool_t registered;
62
63         char *last_network;
64         struct connman_network *network;
65         GHashTable *networks;
66
67         DBusMessage *pending;
68         guint timeout;
69 };
70
71 static gboolean device_scan_trigger(gpointer user_data)
72 {
73         struct connman_device *device = user_data;
74
75         DBG("device %p", device);
76
77         if (device->driver == NULL) {
78                 device->scan_timeout = 0;
79                 return FALSE;
80         }
81
82         if (device->driver->scan)
83                 device->driver->scan(device);
84
85         return TRUE;
86 }
87
88 static void clear_scan_trigger(struct connman_device *device)
89 {
90         if (device->scan_timeout > 0) {
91                 g_source_remove(device->scan_timeout);
92                 device->scan_timeout = 0;
93         }
94 }
95
96 static void reset_scan_trigger(struct connman_device *device)
97 {
98         clear_scan_trigger(device);
99
100         if (device->scan_interval > 0) {
101                 guint interval = device->scan_interval;
102                 device->scan_timeout = g_timeout_add_seconds(interval,
103                                         device_scan_trigger, device);
104         }
105 }
106
107 static void force_scan_trigger(struct connman_device *device)
108 {
109         clear_scan_trigger(device);
110
111         device->scan_timeout = g_timeout_add_seconds(5,
112                                         device_scan_trigger, device);
113 }
114
115 void connman_device_schedule_scan(struct connman_device *device)
116 {
117         reset_scan_trigger(device);
118 }
119
120 static const char *type2description(enum connman_device_type type)
121 {
122         switch (type) {
123         case CONNMAN_DEVICE_TYPE_UNKNOWN:
124         case CONNMAN_DEVICE_TYPE_VENDOR:
125                 break;
126         case CONNMAN_DEVICE_TYPE_ETHERNET:
127                 return "Ethernet";
128         case CONNMAN_DEVICE_TYPE_WIFI:
129                 return "Wireless";
130         case CONNMAN_DEVICE_TYPE_WIMAX:
131                 return "WiMAX";
132         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
133                 return "Bluetooth";
134         case CONNMAN_DEVICE_TYPE_GPS:
135                 return "GPS";
136         case CONNMAN_DEVICE_TYPE_CELLULAR:
137                 return "Cellular";
138         }
139
140         return NULL;
141 }
142
143 static const char *type2string(enum connman_device_type type)
144 {
145         switch (type) {
146         case CONNMAN_DEVICE_TYPE_UNKNOWN:
147         case CONNMAN_DEVICE_TYPE_VENDOR:
148                 break;
149         case CONNMAN_DEVICE_TYPE_ETHERNET:
150                 return "ethernet";
151         case CONNMAN_DEVICE_TYPE_WIFI:
152                 return "wifi";
153         case CONNMAN_DEVICE_TYPE_WIMAX:
154                 return "wimax";
155         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
156                 return "bluetooth";
157         case CONNMAN_DEVICE_TYPE_GPS:
158                 return "gps";
159         case CONNMAN_DEVICE_TYPE_CELLULAR:
160                 return "cellular";
161         }
162
163         return NULL;
164 }
165
166 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
167 {
168         enum connman_device_type type = connman_device_get_type(device);
169
170         switch (type) {
171         case CONNMAN_DEVICE_TYPE_UNKNOWN:
172         case CONNMAN_DEVICE_TYPE_VENDOR:
173         case CONNMAN_DEVICE_TYPE_GPS:
174                 break;
175         case CONNMAN_DEVICE_TYPE_ETHERNET:
176                 return CONNMAN_SERVICE_TYPE_ETHERNET;
177         case CONNMAN_DEVICE_TYPE_WIFI:
178                 return CONNMAN_SERVICE_TYPE_WIFI;
179         case CONNMAN_DEVICE_TYPE_WIMAX:
180                 return CONNMAN_SERVICE_TYPE_WIMAX;
181         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
182                 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
183         case CONNMAN_DEVICE_TYPE_CELLULAR:
184                 return CONNMAN_SERVICE_TYPE_CELLULAR;
185         }
186
187         return CONNMAN_SERVICE_TYPE_UNKNOWN;
188 }
189
190 static void powered_changed(struct connman_device *device)
191 {
192         connman_dbus_property_changed_basic(device->element.path,
193                                 CONNMAN_DEVICE_INTERFACE, "Powered",
194                                         DBUS_TYPE_BOOLEAN, &device->powered);
195 }
196
197 static void blocked_changed(struct connman_device *device)
198 {
199         connman_dbus_property_changed_basic(device->element.path,
200                                 CONNMAN_DEVICE_INTERFACE, "Blocked",
201                                         DBUS_TYPE_BOOLEAN, &device->blocked);
202 }
203
204 int __connman_device_enable(struct connman_device *device)
205 {
206         int err;
207
208         DBG("device %p", device);
209
210         if (!device->driver || !device->driver->enable)
211                 return -EOPNOTSUPP;
212
213         if (device->powered_pending == TRUE)
214                 return -EALREADY;
215
216         if (device->blocked == TRUE)
217                 return -ENOLINK;
218
219         err = device->driver->enable(device);
220         if (err < 0) {
221                 if (err == -EINPROGRESS) {
222                         device->powered_pending = TRUE;
223                         device->offlinemode = FALSE;
224                         if (__connman_profile_get_offlinemode() == TRUE)
225                                 __connman_profile_set_offlinemode(FALSE, FALSE);
226                 }
227                 return err;
228         }
229
230         device->powered_pending = TRUE;
231         device->powered = TRUE;
232         device->offlinemode = FALSE;
233         if (__connman_profile_get_offlinemode() == TRUE)
234                 __connman_profile_set_offlinemode(FALSE, FALSE);
235
236         __connman_technology_enable_device(device);
237
238         return 0;
239 }
240
241 int __connman_device_disable(struct connman_device *device)
242 {
243         int err;
244
245         DBG("device %p", device);
246
247         if (!device->driver || !device->driver->disable)
248                 return -EOPNOTSUPP;
249
250         if (device->powered == FALSE)
251                 return -ENOLINK;
252
253         if (device->powered_pending == FALSE)
254                 return -EALREADY;
255
256         device->reconnect = FALSE;
257
258         clear_scan_trigger(device);
259
260         g_hash_table_remove_all(device->networks);
261
262         err = device->driver->disable(device);
263         if (err < 0) {
264                 if (err == -EINPROGRESS)
265                         device->powered_pending = FALSE;
266                 return err;
267         }
268
269         device->powered_pending = FALSE;
270         device->powered = FALSE;
271
272         __connman_technology_disable_device(device);
273
274         return 0;
275 }
276
277 static int set_powered(struct connman_device *device, connman_bool_t powered)
278 {
279         DBG("device %p powered %d", device, powered);
280
281         if (powered == TRUE)
282                 return __connman_device_enable(device);
283         else
284                 return __connman_device_disable(device);
285 }
286
287 void __connman_device_list(DBusMessageIter *iter, void *user_data)
288 {
289         __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, iter);
290 }
291
292 static void append_path(gpointer key, gpointer value, gpointer user_data)
293 {
294         struct connman_element *element = value;
295         DBusMessageIter *iter = user_data;
296
297         dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
298                                                         &element->path);
299 }
300
301 static void append_networks(DBusMessageIter *iter, void *user_data)
302 {
303         struct connman_device *device = user_data;
304
305         g_hash_table_foreach(device->networks, append_path, iter);
306 }
307
308 static DBusMessage *get_properties(DBusConnection *conn,
309                                         DBusMessage *msg, void *data)
310 {
311         struct connman_device *device = data;
312         DBusMessage *reply;
313         DBusMessageIter array, dict;
314         const char *str;
315
316         DBG("conn %p", conn);
317
318         reply = dbus_message_new_method_return(msg);
319         if (reply == NULL)
320                 return NULL;
321
322         dbus_message_iter_init_append(reply, &array);
323
324         connman_dbus_dict_open(&array, &dict);
325
326         if (device->name != NULL)
327                 connman_dbus_dict_append_basic(&dict, "Name",
328                                         DBUS_TYPE_STRING, &device->name);
329
330         str = type2string(device->type);
331         if (str != NULL)
332                 connman_dbus_dict_append_basic(&dict, "Type",
333                                                 DBUS_TYPE_STRING, &str);
334
335         if (device->address != NULL)
336                 connman_dbus_dict_append_basic(&dict, "Address",
337                                         DBUS_TYPE_STRING, &device->address);
338
339         if (device->interface != NULL)
340                 connman_dbus_dict_append_basic(&dict, "Interface",
341                                         DBUS_TYPE_STRING, &device->interface);
342
343         connman_dbus_dict_append_basic(&dict, "Powered",
344                                         DBUS_TYPE_BOOLEAN, &device->powered);
345
346         connman_dbus_dict_append_basic(&dict, "Blocked",
347                                         DBUS_TYPE_BOOLEAN, &device->blocked);
348
349         if (device->driver && device->driver->scan)
350                 connman_dbus_dict_append_basic(&dict, "Scanning",
351                                         DBUS_TYPE_BOOLEAN, &device->scanning);
352
353         switch (device->mode) {
354         case CONNMAN_DEVICE_MODE_UNKNOWN:
355                 break;
356         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
357         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
358                 if (device->scan_interval > 0)
359                         connman_dbus_dict_append_basic(&dict, "ScanInterval",
360                                 DBUS_TYPE_UINT16, &device->scan_interval);
361
362                 connman_dbus_dict_append_array(&dict, "Networks",
363                                 DBUS_TYPE_OBJECT_PATH, append_networks, device);
364                 break;
365         }
366
367         connman_dbus_dict_close(&array, &dict);
368
369         return reply;
370 }
371
372 static gboolean powered_timeout(gpointer user_data)
373 {
374         struct connman_device *device = user_data;
375
376         DBG("device %p", device);
377
378         device->timeout = 0;
379
380         if (device->pending != NULL) {
381                 DBusMessage *reply;
382
383                 reply = __connman_error_operation_timeout(device->pending);
384                 if (reply != NULL)
385                         g_dbus_send_message(connection, reply);
386
387                 dbus_message_unref(device->pending);
388                 device->pending = NULL;
389         }
390
391         return FALSE;
392 }
393
394 static DBusMessage *set_property(DBusConnection *conn,
395                                         DBusMessage *msg, void *data)
396 {
397         struct connman_device *device = data;
398         DBusMessageIter iter, value;
399         const char *name;
400         int type;
401
402         DBG("conn %p", conn);
403
404         if (dbus_message_iter_init(msg, &iter) == FALSE)
405                 return __connman_error_invalid_arguments(msg);
406
407         dbus_message_iter_get_basic(&iter, &name);
408         dbus_message_iter_next(&iter);
409         dbus_message_iter_recurse(&iter, &value);
410
411         type = dbus_message_iter_get_arg_type(&value);
412
413         if (g_str_equal(name, "Powered") == TRUE) {
414                 connman_bool_t powered;
415                 int err;
416
417                 if (type != DBUS_TYPE_BOOLEAN)
418                         return __connman_error_invalid_arguments(msg);
419
420                 dbus_message_iter_get_basic(&value, &powered);
421
422                 device->powered_persistent = powered;
423
424                 __connman_storage_save_device(device);
425
426                 if (device->powered == powered)
427                         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
428
429                 if (device->pending != NULL)
430                         return __connman_error_in_progress(msg);
431
432                 err = set_powered(device, powered);
433                 if (err < 0) {
434                         if (err != -EINPROGRESS)
435                                 return __connman_error_failed(msg, -err);
436
437                         device->pending = dbus_message_ref(msg);
438
439                         device->timeout = g_timeout_add_seconds(15,
440                                                 powered_timeout, device);
441
442                         return NULL;
443                 }
444         } else if (g_str_equal(name, "ScanInterval") == TRUE) {
445                 connman_uint16_t interval;
446
447                 switch (device->mode) {
448                 case CONNMAN_DEVICE_MODE_UNKNOWN:
449                 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
450                 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
451                         break;
452                 }
453
454                 if (type != DBUS_TYPE_UINT16)
455                         return __connman_error_invalid_arguments(msg);
456
457                 dbus_message_iter_get_basic(&value, &interval);
458
459                 if (device->scan_interval != interval) {
460                         device->scan_interval = interval;
461
462                         __connman_storage_save_device(device);
463
464                         reset_scan_trigger(device);
465                 }
466         } else
467                 return __connman_error_invalid_property(msg);
468
469         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
470 }
471
472 static DBusMessage *propose_scan(DBusConnection *conn,
473                                         DBusMessage *msg, void *data)
474 {
475         struct connman_device *device = data;
476         int err;
477
478         DBG("conn %p", conn);
479
480         switch (device->mode) {
481         case CONNMAN_DEVICE_MODE_UNKNOWN:
482                 return __connman_error_not_supported(msg);
483         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
484         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
485                 break;
486         }
487
488         err = __connman_device_scan(device);
489         if (err < 0)
490                 return __connman_error_failed(msg, -err);
491
492         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
493 }
494
495 static GDBusMethodTable device_methods[] = {
496         { "GetProperties", "",      "a{sv}", get_properties },
497         { "SetProperty",   "sv",    "",      set_property,
498                                                 G_DBUS_METHOD_FLAG_ASYNC },
499         { "ProposeScan",   "",      "",      propose_scan   },
500         { },
501 };
502
503 static GDBusSignalTable device_signals[] = {
504         { "PropertyChanged", "sv" },
505         { },
506 };
507
508 static int register_interface(struct connman_element *element)
509 {
510         struct connman_device *device = element->device;
511
512         DBG("element %p name %s", element, element->name);
513
514         if (g_dbus_register_interface(connection, element->path,
515                                         CONNMAN_DEVICE_INTERFACE,
516                                         device_methods, device_signals,
517                                         NULL, device, NULL) == FALSE) {
518                 connman_error("Failed to register %s device", element->path);
519                 return -EIO;
520         }
521
522         device->registered = TRUE;
523
524         return 0;
525 }
526
527 static void unregister_interface(struct connman_element *element)
528 {
529         struct connman_device *device = element->device;
530
531         DBG("element %p name %s", element, element->name);
532
533         device->registered = FALSE;
534
535         g_dbus_unregister_interface(connection, element->path,
536                                                 CONNMAN_DEVICE_INTERFACE);
537 }
538
539 static int setup_device(struct connman_device *device)
540 {
541         int err;
542
543         DBG("device %p", device);
544
545         err = register_interface(&device->element);
546         if (err < 0) {
547                 if (device->driver->remove)
548                         device->driver->remove(device);
549                 device->driver = NULL;
550                 return err;
551         }
552
553         __connman_technology_add_device(device);
554
555         switch (device->mode) {
556         case CONNMAN_DEVICE_MODE_UNKNOWN:
557         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
558         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
559                 break;
560         }
561
562         if (device->offlinemode == FALSE &&
563                                 device->powered_persistent == TRUE)
564                 __connman_device_enable(device);
565
566         return 0;
567 }
568
569 static void probe_driver(struct connman_element *element, gpointer user_data)
570 {
571         struct connman_device_driver *driver = user_data;
572
573         DBG("element %p name %s", element, element->name);
574
575         if (element->device == NULL)
576                 return;
577
578         if (element->device->driver != NULL)
579                 return;
580
581         if (driver->type != element->device->type)
582                 return;
583
584         if (driver->probe(element->device) < 0)
585                 return;
586
587         element->device->driver = driver;
588
589         setup_device(element->device);
590 }
591
592 static void remove_device(struct connman_device *device)
593 {
594         int err;
595
596         DBG("device %p", device);
597
598         err = __connman_device_disable(device);
599         if (err < 0 && err == -EINPROGRESS)
600                 __connman_technology_disable_device(device);
601
602         switch (device->mode) {
603         case CONNMAN_DEVICE_MODE_UNKNOWN:
604         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
605         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
606                 break;
607         }
608
609         __connman_technology_remove_device(device);
610
611         unregister_interface(&device->element);
612
613         if (device->driver->remove)
614                 device->driver->remove(device);
615
616         device->driver = NULL;
617 }
618
619 static void remove_driver(struct connman_element *element, gpointer user_data)
620 {
621         struct connman_device_driver *driver = user_data;
622
623         DBG("element %p name %s", element, element->name);
624
625         if (element->device == NULL)
626                 return;
627
628         if (element->device->driver == driver)
629                 remove_device(element->device);
630 }
631
632 connman_bool_t __connman_device_has_driver(struct connman_device *device)
633 {
634         if (device == NULL || device->driver == NULL)
635                 return FALSE;
636
637         return device->registered;
638 }
639
640 static GSList *driver_list = NULL;
641
642 static gint compare_priority(gconstpointer a, gconstpointer b)
643 {
644         const struct connman_device_driver *driver1 = a;
645         const struct connman_device_driver *driver2 = b;
646
647         return driver2->priority - driver1->priority;
648 }
649
650 /**
651  * connman_device_driver_register:
652  * @driver: device driver definition
653  *
654  * Register a new device driver
655  *
656  * Returns: %0 on success
657  */
658 int connman_device_driver_register(struct connman_device_driver *driver)
659 {
660         DBG("driver %p name %s", driver, driver->name);
661
662         driver_list = g_slist_insert_sorted(driver_list, driver,
663                                                         compare_priority);
664
665         __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
666                                                 probe_driver, driver);
667
668         return 0;
669 }
670
671 /**
672  * connman_device_driver_unregister:
673  * @driver: device driver definition
674  *
675  * Remove a previously registered device driver
676  */
677 void connman_device_driver_unregister(struct connman_device_driver *driver)
678 {
679         DBG("driver %p name %s", driver, driver->name);
680
681         driver_list = g_slist_remove(driver_list, driver);
682
683         __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
684                                                 remove_driver, driver);
685 }
686
687 static void unregister_network(gpointer data)
688 {
689         struct connman_network *network = data;
690
691         DBG("network %p", network);
692
693         connman_element_unregister((struct connman_element *) network);
694
695         __connman_network_set_device(network, NULL);
696
697         connman_network_unref(network);
698 }
699
700 static void device_destruct(struct connman_element *element)
701 {
702         struct connman_device *device = element->device;
703
704         DBG("element %p name %s", element, element->name);
705
706         if (device->timeout > 0) {
707                 g_source_remove(device->timeout);
708                 device->timeout = 0;
709         }
710
711         clear_scan_trigger(device);
712
713         if (device->pending != NULL) {
714                 dbus_message_unref(device->pending);
715                 device->pending = NULL;
716         }
717
718         g_free(device->ident);
719         g_free(device->node);
720         g_free(device->name);
721         g_free(device->address);
722         g_free(device->control);
723         g_free(device->interface);
724
725         g_free(device->last_network);
726
727         g_hash_table_destroy(device->networks);
728         device->networks = NULL;
729 }
730
731 /**
732  * connman_device_create:
733  * @node: device node name (for example an address)
734  * @type: device type
735  *
736  * Allocate a new device of given #type and assign the #node name to it.
737  *
738  * Returns: a newly-allocated #connman_device structure
739  */
740 struct connman_device *connman_device_create(const char *node,
741                                                 enum connman_device_type type)
742 {
743         struct connman_device *device;
744         const char *str;
745
746         DBG("node %s type %d", node, type);
747
748         device = g_try_new0(struct connman_device, 1);
749         if (device == NULL)
750                 return NULL;
751
752         DBG("device %p", device);
753
754         __connman_element_initialize(&device->element);
755
756         device->element.name = g_strdup(node);
757         device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
758
759         device->element.device = device;
760         device->element.destruct = device_destruct;
761
762         str = type2string(type);
763         if (str != NULL)
764                 connman_element_set_string(&device->element,
765                                         CONNMAN_PROPERTY_ID_TYPE, str);
766
767         device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
768
769         device->type = type;
770         device->name = g_strdup(type2description(device->type));
771         device->mode = CONNMAN_DEVICE_MODE_UNKNOWN;
772
773         device->powered_persistent = TRUE;
774
775         device->phyindex = -1;
776
777         switch (type) {
778         case CONNMAN_DEVICE_TYPE_UNKNOWN:
779         case CONNMAN_DEVICE_TYPE_VENDOR:
780                 device->scan_interval = 0;
781                 break;
782         case CONNMAN_DEVICE_TYPE_ETHERNET:
783         case CONNMAN_DEVICE_TYPE_WIFI:
784                 device->scan_interval = 300;
785                 break;
786         case CONNMAN_DEVICE_TYPE_WIMAX:
787                 device->scan_interval = 0;
788                 break;
789         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
790                 device->scan_interval = 0;
791                 break;
792         case CONNMAN_DEVICE_TYPE_GPS:
793                 device->scan_interval = 0;
794                 break;
795         case CONNMAN_DEVICE_TYPE_CELLULAR:
796                 device->scan_interval = 0;
797                 break;
798         }
799
800         device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
801                                                 g_free, unregister_network);
802
803         return device;
804 }
805
806 /**
807  * connman_device_ref:
808  * @device: device structure
809  *
810  * Increase reference counter of device
811  */
812 struct connman_device *connman_device_ref(struct connman_device *device)
813 {
814         if (connman_element_ref(&device->element) == NULL)
815                 return NULL;
816
817         return device;
818 }
819
820 /**
821  * connman_device_unref:
822  * @device: device structure
823  *
824  * Decrease reference counter of device
825  */
826 void connman_device_unref(struct connman_device *device)
827 {
828         connman_element_unref(&device->element);
829 }
830
831 const char *__connman_device_get_type(struct connman_device *device)
832 {
833         return type2string(device->type);
834 }
835
836 /**
837  * connman_device_get_type:
838  * @device: device structure
839  *
840  * Get type of device
841  */
842 enum connman_device_type connman_device_get_type(struct connman_device *device)
843 {
844         return device->type;
845 }
846
847 /**
848  * connman_device_get_name:
849  * @device: device structure
850  *
851  * Get unique name of device
852  */
853 const char *connman_device_get_name(struct connman_device *device)
854 {
855         return device->element.name;
856 }
857
858 /**
859  * connman_device_get_path:
860  * @device: device structure
861  *
862  * Get path name of device
863  */
864 const char *connman_device_get_path(struct connman_device *device)
865 {
866         return device->element.path;
867 }
868
869 /**
870  * connman_device_set_index:
871  * @device: device structure
872  * @index: index number
873  *
874  * Set index number of device
875  */
876 void connman_device_set_index(struct connman_device *device, int index)
877 {
878         device->element.index = index;
879 }
880
881 /**
882  * connman_device_get_index:
883  * @device: device structure
884  *
885  * Get index number of device
886  */
887 int connman_device_get_index(struct connman_device *device)
888 {
889         return device->element.index;
890 }
891
892 int __connman_device_get_phyindex(struct connman_device *device)
893 {
894         return device->phyindex;
895 }
896
897 void __connman_device_set_phyindex(struct connman_device *device,
898                                                         int phyindex)
899 {
900         device->phyindex = phyindex;
901 }
902
903 /**
904  * connman_device_set_interface:
905  * @device: device structure
906  * @interface: interface name
907  * @control: control interface
908  *
909  * Set interface name of device
910  */
911 void connman_device_set_interface(struct connman_device *device,
912                                 const char *interface, const char *control)
913 {
914         g_free(device->element.devname);
915         device->element.devname = g_strdup(interface);
916
917         g_free(device->interface);
918         device->interface = g_strdup(interface);
919
920         g_free(device->control);
921         device->control = g_strdup(control);
922
923         if (device->name == NULL) {
924                 const char *str = type2description(device->type);
925                 if (str != NULL && device->interface != NULL)
926                         device->name = g_strdup_printf("%s (%s)", str,
927                                                         device->interface);
928         }
929 }
930
931 const char *connman_device_get_control(struct connman_device *device)
932 {
933         return device->control;
934 }
935
936 /**
937  * connman_device_set_ident:
938  * @device: device structure
939  * @ident: unique identifier
940  *
941  * Set unique identifier of device
942  */
943 void connman_device_set_ident(struct connman_device *device,
944                                                         const char *ident)
945 {
946         g_free(device->ident);
947         device->ident = g_strdup(ident);
948 }
949
950 const char *connman_device_get_ident(struct connman_device *device)
951 {
952         return device->ident;
953 }
954
955 /**
956  * connman_device_set_mode:
957  * @device: device structure
958  * @mode: network mode
959  *
960  * Change network mode of device
961  */
962 void connman_device_set_mode(struct connman_device *device,
963                                                 enum connman_device_mode mode)
964 {
965         device->mode = mode;
966 }
967
968 /**
969  * connman_device_get_mode:
970  * @device: device structure
971  *
972  * Get network mode of device
973  */
974 enum connman_device_mode connman_device_get_mode(struct connman_device *device)
975 {
976         return device->mode;
977 }
978
979 /**
980  * connman_device_set_powered:
981  * @device: device structure
982  * @powered: powered state
983  *
984  * Change power state of device
985  */
986 int connman_device_set_powered(struct connman_device *device,
987                                                 connman_bool_t powered)
988 {
989         DBG("driver %p powered %d", device, powered);
990
991         if (device->timeout > 0) {
992                 g_source_remove(device->timeout);
993                 device->timeout = 0;
994         }
995
996         if (device->pending != NULL) {
997                 g_dbus_send_reply(connection, device->pending,
998                                                         DBUS_TYPE_INVALID);
999
1000                 dbus_message_unref(device->pending);
1001                 device->pending = NULL;
1002         }
1003
1004         if (device->powered == powered) {
1005                 device->powered_pending = powered;
1006                 return -EALREADY;
1007         }
1008
1009         if (powered == TRUE)
1010                 __connman_device_enable(device);
1011         else
1012                 __connman_device_disable(device);
1013
1014         device->powered = powered;
1015         device->powered_pending = powered;
1016
1017         if (device->powered == TRUE)
1018                 __connman_technology_enable_device(device);
1019         else
1020                 __connman_technology_disable_device(device);
1021
1022         if (device->offlinemode == TRUE && powered == TRUE) {
1023                 powered_changed(device);
1024                 return connman_device_set_powered(device, FALSE);
1025         }
1026
1027         if (device->registered == FALSE)
1028                 return 0;
1029
1030         powered_changed(device);
1031
1032         if (powered == FALSE)
1033                 return 0;
1034
1035         reset_scan_trigger(device);
1036
1037         if (device->driver->scan)
1038                 device->driver->scan(device);
1039
1040         return 0;
1041 }
1042
1043 int __connman_device_set_blocked(struct connman_device *device,
1044                                                 connman_bool_t blocked)
1045 {
1046         connman_bool_t powered;
1047
1048         DBG("device %p blocked %d", device, blocked);
1049
1050         device->blocked = blocked;
1051
1052         blocked_changed(device);
1053
1054         if (device->offlinemode == TRUE)
1055                 return 0;
1056
1057         connman_info("%s {rfkill} blocked %d", device->interface, blocked);
1058
1059         if (blocked == FALSE)
1060                 powered = device->powered_persistent;
1061         else
1062                 powered = FALSE;
1063
1064         return set_powered(device, powered);
1065 }
1066
1067 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
1068 {
1069         return device->blocked;
1070 }
1071
1072 int __connman_device_scan(struct connman_device *device)
1073 {
1074         if (!device->driver || !device->driver->scan)
1075                 return -EOPNOTSUPP;
1076
1077         if (device->powered == FALSE)
1078                 return -ENOLINK;
1079
1080         reset_scan_trigger(device);
1081
1082         return device->driver->scan(device);
1083 }
1084
1085 int __connman_device_enable_persistent(struct connman_device *device)
1086 {
1087         int err;
1088
1089         DBG("device %p", device);
1090
1091         device->powered_persistent = TRUE;
1092
1093         __connman_storage_save_device(device);
1094
1095         err = __connman_device_enable(device);
1096         if (err == 0 || err == -EINPROGRESS) {
1097                 device->offlinemode = FALSE;
1098                 if (__connman_profile_get_offlinemode() == TRUE) {
1099                         __connman_profile_set_offlinemode(FALSE, FALSE);
1100
1101                         __connman_profile_save_default();
1102                 }
1103         }
1104
1105         return err;
1106 }
1107
1108 int __connman_device_disable_persistent(struct connman_device *device)
1109 {
1110         DBG("device %p", device);
1111
1112         device->powered_persistent = FALSE;
1113
1114         __connman_storage_save_device(device);
1115
1116         return __connman_device_disable(device);
1117 }
1118
1119 int __connman_device_disconnect(struct connman_device *device)
1120 {
1121         GHashTableIter iter;
1122         gpointer key, value;
1123
1124         DBG("device %p", device);
1125
1126         connman_device_set_disconnected(device, TRUE);
1127
1128         g_hash_table_iter_init(&iter, device->networks);
1129
1130         while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1131                 struct connman_network *network = value;
1132
1133                 if (__connman_network_get_connecting(network) == TRUE) {
1134                         /*
1135                          * Skip network in the process of connecting.
1136                          * This is a workaround for WiFi networks serviced
1137                          * by the supplicant plugin that hold a reference
1138                          * to the network.  If we disconnect the network
1139                          * here then the referenced object will not be
1140                          * registered and usage (like launching DHCP client)
1141                          * will fail.  There is nothing to be gained by
1142                          * removing the network here anyway.
1143                          */
1144                         connman_warn("Skipping disconnect of %s",
1145                                 connman_network_get_identifier(network));
1146                         continue;
1147                 }
1148
1149                 __connman_network_disconnect(network);
1150         }
1151
1152         return 0;
1153 }
1154
1155 static void mark_network_unavailable(gpointer key, gpointer value,
1156                                                         gpointer user_data)
1157 {
1158         struct connman_network *network = value;
1159
1160         if (connman_network_get_connected(network) == TRUE)
1161                 return;
1162
1163         connman_network_set_available(network, FALSE);
1164 }
1165
1166 static gboolean remove_unavailable_network(gpointer key, gpointer value,
1167                                                         gpointer user_data)
1168 {
1169         struct connman_network *network = value;
1170
1171         if (connman_network_get_connected(network) == TRUE)
1172                 return FALSE;
1173
1174         if (connman_network_get_available(network) == TRUE)
1175                 return FALSE;
1176
1177         return TRUE;
1178 }
1179
1180 void __connman_device_cleanup_networks(struct connman_device *device)
1181 {
1182         g_hash_table_foreach_remove(device->networks,
1183                                         remove_unavailable_network, NULL);
1184 }
1185
1186 static void scanning_changed(struct connman_device *device)
1187 {
1188         connman_dbus_property_changed_basic(device->element.path,
1189                                 CONNMAN_DEVICE_INTERFACE, "Scanning",
1190                                         DBUS_TYPE_BOOLEAN, &device->scanning);
1191 }
1192
1193 /**
1194  * connman_device_set_scanning:
1195  * @device: device structure
1196  * @scanning: scanning state
1197  *
1198  * Change scanning state of device
1199  */
1200 int connman_device_set_scanning(struct connman_device *device,
1201                                                 connman_bool_t scanning)
1202 {
1203         DBG("device %p scanning %d", device, scanning);
1204
1205         if (!device->driver || !device->driver->scan)
1206                 return -EINVAL;
1207
1208         if (device->scanning == scanning)
1209                 return -EALREADY;
1210
1211         device->scanning = scanning;
1212
1213         scanning_changed(device);
1214
1215         if (scanning == TRUE) {
1216                 reset_scan_trigger(device);
1217
1218                 g_hash_table_foreach(device->networks,
1219                                         mark_network_unavailable, NULL);
1220
1221                 return 0;
1222         }
1223
1224         __connman_device_cleanup_networks(device);
1225
1226         if (device->connections > 0)
1227                 return 0;
1228
1229         if (device->disconnected == TRUE)
1230                 return 0;
1231
1232         __connman_service_auto_connect();
1233
1234         return 0;
1235 }
1236
1237 /**
1238  * connman_device_set_disconnected:
1239  * @device: device structure
1240  * @disconnected: disconnected state
1241  *
1242  * Change disconnected state of device (only for device with networks)
1243  */
1244 int connman_device_set_disconnected(struct connman_device *device,
1245                                                 connman_bool_t disconnected)
1246 {
1247         DBG("device %p disconnected %d", device, disconnected);
1248
1249         switch (device->mode) {
1250         case CONNMAN_DEVICE_MODE_UNKNOWN:
1251                 return -EINVAL;
1252         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1253         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1254                 break;
1255         }
1256
1257         if (device->disconnected == disconnected)
1258                 return -EALREADY;
1259
1260         device->disconnected = disconnected;
1261
1262         if (disconnected == TRUE)
1263                 force_scan_trigger(device);
1264
1265         return 0;
1266 }
1267
1268 /**
1269  * connman_device_get_disconnected:
1270  * @device: device structure
1271  *
1272  * Get device disconnected state
1273  */
1274 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
1275 {
1276         return device->disconnected;
1277 }
1278
1279 /**
1280  * connman_device_set_string:
1281  * @device: device structure
1282  * @key: unique identifier
1283  * @value: string value
1284  *
1285  * Set string value for specific key
1286  */
1287 int connman_device_set_string(struct connman_device *device,
1288                                         const char *key, const char *value)
1289 {
1290         DBG("device %p key %s value %s", device, key, value);
1291
1292         if (g_str_equal(key, "Address") == TRUE) {
1293                 g_free(device->address);
1294                 device->address = g_strdup(value);
1295         } else if (g_str_equal(key, "Name") == TRUE) {
1296                 g_free(device->name);
1297                 device->name = g_strdup(value);
1298         } else if (g_str_equal(key, "Node") == TRUE) {
1299                 g_free(device->node);
1300                 device->node = g_strdup(value);
1301         }
1302
1303         return connman_element_set_string(&device->element, key, value);
1304 }
1305
1306 /**
1307  * connman_device_get_string:
1308  * @device: device structure
1309  * @key: unique identifier
1310  *
1311  * Get string value for specific key
1312  */
1313 const char *connman_device_get_string(struct connman_device *device,
1314                                                         const char *key)
1315 {
1316         DBG("device %p key %s", device, key);
1317
1318         if (g_str_equal(key, "Address") == TRUE)
1319                 return device->address;
1320         else if (g_str_equal(key, "Name") == TRUE)
1321                 return device->name;
1322         else if (g_str_equal(key, "Node") == TRUE)
1323                 return device->node;
1324         else if (g_str_equal(key, "Interface") == TRUE)
1325                 return device->interface;
1326
1327         return connman_element_get_string(&device->element, key);
1328 }
1329
1330 static void set_offlinemode(struct connman_element *element, gpointer user_data)
1331 {
1332         struct connman_device *device = element->device;
1333         connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
1334         connman_bool_t powered;
1335
1336         DBG("element %p name %s", element, element->name);
1337
1338         if (device == NULL)
1339                 return;
1340
1341         device->offlinemode = offlinemode;
1342
1343         if (device->blocked == TRUE)
1344                 return;
1345
1346         powered = (offlinemode == TRUE) ? FALSE : TRUE;
1347
1348         if (device->powered == powered)
1349                 return;
1350
1351         if (device->powered_persistent == FALSE)
1352                 powered = FALSE;
1353
1354         set_powered(device, powered);
1355 }
1356
1357 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
1358 {
1359         DBG("offlinmode %d", offlinemode);
1360
1361         __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
1362                         set_offlinemode, GUINT_TO_POINTER(offlinemode));
1363
1364         __connman_notifier_offlinemode(offlinemode);
1365
1366         return 0;
1367 }
1368
1369 void __connman_device_increase_connections(struct connman_device *device)
1370 {
1371         if (device == NULL)
1372                 return;
1373
1374         device->connections++;
1375 }
1376
1377 void __connman_device_decrease_connections(struct connman_device *device)
1378 {
1379         if (device == NULL)
1380                 return;
1381
1382         device->connections--;
1383 }
1384
1385 /**
1386  * connman_device_add_network:
1387  * @device: device structure
1388  * @network: network structure
1389  *
1390  * Add new network to the device
1391  */
1392 int connman_device_add_network(struct connman_device *device,
1393                                         struct connman_network *network)
1394 {
1395         const char *identifier = connman_network_get_identifier(network);
1396         int err;
1397
1398         DBG("device %p network %p", device, network);
1399
1400         if (identifier == NULL)
1401                 return -EINVAL;
1402
1403         switch (device->mode) {
1404         case CONNMAN_DEVICE_MODE_UNKNOWN:
1405                 return -EINVAL;
1406         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1407         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1408                 break;
1409         }
1410
1411         __connman_network_set_device(network, device);
1412
1413         err = connman_element_register((struct connman_element *) network,
1414                                                         &device->element);
1415         if (err < 0) {
1416                 __connman_network_set_device(network, NULL);
1417                 return err;
1418         }
1419
1420         g_hash_table_insert(device->networks, g_strdup(identifier),
1421                                                                 network);
1422
1423         return 0;
1424 }
1425
1426 /**
1427  * connman_device_get_network:
1428  * @device: device structure
1429  * @identifier: network identifier
1430  *
1431  * Get network for given identifier
1432  */
1433 struct connman_network *connman_device_get_network(struct connman_device *device,
1434                                                         const char *identifier)
1435 {
1436         DBG("device %p identifier %s", device, identifier);
1437
1438         return g_hash_table_lookup(device->networks, identifier);
1439 }
1440
1441 /**
1442  * connman_device_remove_network:
1443  * @device: device structure
1444  * @identifier: network identifier
1445  *
1446  * Remove network for given identifier
1447  */
1448 int connman_device_remove_network(struct connman_device *device,
1449                                                         const char *identifier)
1450 {
1451         DBG("device %p identifier %s", device, identifier);
1452
1453         g_hash_table_remove(device->networks, identifier);
1454
1455         return 0;
1456 }
1457
1458 void connman_device_remove_all_networks(struct connman_device *device)
1459 {
1460         g_hash_table_remove_all(device->networks);
1461 }
1462
1463 void __connman_device_set_network(struct connman_device *device,
1464                                         struct connman_network *network)
1465 {
1466         const char *name;
1467
1468         if (device == NULL)
1469                 return;
1470
1471         if (device->network == network)
1472                 return;
1473
1474         if (device->network != NULL)
1475                 connman_network_unref(device->network);
1476
1477         if (network != NULL) {
1478                 name = connman_network_get_string(network,
1479                                                 CONNMAN_PROPERTY_ID_NAME);
1480                 g_free(device->last_network);
1481                 device->last_network = g_strdup(name);
1482
1483                 device->network = connman_network_ref(network);
1484         } else {
1485                 g_free(device->last_network);
1486                 device->last_network = NULL;
1487
1488                 device->network = NULL;
1489         }
1490 }
1491
1492 void __connman_device_set_reconnect(struct connman_device *device,
1493                                                 connman_bool_t reconnect)
1494 {
1495         device->reconnect = reconnect;
1496 }
1497
1498 connman_bool_t  __connman_device_get_reconnect(
1499                                 struct connman_device *device)
1500 {
1501         return device->reconnect;
1502 }
1503
1504 /**
1505  * connman_device_register:
1506  * @device: device structure
1507  *
1508  * Register device with the system
1509  */
1510 int connman_device_register(struct connman_device *device)
1511 {
1512         __connman_storage_load_device(device);
1513
1514         device->offlinemode = __connman_profile_get_offlinemode();
1515
1516         return connman_element_register(&device->element, NULL);
1517 }
1518
1519 /**
1520  * connman_device_unregister:
1521  * @device: device structure
1522  *
1523  * Unregister device with the system
1524  */
1525 void connman_device_unregister(struct connman_device *device)
1526 {
1527         __connman_storage_save_device(device);
1528
1529         connman_element_unregister(&device->element);
1530 }
1531
1532 /**
1533  * connman_device_get_data:
1534  * @device: device structure
1535  *
1536  * Get private device data pointer
1537  */
1538 void *connman_device_get_data(struct connman_device *device)
1539 {
1540         return device->driver_data;
1541 }
1542
1543 /**
1544  * connman_device_set_data:
1545  * @device: device structure
1546  * @data: data pointer
1547  *
1548  * Set private device data pointer
1549  */
1550 void connman_device_set_data(struct connman_device *device, void *data)
1551 {
1552         device->driver_data = data;
1553 }
1554
1555 static gboolean match_driver(struct connman_device *device,
1556                                         struct connman_device_driver *driver)
1557 {
1558         if (device->type == driver->type ||
1559                         driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1560                 return TRUE;
1561
1562         return FALSE;
1563 }
1564
1565 static int device_probe(struct connman_element *element)
1566 {
1567         struct connman_device *device = element->device;
1568         GSList *list;
1569
1570         DBG("element %p name %s", element, element->name);
1571
1572         if (device == NULL)
1573                 return -ENODEV;
1574
1575         if (device->driver != NULL)
1576                 return -EALREADY;
1577
1578         for (list = driver_list; list; list = list->next) {
1579                 struct connman_device_driver *driver = list->data;
1580
1581                 if (match_driver(device, driver) == FALSE)
1582                         continue;
1583
1584                 DBG("driver %p name %s", driver, driver->name);
1585
1586                 if (driver->probe(device) == 0) {
1587                         device->driver = driver;
1588                         break;
1589                 }
1590         }
1591
1592         if (device->driver == NULL)
1593                 return -ENODEV;
1594
1595         return setup_device(device);
1596 }
1597
1598 static void device_remove(struct connman_element *element)
1599 {
1600         struct connman_device *device = element->device;
1601
1602         DBG("element %p name %s", element, element->name);
1603
1604         if (device == NULL)
1605                 return;
1606
1607         if (device->driver == NULL)
1608                 return;
1609
1610         remove_device(device);
1611 }
1612
1613 static struct connman_driver device_driver = {
1614         .name           = "device",
1615         .type           = CONNMAN_ELEMENT_TYPE_DEVICE,
1616         .priority       = CONNMAN_DRIVER_PRIORITY_LOW,
1617         .probe          = device_probe,
1618         .remove         = device_remove,
1619 };
1620
1621 static int device_load(struct connman_device *device)
1622 {
1623         const char *ident = __connman_profile_active_ident();
1624         GKeyFile *keyfile;
1625         GError *error = NULL;
1626         gchar *identifier;
1627         connman_bool_t powered;
1628         int val;
1629
1630         DBG("device %p", device);
1631
1632         keyfile = __connman_storage_open_profile(ident);
1633         if (keyfile == NULL)
1634                 return 0;
1635
1636         identifier = g_strdup_printf("device_%s", device->element.name);
1637         if (identifier == NULL)
1638                 goto done;
1639
1640         powered = g_key_file_get_boolean(keyfile, identifier,
1641                                                 "Powered", &error);
1642         if (error == NULL)
1643                 device->powered_persistent = powered;
1644         g_clear_error(&error);
1645
1646         switch (device->mode) {
1647         case CONNMAN_DEVICE_MODE_UNKNOWN:
1648                 break;
1649         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1650         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1651                 val = g_key_file_get_integer(keyfile, identifier,
1652                                                 "ScanInterval", &error);
1653                 if (error == NULL && val > 0)
1654                         device->scan_interval = val;
1655                 g_clear_error(&error);
1656                 break;
1657         }
1658
1659 done:
1660         g_free(identifier);
1661
1662         __connman_storage_close_profile(ident, keyfile, FALSE);
1663
1664         return 0;
1665 }
1666
1667 static int device_save(struct connman_device *device)
1668 {
1669         const char *ident = __connman_profile_active_ident();
1670         GKeyFile *keyfile;
1671         gchar *identifier;
1672
1673         DBG("device %p", device);
1674
1675         keyfile = __connman_storage_open_profile(ident);
1676         if (keyfile == NULL)
1677                 return 0;
1678
1679         identifier = g_strdup_printf("device_%s", device->element.name);
1680         if (identifier == NULL)
1681                 goto done;
1682
1683         g_key_file_set_boolean(keyfile, identifier,
1684                                         "Powered", device->powered_persistent);
1685
1686         switch (device->mode) {
1687         case CONNMAN_DEVICE_MODE_UNKNOWN:
1688                 break;
1689         case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1690         case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1691                 if (device->scan_interval > 0)
1692                         g_key_file_set_integer(keyfile, identifier,
1693                                         "ScanInterval", device->scan_interval);
1694                 break;
1695         }
1696
1697 done:
1698         g_free(identifier);
1699
1700         __connman_storage_close_profile(ident, keyfile, TRUE);
1701
1702         return 0;
1703 }
1704
1705 static struct connman_storage device_storage = {
1706         .name           = "device",
1707         .priority       = CONNMAN_STORAGE_PRIORITY_LOW,
1708         .device_load    = device_load,
1709         .device_save    = device_save,
1710 };
1711
1712 int __connman_device_init(void)
1713 {
1714         DBG("");
1715
1716         connection = connman_dbus_get_connection();
1717
1718         if (connman_storage_register(&device_storage) < 0)
1719                 connman_error("Failed to register device storage");
1720
1721         return connman_driver_register(&device_driver);
1722 }
1723
1724 void __connman_device_cleanup(void)
1725 {
1726         DBG("");
1727
1728         connman_driver_unregister(&device_driver);
1729
1730         connman_storage_unregister(&device_storage);
1731
1732         dbus_connection_unref(connection);
1733 }