Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: src/device.c

Issue 6659006: flimflam: add support for multiple profiles (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/flimflam.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (ipconfig == NULL) { 243 if (ipconfig == NULL) {
244 connman_error("%s: failed to create %s ipconfig for %s", 244 connman_error("%s: failed to create %s ipconfig for %s",
245 __func__, type2string(type), device->name); 245 __func__, type2string(type), device->name);
246 return NULL; 246 return NULL;
247 } 247 }
248 /* ipconfig's are children of the device */ 248 /* ipconfig's are children of the device */
249 /* TODO(sleffler) check return value */ 249 /* TODO(sleffler) check return value */
250 connman_ipconfig_register(ipconfig, &device->element); 250 connman_ipconfig_register(ipconfig, &device->element);
251 device->configmask |= 1<<(ix-1); 251 device->configmask |= 1<<(ix-1);
252 252
253 » __connman_storage_save_device(device); 253 » __connman_profile_save_device(device);
254 254
255 return ipconfig; 255 return ipconfig;
256 } 256 }
257 257
258 /** 258 /**
259 * set_connected 259 * set_connected
260 * @device: connman device that is now (dis)connected 260 * @device: connman device that is now (dis)connected
261 * @connected: is device connected or disconnected 261 * @connected: is device connected or disconnected
262 * 262 *
263 * Returns: %0 on success 263 * Returns: %0 on success
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 int type, err; 618 int type, err;
619 619
620 type = dbus_message_iter_get_arg_type(&value); 620 type = dbus_message_iter_get_arg_type(&value);
621 if (type != DBUS_TYPE_BOOLEAN) 621 if (type != DBUS_TYPE_BOOLEAN)
622 return __connman_error_invalid_arguments(msg); 622 return __connman_error_invalid_arguments(msg);
623 623
624 dbus_message_iter_get_basic(&value, &powered); 624 dbus_message_iter_get_basic(&value, &powered);
625 625
626 device->powered_persistent = powered; 626 device->powered_persistent = powered;
627 627
628 » » __connman_storage_save_device(device); 628 » » __connman_profile_save_device(device);
629 629
630 if (device->powered == powered) 630 if (device->powered == powered)
631 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 631 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
632 632
633 if (device->pending != NULL) 633 if (device->pending != NULL)
634 return __connman_error_in_progress(msg); 634 return __connman_error_in_progress(msg);
635 635
636 err = set_powered(device, powered); 636 err = set_powered(device, powered);
637 if (err < 0) { 637 if (err < 0) {
638 if (err != -EINPROGRESS) 638 if (err != -EINPROGRESS)
639 return __connman_error_failed(msg, -err); 639 return __connman_error_failed(msg, -err);
640 640
641 device->pending = dbus_message_ref(msg); 641 device->pending = dbus_message_ref(msg);
642 642
643 device->timeout = g_timeout_add_seconds(15, 643 device->timeout = g_timeout_add_seconds(15,
644 powered_timeout, device); 644 powered_timeout, device);
645 645
646 return NULL; 646 return NULL;
647 } 647 }
648 } else if (g_str_equal(name, "ScanInterval") == TRUE) { 648 } else if (g_str_equal(name, "ScanInterval") == TRUE) {
649 connman_uint16_t interval; 649 connman_uint16_t interval;
650 650
651 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) 651 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16))
652 return __connman_error_invalid_arguments(msg); 652 return __connman_error_invalid_arguments(msg);
653 dbus_message_iter_get_basic(&value, &interval); 653 dbus_message_iter_get_basic(&value, &interval);
654 654
655 if (device->scan_interval != interval) { 655 if (device->scan_interval != interval) {
656 device->scan_interval = interval; 656 device->scan_interval = interval;
657 device->scan_parameters_nondefault = TRUE; 657 device->scan_parameters_nondefault = TRUE;
658 » » » __connman_storage_save_device(device); 658 » » » __connman_profile_save_device(device);
659 connman_element_update(&device->element); 659 connman_element_update(&device->element);
660 660
661 if (device->scan_timeout != 0) 661 if (device->scan_timeout != 0)
662 bgscan_enable(device); 662 bgscan_enable(device);
663 } 663 }
664 } else if (g_str_equal(name, "BgscanMethod") == TRUE) { 664 } else if (g_str_equal(name, "BgscanMethod") == TRUE) {
665 const char *method; 665 const char *method;
666 666
667 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_STRING)) 667 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_STRING))
668 return __connman_error_invalid_arguments(msg); 668 return __connman_error_invalid_arguments(msg);
669 dbus_message_iter_get_basic(&value, &method); 669 dbus_message_iter_get_basic(&value, &method);
670 670
671 if (g_strcmp0(method, device->scan_method) != 0) { 671 if (g_strcmp0(method, device->scan_method) != 0) {
672 g_free(device->scan_method); 672 g_free(device->scan_method);
673 device->scan_method = g_strdup(method); 673 device->scan_method = g_strdup(method);
674 device->scan_parameters_nondefault = TRUE; 674 device->scan_parameters_nondefault = TRUE;
675 » » » __connman_storage_save_device(device); 675 » » » __connman_profile_save_device(device);
676 connman_element_update(&device->element); 676 connman_element_update(&device->element);
677 } 677 }
678 } else if (g_str_equal(name, "BgscanShortInterval") == TRUE) { 678 } else if (g_str_equal(name, "BgscanShortInterval") == TRUE) {
679 connman_uint16_t interval; 679 connman_uint16_t interval;
680 680
681 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16)) 681 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_UINT16))
682 return __connman_error_invalid_arguments(msg); 682 return __connman_error_invalid_arguments(msg);
683 dbus_message_iter_get_basic(&value, &interval); 683 dbus_message_iter_get_basic(&value, &interval);
684 684
685 if (device->scan_short != interval) { 685 if (device->scan_short != interval) {
686 device->scan_short = interval; 686 device->scan_short = interval;
687 device->scan_parameters_nondefault = TRUE; 687 device->scan_parameters_nondefault = TRUE;
688 » » » __connman_storage_save_device(device); 688 » » » __connman_profile_save_device(device);
689 connman_element_update(&device->element); 689 connman_element_update(&device->element);
690 } 690 }
691 } else if (g_str_equal(name, "BgscanSignalThreshold") == TRUE) { 691 } else if (g_str_equal(name, "BgscanSignalThreshold") == TRUE) {
692 int threshold; 692 int threshold;
693 693
694 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_INT32)) 694 if (!check_bgscan_parameter(device, &value, DBUS_TYPE_INT32))
695 return __connman_error_invalid_arguments(msg); 695 return __connman_error_invalid_arguments(msg);
696 dbus_message_iter_get_basic(&value, &threshold); 696 dbus_message_iter_get_basic(&value, &threshold);
697 697
698 if (device->signal_threshold != threshold) { 698 if (device->signal_threshold != threshold) {
699 device->signal_threshold = threshold; 699 device->signal_threshold = threshold;
700 device->scan_parameters_nondefault = TRUE; 700 device->scan_parameters_nondefault = TRUE;
701 » » » __connman_storage_save_device(device); 701 » » » __connman_profile_save_device(device);
702 connman_element_update(&device->element); 702 connman_element_update(&device->element);
703 } 703 }
704 } else 704 } else
705 return __connman_error_invalid_property(msg); 705 return __connman_error_invalid_property(msg);
706 706
707 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 707 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
708 } 708 }
709 709
710 static DBusMessage *propose_scan(DBusConnection *conn, DBusMessage *msg, 710 static DBusMessage *propose_scan(DBusConnection *conn, DBusMessage *msg,
711 void *data) 711 void *data)
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 1516
1517 return set_powered(device, TRUE); 1517 return set_powered(device, TRUE);
1518 } 1518 }
1519 1519
1520 int __connman_device_enable_persistent(struct connman_device *device) 1520 int __connman_device_enable_persistent(struct connman_device *device)
1521 { 1521 {
1522 _DBG_DEVICE("device %p", device); 1522 _DBG_DEVICE("device %p", device);
1523 1523
1524 device->powered_persistent = TRUE; 1524 device->powered_persistent = TRUE;
1525 1525
1526 » __connman_storage_save_device(device); 1526 » __connman_profile_save_device(device);
1527 1527
1528 return __connman_device_enable(device); 1528 return __connman_device_enable(device);
1529 } 1529 }
1530 1530
1531 int __connman_device_disable(struct connman_device *device) 1531 int __connman_device_disable(struct connman_device *device)
1532 { 1532 {
1533 _DBG_DEVICE("device %p", device); 1533 _DBG_DEVICE("device %p", device);
1534 1534
1535 if (device->driver == NULL || device->driver->disable == NULL) 1535 if (device->driver == NULL || device->driver->disable == NULL)
1536 return -EOPNOTSUPP; 1536 return -EOPNOTSUPP;
1537 if (device->powered == FALSE) 1537 if (device->powered == FALSE)
1538 return -ENOLINK; 1538 return -ENOLINK;
1539 1539
1540 return set_powered(device, FALSE); 1540 return set_powered(device, FALSE);
1541 } 1541 }
1542 1542
1543 int __connman_device_disable_persistent(struct connman_device *device) 1543 int __connman_device_disable_persistent(struct connman_device *device)
1544 { 1544 {
1545 _DBG_DEVICE("device %p", device); 1545 _DBG_DEVICE("device %p", device);
1546 1546
1547 device->powered_persistent = FALSE; 1547 device->powered_persistent = FALSE;
1548 1548
1549 » __connman_storage_save_device(device); 1549 » __connman_profile_save_device(device);
1550 1550
1551 return __connman_device_disable(device); 1551 return __connman_device_disable(device);
1552 } 1552 }
1553 1553
1554 int __connman_device_connect(struct connman_device *device) 1554 int __connman_device_connect(struct connman_device *device)
1555 { 1555 {
1556 _DBG_DEVICE("device %p", device); 1556 _DBG_DEVICE("device %p", device);
1557 1557
1558 if (device->connected == TRUE) 1558 if (device->connected == TRUE)
1559 return -EALREADY; 1559 return -EALREADY;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 /** 2038 /**
2039 * connman_device_register: 2039 * connman_device_register:
2040 * @device: device structure 2040 * @device: device structure
2041 * 2041 *
2042 * Register device with the system 2042 * Register device with the system
2043 */ 2043 */
2044 int connman_device_register(struct connman_device *device) 2044 int connman_device_register(struct connman_device *device)
2045 { 2045 {
2046 _DBG_DEVICE("device %p", device); 2046 _DBG_DEVICE("device %p", device);
2047 2047
2048 » __connman_storage_load_device(device); 2048 » __connman_profile_load_device(device);
2049 2049
2050 device->offlinemode = __connman_profile_get_offlinemode(); 2050 device->offlinemode = __connman_profile_get_offlinemode();
2051 2051
2052 return connman_element_register(&device->element, NULL); 2052 return connman_element_register(&device->element, NULL);
2053 } 2053 }
2054 2054
2055 /** 2055 /**
2056 * connman_device_unregister: 2056 * connman_device_unregister:
2057 * @device: device structure 2057 * @device: device structure
2058 * 2058 *
2059 * Unregister device with the system 2059 * Unregister device with the system
2060 */ 2060 */
2061 void connman_device_unregister(struct connman_device *device) 2061 void connman_device_unregister(struct connman_device *device)
2062 { 2062 {
2063 _DBG_DEVICE("device %p", device); 2063 _DBG_DEVICE("device %p", device);
2064 2064
2065 » __connman_storage_save_device(device); 2065 » __connman_profile_save_device(device);
2066 2066
2067 connman_element_unregister(&device->element); 2067 connman_element_unregister(&device->element);
2068 } 2068 }
2069 2069
2070 /** 2070 /**
2071 * connman_device_get_data: 2071 * connman_device_get_data:
2072 * @device: device structure 2072 * @device: device structure
2073 * 2073 *
2074 * Get private device data pointer 2074 * Get private device data pointer
2075 */ 2075 */
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 if (ipconfig == NULL) { 2186 if (ipconfig == NULL) {
2187 connman_error("%s: invalid ipconfig type %s (%d)", 2187 connman_error("%s: invalid ipconfig type %s (%d)",
2188 __func__, str, type); 2188 __func__, str, type);
2189 return FALSE; 2189 return FALSE;
2190 } 2190 }
2191 device->configmask |= 1<<ix; 2191 device->configmask |= 1<<ix;
2192 } 2192 }
2193 return TRUE; 2193 return TRUE;
2194 } 2194 }
2195 2195
2196 static int device_load(struct connman_device *device) 2196 static int device_load(struct connman_device *device, GKeyFile *keyfile)
2197 { 2197 {
2198 const char *ident = __connman_profile_active_ident();
2199 GKeyFile *keyfile;
2200 GError *error = NULL; 2198 GError *error = NULL;
2201 gchar *identifier; 2199 gchar *identifier;
2202 gchar *method; 2200 gchar *method;
2203 connman_bool_t powered; 2201 connman_bool_t powered;
2204 int val; 2202 int val;
2205 gchar **configs; 2203 gchar **configs;
2206 gsize nconfigs; 2204 gsize nconfigs;
2205 int err = 0;
2207 2206
2208 _DBG_DEVICE("device %p", device); 2207 _DBG_DEVICE("device %p", device);
2209 2208
2210 » keyfile = __connman_storage_open(ident); 2209 » identifier = g_strdup_printf("device_%s", device->element.name);
2211 » if (keyfile == NULL) 2210 » if (identifier == NULL) {
2212 » » return 0; 2211 » » err = -ENOMEM;
2212 » » goto done;
2213 » }
2213 2214
2214 » identifier = g_strdup_printf("device_%s", device->element.name); 2215 » if (g_key_file_has_group(keyfile, identifier) == FALSE) {
2215 » if (identifier == NULL) 2216 » » err = -ESRCH;
2216 goto done; 2217 goto done;
2218 }
2217 2219
2218 powered = g_key_file_get_boolean(keyfile, identifier, 2220 powered = g_key_file_get_boolean(keyfile, identifier,
2219 "Powered", &error); 2221 "Powered", &error);
2220 if (error == NULL) 2222 if (error == NULL)
2221 device->powered_persistent = powered; 2223 device->powered_persistent = powered;
2222 g_clear_error(&error); 2224 g_clear_error(&error);
2223 2225
2224 switch (device->mode) { 2226 switch (device->mode) {
2225 case CONNMAN_DEVICE_MODE_UNKNOWN: 2227 case CONNMAN_DEVICE_MODE_UNKNOWN:
2226 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: 2228 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 2263
2262 configs = g_key_file_get_string_list(keyfile, identifier, "IPConfigs", 2264 configs = g_key_file_get_string_list(keyfile, identifier, "IPConfigs",
2263 &nconfigs, &error); 2265 &nconfigs, &error);
2264 if (error == NULL && configs != NULL) 2266 if (error == NULL && configs != NULL)
2265 device_load_ipconfigs(device, nconfigs, configs); 2267 device_load_ipconfigs(device, nconfigs, configs);
2266 g_strfreev(configs); 2268 g_strfreev(configs);
2267 g_clear_error(&error); 2269 g_clear_error(&error);
2268 done: 2270 done:
2269 g_free(identifier); 2271 g_free(identifier);
2270 2272
2271 » __connman_storage_close(ident, keyfile, FALSE); 2273 » return err;
2272
2273 » return 0;
2274 } 2274 }
2275 2275
2276 static int device_save(struct connman_device *device) 2276 static int device_save(struct connman_device *device, GKeyFile *keyfile)
2277 { 2277 {
2278 const char *ident = __connman_profile_active_ident();
2279 GKeyFile *keyfile;
2280 gchar *identifier; 2278 gchar *identifier;
2281 const char const *paths[32]; 2279 const char const *paths[32];
2282 int npaths; 2280 int npaths;
2283 int i; 2281 int i;
2284 2282
2285 _DBG_DEVICE("device %p", device); 2283 _DBG_DEVICE("device %p", device);
2286 2284
2287 keyfile = __connman_storage_open(ident);
2288 if (keyfile == NULL)
2289 return 0;
2290
2291 identifier = g_strdup_printf("device_%s", device->element.name); 2285 identifier = g_strdup_printf("device_%s", device->element.name);
2292 if (identifier == NULL) 2286 if (identifier == NULL)
2293 goto done; 2287 goto done;
2294 2288
2295 g_key_file_set_boolean(keyfile, identifier, 2289 g_key_file_set_boolean(keyfile, identifier,
2296 "Powered", device->powered_persistent); 2290 "Powered", device->powered_persistent);
2297 switch (device->mode) { 2291 switch (device->mode) {
2298 case CONNMAN_DEVICE_MODE_UNKNOWN: 2292 case CONNMAN_DEVICE_MODE_UNKNOWN:
2299 case CONNMAN_DEVICE_MODE_TRANSPORT_IP: 2293 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
2300 break; 2294 break;
(...skipping 18 matching lines...) Expand all
2319 } 2313 }
2320 2314
2321 __connman_ipconfig_get_keys(device, 32, paths, &npaths); 2315 __connman_ipconfig_get_keys(device, 32, paths, &npaths);
2322 g_key_file_set_string_list(keyfile, identifier, "IPConfigs", 2316 g_key_file_set_string_list(keyfile, identifier, "IPConfigs",
2323 paths, npaths); 2317 paths, npaths);
2324 for (i = 0; i < npaths; i++) 2318 for (i = 0; i < npaths; i++)
2325 g_free((gpointer)paths[i]); 2319 g_free((gpointer)paths[i]);
2326 done: 2320 done:
2327 g_free(identifier); 2321 g_free(identifier);
2328 2322
2329 __connman_storage_close(ident, keyfile, TRUE);
2330
2331 return 0; 2323 return 0;
2332 } 2324 }
2333 2325
2334 static struct connman_storage device_storage = { 2326 static struct connman_storage device_storage = {
2335 .name = "device", 2327 .name = "device",
2336 .priority = CONNMAN_STORAGE_PRIORITY_LOW, 2328 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
2337 .device_load = device_load, 2329 .device_load = device_load,
2338 .device_save = device_save, 2330 .device_save = device_save,
2339 }; 2331 };
2340 2332
2341 int __connman_device_init(void) 2333 int __connman_device_init(void)
2342 { 2334 {
2343 /* TODO(sleffler) check return values */ 2335 /* TODO(sleffler) check return values */
2344 connection = connman_dbus_get_connection(); 2336 connection = connman_dbus_get_connection();
2345 if (connman_storage_register(&device_storage) < 0) 2337 if (connman_storage_register(&device_storage) < 0)
2346 connman_error("%s: failed to register storage", __func__); 2338 connman_error("%s: failed to register storage", __func__);
2347 return connman_driver_register(&device_driver); 2339 return connman_driver_register(&device_driver);
2348 } 2340 }
2349 2341
2350 void __connman_device_cleanup(void) 2342 void __connman_device_cleanup(void)
2351 { 2343 {
2352 connman_driver_unregister(&device_driver); 2344 connman_driver_unregister(&device_driver);
2353 connman_storage_unregister(&device_storage); 2345 connman_storage_unregister(&device_storage);
2354 dbus_connection_unref(connection); 2346 dbus_connection_unref(connection);
2355 } 2347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698