wpa_supplicant: Add an option to specify SSID in neighbor report requests
[mech_eap.git] / wpa_supplicant / ctrl_iface.c
index 8cee4bf..19c0146 100644 (file)
@@ -47,6 +47,7 @@
 #include "wnm_sta.h"
 #include "offchannel.h"
 #include "drivers/driver.h"
+#include "mesh.h"
 
 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
                                            char *buf, int len);
@@ -649,6 +650,56 @@ static int ctrl_iface_get_capability_tdls(
 #endif /* CONFIG_TDLS */
 
 
+static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
+{
+       char *token, *context = NULL;
+       struct wmm_ac_ts_setup_params params = {
+               .tsid = 0xff,
+               .direction = 0xff,
+       };
+
+       while ((token = str_token(cmd, " ", &context))) {
+               if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
+                   sscanf(token, "up=%i", &params.user_priority) == 1 ||
+                   sscanf(token, "nominal_msdu_size=%i",
+                          &params.nominal_msdu_size) == 1 ||
+                   sscanf(token, "mean_data_rate=%i",
+                          &params.mean_data_rate) == 1 ||
+                   sscanf(token, "min_phy_rate=%i",
+                          &params.minimum_phy_rate) == 1 ||
+                   sscanf(token, "sba=%i",
+                          &params.surplus_bandwidth_allowance) == 1)
+                       continue;
+
+               if (os_strcasecmp(token, "downlink") == 0) {
+                       params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
+               } else if (os_strcasecmp(token, "uplink") == 0) {
+                       params.direction = WMM_TSPEC_DIRECTION_UPLINK;
+               } else if (os_strcasecmp(token, "bidi") == 0) {
+                       params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
+               } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
+                       params.fixed_nominal_msdu = 1;
+               } else {
+                       wpa_printf(MSG_DEBUG,
+                                  "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
+                                  token);
+                       return -1;
+               }
+
+       }
+
+       return wpas_wmm_ac_addts(wpa_s, &params);
+}
+
+
+static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
+{
+       u8 tsid = atoi(cmd);
+
+       return wpas_wmm_ac_delts(wpa_s, tsid);
+}
+
+
 #ifdef CONFIG_IEEE80211R
 static int wpa_supplicant_ctrl_iface_ft_ds(
        struct wpa_supplicant *wpa_s, char *addr)
@@ -2155,6 +2206,14 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
        }
 #endif /* CONFIG_IEEE80211W */
 
+       if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
+               ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
+                                 pos == start ? "" : "+");
+               if (ret < 0 || ret >= end - pos)
+                       return pos;
+               pos += ret;
+       }
+
        pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
 
        if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
@@ -2357,6 +2416,83 @@ static int wpa_supplicant_ctrl_iface_scan_results(
 }
 
 
+#ifdef CONFIG_MESH
+
+static int wpa_supplicant_ctrl_iface_mesh_group_add(
+       struct wpa_supplicant *wpa_s, char *cmd)
+{
+       int id;
+       struct wpa_ssid *ssid;
+
+       id = atoi(cmd);
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
+
+       ssid = wpa_config_get_network(wpa_s->conf, id);
+       if (ssid == NULL) {
+               wpa_printf(MSG_DEBUG,
+                          "CTRL_IFACE: Could not find network id=%d", id);
+               return -1;
+       }
+       if (ssid->mode != WPAS_MODE_MESH) {
+               wpa_printf(MSG_DEBUG,
+                          "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
+               return -1;
+       }
+       if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
+           ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
+               wpa_printf(MSG_ERROR,
+                          "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
+               return -1;
+       }
+
+       /*
+        * TODO: If necessary write our own group_add function,
+        * for now we can reuse select_network
+        */
+       wpa_supplicant_select_network(wpa_s, ssid);
+
+       return 0;
+}
+
+
+static int wpa_supplicant_ctrl_iface_mesh_group_remove(
+       struct wpa_supplicant *wpa_s, char *cmd)
+{
+       if (!cmd) {
+               wpa_printf(MSG_ERROR,
+                          "CTRL_IFACE: MESH_GROUP_REMOVE ifname cannot be empty");
+               return -1;
+       }
+
+       /*
+        * TODO: Support a multiple mesh and other iface type combinations
+        */
+       if (os_strcmp(cmd, wpa_s->ifname) != 0) {
+               wpa_printf(MSG_DEBUG,
+                          "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
+                          cmd);
+               return -1;
+       }
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
+
+       wpa_s->reassociate = 0;
+       wpa_s->disconnected = 1;
+       wpa_supplicant_cancel_sched_scan(wpa_s);
+       wpa_supplicant_cancel_scan(wpa_s);
+
+       /*
+        * TODO: If necessary write our own group_remove function,
+        * for now we can reuse deauthenticate
+        */
+       wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+
+       return 0;
+}
+
+#endif /* CONFIG_MESH */
+
+
 static int wpa_supplicant_ctrl_iface_select_network(
        struct wpa_supplicant *wpa_s, char *cmd)
 {
@@ -3387,8 +3523,8 @@ static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
                                continue;
                        ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
                                          chnl[i].chan, chnl[i].freq,
-                                         chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
-                                         " (NO_IBSS)" : "",
+                                         chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
+                                         " (NO_IR)" : "",
                                          chnl[i].flag & HOSTAPD_CHAN_RADAR ?
                                          " (DFS)" : "");
 
@@ -3789,6 +3925,16 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
        }
 #endif /* CONFIG_INTERWORKING */
 
+#ifdef CONFIG_MESH
+       if (mask & WPA_BSS_MASK_MESH_SCAN) {
+               ie = (const u8 *) (bss + 1);
+               ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
+               if (ret < 0 || ret >= end - pos)
+                       return 0;
+               pos += ret;
+       }
+#endif /* CONFIG_MESH */
+
        if (mask & WPA_BSS_MASK_DELIM) {
                ret = os_snprintf(pos, end - pos, "====\n");
                if (ret < 0 || ret >= end - pos)
@@ -5035,6 +5181,7 @@ static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
 {
        os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
        wpa_s->force_long_sd = 0;
+       wpas_p2p_stop_find(wpa_s);
        if (wpa_s->global->p2p)
                p2p_flush(wpa_s->global->p2p);
 }
@@ -6676,6 +6823,44 @@ static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
 }
 
 
+static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+
+       if (neighbor_rep) {
+               wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
+                            "length=%u",
+                            (unsigned int) wpabuf_len(neighbor_rep));
+               wpabuf_free(neighbor_rep);
+       } else {
+               wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
+       }
+}
+
+
+static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
+                                           char *cmd)
+{
+       struct wpa_ssid ssid;
+       struct wpa_ssid *ssid_p = NULL;
+       int ret = 0;
+
+       if (os_strncmp(cmd, " ssid=", 6) == 0) {
+               ssid.ssid_len = os_strlen(cmd + 6);
+               if (ssid.ssid_len > 32)
+                       return -1;
+               ssid.ssid = (u8 *) (cmd + 6);
+               ssid_p = &ssid;
+       }
+
+       ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p,
+                                                wpas_ctrl_neighbor_rep_cb,
+                                                wpa_s);
+
+       return ret;
+}
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                         char *buf, size_t *resp_len)
 {
@@ -6895,6 +7080,15 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
                        reply_len = -1;
 #endif /* CONFIG_IBSS_RSN */
+#ifdef CONFIG_MESH
+       } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
+               if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
+                       reply_len = -1;
+       } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
+               if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
+                                                               buf + 18))
+                       reply_len = -1;
+#endif /* CONFIG_MESH */
 #ifdef CONFIG_P2P
        } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
                if (p2p_ctrl_find(wpa_s, buf + 9))
@@ -7198,6 +7392,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
                        reply_len = -1;
 #endif /* CONFIG_TDLS */
+       } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
+               reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
+       } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
+               if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
+                       reply_len = -1;
+       } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
+               if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
+                       reply_len = -1;
        } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
                reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
                                                       reply_size);
@@ -7261,6 +7463,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
                if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
+               if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20))
+                       reply_len = -1;
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;