| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 char *private_key_passwd; | 89 char *private_key_passwd; |
| 90 char *key_id; | 90 char *key_id; |
| 91 char *ca_cert; /* formerly authpath */ | 91 char *ca_cert; /* formerly authpath */ |
| 92 char *ca_cert_id; | 92 char *ca_cert_id; |
| 93 connman_bool_t use_system_cas; | 93 connman_bool_t use_system_cas; |
| 94 char *pin; | 94 char *pin; |
| 95 char *password; | 95 char *password; |
| 96 char *key_mgmt; | 96 char *key_mgmt; |
| 97 } eap; | 97 } eap; |
| 98 | 98 |
| 99 » char *profile; | 99 » const struct connman_storage_ident *profile; |
| 100 char *proxy_config; | 100 char *proxy_config; |
| 101 | 101 |
| 102 /* TODO(sleffler) overlay storage */ | 102 /* TODO(sleffler) overlay storage */ |
| 103 struct { | 103 struct { |
| 104 char *operator_name; | 104 char *operator_name; |
| 105 char *operator_code; | 105 char *operator_code; |
| 106 char *olp_url; | 106 char *olp_url; |
| 107 char *usage_url; | 107 char *usage_url; |
| 108 enum connman_network_activation_state activation_state; | 108 enum connman_network_activation_state activation_state; |
| 109 enum connman_network_cellular_technology network_technology; | 109 enum connman_network_cellular_technology network_technology; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 static const char* kEAPPrivateKey = "EAP.PrivateKey"; | 209 static const char* kEAPPrivateKey = "EAP.PrivateKey"; |
| 210 static const char* kEAPPrivateKeyPassword = "EAP.PrivateKeyPassword"; | 210 static const char* kEAPPrivateKeyPassword = "EAP.PrivateKeyPassword"; |
| 211 static const char* kEAPKeyID = "EAP.KeyID"; | 211 static const char* kEAPKeyID = "EAP.KeyID"; |
| 212 static const char* kEAPCACert = "EAP.CACert"; | 212 static const char* kEAPCACert = "EAP.CACert"; |
| 213 static const char* kEAPCACertID = "EAP.CACertID"; | 213 static const char* kEAPCACertID = "EAP.CACertID"; |
| 214 static const char* kEAPUseSystemCAs = "EAP.UseSystemCAs"; | 214 static const char* kEAPUseSystemCAs = "EAP.UseSystemCAs"; |
| 215 static const char* kEAPPIN = "EAP.PIN"; | 215 static const char* kEAPPIN = "EAP.PIN"; |
| 216 static const char* kEAPPassword = "EAP.Password"; | 216 static const char* kEAPPassword = "EAP.Password"; |
| 217 static const char* kEAPKeyMgmt = "EAP.KeyMgmt"; | 217 static const char* kEAPKeyMgmt = "EAP.KeyMgmt"; |
| 218 | 218 |
| 219 static void service_clear_passphrase(struct connman_service *service); |
| 219 static void service_modified(struct connman_service *service); | 220 static void service_modified(struct connman_service *service); |
| 221 static void service_clear_eap(struct connman_service *service); |
| 220 static void __service_resort(struct connman_service *service); | 222 static void __service_resort(struct connman_service *service); |
| 223 static void set_reconnect_state(struct connman_service *service, |
| 224 connman_bool_t onoff); |
| 221 | 225 |
| 222 static connman_bool_t is_timeset(const GTimeVal *tv) | 226 static connman_bool_t is_timeset(const GTimeVal *tv) |
| 223 { | 227 { |
| 224 return !(tv->tv_sec == 0 && tv->tv_usec == 0); | 228 return !(tv->tv_sec == 0 && tv->tv_usec == 0); |
| 225 } | 229 } |
| 226 | 230 |
| 227 static void append_path(gpointer value, gpointer user_data) | 231 static void append_path(gpointer value, gpointer user_data) |
| 228 { | 232 { |
| 229 struct connman_service *service = value; | 233 struct connman_service *service = value; |
| 230 DBusMessageIter *iter = user_data; | 234 DBusMessageIter *iter = user_data; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 { | 389 { |
| 386 struct find_data data = { .path = path, .service = NULL }; | 390 struct find_data data = { .path = path, .service = NULL }; |
| 387 | 391 |
| 388 _DBG_SERVICE("path %s", path); | 392 _DBG_SERVICE("path %s", path); |
| 389 | 393 |
| 390 g_sequence_foreach(service_list, compare_path, &data); | 394 g_sequence_foreach(service_list, compare_path, &data); |
| 391 | 395 |
| 392 return data.service; | 396 return data.service; |
| 393 } | 397 } |
| 394 | 398 |
| 399 static void invalidate_profile(gpointer value, gpointer user_data) |
| 400 { |
| 401 struct connman_service *service = value; |
| 402 const struct connman_storage_ident *profile = user_data; |
| 403 |
| 404 if (service->profile == profile) { |
| 405 /* |
| 406 * Invalidate profile-related data and force a re-load |
| 407 * the next time the service is to be used (so it can |
| 408 * come from the active profile). |
| 409 */ |
| 410 service->profile = NULL; |
| 411 |
| 412 /* |
| 413 * network_disconnect may drop the last reference to the |
| 414 * service and cause it to be freed, so take a reference |
| 415 * temporarily until we are done with it. |
| 416 */ |
| 417 connman_service_ref(service); |
| 418 /* TODO(sleffler) skip wired ethernet, open auth? */ |
| 419 __connman_service_disconnect(service); |
| 420 service_clear_passphrase(service); |
| 421 service_clear_eap(service); |
| 422 connman_service_unref(service); |
| 423 } |
| 424 } |
| 425 |
| 426 void __connman_service_invalidate_profile(const struct connman_storage_ident *id
ent) |
| 427 { |
| 428 _DBG_SERVICE("ident %s/%s", ident->user, ident->ident); |
| 429 |
| 430 g_sequence_foreach(service_list, invalidate_profile, (gpointer) ident); |
| 431 } |
| 432 |
| 395 static const char *identifier(struct connman_service *service) | 433 static const char *identifier(struct connman_service *service) |
| 396 { | 434 { |
| 397 return service ? service->identifier : "<nil>"; | 435 return service ? service->identifier : "<nil>"; |
| 398 } | 436 } |
| 399 | 437 |
| 400 static const char *type2string(enum connman_service_type type) | 438 static const char *type2string(enum connman_service_type type) |
| 401 { | 439 { |
| 402 switch (type) { | 440 switch (type) { |
| 403 case CONNMAN_SERVICE_TYPE_UNKNOWN: | 441 case CONNMAN_SERVICE_TYPE_UNKNOWN: |
| 404 break; | 442 break; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } | 792 } |
| 755 | 793 |
| 756 static void hidden_ssid_changed(struct connman_service *service) | 794 static void hidden_ssid_changed(struct connman_service *service) |
| 757 { | 795 { |
| 758 if (service->path != NULL) | 796 if (service->path != NULL) |
| 759 connman_dbus_send_property_changed_variant(service->path, | 797 connman_dbus_send_property_changed_variant(service->path, |
| 760 CONNMAN_SERVICE_INTERFACE, "WiFi.HiddenSSID", | 798 CONNMAN_SERVICE_INTERFACE, "WiFi.HiddenSSID", |
| 761 DBUS_TYPE_BOOLEAN, &service->wifi.hidden_ssid); | 799 DBUS_TYPE_BOOLEAN, &service->wifi.hidden_ssid); |
| 762 } | 800 } |
| 763 | 801 |
| 764 /** | |
| 765 * connman_service_append_hidden_ssids: | |
| 766 * @hidden_ssids: pointer to a list of hidden SSIDs | |
| 767 * | |
| 768 * Append the list of SSIDs whose services whose WiFi.HiddenSSID property is | |
| 769 * TRUE. These SSIDs should be directly probed whenever performing a WiFi | |
| 770 * network scan. | |
| 771 * | |
| 772 * Return -EINVAL if profile could not be parsed cleanly | |
| 773 */ | |
| 774 int connman_service_append_hidden_ssids(GSList **hidden_ssids) | |
| 775 { | |
| 776 const char *ident = __connman_profile_active_ident(); | |
| 777 GKeyFile *keyfile; | |
| 778 gchar **keys; | |
| 779 int ret = 0; | |
| 780 | |
| 781 _DBG_SERVICE("ident %s", ident); | |
| 782 | |
| 783 keyfile = __connman_storage_open(ident); | |
| 784 if (keyfile == NULL) | |
| 785 return -EINVAL; | |
| 786 | |
| 787 keys = g_key_file_get_groups(keyfile, NULL); | |
| 788 if (keys == NULL) { | |
| 789 ret = -EINVAL; | |
| 790 goto done; | |
| 791 } | |
| 792 | |
| 793 for (; *keys != NULL; keys++) { | |
| 794 gchar *key = *keys; | |
| 795 gchar *hex_ssid; | |
| 796 struct blob *ssid; | |
| 797 | |
| 798 if (g_ascii_strncasecmp(key, "wifi_", 5) != 0) | |
| 799 continue; | |
| 800 | |
| 801 if (!g_key_file_get_boolean(keyfile, key, "WiFi.HiddenSSID", | |
| 802 NULL)) | |
| 803 continue; | |
| 804 | |
| 805 hex_ssid = g_key_file_get_string(keyfile, key, "SSID", NULL); | |
| 806 if (hex_ssid == NULL) | |
| 807 continue; | |
| 808 | |
| 809 _DBG_SERVICE("service %s", key); | |
| 810 | |
| 811 ret = blob_new_from_hex(&ssid, hex_ssid); | |
| 812 g_free(hex_ssid); | |
| 813 if (ret < 0) | |
| 814 goto done; | |
| 815 | |
| 816 _DBG_SERVICE("ssid %.*s", ssid->len, ssid->data); | |
| 817 *hidden_ssids = g_slist_prepend(*hidden_ssids, ssid); | |
| 818 } | |
| 819 | |
| 820 done: | |
| 821 g_key_file_free(keyfile); | |
| 822 | |
| 823 return ret; | |
| 824 } | |
| 825 | |
| 826 static connman_bool_t is_connectable(const struct connman_service *service) | 802 static connman_bool_t is_connectable(const struct connman_service *service) |
| 827 { | 803 { |
| 828 | 804 |
| 829 if (service->security == CONNMAN_SERVICE_SECURITY_802_1X) { | 805 if (service->security == CONNMAN_SERVICE_SECURITY_802_1X) { |
| 830 /* Identity is required for EAP. */ | 806 /* Identity is required for EAP. */ |
| 831 if (service->eap.identity == NULL) { | 807 if (service->eap.identity == NULL) { |
| 832 _DBG_SERVICE("NOT CONNECTABLE: identity is NULL"); | 808 _DBG_SERVICE("NOT CONNECTABLE: identity is NULL"); |
| 833 return FALSE; | 809 return FALSE; |
| 834 } | 810 } |
| 835 | 811 |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 | 1428 |
| 1453 if (service->network != NULL) | 1429 if (service->network != NULL) |
| 1454 prepare_network_string(service, networkname, | 1430 prepare_network_string(service, networkname, |
| 1455 *storage); | 1431 *storage); |
| 1456 | 1432 |
| 1457 if (service->path != NULL) | 1433 if (service->path != NULL) |
| 1458 connman_dbus_send_property_changed_variant(service->path, | 1434 connman_dbus_send_property_changed_variant(service->path, |
| 1459 CONNMAN_SERVICE_INTERFACE, servicename, | 1435 CONNMAN_SERVICE_INTERFACE, servicename, |
| 1460 DBUS_TYPE_STRING, storage); | 1436 DBUS_TYPE_STRING, storage); |
| 1461 | 1437 |
| 1462 » __connman_storage_save_service(service); | 1438 » service_modified(service); |
| 1463 | 1439 |
| 1464 return NULL; | 1440 return NULL; |
| 1465 } | 1441 } |
| 1466 | 1442 |
| 1467 static void free_apn(struct connman_service *service) | 1443 static void free_apn(struct connman_service *service) |
| 1468 { | 1444 { |
| 1469 struct connman_network_apn *apn = &service->cellular.apn; | 1445 struct connman_network_apn *apn = &service->cellular.apn; |
| 1470 | 1446 |
| 1471 g_free(apn->apn); | 1447 g_free(apn->apn); |
| 1472 apn->apn = NULL; | 1448 apn->apn = NULL; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 g_strdup(service->cellular.operator_code); | 1524 g_strdup(service->cellular.operator_code); |
| 1549 apn->username = g_strdup(username); | 1525 apn->username = g_strdup(username); |
| 1550 apn->password = g_strdup(password); | 1526 apn->password = g_strdup(password); |
| 1551 /* | 1527 /* |
| 1552 * Clear the last-good-apn, otherwise the one | 1528 * Clear the last-good-apn, otherwise the one |
| 1553 * the user just set won't be used. | 1529 * the user just set won't be used. |
| 1554 */ | 1530 */ |
| 1555 __connman_service_save_last_good_apn(service, NULL); | 1531 __connman_service_save_last_good_apn(service, NULL); |
| 1556 } | 1532 } |
| 1557 | 1533 |
| 1558 » __connman_storage_save_service(service); | 1534 » __connman_profile_save_service(service); |
| 1559 connman_dbus_property_changed_string_dict(service->path, | 1535 connman_dbus_property_changed_string_dict(service->path, |
| 1560 CONNMAN_SERVICE_INTERFACE, | 1536 CONNMAN_SERVICE_INTERFACE, |
| 1561 "Cellular.APN", append_apn, apn); | 1537 "Cellular.APN", append_apn, apn); |
| 1562 return NULL; | 1538 return NULL; |
| 1563 } | 1539 } |
| 1564 | 1540 |
| 1565 static DBusMessage *set_property(DBusConnection *conn, | 1541 static DBusMessage *set_property(DBusConnection *conn, |
| 1566 DBusMessage *msg, void *user_data) | 1542 DBusMessage *msg, void *user_data) |
| 1567 { | 1543 { |
| 1568 struct connman_service *service = user_data; | 1544 struct connman_service *service = user_data; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1597 | 1573 |
| 1598 dbus_message_iter_get_basic(&value, &hidden_ssid); | 1574 dbus_message_iter_get_basic(&value, &hidden_ssid); |
| 1599 | 1575 |
| 1600 if (service->wifi.hidden_ssid == hidden_ssid) | 1576 if (service->wifi.hidden_ssid == hidden_ssid) |
| 1601 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); | 1577 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); |
| 1602 | 1578 |
| 1603 service->wifi.hidden_ssid = hidden_ssid; | 1579 service->wifi.hidden_ssid = hidden_ssid; |
| 1604 | 1580 |
| 1605 hidden_ssid_changed(service); | 1581 hidden_ssid_changed(service); |
| 1606 | 1582 |
| 1607 » » __connman_storage_save_service(service); | 1583 » » service_modified(service); |
| 1608 | |
| 1609 } else if (g_str_equal(name, "Passphrase") == TRUE) { | 1584 } else if (g_str_equal(name, "Passphrase") == TRUE) { |
| 1610 const char *passphrase; | 1585 const char *passphrase; |
| 1611 | 1586 |
| 1612 if (type != DBUS_TYPE_STRING) | 1587 if (type != DBUS_TYPE_STRING) |
| 1613 return __connman_error_invalid_arguments(msg); | 1588 return __connman_error_invalid_arguments(msg); |
| 1614 | 1589 |
| 1615 if (__connman_security_check_privilege(msg, | 1590 if (__connman_security_check_privilege(msg, |
| 1616 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0) | 1591 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0) |
| 1617 return __connman_error_permission_denied(msg); | 1592 return __connman_error_permission_denied(msg); |
| 1618 | 1593 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1640 * passphrase has never been tried. | 1615 * passphrase has never been tried. |
| 1641 */ | 1616 */ |
| 1642 service->last_attempt.tv_sec = 0; | 1617 service->last_attempt.tv_sec = 0; |
| 1643 service->last_attempt.tv_usec = 0; | 1618 service->last_attempt.tv_usec = 0; |
| 1644 | 1619 |
| 1645 passphrase_required_changed(service); | 1620 passphrase_required_changed(service); |
| 1646 | 1621 |
| 1647 if (service->network != NULL) | 1622 if (service->network != NULL) |
| 1648 prepare_network_passphrase(service); | 1623 prepare_network_passphrase(service); |
| 1649 | 1624 |
| 1650 » » __connman_storage_save_service(service); | 1625 » » service_modified(service); |
| 1651 } else if (g_str_equal(name, kEAPIdentity) == TRUE) { | 1626 } else if (g_str_equal(name, kEAPIdentity) == TRUE) { |
| 1652 returnmsg = set_eap_string(service, msg, type, &value, | 1627 returnmsg = set_eap_string(service, msg, type, &value, |
| 1653 &service->eap.identity, | 1628 &service->eap.identity, |
| 1654 kEAPIdentity, CONNMAN_WIFI_EAP_IDENTITY); | 1629 kEAPIdentity, CONNMAN_WIFI_EAP_IDENTITY); |
| 1655 if (returnmsg != NULL) | 1630 if (returnmsg != NULL) |
| 1656 return returnmsg; | 1631 return returnmsg; |
| 1657 } else if (g_str_equal(name, kEAPEAP) == TRUE) { | 1632 } else if (g_str_equal(name, kEAPEAP) == TRUE) { |
| 1658 returnmsg = set_eap_string(service, msg, type, &value, | 1633 returnmsg = set_eap_string(service, msg, type, &value, |
| 1659 &service->eap.eap, | 1634 &service->eap.eap, |
| 1660 kEAPEAP, CONNMAN_WIFI_EAP_EAP); | 1635 kEAPEAP, CONNMAN_WIFI_EAP_EAP); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 service->eap.use_system_cas = use_system_cas; | 1702 service->eap.use_system_cas = use_system_cas; |
| 1728 | 1703 |
| 1729 connman_network_set_uint8(service->network, | 1704 connman_network_set_uint8(service->network, |
| 1730 CONNMAN_WIFI_EAP_USESYSTEMCAS, | 1705 CONNMAN_WIFI_EAP_USESYSTEMCAS, |
| 1731 service->eap.use_system_cas); | 1706 service->eap.use_system_cas); |
| 1732 | 1707 |
| 1733 connman_dbus_send_property_changed_variant(service->path, | 1708 connman_dbus_send_property_changed_variant(service->path, |
| 1734 CONNMAN_SERVICE_INTERFACE, kEAPUseSystemCAs, | 1709 CONNMAN_SERVICE_INTERFACE, kEAPUseSystemCAs, |
| 1735 DBUS_TYPE_BOOLEAN, &service->eap.use_system_cas); | 1710 DBUS_TYPE_BOOLEAN, &service->eap.use_system_cas); |
| 1736 | 1711 |
| 1737 » » __connman_storage_save_service(service); | 1712 » » __connman_profile_save_service(service); |
| 1738 } else if (g_str_equal(name, kEAPPIN) == TRUE) { | 1713 } else if (g_str_equal(name, kEAPPIN) == TRUE) { |
| 1739 returnmsg = set_eap_string(service, msg, type, &value, | 1714 returnmsg = set_eap_string(service, msg, type, &value, |
| 1740 &service->eap.pin, | 1715 &service->eap.pin, |
| 1741 kEAPPIN, CONNMAN_WIFI_EAP_PIN); | 1716 kEAPPIN, CONNMAN_WIFI_EAP_PIN); |
| 1742 if (returnmsg != NULL) | 1717 if (returnmsg != NULL) |
| 1743 return returnmsg; | 1718 return returnmsg; |
| 1744 } else if (g_str_equal(name, kEAPPassword) == TRUE) { | 1719 } else if (g_str_equal(name, kEAPPassword) == TRUE) { |
| 1745 returnmsg = set_eap_string(service, msg, type, &value, | 1720 returnmsg = set_eap_string(service, msg, type, &value, |
| 1746 &service->eap.password, | 1721 &service->eap.password, |
| 1747 kEAPPassword, CONNMAN_WIFI_EAP_PASSWORD); | 1722 kEAPPassword, CONNMAN_WIFI_EAP_PASSWORD); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1764 | 1739 |
| 1765 dbus_message_iter_get_basic(&value, &autoconnect); | 1740 dbus_message_iter_get_basic(&value, &autoconnect); |
| 1766 | 1741 |
| 1767 if (service->autoconnect == autoconnect) | 1742 if (service->autoconnect == autoconnect) |
| 1768 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); | 1743 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); |
| 1769 | 1744 |
| 1770 service->autoconnect = autoconnect; | 1745 service->autoconnect = autoconnect; |
| 1771 | 1746 |
| 1772 autoconnect_changed(service); | 1747 autoconnect_changed(service); |
| 1773 | 1748 |
| 1774 » » __connman_storage_save_service(service); | 1749 » » service_modified(service); |
| 1775 } else if (g_str_equal(name, "ProxyConfig") == TRUE) { | 1750 } else if (g_str_equal(name, "ProxyConfig") == TRUE) { |
| 1776 const char *proxy_config; | 1751 const char *proxy_config; |
| 1777 | 1752 |
| 1778 if (type != DBUS_TYPE_STRING) | 1753 if (type != DBUS_TYPE_STRING) |
| 1779 return __connman_error_invalid_arguments(msg); | 1754 return __connman_error_invalid_arguments(msg); |
| 1780 | 1755 |
| 1781 dbus_message_iter_get_basic(&value, &proxy_config); | 1756 dbus_message_iter_get_basic(&value, &proxy_config); |
| 1782 | 1757 |
| 1783 g_free(service->proxy_config); | 1758 g_free(service->proxy_config); |
| 1784 service->proxy_config = g_strdup(proxy_config); | 1759 service->proxy_config = g_strdup(proxy_config); |
| 1785 | 1760 |
| 1786 proxy_configuration_changed(service); | 1761 proxy_configuration_changed(service); |
| 1787 | 1762 |
| 1788 » » __connman_storage_save_service(service); | 1763 » » service_modified(service); |
| 1789 } else if (g_str_has_prefix(name, "Priority") == TRUE) { | 1764 } else if (g_str_has_prefix(name, "Priority") == TRUE) { |
| 1790 int pri; | 1765 int pri; |
| 1791 | 1766 |
| 1792 if (type != DBUS_TYPE_INT32) | 1767 if (type != DBUS_TYPE_INT32) |
| 1793 return __connman_error_invalid_arguments(msg); | 1768 return __connman_error_invalid_arguments(msg); |
| 1794 | 1769 |
| 1795 dbus_message_iter_get_basic(&value, &pri); | 1770 dbus_message_iter_get_basic(&value, &pri); |
| 1796 | 1771 |
| 1797 if (!(CONNMAN_SERVICE_PRI_MIN <= pri && | 1772 if (!(CONNMAN_SERVICE_PRI_MIN <= pri && |
| 1798 pri <= CONNMAN_SERVICE_PRI_MAX)) { | 1773 pri <= CONNMAN_SERVICE_PRI_MAX)) { |
| 1799 _DBG_SERVICE("service priority %d out of range", pri); | 1774 _DBG_SERVICE("service priority %d out of range", pri); |
| 1800 return __connman_error_invalid_arguments(msg); | 1775 return __connman_error_invalid_arguments(msg); |
| 1801 } | 1776 } |
| 1802 | 1777 |
| 1803 if (service->pri != pri) { | 1778 if (service->pri != pri) { |
| 1804 service->pri = pri; | 1779 service->pri = pri; |
| 1805 __service_resort(service); | 1780 __service_resort(service); |
| 1806 | 1781 |
| 1807 service_priority_changed(service); | 1782 service_priority_changed(service); |
| 1808 | 1783 |
| 1809 » » » __connman_storage_save_service(service); | 1784 » » » service_modified(service); |
| 1810 } | 1785 } |
| 1811 } else if (g_str_equal(name, "Cellular.APN") == TRUE) { | 1786 } else if (g_str_equal(name, "Cellular.APN") == TRUE) { |
| 1812 returnmsg = set_apn_from_property(service, msg, type, &value); | 1787 returnmsg = set_apn_from_property(service, msg, type, &value); |
| 1813 if (returnmsg != NULL) | 1788 if (returnmsg != NULL) |
| 1814 return returnmsg; | 1789 return returnmsg; |
| 1815 } else | 1790 } else |
| 1816 return __connman_error_invalid_property(msg); | 1791 return __connman_error_invalid_property(msg); |
| 1817 | 1792 |
| 1818 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); | 1793 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); |
| 1819 } | 1794 } |
| 1820 | 1795 |
| 1821 static void state_change(struct connman_service *service, | 1796 static void state_change(struct connman_service *service, |
| 1822 enum connman_service_state state, int notify) | 1797 enum connman_service_state state, int notify) |
| 1823 { | 1798 { |
| 1824 _DBG_SERVICE("service state change (%p) %s -> %s", service, | 1799 _DBG_SERVICE("service state change (%p) %s -> %s", service, |
| 1825 __statename(service->state), __statename(state)); | 1800 __statename(service->state), __statename(state)); |
| 1826 service->state = state; | 1801 service->state = state; |
| 1827 g_get_current_time(&service->last_state[state]); | 1802 g_get_current_time(&service->last_state[state]); |
| 1828 if (notify == TRUE) | 1803 if (notify == TRUE) |
| 1829 __connman_notifier_service_state_changed(service); | 1804 __connman_notifier_service_state_changed(service); |
| 1830 } | 1805 } |
| 1831 | 1806 |
| 1832 static void set_idle(struct connman_service *service) | 1807 static void set_idle(struct connman_service *service) |
| 1833 { | 1808 { |
| 1834 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN; | 1809 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN; |
| 1835 state_change(service, CONNMAN_SERVICE_STATE_IDLE, TRUE); | 1810 state_change(service, CONNMAN_SERVICE_STATE_IDLE, TRUE); |
| 1836 } | 1811 } |
| 1837 | 1812 |
| 1838 static void __connman_service_clear_passphrase(struct connman_service *service) | 1813 static void service_clear_passphrase(struct connman_service *service) |
| 1839 { | 1814 { |
| 1840 g_free(service->passphrase); | 1815 g_free(service->passphrase); |
| 1841 service->passphrase = NULL; | 1816 service->passphrase = NULL; |
| 1842 | 1817 |
| 1843 memset(&service->wifi, 0, sizeof(service->wifi)); | 1818 memset(&service->wifi, 0, sizeof(service->wifi)); |
| 1819 } |
| 1820 |
| 1821 static void __connman_service_clear_passphrase(struct connman_service *service) |
| 1822 { |
| 1823 service_clear_passphrase(service); |
| 1844 | 1824 |
| 1845 passphrase_required_changed(service); | 1825 passphrase_required_changed(service); |
| 1846 } | 1826 } |
| 1847 | 1827 |
| 1848 static void service_modified(struct connman_service *service) | 1828 static void service_modified(struct connman_service *service) |
| 1849 { | 1829 { |
| 1850 g_get_current_time(&service->modified); | 1830 g_get_current_time(&service->modified); |
| 1851 » __connman_storage_save_service(service); | 1831 |
| 1832 » service->profile = __connman_profile_active_ident(); |
| 1833 » __connman_profile_save_service(service); |
| 1852 } | 1834 } |
| 1853 | 1835 |
| 1854 void __connman_service_reset(struct connman_service *service) | 1836 static void service_clear_eap(struct connman_service *service) |
| 1855 { | 1837 { |
| 1856 connman_service_set_favorite(service, FALSE); | |
| 1857 __connman_service_clear_passphrase(service); | |
| 1858 | |
| 1859 g_free(service->eap.identity); | 1838 g_free(service->eap.identity); |
| 1860 service->eap.identity = NULL; | 1839 service->eap.identity = NULL; |
| 1861 | 1840 |
| 1862 g_free(service->eap.eap); | 1841 g_free(service->eap.eap); |
| 1863 service->eap.eap = NULL; | 1842 service->eap.eap = NULL; |
| 1864 | 1843 |
| 1865 g_free(service->eap.inner_eap); | 1844 g_free(service->eap.inner_eap); |
| 1866 service->eap.inner_eap = NULL; | 1845 service->eap.inner_eap = NULL; |
| 1867 | 1846 |
| 1868 g_free(service->eap.anonymous_identity); | 1847 g_free(service->eap.anonymous_identity); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1889 g_free(service->eap.ca_cert_id); | 1868 g_free(service->eap.ca_cert_id); |
| 1890 service->eap.ca_cert_id = NULL; | 1869 service->eap.ca_cert_id = NULL; |
| 1891 | 1870 |
| 1892 service->eap.use_system_cas = TRUE; | 1871 service->eap.use_system_cas = TRUE; |
| 1893 | 1872 |
| 1894 g_free(service->eap.pin); | 1873 g_free(service->eap.pin); |
| 1895 service->eap.pin = NULL; | 1874 service->eap.pin = NULL; |
| 1896 | 1875 |
| 1897 g_free(service->eap.password); | 1876 g_free(service->eap.password); |
| 1898 service->eap.password = NULL; | 1877 service->eap.password = NULL; |
| 1878 } |
| 1879 |
| 1880 void __connman_service_reset(struct connman_service *service) |
| 1881 { |
| 1882 connman_service_set_favorite(service, FALSE); |
| 1883 __connman_service_clear_passphrase(service); |
| 1884 service_clear_eap(service); |
| 1899 | 1885 |
| 1900 service_modified(service); | 1886 service_modified(service); |
| 1901 } | 1887 } |
| 1902 | 1888 |
| 1903 static DBusMessage *clear_property(DBusConnection *conn, | 1889 static DBusMessage *clear_property(DBusConnection *conn, |
| 1904 DBusMessage *msg, void *user_data) | 1890 DBusMessage *msg, void *user_data) |
| 1905 { | 1891 { |
| 1906 struct connman_service *service = user_data; | 1892 struct connman_service *service = user_data; |
| 1907 const char *name; | 1893 const char *name; |
| 1908 | 1894 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 /* | 2242 /* |
| 2257 * Attempt autoconnect on the device associated with the specified | 2243 * Attempt autoconnect on the device associated with the specified |
| 2258 * service. Note this is deferred to the main event loop. | 2244 * service. Note this is deferred to the main event loop. |
| 2259 */ | 2245 */ |
| 2260 void connman_service_auto_connect(struct connman_service *service) | 2246 void connman_service_auto_connect(struct connman_service *service) |
| 2261 { | 2247 { |
| 2262 struct connman_device *device = connman_service_get_device(service); | 2248 struct connman_device *device = connman_service_get_device(service); |
| 2263 __connman_service_device_auto_connect(device); | 2249 __connman_service_device_auto_connect(device); |
| 2264 } | 2250 } |
| 2265 | 2251 |
| 2252 static gboolean auto_connect_any(gpointer data) |
| 2253 { |
| 2254 _DBG_SERVICE(""); |
| 2255 |
| 2256 if (__connman_connection_is_online() == FALSE) |
| 2257 __auto_connect(NULL, NULL); |
| 2258 return FALSE; |
| 2259 } |
| 2260 |
| 2261 /* |
| 2262 * Attempt autoconnect on any device, but only if offline. |
| 2263 */ |
| 2264 void __connman_service_auto_connect_any(void) |
| 2265 { |
| 2266 g_idle_add(auto_connect_any, NULL); |
| 2267 } |
| 2268 |
| 2266 /** | 2269 /** |
| 2267 * __connman_service_set_activation_state: | 2270 * __connman_service_set_activation_state: |
| 2268 * @service: service structure | 2271 * @service: service structure |
| 2269 * @activation state: control interface | 2272 * @activation state: control interface |
| 2270 * @err: if the activation failed a reason for the failure | 2273 * @err: if the activation failed a reason for the failure |
| 2271 * | 2274 * |
| 2272 * Set the activation state of the network | 2275 * Set the activation state of the network |
| 2273 */ | 2276 */ |
| 2274 void __connman_service_set_activation_state(struct connman_service *service, | 2277 void __connman_service_set_activation_state(struct connman_service *service, |
| 2275 enum connman_network_activation_state activation_state, | 2278 enum connman_network_activation_state activation_state, |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2788 g_dbus_unregister_interface(connection, path, | 2791 g_dbus_unregister_interface(connection, path, |
| 2789 CONNMAN_SERVICE_INTERFACE); | 2792 CONNMAN_SERVICE_INTERFACE); |
| 2790 g_free(path); | 2793 g_free(path); |
| 2791 } | 2794 } |
| 2792 | 2795 |
| 2793 if (service->network != NULL) | 2796 if (service->network != NULL) |
| 2794 connman_network_unref(service->network); | 2797 connman_network_unref(service->network); |
| 2795 if (service->provider != NULL) | 2798 if (service->provider != NULL) |
| 2796 connman_provider_unref(service->provider); | 2799 connman_provider_unref(service->provider); |
| 2797 | 2800 |
| 2798 g_free(service->profile); | |
| 2799 g_free(service->name); | 2801 g_free(service->name); |
| 2800 g_free(service->passphrase); | 2802 g_free(service->passphrase); |
| 2801 g_free(service->eap.identity); | 2803 g_free(service->eap.identity); |
| 2802 g_free(service->eap.eap); | 2804 g_free(service->eap.eap); |
| 2803 g_free(service->eap.inner_eap); | 2805 g_free(service->eap.inner_eap); |
| 2804 g_free(service->eap.anonymous_identity); | 2806 g_free(service->eap.anonymous_identity); |
| 2805 g_free(service->eap.client_cert); | 2807 g_free(service->eap.client_cert); |
| 2806 g_free(service->eap.cert_id); | 2808 g_free(service->eap.cert_id); |
| 2807 g_free(service->eap.private_key); | 2809 g_free(service->eap.private_key); |
| 2808 g_free(service->eap.private_key_passwd); | 2810 g_free(service->eap.private_key_passwd); |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3878 | 3880 |
| 3879 /* NB: Set HiddenSSID = FALSE when creating service not in scan list */ | 3881 /* NB: Set HiddenSSID = FALSE when creating service not in scan list */ |
| 3880 reply = __connman_get_wifi_service_int(msg, &service, &created, FALSE); | 3882 reply = __connman_get_wifi_service_int(msg, &service, &created, FALSE); |
| 3881 if (reply != NULL) | 3883 if (reply != NULL) |
| 3882 return reply; | 3884 return reply; |
| 3883 else if (service == NULL) | 3885 else if (service == NULL) |
| 3884 return __connman_error_internal_error(msg); | 3886 return __connman_error_internal_error(msg); |
| 3885 | 3887 |
| 3886 _DBG_SERVICE("service %p created %d", service, created); | 3888 _DBG_SERVICE("service %p created %d", service, created); |
| 3887 | 3889 |
| 3888 » __connman_storage_save_service(service); | 3890 » service_modified(service); |
| 3889 | 3891 |
| 3890 /* | 3892 /* |
| 3891 * If __connman_get_wifi_service_int created the network object | 3893 * If __connman_get_wifi_service_int created the network object |
| 3892 * because the service didn't already exist, then we need to | 3894 * because the service didn't already exist, then we need to |
| 3893 * get rid of it and the associated service. Removing the network | 3895 * get rid of it and the associated service. Removing the network |
| 3894 * from the device will do this; this will be the only reference | 3896 * from the device will do this; this will be the only reference |
| 3895 * to the network and when it's reclaimed the service will also | 3897 * to the network and when it's reclaimed the service will also |
| 3896 * go away because the network layer calls up into the service | 3898 * go away because the network layer calls up into the service |
| 3897 * layer to clear the (unreferenced) pointer. | 3899 * layer to clear the (unreferenced) pointer. |
| 3898 */ | 3900 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3925 } | 3927 } |
| 3926 | 3928 |
| 3927 service = connman_service_create(); | 3929 service = connman_service_create(); |
| 3928 if (service == NULL) | 3930 if (service == NULL) |
| 3929 return NULL; | 3931 return NULL; |
| 3930 | 3932 |
| 3931 _DBG_SERVICE("service %p", service); | 3933 _DBG_SERVICE("service %p", service); |
| 3932 | 3934 |
| 3933 service->identifier = g_strdup(identifier); | 3935 service->identifier = g_strdup(identifier); |
| 3934 | 3936 |
| 3935 » service->profile = g_strdup(__connman_profile_active_ident()); | 3937 » service->profile = __connman_profile_active_ident(); |
| 3936 | 3938 |
| 3937 » __connman_storage_load_service(service); | 3939 » __connman_profile_load_service(service); |
| 3938 | 3940 |
| 3939 iter = g_sequence_insert_sorted(service_list, service, | 3941 iter = g_sequence_insert_sorted(service_list, service, |
| 3940 service_compare, NULL); | 3942 service_compare, NULL); |
| 3941 | 3943 |
| 3942 g_hash_table_insert(service_hash, service->identifier, iter); | 3944 g_hash_table_insert(service_hash, service->identifier, iter); |
| 3943 | 3945 |
| 3944 return service; | 3946 return service; |
| 3945 } | 3947 } |
| 3946 | 3948 |
| 3947 static int service_register(struct connman_service *service) | 3949 static int service_register(struct connman_service *service) |
| 3948 { | 3950 { |
| 3949 const char *path = __connman_profile_active_path(); | 3951 const char *path = __connman_profile_active_path(); |
| 3950 | 3952 |
| 3951 _DBG_SERVICE("service %p", service); | 3953 _DBG_SERVICE("service %p", service); |
| 3952 | 3954 |
| 3953 if (service->path != NULL) | 3955 if (service->path != NULL) |
| 3954 return -EALREADY; | 3956 return -EALREADY; |
| 3955 | 3957 |
| 3956 service->path = g_strdup_printf("%s/%s", path, service->identifier); | 3958 service->path = g_strdup_printf("%s/%s", path, service->identifier); |
| 3957 | 3959 |
| 3958 _DBG_SERVICE("path %s", service->path); | 3960 _DBG_SERVICE("path %s", service->path); |
| 3959 | 3961 |
| 3960 g_dbus_register_interface(connection, service->path, | 3962 g_dbus_register_interface(connection, service->path, |
| 3961 CONNMAN_SERVICE_INTERFACE, | 3963 CONNMAN_SERVICE_INTERFACE, |
| 3962 service_methods, service_signals, | 3964 service_methods, service_signals, |
| 3963 NULL, service, NULL); | 3965 NULL, service, NULL); |
| 3964 | 3966 |
| 3965 » __connman_storage_load_service(service); | 3967 » __connman_profile_load_service(service); |
| 3966 | 3968 |
| 3967 __service_resort(service); | 3969 __service_resort(service); |
| 3968 | 3970 |
| 3969 __connman_profile_changed(TRUE); | 3971 __connman_profile_changed(TRUE); |
| 3970 | 3972 |
| 3971 return 0; | 3973 return 0; |
| 3972 } | 3974 } |
| 3973 | 3975 |
| 3974 /** | 3976 /** |
| 3975 * __connman_service_lookup_from_device: | 3977 * __connman_service_lookup_from_device: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4024 __connman_profile_changed(TRUE); | 4026 __connman_profile_changed(TRUE); |
| 4025 return service; | 4027 return service; |
| 4026 } | 4028 } |
| 4027 | 4029 |
| 4028 service->type = __connman_device_get_service_type(device); | 4030 service->type = __connman_device_get_service_type(device); |
| 4029 | 4031 |
| 4030 service->autoconnect = FALSE; | 4032 service->autoconnect = FALSE; |
| 4031 | 4033 |
| 4032 service->device = device; | 4034 service->device = device; |
| 4033 | 4035 |
| 4034 » __connman_storage_load_service(service); | 4036 » __connman_profile_load_service(service); |
| 4035 | 4037 |
| 4036 service_register(service); | 4038 service_register(service); |
| 4037 | 4039 |
| 4038 __connman_profile_changed(TRUE); | 4040 __connman_profile_changed(TRUE); |
| 4039 | 4041 |
| 4040 if (service->favorite == TRUE) | 4042 if (service->favorite == TRUE) |
| 4041 connman_service_auto_connect(service); | 4043 connman_service_auto_connect(service); |
| 4042 | 4044 |
| 4043 return service; | 4045 return service; |
| 4044 } | 4046 } |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4441 } | 4443 } |
| 4442 | 4444 |
| 4443 str = connman_network_get_string(network, "WiFi.Mode"); | 4445 str = connman_network_get_string(network, "WiFi.Mode"); |
| 4444 service->mode = convert_wifi_mode(str); | 4446 service->mode = convert_wifi_mode(str); |
| 4445 | 4447 |
| 4446 str = connman_network_get_string(network, "WiFi.Security"); | 4448 str = connman_network_get_string(network, "WiFi.Security"); |
| 4447 service->security = convert_wifi_security(str); | 4449 service->security = convert_wifi_security(str); |
| 4448 | 4450 |
| 4449 update_from_network(service, network, FALSE); | 4451 update_from_network(service, network, FALSE); |
| 4450 | 4452 |
| 4451 » __connman_storage_load_service(service); | 4453 » __connman_profile_load_service(service); |
| 4452 | 4454 |
| 4453 service_register(service); | 4455 service_register(service); |
| 4454 | 4456 |
| 4455 __connman_profile_changed(TRUE); | 4457 __connman_profile_changed(TRUE); |
| 4456 | 4458 |
| 4457 if (service->favorite == TRUE) | 4459 if (service->favorite == TRUE) |
| 4458 connman_service_auto_connect(service); | 4460 connman_service_auto_connect(service); |
| 4459 | 4461 |
| 4460 return service; | 4462 return service; |
| 4461 } | 4463 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4649 service->cellular.last_good_apn.apn = g_strdup(apn->apn); | 4651 service->cellular.last_good_apn.apn = g_strdup(apn->apn); |
| 4650 service->cellular.last_good_apn.network_id = g_strdup(apn->netwo
rk_id); | 4652 service->cellular.last_good_apn.network_id = g_strdup(apn->netwo
rk_id); |
| 4651 service->cellular.last_good_apn.username = g_strdup(apn->usernam
e); | 4653 service->cellular.last_good_apn.username = g_strdup(apn->usernam
e); |
| 4652 service->cellular.last_good_apn.password = g_strdup(apn->passwor
d); | 4654 service->cellular.last_good_apn.password = g_strdup(apn->passwor
d); |
| 4653 } else { | 4655 } else { |
| 4654 service->cellular.last_good_apn.apn = NULL; | 4656 service->cellular.last_good_apn.apn = NULL; |
| 4655 service->cellular.last_good_apn.network_id = NULL; | 4657 service->cellular.last_good_apn.network_id = NULL; |
| 4656 service->cellular.last_good_apn.username = NULL; | 4658 service->cellular.last_good_apn.username = NULL; |
| 4657 service->cellular.last_good_apn.password = NULL; | 4659 service->cellular.last_good_apn.password = NULL; |
| 4658 } | 4660 } |
| 4659 » __connman_storage_save_service(service); | 4661 |
| 4662 » __connman_profile_save_service(service); |
| 4660 } | 4663 } |
| 4661 | 4664 |
| 4662 static void populate_service_from_keyfile(GKeyFile *keyfile, | 4665 static void populate_service_from_keyfile(GKeyFile *keyfile, |
| 4663 struct connman_service *service, | 4666 struct connman_service *service, |
| 4664 const char *key, | 4667 const char *key, |
| 4665 char **storage) | 4668 char **storage) |
| 4666 { | 4669 { |
| 4667 char *str; | 4670 char *str; |
| 4668 | 4671 |
| 4669 str = g_key_file_get_string(keyfile, service->identifier, key, NULL); | 4672 str = g_key_file_get_string(keyfile, service->identifier, key, NULL); |
| 4670 if (str != NULL) { | 4673 if (str != NULL) { |
| 4671 g_free(*storage); | 4674 g_free(*storage); |
| 4672 *storage = str; | 4675 *storage = str; |
| 4673 } | 4676 } |
| 4674 } | 4677 } |
| 4675 | 4678 |
| 4676 /* | 4679 /* |
| 4677 * Construct old-style entries for wpa/rsn services. | 4680 * Construct old-style entries for wpa/rsn services. |
| 4678 */ | 4681 */ |
| 4679 static char *__old_security(GKeyFile *keyfile, | 4682 static char *__old_security(GKeyFile *keyfile, |
| 4680 const struct connman_service *service) | 4683 const struct connman_service *service) |
| 4681 { | 4684 { |
| 4682 char *group = NULL; | 4685 char *group = NULL; |
| 4683 | 4686 |
| 4684 if (service->security == CONNMAN_SERVICE_SECURITY_WPA) { | 4687 if (service->security == CONNMAN_SERVICE_SECURITY_WPA) { |
| 4685 group = g_strdup(service->identifier); | 4688 group = g_strdup(service->identifier); |
| 4686 g_strlcpy(group + strlen(group) - 3, "wpa", 4); | 4689 g_strlcpy(group + strlen(group) - 3, "wpa", 4); |
| 4690 if (g_key_file_has_group(keyfile, group) == FALSE) { |
| 4691 g_free(group); |
| 4692 group = NULL; |
| 4693 } |
| 4687 } else if (service->security == CONNMAN_SERVICE_SECURITY_RSN) { | 4694 } else if (service->security == CONNMAN_SERVICE_SECURITY_RSN) { |
| 4688 group = g_strdup(service->identifier); | 4695 group = g_strdup(service->identifier); |
| 4689 g_strlcpy(group + strlen(group) - 3, "rsn", 4); | 4696 g_strlcpy(group + strlen(group) - 3, "rsn", 4); |
| 4697 if (g_key_file_has_group(keyfile, group) == FALSE) { |
| 4698 g_free(group); |
| 4699 group = NULL; |
| 4700 } |
| 4690 } | 4701 } |
| 4691 return group; | 4702 return group; |
| 4692 } | 4703 } |
| 4693 | 4704 |
| 4694 static void load_apn(struct connman_service *service, | 4705 static void load_apn(struct connman_service *service, |
| 4695 GKeyFile *keyfile, | 4706 GKeyFile *keyfile, |
| 4696 const char *group, | 4707 const char *group, |
| 4697 struct connman_network_apn *apn, | 4708 struct connman_network_apn *apn, |
| 4698 const char *keytag) | 4709 const char *keytag) |
| 4699 { | 4710 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4720 apn->password = NULL; | 4731 apn->password = NULL; |
| 4721 apn->network_id = NULL; | 4732 apn->network_id = NULL; |
| 4722 } | 4733 } |
| 4723 | 4734 |
| 4724 g_free(apn_key); | 4735 g_free(apn_key); |
| 4725 g_free(username_key); | 4736 g_free(username_key); |
| 4726 g_free(password_key); | 4737 g_free(password_key); |
| 4727 g_free(network_id_key); | 4738 g_free(network_id_key); |
| 4728 } | 4739 } |
| 4729 | 4740 |
| 4730 static int service_load(struct connman_service *service) | 4741 static int service_load(struct connman_service *service, GKeyFile *keyfile) |
| 4731 { | 4742 { |
| 4732 const char *ident = service->profile; | |
| 4733 const char *group = service->identifier; | 4743 const char *group = service->identifier; |
| 4734 GKeyFile *keyfile; | |
| 4735 GError *error = NULL; | 4744 GError *error = NULL; |
| 4736 gchar *pathname, *data = NULL; | |
| 4737 gsize length; | |
| 4738 gchar *str; | 4745 gchar *str; |
| 4739 connman_bool_t autoconnect, use_system_cas; | 4746 connman_bool_t autoconnect, use_system_cas; |
| 4740 unsigned int ssid_len; | 4747 unsigned int ssid_len; |
| 4741 struct connman_network_apn *apn; | 4748 struct connman_network_apn *apn; |
| 4742 int err = 0, pri; | 4749 int err = 0, pri; |
| 4743 | 4750 |
| 4744 _DBG_SERVICE("service %p", service); | 4751 _DBG_SERVICE("service %p", service); |
| 4745 | 4752 |
| 4746 » if (ident == NULL) | 4753 » if (g_key_file_has_group(keyfile, group) == FALSE) { |
| 4747 » » return -EINVAL; | 4754 » » char *old_group; |
| 4748 | 4755 » » /* |
| 4749 » pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident); | 4756 » » * Handle upgrade of old-style entries for wpa/rsn services. |
| 4750 » if (pathname == NULL) | 4757 » » */ |
| 4751 » » return -ENOMEM; | 4758 » » if (g_str_has_suffix(group, "_psk") == FALSE) { |
| 4752 | 4759 » » » err = -ESRCH; |
| 4753 » keyfile = g_key_file_new(); | 4760 » » » goto done; |
| 4754 | |
| 4755 » if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) { | |
| 4756 » » g_free(pathname); | |
| 4757 » » return -ENOENT; | |
| 4758 » } | |
| 4759 | |
| 4760 » g_free(pathname); | |
| 4761 | |
| 4762 » if (g_key_file_load_from_data(keyfile, data, length, | |
| 4763 » » » » » » » 0, NULL) == FALSE) { | |
| 4764 » » g_free(data); | |
| 4765 » » return -EILSEQ; | |
| 4766 » } | |
| 4767 | |
| 4768 » g_free(data); | |
| 4769 | |
| 4770 » /* | |
| 4771 » * Handle upgrade of old-style entries for wpa/rsn services. | |
| 4772 » */ | |
| 4773 » if (g_key_file_has_group(keyfile, group) == FALSE && | |
| 4774 » g_str_has_suffix(group, "_psk") == TRUE) { | |
| 4775 » » char *old_group = __old_security(keyfile, service); | |
| 4776 » » if (old_group != NULL) { | |
| 4777 » » » _DBG_SERVICE("check old entry %s", old_group); | |
| 4778 » » » group = old_group; | |
| 4779 } | 4761 } |
| 4762 old_group = __old_security(keyfile, service); |
| 4763 if (old_group == NULL) { |
| 4764 err = -ESRCH; |
| 4765 goto done; |
| 4766 } |
| 4767 _DBG_SERVICE("check old entry %s", old_group); |
| 4768 group = old_group; |
| 4780 } | 4769 } |
| 4781 | 4770 |
| 4782 switch (service->type) { | 4771 switch (service->type) { |
| 4783 case CONNMAN_SERVICE_TYPE_UNKNOWN: | 4772 case CONNMAN_SERVICE_TYPE_UNKNOWN: |
| 4784 case CONNMAN_SERVICE_TYPE_ETHERNET: | 4773 case CONNMAN_SERVICE_TYPE_ETHERNET: |
| 4785 case CONNMAN_SERVICE_TYPE_VPN: | 4774 case CONNMAN_SERVICE_TYPE_VPN: |
| 4786 break; | 4775 break; |
| 4787 case CONNMAN_SERVICE_TYPE_WIFI: | 4776 case CONNMAN_SERVICE_TYPE_WIFI: |
| 4788 service->wifi.hidden_ssid = g_key_file_get_boolean(keyfile, | 4777 service->wifi.hidden_ssid = g_key_file_get_boolean(keyfile, |
| 4789 group, "WiFi.HiddenSSID", NULL); | 4778 group, "WiFi.HiddenSSID", NULL); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4855 g_free(str); | 4844 g_free(str); |
| 4856 } | 4845 } |
| 4857 | 4846 |
| 4858 str = g_key_file_get_string(keyfile, | 4847 str = g_key_file_get_string(keyfile, |
| 4859 group, "LastAttempt", NULL); | 4848 group, "LastAttempt", NULL); |
| 4860 if (str != NULL) { | 4849 if (str != NULL) { |
| 4861 g_time_val_from_iso8601(str, &service->last_attempt); | 4850 g_time_val_from_iso8601(str, &service->last_attempt); |
| 4862 g_free(str); | 4851 g_free(str); |
| 4863 } | 4852 } |
| 4864 | 4853 |
| 4865 » str = __connman_storage_get_encrypted_value(keyfile, service->profile, | 4854 » str = __connman_storage_get_encrypted_value(keyfile, group, |
| 4866 » group, "Passphrase"); | 4855 » "Passphrase"); |
| 4867 if (str != NULL) { | 4856 if (str != NULL) { |
| 4868 connman_bool_t valid_pass = TRUE; | 4857 connman_bool_t valid_pass = TRUE; |
| 4869 g_free(service->passphrase); | 4858 g_free(service->passphrase); |
| 4870 service->passphrase = NULL; | 4859 service->passphrase = NULL; |
| 4871 | 4860 |
| 4872 switch (service->security) { | 4861 switch (service->security) { |
| 4873 case CONNMAN_SERVICE_SECURITY_WEP: | 4862 case CONNMAN_SERVICE_SECURITY_WEP: |
| 4874 valid_pass = __connman_service_parse_wep_key(str, | 4863 valid_pass = __connman_service_parse_wep_key(str, |
| 4875 &service->wifi.wep_key_idx, | 4864 &service->wifi.wep_key_idx, |
| 4876 &service->wifi.wep_key_len, | 4865 &service->wifi.wep_key_len, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4934 pri = g_key_file_get_integer(keyfile, | 4923 pri = g_key_file_get_integer(keyfile, |
| 4935 group, "Priority", &error); | 4924 group, "Priority", &error); |
| 4936 if (error == NULL) | 4925 if (error == NULL) |
| 4937 service->pri = pri; | 4926 service->pri = pri; |
| 4938 | 4927 |
| 4939 apn = &service->cellular.apn; | 4928 apn = &service->cellular.apn; |
| 4940 load_apn(service, keyfile, group, &service->cellular.apn, "APN"); | 4929 load_apn(service, keyfile, group, &service->cellular.apn, "APN"); |
| 4941 load_apn(service, keyfile, group, &service->cellular.last_good_apn, | 4930 load_apn(service, keyfile, group, &service->cellular.last_good_apn, |
| 4942 "LastGoodAPN"); | 4931 "LastGoodAPN"); |
| 4943 done: | 4932 done: |
| 4944 g_key_file_free(keyfile); | |
| 4945 | |
| 4946 if (group != service->identifier) | 4933 if (group != service->identifier) |
| 4947 g_free((char *)group); | 4934 g_free((char *)group); |
| 4948 | 4935 |
| 4949 return err; | 4936 return err; |
| 4950 } | 4937 } |
| 4951 | 4938 |
| 4952 static void save_property(GKeyFile *keyfile, struct connman_service *service, | 4939 static void save_property(GKeyFile *keyfile, struct connman_service *service, |
| 4953 const char *key, const char *value) | 4940 const char *key, const char *value) |
| 4954 { | 4941 { |
| 4955 if (value != NULL && strlen(value) > 0) | 4942 if (value != NULL && strlen(value) > 0) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4983 password_key, NULL); | 4970 password_key, NULL); |
| 4984 g_key_file_remove_key(keyfile, service->identifier, | 4971 g_key_file_remove_key(keyfile, service->identifier, |
| 4985 network_id_key, NULL); | 4972 network_id_key, NULL); |
| 4986 } | 4973 } |
| 4987 g_free(apn_key); | 4974 g_free(apn_key); |
| 4988 g_free(username_key); | 4975 g_free(username_key); |
| 4989 g_free(password_key); | 4976 g_free(password_key); |
| 4990 g_free(network_id_key); | 4977 g_free(network_id_key); |
| 4991 } | 4978 } |
| 4992 | 4979 |
| 4993 static int service_save(struct connman_service *service) | 4980 static int service_save(struct connman_service *service, GKeyFile *keyfile) |
| 4994 { | 4981 { |
| 4995 const char *ident = service->profile; | |
| 4996 GKeyFile *keyfile; | |
| 4997 gchar *pathname, *data = NULL; | |
| 4998 gsize length; | |
| 4999 gchar *str; | 4982 gchar *str; |
| 5000 int err = 0; | |
| 5001 | 4983 |
| 5002 _DBG_SERVICE("service %p", service); | 4984 _DBG_SERVICE("service %p", service); |
| 5003 | 4985 |
| 5004 if (ident == NULL) | |
| 5005 return -EINVAL; | |
| 5006 | |
| 5007 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident); | |
| 5008 if (pathname == NULL) | |
| 5009 return -ENOMEM; | |
| 5010 | |
| 5011 keyfile = g_key_file_new(); | |
| 5012 | |
| 5013 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) | |
| 5014 goto update; | |
| 5015 | |
| 5016 if (length > 0) { | |
| 5017 if (g_key_file_load_from_data(keyfile, data, length, | |
| 5018 0, NULL) == FALSE) | |
| 5019 goto done; | |
| 5020 } | |
| 5021 | |
| 5022 g_free(data); | |
| 5023 | |
| 5024 update: | |
| 5025 if (service->name != NULL) | 4986 if (service->name != NULL) |
| 5026 g_key_file_set_string(keyfile, service->identifier, | 4987 g_key_file_set_string(keyfile, service->identifier, |
| 5027 "Name", service->name); | 4988 "Name", service->name); |
| 5028 | 4989 |
| 5029 switch (service->type) { | 4990 switch (service->type) { |
| 5030 case CONNMAN_SERVICE_TYPE_UNKNOWN: | 4991 case CONNMAN_SERVICE_TYPE_UNKNOWN: |
| 5031 case CONNMAN_SERVICE_TYPE_ETHERNET: | 4992 case CONNMAN_SERVICE_TYPE_ETHERNET: |
| 5032 case CONNMAN_SERVICE_TYPE_VPN: | 4993 case CONNMAN_SERVICE_TYPE_VPN: |
| 5033 break; | 4994 break; |
| 5034 case CONNMAN_SERVICE_TYPE_WIFI: | 4995 case CONNMAN_SERVICE_TYPE_WIFI: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5084 if (is_timeset(&service->last_attempt)) { | 5045 if (is_timeset(&service->last_attempt)) { |
| 5085 str = g_time_val_to_iso8601(&service->last_attempt); | 5046 str = g_time_val_to_iso8601(&service->last_attempt); |
| 5086 if (str != NULL) { | 5047 if (str != NULL) { |
| 5087 g_key_file_set_string(keyfile, service->identifier, | 5048 g_key_file_set_string(keyfile, service->identifier, |
| 5088 "LastAttempt", str); | 5049 "LastAttempt", str); |
| 5089 g_free(str); | 5050 g_free(str); |
| 5090 } | 5051 } |
| 5091 } | 5052 } |
| 5092 | 5053 |
| 5093 if (service->passphrase != NULL && strlen(service->passphrase) > 0) { | 5054 if (service->passphrase != NULL && strlen(service->passphrase) > 0) { |
| 5094 __connman_storage_set_encrypted_value(keyfile, service->profile, | 5055 __connman_storage_set_encrypted_value(keyfile, |
| 5095 service->identifier, "Passphrase", service->passphrase); | 5056 service->identifier, "Passphrase", service->passphrase); |
| 5096 } else { | 5057 } else { |
| 5097 g_key_file_remove_key(keyfile, service->identifier, | 5058 g_key_file_remove_key(keyfile, service->identifier, |
| 5098 "Passphrase", NULL); | 5059 "Passphrase", NULL); |
| 5099 } | 5060 } |
| 5100 | 5061 |
| 5101 save_property(keyfile, service, kEAPIdentity, service->eap.identity); | 5062 save_property(keyfile, service, kEAPIdentity, service->eap.identity); |
| 5102 save_property(keyfile, service, kEAPEAP, service->eap.eap); | 5063 save_property(keyfile, service, kEAPEAP, service->eap.eap); |
| 5103 save_property(keyfile, service, kEAPInnerEAP, service->eap.inner_eap); | 5064 save_property(keyfile, service, kEAPInnerEAP, service->eap.inner_eap); |
| 5104 save_property(keyfile, service, kEAPAnonymousIdentity, | 5065 save_property(keyfile, service, kEAPAnonymousIdentity, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5130 g_key_file_set_integer(keyfile, service->identifier, | 5091 g_key_file_set_integer(keyfile, service->identifier, |
| 5131 "Priority", service->pri); | 5092 "Priority", service->pri); |
| 5132 else | 5093 else |
| 5133 g_key_file_remove_key(keyfile, service->identifier, | 5094 g_key_file_remove_key(keyfile, service->identifier, |
| 5134 "Priority", NULL); | 5095 "Priority", NULL); |
| 5135 | 5096 |
| 5136 save_apn(service, keyfile, &service->cellular.apn, "APN"); | 5097 save_apn(service, keyfile, &service->cellular.apn, "APN"); |
| 5137 save_apn(service, keyfile, &service->cellular.last_good_apn, | 5098 save_apn(service, keyfile, &service->cellular.last_good_apn, |
| 5138 "LastGoodAPN"); | 5099 "LastGoodAPN"); |
| 5139 | 5100 |
| 5140 » data = g_key_file_to_data(keyfile, &length, NULL); | 5101 » return 0; |
| 5141 | |
| 5142 » if (g_file_set_contents(pathname, data, length, NULL) == FALSE) | |
| 5143 » » connman_error("Failed to store service information"); | |
| 5144 | |
| 5145 done: | |
| 5146 » g_free(data); | |
| 5147 | |
| 5148 » g_key_file_free(keyfile); | |
| 5149 | |
| 5150 » g_free(pathname); | |
| 5151 | |
| 5152 » return err; | |
| 5153 } | 5102 } |
| 5154 | 5103 |
| 5155 static struct connman_storage service_storage = { | 5104 static struct connman_storage service_storage = { |
| 5156 .name = "service", | 5105 .name = "service", |
| 5157 .priority = CONNMAN_STORAGE_PRIORITY_LOW, | 5106 .priority = CONNMAN_STORAGE_PRIORITY_LOW, |
| 5158 .service_load = service_load, | 5107 .service_load = service_load, |
| 5159 .service_save = service_save, | 5108 .service_save = service_save, |
| 5160 }; | 5109 }; |
| 5161 | 5110 |
| 5162 static struct connman_notifier service_notifier = { | 5111 static struct connman_notifier service_notifier = { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5203 service_list = NULL; | 5152 service_list = NULL; |
| 5204 | 5153 |
| 5205 g_hash_table_destroy(service_hash); | 5154 g_hash_table_destroy(service_hash); |
| 5206 service_hash = NULL; | 5155 service_hash = NULL; |
| 5207 | 5156 |
| 5208 connman_storage_unregister(&service_storage); | 5157 connman_storage_unregister(&service_storage); |
| 5209 connman_notifier_unregister(&service_notifier); | 5158 connman_notifier_unregister(&service_notifier); |
| 5210 | 5159 |
| 5211 dbus_connection_unref(connection); | 5160 dbus_connection_unref(connection); |
| 5212 } | 5161 } |
| OLD | NEW |