Chromium Code Reviews| Index: src/wifi.c |
| diff --git a/src/wifi.c b/src/wifi.c |
| index 72f250079ea0edfff9d76b049157a73d55d70349..815945d5c95655bd4012bca75633326a187ffd41 100644 |
| --- a/src/wifi.c |
| +++ b/src/wifi.c |
| @@ -23,10 +23,28 @@ |
| #include <config.h> |
| #endif |
| +#include <net/ethernet.h> |
| + |
| #include <glib.h> |
| #include "connman.h" |
| +static inline gboolean ispsk(const char *security) |
| +{ |
| + return (g_strcmp0(security, "wpa") == 0 || |
| + g_strcmp0(security, "rsn") == 0 || |
| + g_strcmp0(security, "psk") == 0); |
| +} |
| + |
| +/* |
| + * Construct a ``group name'' when creating a wifi service (see |
| + * __connman_get_wifi_service_int). This string incorporates the |
| + * SSID, security, and operating mode of all devices that should |
| + * be grouped together. Note that we promote all PSK security |
| + * settings to "psk" so services created before the device shows |
| + * up in a scan result can be located when their associated |
| + * network is created. |
| + */ |
| char *connman_wifi_build_group_name(const unsigned char *ssid, |
| unsigned int ssid_len, |
| const char *mode, |
| @@ -44,7 +62,93 @@ char *connman_wifi_build_group_name(const unsigned char *ssid, |
| g_string_append_printf(str, "%02x", ssid[i]); |
| } |
| - g_string_append_printf(str, "_%s_%s", mode, security); |
| + /* NB: use "psk" for all wpa/rsn/psk services */ |
| + g_string_append_printf(str, "_%s_%s", mode, |
| + ispsk(security) ? "psk" : security); |
| + |
| + return g_string_free(str, FALSE); |
| +} |
| + |
| +/* |
| + * Table of well-known SSID's that we want to disambiguate when |
| + * constructing service identifiers. Normally all devices with |
| + * the same SSID, security setup, and operating mode will be |
| + * merged to the same service. A service advertising one of |
| + * these SSID's will have a unique group name constructed that |
| + * ensures like-devices will not be grouped together. |
| + * |
| + * TODO(sleffler) externalize this table and make it's use optional |
| + */ |
| +static struct { |
| + char *name; |
| + char *value; |
| +} special_ssid[] = { |
| + { "<hidden>", "hidden" }, |
| + { "default", "linksys" }, |
| + { "wireless" }, |
| + { "linksys" }, |
| + { "netgear" }, |
| + { "dlink" }, |
| + { "2wire" }, |
| + { "compaq" }, |
| + { "tsunami" }, |
| + { "comcomcom", "3com" }, |
| + { "3Com", "3com" }, |
| + { "Symbol", "symbol" }, |
| + { "Motorola", "motorola" }, |
| + { "Wireless" , "wireless" }, |
| + { "WLAN", "wlan" }, |
| + { } |
| +}; |
| + |
| +/* |
| + * Like connman_wifi_build_group_name but used in the wifi plugins |
| + * when creating network objects from scan results. The group name |
| + * must match the strings constructed above so the associated services |
|
Paul Stewart
2011/03/03 23:08:06
Need to disambiguate "above" here.
|
| + * are matched up. This routine differs in that it does uniquification |
| + * of devices that beacon well-known SSID's that we don't want to |
| + * merge into a group. |
| + */ |
| +char *connman_wifi_build_group(const char *addr, const char *name, |
| + const unsigned char *ssid, unsigned int ssid_len, |
| + const char *mode, const char *security) |
| +{ |
| + GString *str; |
| + unsigned int i; |
| + |
| + if (addr == NULL) |
| + return NULL; |
| + |
| + str = g_string_sized_new((ssid_len * 2) + 24); |
| + if (str == NULL) |
| + return NULL; |
| + |
| + if (ssid == NULL) { |
| + g_string_append_printf(str, "hidden_%s", addr); |
| + goto done; |
| + } |
| + |
| + for (i = 0; special_ssid[i].name; i++) { |
| + if (g_strcmp0(special_ssid[i].name, name) == 0) { |
| + if (special_ssid[i].value == NULL) |
| + g_string_append_printf(str, "%s_%.*s", |
| + name, 2*ETH_ALEN, addr); |
| + else |
| + g_string_append_printf(str, "%s_%.*s", |
| + special_ssid[i].value, 2*ETH_ALEN, addr); |
| + goto done; |
| + } |
| + } |
| + |
| + if (ssid_len > 0 && ssid[0] != '\0') { |
| + for (i = 0; i < ssid_len; i++) |
| + g_string_append_printf(str, "%02x", ssid[i]); |
| + } else |
| + g_string_append_printf(str, "hidden_%.*s", 2*ETH_ALEN, addr); |
| +done: |
| + /* NB: use "psk" for all wpa/rsn/psk services */ |
| + g_string_append_printf(str, "_%s_%s", mode, |
| + ispsk(security) ? "psk" : security); |
| return g_string_free(str, FALSE); |
| } |