| OLD | NEW |
| 1 /* | 1 /* |
| 2 * | 2 * |
| 3 * Connection Manager | 3 * Connection Manager |
| 4 * | 4 * |
| 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. | 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. |
| 6 * | 6 * |
| 7 * This program is free software; you can redistribute it and/or modify | 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 | 8 * it under the terms of the GNU General Public License version 2 as |
| 9 * published by the Free Software Foundation. | 9 * published by the Free Software Foundation. |
| 10 * | 10 * |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (ipconfig == NULL) { | 247 if (ipconfig == NULL) { |
| 248 connman_error("%s: failed to create %s ipconfig for %s", | 248 connman_error("%s: failed to create %s ipconfig for %s", |
| 249 __func__, type2string(type), device->name); | 249 __func__, type2string(type), device->name); |
| 250 return NULL; | 250 return NULL; |
| 251 } | 251 } |
| 252 /* ipconfig's are children of the device */ | 252 /* ipconfig's are children of the device */ |
| 253 /* TODO(sleffler) check return value */ | 253 /* TODO(sleffler) check return value */ |
| 254 connman_ipconfig_register(ipconfig, &device->element); | 254 connman_ipconfig_register(ipconfig, &device->element); |
| 255 device->configmask |= 1<<(ix-1); | 255 device->configmask |= 1<<(ix-1); |
| 256 | 256 |
| 257 » __connman_storage_save_device(device); | 257 » __connman_profile_save_device(device); |
| 258 | 258 |
| 259 return ipconfig; | 259 return ipconfig; |
| 260 } | 260 } |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * set_connected | 263 * set_connected |
| 264 * @device: connman device that is now (dis)connected | 264 * @device: connman device that is now (dis)connected |
| 265 * @connected: is device connected or disconnected | 265 * @connected: is device connected or disconnected |
| 266 * | 266 * |
| 267 * Returns: %0 on success | 267 * Returns: %0 on success |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 int type, err; | 629 int type, err; |
| 630 | 630 |
| 631 type = dbus_message_iter_get_arg_type(&value); | 631 type = dbus_message_iter_get_arg_type(&value); |
| 632 if (type != DBUS_TYPE_BOOLEAN) | 632 if (type != DBUS_TYPE_BOOLEAN) |
| 633 return __connman_error_invalid_arguments(msg); | 633 return __connman_error_invalid_arguments(msg); |
| 634 | 634 |
| 635 dbus_message_iter_get_basic(&value, &powered); | 635 dbus_message_iter_get_basic(&value, &powered); |
| 636 | 636 |
| 637 device->powered_persistent = powered; | 637 device->powered_persistent = powered; |
| 638 | 638 |
| 639 » » __connman_storage_save_device(device); | 639 » » __connman_profile_save_device(device); |
| 640 | 640 |
| 641 if (device->powered == powered) | 641 if (device->powered == powered) |
| 642 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); | 642 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); |
| 643 | 643 |
| 644 if (device->pending != NULL) | 644 if (device->pending != NULL) |
| 645 return __connman_error_in_progress(msg); | 645 return __connman_error_in_progress(msg); |
| 646 | 646 |
| 647 err = set_powered(device, powered); | 647 err = set_powered(device, powered); |
| 648 if (err < 0) { | 648 if (err < 0) { |
| 649 if (err != -EINPROGRESS) | 649 if (err != -EINPROGRESS) |
| 650 return __connman_error_failed(msg, -err); | 650 return __connman_error_failed(msg, -err); |
| 651 | 651 |
| 652 device->pending = dbus_message_ref(msg); | 652 device->pending = dbus_message_ref(msg); |
| 653 | 653 |
| 654 device->timeout = g_timeout_add_seconds(15, | 654 device->timeout = g_timeout_add_seconds(15, |
| 655 powered_timeout, device); | 655 powered_timeout, device); |
| 656 | 656 |
| 657 return NULL; | 657 return NULL; |
| 658 } | 658 } |
| 659 } else if (g_str_equal(name, "ScanInterval") == TRUE) { | 659 } else if (g_str_equal(name, "ScanInterval") == TRUE) { |
| 660 connman_uint16_t interval; | 660 connman_uint16_t interval; |
| 661 | 661 |
| 662 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) | 662 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) |
| 663 return __connman_error_invalid_arguments(msg); | 663 return __connman_error_invalid_arguments(msg); |
| 664 dbus_message_iter_get_basic(&value, &interval); | 664 dbus_message_iter_get_basic(&value, &interval); |
| 665 | 665 |
| 666 if (device->scan_interval != interval) { | 666 if (device->scan_interval != interval) { |
| 667 device->scan_interval = interval; | 667 device->scan_interval = interval; |
| 668 device->scan_parameters_nondefault = TRUE; | 668 device->scan_parameters_nondefault = TRUE; |
| 669 » » » __connman_storage_save_device(device); | 669 » » » __connman_profile_save_device(device); |
| 670 connman_element_update(&device->element); | 670 connman_element_update(&device->element); |
| 671 | 671 |
| 672 if (device->scan_timeout != 0) | 672 if (device->scan_timeout != 0) |
| 673 bgscan_enable(device); | 673 bgscan_enable(device); |
| 674 } | 674 } |
| 675 } else if (g_str_equal(name, "BgscanMethod") == TRUE) { | 675 } else if (g_str_equal(name, "BgscanMethod") == TRUE) { |
| 676 const char *method; | 676 const char *method; |
| 677 | 677 |
| 678 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_STRING)) | 678 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_STRING)) |
| 679 return __connman_error_invalid_arguments(msg); | 679 return __connman_error_invalid_arguments(msg); |
| 680 dbus_message_iter_get_basic(&value, &method); | 680 dbus_message_iter_get_basic(&value, &method); |
| 681 | 681 |
| 682 if (g_strcmp0(method, device->scan_method) != 0) { | 682 if (g_strcmp0(method, device->scan_method) != 0) { |
| 683 g_free(device->scan_method); | 683 g_free(device->scan_method); |
| 684 device->scan_method = g_strdup(method); | 684 device->scan_method = g_strdup(method); |
| 685 device->scan_parameters_nondefault = TRUE; | 685 device->scan_parameters_nondefault = TRUE; |
| 686 » » » __connman_storage_save_device(device); | 686 » » » __connman_profile_save_device(device); |
| 687 connman_element_update(&device->element); | 687 connman_element_update(&device->element); |
| 688 } | 688 } |
| 689 } else if (g_str_equal(name, "BgscanShortInterval") == TRUE) { | 689 } else if (g_str_equal(name, "BgscanShortInterval") == TRUE) { |
| 690 connman_uint16_t interval; | 690 connman_uint16_t interval; |
| 691 | 691 |
| 692 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) | 692 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) |
| 693 return __connman_error_invalid_arguments(msg); | 693 return __connman_error_invalid_arguments(msg); |
| 694 dbus_message_iter_get_basic(&value, &interval); | 694 dbus_message_iter_get_basic(&value, &interval); |
| 695 | 695 |
| 696 if (device->scan_short != interval) { | 696 if (device->scan_short != interval) { |
| 697 device->scan_short = interval; | 697 device->scan_short = interval; |
| 698 device->scan_parameters_nondefault = TRUE; | 698 device->scan_parameters_nondefault = TRUE; |
| 699 » » » __connman_storage_save_device(device); | 699 » » » __connman_profile_save_device(device); |
| 700 connman_element_update(&device->element); | 700 connman_element_update(&device->element); |
| 701 } | 701 } |
| 702 } else if (g_str_equal(name, "BgscanSignalThreshold") == TRUE) { | 702 } else if (g_str_equal(name, "BgscanSignalThreshold") == TRUE) { |
| 703 int threshold; | 703 int threshold; |
| 704 | 704 |
| 705 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_INT32)) | 705 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_INT32)) |
| 706 return __connman_error_invalid_arguments(msg); | 706 return __connman_error_invalid_arguments(msg); |
| 707 dbus_message_iter_get_basic(&value, &threshold); | 707 dbus_message_iter_get_basic(&value, &threshold); |
| 708 | 708 |
| 709 if (device->signal_threshold != threshold) { | 709 if (device->signal_threshold != threshold) { |
| 710 device->signal_threshold = threshold; | 710 device->signal_threshold = threshold; |
| 711 device->scan_parameters_nondefault = TRUE; | 711 device->scan_parameters_nondefault = TRUE; |
| 712 » » » __connman_storage_save_device(device); | 712 » » » __connman_profile_save_device(device); |
| 713 connman_element_update(&device->element); | 713 connman_element_update(&device->element); |
| 714 } | 714 } |
| 715 } else | 715 } else |
| 716 return __connman_error_invalid_property(msg); | 716 return __connman_error_invalid_property(msg); |
| 717 | 717 |
| 718 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); | 718 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); |
| 719 } | 719 } |
| 720 | 720 |
| 721 static DBusMessage *propose_scan(DBusConnection *conn, DBusMessage *msg, | 721 static DBusMessage *propose_scan(DBusConnection *conn, DBusMessage *msg, |
| 722 void *data) | 722 void *data) |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 | 1529 |
| 1530 return set_powered(device, TRUE); | 1530 return set_powered(device, TRUE); |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 int __connman_device_enable_persistent(struct connman_device *device) | 1533 int __connman_device_enable_persistent(struct connman_device *device) |
| 1534 { | 1534 { |
| 1535 _DBG_DEVICE("device %p", device); | 1535 _DBG_DEVICE("device %p", device); |
| 1536 | 1536 |
| 1537 device->powered_persistent = TRUE; | 1537 device->powered_persistent = TRUE; |
| 1538 | 1538 |
| 1539 » __connman_storage_save_device(device); | 1539 » __connman_profile_save_device(device); |
| 1540 | 1540 |
| 1541 return __connman_device_enable(device); | 1541 return __connman_device_enable(device); |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 int __connman_device_disable(struct connman_device *device) | 1544 int __connman_device_disable(struct connman_device *device) |
| 1545 { | 1545 { |
| 1546 _DBG_DEVICE("device %p", device); | 1546 _DBG_DEVICE("device %p", device); |
| 1547 | 1547 |
| 1548 if (device->driver == NULL || device->driver->disable == NULL) | 1548 if (device->driver == NULL || device->driver->disable == NULL) |
| 1549 return -EOPNOTSUPP; | 1549 return -EOPNOTSUPP; |
| 1550 if (device->powered == FALSE) | 1550 if (device->powered == FALSE) |
| 1551 return -ENOLINK; | 1551 return -ENOLINK; |
| 1552 | 1552 |
| 1553 return set_powered(device, FALSE); | 1553 return set_powered(device, FALSE); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 int __connman_device_disable_persistent(struct connman_device *device) | 1556 int __connman_device_disable_persistent(struct connman_device *device) |
| 1557 { | 1557 { |
| 1558 _DBG_DEVICE("device %p", device); | 1558 _DBG_DEVICE("device %p", device); |
| 1559 | 1559 |
| 1560 device->powered_persistent = FALSE; | 1560 device->powered_persistent = FALSE; |
| 1561 | 1561 |
| 1562 » __connman_storage_save_device(device); | 1562 » __connman_profile_save_device(device); |
| 1563 | 1563 |
| 1564 return __connman_device_disable(device); | 1564 return __connman_device_disable(device); |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 int __connman_device_connect(struct connman_device *device) | 1567 int __connman_device_connect(struct connman_device *device) |
| 1568 { | 1568 { |
| 1569 _DBG_DEVICE("device %p", device); | 1569 _DBG_DEVICE("device %p", device); |
| 1570 | 1570 |
| 1571 if (device->connected == TRUE) | 1571 if (device->connected == TRUE) |
| 1572 return -EALREADY; | 1572 return -EALREADY; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 /** | 2061 /** |
| 2062 * connman_device_register: | 2062 * connman_device_register: |
| 2063 * @device: device structure | 2063 * @device: device structure |
| 2064 * | 2064 * |
| 2065 * Register device with the system | 2065 * Register device with the system |
| 2066 */ | 2066 */ |
| 2067 int connman_device_register(struct connman_device *device) | 2067 int connman_device_register(struct connman_device *device) |
| 2068 { | 2068 { |
| 2069 _DBG_DEVICE("device %p", device); | 2069 _DBG_DEVICE("device %p", device); |
| 2070 | 2070 |
| 2071 » __connman_storage_load_device(device); | 2071 » __connman_profile_load_device(device); |
| 2072 | 2072 |
| 2073 device->offlinemode = __connman_profile_get_offlinemode(); | 2073 device->offlinemode = __connman_profile_get_offlinemode(); |
| 2074 | 2074 |
| 2075 return connman_element_register(&device->element, NULL); | 2075 return connman_element_register(&device->element, NULL); |
| 2076 } | 2076 } |
| 2077 | 2077 |
| 2078 /** | 2078 /** |
| 2079 * connman_device_unregister: | 2079 * connman_device_unregister: |
| 2080 * @device: device structure | 2080 * @device: device structure |
| 2081 * | 2081 * |
| 2082 * Unregister device with the system | 2082 * Unregister device with the system |
| 2083 */ | 2083 */ |
| 2084 void connman_device_unregister(struct connman_device *device) | 2084 void connman_device_unregister(struct connman_device *device) |
| 2085 { | 2085 { |
| 2086 _DBG_DEVICE("device %p", device); | 2086 _DBG_DEVICE("device %p", device); |
| 2087 | 2087 |
| 2088 » __connman_storage_save_device(device); | 2088 » __connman_profile_save_device(device); |
| 2089 | 2089 |
| 2090 connman_element_unregister(&device->element); | 2090 connman_element_unregister(&device->element); |
| 2091 } | 2091 } |
| 2092 | 2092 |
| 2093 /** | 2093 /** |
| 2094 * connman_device_get_data: | 2094 * connman_device_get_data: |
| 2095 * @device: device structure | 2095 * @device: device structure |
| 2096 * | 2096 * |
| 2097 * Get private device data pointer | 2097 * Get private device data pointer |
| 2098 */ | 2098 */ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 if (ipconfig == NULL) { | 2209 if (ipconfig == NULL) { |
| 2210 connman_error("%s: invalid ipconfig type %s (%d)", | 2210 connman_error("%s: invalid ipconfig type %s (%d)", |
| 2211 __func__, str, type); | 2211 __func__, str, type); |
| 2212 return FALSE; | 2212 return FALSE; |
| 2213 } | 2213 } |
| 2214 device->configmask |= 1<<ix; | 2214 device->configmask |= 1<<ix; |
| 2215 } | 2215 } |
| 2216 return TRUE; | 2216 return TRUE; |
| 2217 } | 2217 } |
| 2218 | 2218 |
| 2219 static int device_load(struct connman_device *device) | 2219 static int device_load(struct connman_device *device, GKeyFile *keyfile) |
| 2220 { | 2220 { |
| 2221 const char *ident = __connman_profile_active_ident(); | |
| 2222 GKeyFile *keyfile; | |
| 2223 GError *error = NULL; | 2221 GError *error = NULL; |
| 2224 gchar *identifier; | 2222 gchar *identifier; |
| 2225 gchar *method; | 2223 gchar *method; |
| 2226 connman_bool_t powered; | 2224 connman_bool_t powered; |
| 2227 int val; | 2225 int val; |
| 2228 gchar **configs; | 2226 gchar **configs; |
| 2229 gsize nconfigs; | 2227 gsize nconfigs; |
| 2228 int err = 0; |
| 2230 | 2229 |
| 2231 _DBG_DEVICE("device %p", device); | 2230 _DBG_DEVICE("device %p", device); |
| 2232 | 2231 |
| 2233 » keyfile = __connman_storage_open(ident); | 2232 » identifier = g_strdup_printf("device_%s", device->element.name); |
| 2234 » if (keyfile == NULL) | 2233 » if (identifier == NULL) { |
| 2235 » » return 0; | 2234 » » err = -ENOMEM; |
| 2235 » » goto done; |
| 2236 » } |
| 2236 | 2237 |
| 2237 » identifier = g_strdup_printf("device_%s", device->element.name); | 2238 » if (g_key_file_has_group(keyfile, identifier) == FALSE) { |
| 2238 » if (identifier == NULL) | 2239 » » err = -ESRCH; |
| 2239 goto done; | 2240 goto done; |
| 2241 } |
| 2240 | 2242 |
| 2241 powered = g_key_file_get_boolean(keyfile, identifier, | 2243 powered = g_key_file_get_boolean(keyfile, identifier, |
| 2242 "Powered", &error); | 2244 "Powered", &error); |
| 2243 if (error == NULL) | 2245 if (error == NULL) |
| 2244 device->powered_persistent = powered; | 2246 device->powered_persistent = powered; |
| 2245 g_clear_error(&error); | 2247 g_clear_error(&error); |
| 2246 | 2248 |
| 2247 switch (device->mode) { | 2249 switch (device->mode) { |
| 2248 case CONNMAN_DEVICE_MODE_UNKNOWN: | 2250 case CONNMAN_DEVICE_MODE_UNKNOWN: |
| 2249 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: | 2251 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 | 2286 |
| 2285 configs = g_key_file_get_string_list(keyfile, identifier, "IPConfigs", | 2287 configs = g_key_file_get_string_list(keyfile, identifier, "IPConfigs", |
| 2286 &nconfigs, &error); | 2288 &nconfigs, &error); |
| 2287 if (error == NULL && configs != NULL) | 2289 if (error == NULL && configs != NULL) |
| 2288 device_load_ipconfigs(device, nconfigs, configs); | 2290 device_load_ipconfigs(device, nconfigs, configs); |
| 2289 g_strfreev(configs); | 2291 g_strfreev(configs); |
| 2290 g_clear_error(&error); | 2292 g_clear_error(&error); |
| 2291 done: | 2293 done: |
| 2292 g_free(identifier); | 2294 g_free(identifier); |
| 2293 | 2295 |
| 2294 » __connman_storage_close(ident, keyfile, FALSE); | 2296 » return err; |
| 2295 | |
| 2296 » return 0; | |
| 2297 } | 2297 } |
| 2298 | 2298 |
| 2299 static int device_save(struct connman_device *device) | 2299 static int device_save(struct connman_device *device, GKeyFile *keyfile) |
| 2300 { | 2300 { |
| 2301 const char *ident = __connman_profile_active_ident(); | |
| 2302 GKeyFile *keyfile; | |
| 2303 gchar *identifier; | 2301 gchar *identifier; |
| 2304 const char const *paths[32]; | 2302 const char const *paths[32]; |
| 2305 int npaths; | 2303 int npaths; |
| 2306 int i; | 2304 int i; |
| 2307 | 2305 |
| 2308 _DBG_DEVICE("device %p", device); | 2306 _DBG_DEVICE("device %p", device); |
| 2309 | 2307 |
| 2310 keyfile = __connman_storage_open(ident); | |
| 2311 if (keyfile == NULL) | |
| 2312 return 0; | |
| 2313 | |
| 2314 identifier = g_strdup_printf("device_%s", device->element.name); | 2308 identifier = g_strdup_printf("device_%s", device->element.name); |
| 2315 if (identifier == NULL) | 2309 if (identifier == NULL) |
| 2316 goto done; | 2310 goto done; |
| 2317 | 2311 |
| 2318 g_key_file_set_boolean(keyfile, identifier, | 2312 g_key_file_set_boolean(keyfile, identifier, |
| 2319 "Powered", device->powered_persistent); | 2313 "Powered", device->powered_persistent); |
| 2320 switch (device->mode) { | 2314 switch (device->mode) { |
| 2321 case CONNMAN_DEVICE_MODE_UNKNOWN: | 2315 case CONNMAN_DEVICE_MODE_UNKNOWN: |
| 2322 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: | 2316 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: |
| 2323 break; | 2317 break; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2342 } | 2336 } |
| 2343 | 2337 |
| 2344 __connman_ipconfig_get_keys(device, 32, paths, &npaths); | 2338 __connman_ipconfig_get_keys(device, 32, paths, &npaths); |
| 2345 g_key_file_set_string_list(keyfile, identifier, "IPConfigs", | 2339 g_key_file_set_string_list(keyfile, identifier, "IPConfigs", |
| 2346 paths, npaths); | 2340 paths, npaths); |
| 2347 for (i = 0; i < npaths; i++) | 2341 for (i = 0; i < npaths; i++) |
| 2348 g_free((gpointer)paths[i]); | 2342 g_free((gpointer)paths[i]); |
| 2349 done: | 2343 done: |
| 2350 g_free(identifier); | 2344 g_free(identifier); |
| 2351 | 2345 |
| 2352 __connman_storage_close(ident, keyfile, TRUE); | |
| 2353 | |
| 2354 return 0; | 2346 return 0; |
| 2355 } | 2347 } |
| 2356 | 2348 |
| 2357 static struct connman_storage device_storage = { | 2349 static struct connman_storage device_storage = { |
| 2358 .name = "device", | 2350 .name = "device", |
| 2359 .priority = CONNMAN_STORAGE_PRIORITY_LOW, | 2351 .priority = CONNMAN_STORAGE_PRIORITY_LOW, |
| 2360 .device_load = device_load, | 2352 .device_load = device_load, |
| 2361 .device_save = device_save, | 2353 .device_save = device_save, |
| 2362 }; | 2354 }; |
| 2363 | 2355 |
| 2364 int __connman_device_init(void) | 2356 int __connman_device_init(void) |
| 2365 { | 2357 { |
| 2366 /* TODO(sleffler) check return values */ | 2358 /* TODO(sleffler) check return values */ |
| 2367 connection = connman_dbus_get_connection(); | 2359 connection = connman_dbus_get_connection(); |
| 2368 if (connman_storage_register(&device_storage) < 0) | 2360 if (connman_storage_register(&device_storage) < 0) |
| 2369 connman_error("%s: failed to register storage", __func__); | 2361 connman_error("%s: failed to register storage", __func__); |
| 2370 return connman_driver_register(&device_driver); | 2362 return connman_driver_register(&device_driver); |
| 2371 } | 2363 } |
| 2372 | 2364 |
| 2373 void __connman_device_cleanup(void) | 2365 void __connman_device_cleanup(void) |
| 2374 { | 2366 { |
| 2375 connman_driver_unregister(&device_driver); | 2367 connman_driver_unregister(&device_driver); |
| 2376 connman_storage_unregister(&device_storage); | 2368 connman_storage_unregister(&device_storage); |
| 2377 dbus_connection_unref(connection); | 2369 dbus_connection_unref(connection); |
| 2378 } | 2370 } |
| OLD | NEW |