37
37
enum connman_device_type type;
38
38
enum connman_device_mode mode;
39
39
connman_bool_t secondary;
40
connman_bool_t offlinemode;
41
connman_bool_t blocked;
40
42
connman_bool_t powered;
43
connman_bool_t powered_pending;
44
connman_bool_t powered_persistent;
41
45
connman_bool_t carrier;
42
46
connman_bool_t scanning;
43
47
connman_bool_t disconnected;
85
static void reset_scan_trigger(struct connman_device *device)
90
static void clear_scan_trigger(struct connman_device *device)
87
92
if (device->scan_timeout > 0) {
88
93
g_source_remove(device->scan_timeout);
89
94
device->scan_timeout = 0;
98
static void reset_scan_trigger(struct connman_device *device)
100
clear_scan_trigger(device);
92
102
if (device->scan_interval > 0) {
93
103
guint interval = device->scan_interval;
109
static void force_scan_trigger(struct connman_device *device)
111
clear_scan_trigger(device);
113
device->scan_timeout = g_timeout_add_seconds(5,
114
device_scan_trigger, device);
99
117
static const char *type2description(enum connman_device_type type)
190
208
switch (device->element.ipv4.method) {
191
209
case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
192
case CONNMAN_IPCONFIG_METHOD_OFF:
210
case CONNMAN_IPCONFIG_METHOD_IGNORE:
194
212
case CONNMAN_IPCONFIG_METHOD_STATIC:
195
213
type = CONNMAN_ELEMENT_TYPE_IPV4;
246
264
static int set_carrier(struct connman_device *device, connman_bool_t carrier)
248
struct connman_service *service;
250
266
if (carrier == TRUE)
251
267
__connman_profile_add_device(device);
253
269
__connman_profile_remove_device(device);
255
service = __connman_service_lookup_from_device(device);
256
__connman_service_set_carrier(service, carrier);
258
271
return set_connected(device, carrier);
303
316
if (powered == TRUE) {
304
317
if (driver->enable) {
318
device->powered_pending = powered;
305
320
err = driver->enable(device);
307
322
__connman_notifier_enable(type);
326
device->powered_pending = powered;
328
clear_scan_trigger(device);
311
330
g_hash_table_remove_all(device->networks);
313
332
set_carrier(device, FALSE);
485
506
dbus_message_iter_get_basic(&value, &powered);
508
device->powered_persistent = powered;
510
__connman_storage_save_device(device);
487
512
if (device->powered == powered)
488
513
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
522
547
if (device->scan_interval != interval) {
523
548
device->scan_interval = interval;
550
__connman_storage_save_device(device);
525
552
reset_scan_trigger(device);
527
554
} else if (g_str_has_prefix(name, "IPv4.") == TRUE) {
557
if (device->ipconfig == NULL)
558
return __connman_error_invalid_property(msg);
530
560
switch (device->mode) {
531
561
case CONNMAN_DEVICE_MODE_UNKNOWN:
532
562
case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
656
684
CONNMAN_DEVICE_INTERFACE);
659
static void device_enable(struct connman_device *device)
661
DBG("device %p", device);
663
if (device->powered == TRUE)
666
if (device->driver->enable) {
667
if (device->driver->enable(device) == 0) {
668
enum connman_service_type type;
670
device->powered = TRUE;
672
type = __connman_device_get_service_type(device);
673
__connman_notifier_enable(type);
678
static void device_disable(struct connman_device *device)
680
DBG("device %p", device);
682
if (device->powered == FALSE)
685
g_hash_table_remove_all(device->networks);
687
if (device->driver->disable) {
688
if (device->driver->disable(device) == 0) {
689
enum connman_service_type type;
691
device->powered = FALSE;
693
type = __connman_device_get_service_type(device);
694
__connman_notifier_disable(type);
699
687
static int setup_device(struct connman_device *device)
689
enum connman_service_type type;
703
692
DBG("device %p", device);
752
746
static void remove_device(struct connman_device *device)
748
enum connman_service_type type;
754
750
DBG("device %p", device);
756
device_disable(device);
752
__connman_device_disable(device);
758
754
switch (device->mode) {
759
755
case CONNMAN_DEVICE_MODE_UNKNOWN:
876
875
g_free(device->control);
877
876
g_free(device->interface);
879
connman_ipconfig_unref(device->ipconfig);
878
if (device->ipconfig != NULL) {
879
connman_ipconfig_unref(device->ipconfig);
880
device->ipconfig = NULL;
881
883
g_free(device->last_network);
927
929
device->mode = CONNMAN_DEVICE_MODE_UNKNOWN;
928
930
device->secondary = FALSE;
932
device->powered_persistent = TRUE;
934
device->phyindex = -1;
931
937
case CONNMAN_DEVICE_TYPE_UNKNOWN:
932
938
case CONNMAN_DEVICE_TYPE_VENDOR:
957
device->ipconfig = connman_ipconfig_create();
958
if (device->ipconfig == NULL) {
959
connman_device_unref(device);
963
963
device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
964
964
g_free, unregister_network);
1039
1039
void connman_device_set_index(struct connman_device *device, int index)
1041
1041
device->element.index = index;
1043
if (device->ipconfig != NULL) {
1044
if (index == connman_ipconfig_get_index(device->ipconfig))
1047
connman_ipconfig_unref(device->ipconfig);
1050
device->ipconfig = connman_ipconfig_create(index);
1052
1061
return device->element.index;
1064
int __connman_device_get_phyindex(struct connman_device *device)
1066
return device->phyindex;
1069
void __connman_device_set_phyindex(struct connman_device *device,
1072
device->phyindex = phyindex;
1056
1076
* connman_device_set_interface:
1057
1077
* @device: device structure
1231
int __connman_device_set_blocked(struct connman_device *device,
1232
connman_bool_t blocked)
1234
connman_bool_t powered;
1236
DBG("device %p blocked %d", device, blocked);
1238
device->blocked = blocked;
1240
if (device->offlinemode == TRUE)
1243
if (blocked == FALSE)
1244
powered = device->powered_persistent;
1248
return set_powered(device, powered);
1211
1252
* connman_device_set_carrier:
1212
1253
* @device: device structure
1244
1285
if (device->powered == FALSE)
1245
1286
return -ENOLINK;
1288
reset_scan_trigger(device);
1247
1290
return device->driver->scan(device);
1250
1293
int __connman_device_enable(struct connman_device *device)
1295
enum connman_service_type type;
1298
DBG("device %p", device);
1252
1300
if (!device->driver || !device->driver->enable)
1253
1301
return -EOPNOTSUPP;
1255
if (device->powered == TRUE)
1303
if (device->powered_pending == TRUE)
1256
1304
return -EALREADY;
1258
device_enable(device);
1306
device->powered_pending = TRUE;
1308
err = device->driver->enable(device);
1312
device->powered = TRUE;
1314
type = __connman_device_get_service_type(device);
1315
__connman_notifier_enable(type);
1320
int __connman_device_enable_persistent(struct connman_device *device)
1322
DBG("device %p", device);
1324
device->powered_persistent = TRUE;
1326
__connman_storage_save_device(device);
1328
return __connman_device_enable(device);
1263
1331
int __connman_device_disable(struct connman_device *device)
1333
enum connman_service_type type;
1336
DBG("device %p", device);
1265
1338
if (!device->driver || !device->driver->disable)
1266
1339
return -EOPNOTSUPP;
1268
1341
if (device->powered == FALSE)
1269
1342
return -ENOLINK;
1271
device_disable(device);
1344
if (device->powered_pending == FALSE)
1347
device->powered_pending = FALSE;
1349
clear_scan_trigger(device);
1351
g_hash_table_remove_all(device->networks);
1353
err = device->driver->disable(device);
1357
device->powered = FALSE;
1359
type = __connman_device_get_service_type(device);
1360
__connman_notifier_disable(type);
1365
int __connman_device_disable_persistent(struct connman_device *device)
1367
DBG("device %p", device);
1369
device->powered_persistent = FALSE;
1371
__connman_storage_save_device(device);
1373
return __connman_device_disable(device);
1276
1376
int __connman_device_connect(struct connman_device *device)
1278
1378
DBG("device %p", device);
1529
1632
if (device == NULL)
1635
device->offlinemode = offlinemode;
1532
1637
powered = (offlinemode == TRUE) ? FALSE : TRUE;
1534
1639
if (device->powered == powered)
1642
if (device->powered_persistent == FALSE)
1537
1645
set_powered(device, powered);
1544
1652
__connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
1545
1653
set_offlinemode, GUINT_TO_POINTER(offlinemode));
1547
__connman_notifier_offline_mode(offlinemode);
1655
__connman_notifier_offlinemode(offlinemode);
1552
1660
void __connman_device_increase_connections(struct connman_device *device)
1554
enum connman_service_type type;
1556
1662
device->connections++;
1558
type = __connman_device_get_service_type(device);
1559
__connman_notifier_connect(type);
1562
1665
void __connman_device_decrease_connections(struct connman_device *device)
1564
enum connman_service_type type;
1566
1667
device->connections--;
1568
type = __connman_device_get_service_type(device);
1569
__connman_notifier_disconnect(type);
1677
1773
int connman_device_register(struct connman_device *device)
1679
enum connman_service_type type;
1681
1775
__connman_storage_load_device(device);
1683
switch (device->mode) {
1684
case CONNMAN_DEVICE_MODE_UNKNOWN:
1685
case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1687
case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1688
case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1689
__connman_storage_init_network(device);
1693
type = __connman_device_get_service_type(device);
1694
__connman_notifier_register(type);
1777
device->offlinemode = __connman_profile_get_offlinemode();
1696
1779
return connman_element_register(&device->element, NULL);
1705
1788
void connman_device_unregister(struct connman_device *device)
1707
enum connman_service_type type;
1709
1790
__connman_storage_save_device(device);
1711
type = __connman_device_get_service_type(device);
1712
__connman_notifier_unregister(type);
1714
1792
connman_element_unregister(&device->element);
1806
1884
static int device_load(struct connman_device *device)
1886
const char *ident = __connman_profile_active_ident();
1808
1887
GKeyFile *keyfile;
1809
gchar *pathname, *identifier, *data = NULL;
1888
GError *error = NULL;
1890
connman_bool_t powered;
1813
1893
DBG("device %p", device);
1815
pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
1816
__connman_profile_active_ident());
1817
if (pathname == NULL)
1820
keyfile = g_key_file_new();
1822
if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
1829
if (g_key_file_load_from_data(keyfile, data, length,
1830
0, NULL) == FALSE) {
1895
keyfile = __connman_storage_open(ident);
1896
if (keyfile == NULL)
1837
1899
identifier = g_strdup_printf("device_%s", device->element.name);
1838
1900
if (identifier == NULL)
1903
powered = g_key_file_get_boolean(keyfile, identifier,
1906
device->powered_persistent = powered;
1907
g_clear_error(&error);
1841
1909
switch (device->mode) {
1842
1910
case CONNMAN_DEVICE_MODE_UNKNOWN:
1843
1911
case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1845
1913
case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1846
1914
case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1847
1915
val = g_key_file_get_integer(keyfile, identifier,
1848
"ScanInterval", NULL);
1916
"ScanInterval", &error);
1917
if (error == NULL && val > 0)
1850
1918
device->scan_interval = val;
1919
g_clear_error(&error);
1855
g_key_file_free(keyfile);
1857
1924
g_free(identifier);
1926
__connman_storage_close(ident, keyfile, FALSE);
1862
1931
static int device_save(struct connman_device *device)
1933
const char *ident = __connman_profile_active_ident();
1864
1934
GKeyFile *keyfile;
1865
gchar *pathname, *identifier = NULL, *data = NULL;
1868
1937
DBG("device %p", device);
1870
pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
1871
__connman_profile_active_ident());
1872
if (pathname == NULL)
1875
keyfile = g_key_file_new();
1877
if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
1881
if (g_key_file_load_from_data(keyfile, data, length,
1939
keyfile = __connman_storage_open(ident);
1940
if (keyfile == NULL)
1889
1943
identifier = g_strdup_printf("device_%s", device->element.name);
1890
1944
if (identifier == NULL)
1947
g_key_file_set_boolean(keyfile, identifier,
1948
"Powered", device->powered_persistent);
1893
1950
switch (device->mode) {
1894
1951
case CONNMAN_DEVICE_MODE_UNKNOWN:
1895
1952
case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1905
data = g_key_file_to_data(keyfile, &length, NULL);
1907
if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
1908
connman_error("Failed to store device information");
1913
g_key_file_free(keyfile);
1915
1963
g_free(identifier);
1965
__connman_storage_close(ident, keyfile, TRUE);