Add support for indicating security methods
[connman] / plugins / 80211.c
index 53b36b6..eaec342 100644 (file)
@@ -54,6 +54,10 @@ struct station_data {
        int wpa_ie_len;
        unsigned char rsn_ie[40];
        int rsn_ie_len;
+
+       int has_wep;
+       int has_wpa;
+       int has_rsn;
 };
 
 struct iface_data {
@@ -67,13 +71,23 @@ struct iface_data {
 static void report_station(struct connman_iface *iface,
                                                struct station_data *station)
 {
+       int security = 0;
+
        if (station == NULL)
                return;
 
        if (station->name == NULL)
                return;
 
-       connman_iface_indicate_station(iface, station->name, station->qual);
+       if (station->has_wep)
+               security |= 0x01;
+       if (station->has_wpa)
+               security |= 0x02;
+       if (station->has_rsn)
+               security |= 0x04;
+
+       connman_iface_indicate_station(iface, station->name,
+                                               station->qual, security);
 }
 
 static struct station_data *create_station(struct iface_data *iface,
@@ -157,6 +171,9 @@ static void print_stations(struct iface_data *iface)
                //                      station->address, station->mode,
                //                              station->name, station->qual);
 
+               if (station->name == NULL)
+                       continue;
+
                g_key_file_set_string(keyfile, station->address,
                                                "Name", station->name);
 
@@ -272,7 +289,8 @@ static int iface_connect(struct connman_iface *iface,
 
        __supplicant_start(iface);
 
-       __supplicant_connect(iface, data->network, data->passphrase);
+       if (data->network != NULL)
+               __supplicant_connect(iface, data->network, data->passphrase);
 
        return 0;
 }
@@ -283,6 +301,9 @@ static int iface_disconnect(struct connman_iface *iface)
 
        printf("[802.11] disconnect %s\n", data->ifname);
 
+       if (data->network != NULL)
+               __supplicant_disconnect(iface);
+
        __supplicant_stop(iface);
 
        return 0;
@@ -295,9 +316,15 @@ static void iface_set_network(struct connman_iface *iface,
 
        printf("[802.11] set network %s\n", data->ifname);
 
+       if (data->network != NULL)
+               __supplicant_disconnect(iface);
+
        g_free(data->network);
 
        data->network = g_strdup(network);
+
+       if (data->network != NULL)
+               __supplicant_connect(iface, data->network, data->passphrase);
 }
 
 static void iface_set_passphrase(struct connman_iface *iface,
@@ -307,9 +334,15 @@ static void iface_set_passphrase(struct connman_iface *iface,
 
        printf("[802.11] set passphrase %s\n", data->ifname);
 
+       if (data->network != NULL)
+               __supplicant_disconnect(iface);
+
        g_free(data->passphrase);
 
        data->passphrase = g_strdup(passphrase);
+
+       if (data->network != NULL)
+               __supplicant_connect(iface, data->network, data->passphrase);
 }
 
 static void parse_genie(struct station_data *station,
@@ -322,8 +355,10 @@ static void parse_genie(struct station_data *station,
 
                switch (data[offset]) {
                case 0xdd:      /* WPA1 (and other) */
+                       station->has_wpa = 1;
                        break;
                case 0x30:      /* WPA2 (RSN) */
+                       station->has_rsn = 1;
                        break;
                default:
                        break;
@@ -366,11 +401,12 @@ static void parse_scan_results(struct connman_iface *iface,
                        break;
                case SIOCGIWESSID:
                        if (station != NULL) {
-                               station->name = malloc(event->len - 7);
+                               station->name = malloc(event->len - IW_EV_POINT_LEN + 1);
                                if (station->name != NULL) {
-                                       memset(station->name, 0, event->len - 7);
-                                       memcpy(station->name, ptr + 8,
-                                                               event->len - 8);
+                                       memset(station->name, 0,
+                                               event->len - IW_EV_POINT_LEN + 1);
+                                       memcpy(station->name, ptr + IW_EV_POINT_LEN,
+                                               event->len - IW_EV_POINT_LEN);
                                }
                        }
                        break;
@@ -384,9 +420,8 @@ static void parse_scan_results(struct connman_iface *iface,
                        break;
                case SIOCGIWENCODE:
                        if (station != NULL) {
-                               if (!(event->u.data.flags & IW_ENCODE_DISABLED)) {
-                                       /* privacy */
-                               }
+                               if (!(event->u.data.flags & IW_ENCODE_DISABLED))
+                                       station->has_wep = 1;
                        }
                        break;
                case SIOCGIWRATE:
@@ -462,7 +497,7 @@ static void iface_scan_results(struct connman_iface *iface)
                                done = 1;
                } else {
                        parse_scan_results(iface, iwr.u.data.pointer,
-                                               iwr.u.data.length);
+                                                       iwr.u.data.length);
                        done = 1;
                }
        }