In case of WiFi networks continue with SSID and security method checks
after verifying the configuration file type. For ethernet and gadget
the configuration file type checking can be combined. This change also
delegates one more instance of explicit service type string checks to
service.c where these strings belong. Once the type is correct, the
additional wifi string comparison can be omitted.
---
src/config.c | 83 ++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 47 insertions(+), 36 deletions(-)
diff --git a/src/config.c b/src/config.c
index cce3c60..276e06b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1100,22 +1100,6 @@ static int try_provision_service(struct
connman_config_service *config,
unsigned int ssid_len;
const char *str;
- type = connman_service_get_type(service);
- if (type == CONNMAN_SERVICE_TYPE_WIFI &&
- g_strcmp0(config->type, "wifi") != 0)
- return -ENOENT;
-
- if (type == CONNMAN_SERVICE_TYPE_ETHERNET &&
- g_strcmp0(config->type, "ethernet") != 0)
- return -ENOENT;
-
- if (type == CONNMAN_SERVICE_TYPE_GADGET &&
- g_strcmp0(config->type, "gadget") != 0)
- return -ENOENT;
-
- DBG("service %p ident %s", service,
- __connman_service_get_ident(service));
-
network = __connman_service_get_network(service);
if (!network) {
connman_error("Service has no network set");
@@ -1125,26 +1109,13 @@ static int try_provision_service(struct
connman_config_service *config,
DBG("network %p ident %s", network,
connman_network_get_identifier(network));
- if (config->mac) {
- struct connman_device *device;
- const char *device_addr;
-
- device = connman_network_get_device(network);
- if (!device) {
- connman_error("Network device is missing");
- return -ENODEV;
- }
-
- device_addr = connman_device_get_string(device, "Address");
-
- DBG("wants %s has %s", config->mac, device_addr);
+ type = connman_service_get_type(service);
- if (g_ascii_strcasecmp(device_addr, config->mac) != 0)
+ switch(type) {
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ if (__connman_service_string2type(config->type) != type)
return -ENOENT;
- }
- if (g_strcmp0(config->type, "wifi") == 0 &&
- type == CONNMAN_SERVICE_TYPE_WIFI) {
ssid = connman_network_get_blob(network, "WiFi.SSID",
&ssid_len);
if (!ssid) {
@@ -1155,12 +1126,53 @@ static int try_provision_service(struct
connman_config_service *config,
if (!config->ssid || ssid_len != config->ssid_len)
return -ENOENT;
- if (memcmp(config->ssid, ssid, ssid_len) != 0)
+ if (memcmp(config->ssid, ssid, ssid_len))
return -ENOENT;
str = connman_network_get_string(network, "WiFi.Security");
if (config->security != __connman_service_string2security(str))
return -ENOENT;
+
+ break;
+
+ case CONNMAN_SERVICE_TYPE_ETHERNET:
+ case CONNMAN_SERVICE_TYPE_GADGET:
+
+ if (__connman_service_string2type(config->type) != type)
+ return -ENOENT;
+
+ break;
+
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ case CONNMAN_SERVICE_TYPE_GPS:
+ case CONNMAN_SERVICE_TYPE_VPN:
+ case CONNMAN_SERVICE_TYPE_P2P:
+
+ return -ENOENT;
+ }
+
+ DBG("service %p ident %s", service,
+ __connman_service_get_ident(service));
+
+ if (config->mac) {
+ struct connman_device *device;
+ const char *device_addr;
+
+ device = connman_network_get_device(network);
+ if (!device) {
+ connman_error("Network device is missing");
+ return -ENODEV;
+ }
+
+ device_addr = connman_device_get_string(device, "Address");
+
+ DBG("wants %s has %s", config->mac, device_addr);
+
+ if (g_ascii_strcasecmp(device_addr, config->mac) != 0)
+ return -ENOENT;
}
if (!config->ipv6_address) {
@@ -1281,8 +1293,7 @@ static int try_provision_service(struct
connman_config_service *config,
__connman_service_set_timeservers(service,
config->timeservers);
- if (g_strcmp0(config->type, "wifi") == 0 &&
- type == CONNMAN_SERVICE_TYPE_WIFI) {
+ if (type == CONNMAN_SERVICE_TYPE_WIFI) {
provision_service_wifi(config, service, network,
ssid, ssid_len);
} else
--
1.9.1
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman