QCA vendor command support to set band to driver
[mech_eap.git] / wpa_supplicant / ctrl_iface.c
index 417ae57..41f9090 100644 (file)
@@ -28,6 +28,7 @@
 #include "rsn_supp/pmksa_cache.h"
 #include "l2_packet/l2_packet.h"
 #include "wps/wps.h"
+#include "fst/fst.h"
 #include "fst/fst_ctrl_iface.h"
 #include "config.h"
 #include "wpa_supplicant_i.h"
@@ -285,6 +286,30 @@ static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
 }
 
 
+static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
+{
+       union wpa_event_data event;
+
+       if (os_strcmp(band, "AUTO") == 0)
+               wpa_s->setband = WPA_SETBAND_AUTO;
+       else if (os_strcmp(band, "5G") == 0)
+               wpa_s->setband = WPA_SETBAND_5G;
+       else if (os_strcmp(band, "2G") == 0)
+               wpa_s->setband = WPA_SETBAND_2G;
+       else
+               return -1;
+
+       if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
+               os_memset(&event, 0, sizeof(event));
+               event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
+               event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
+               wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
+       }
+
+       return 0;
+}
+
+
 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
                                         char *cmd)
 {
@@ -448,14 +473,7 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
                ret = wpas_ctrl_set_blob(wpa_s, value);
 #endif /* CONFIG_NO_CONFIG_BLOBS */
        } else if (os_strcasecmp(cmd, "setband") == 0) {
-               if (os_strcmp(value, "AUTO") == 0)
-                       wpa_s->setband = WPA_SETBAND_AUTO;
-               else if (os_strcmp(value, "5G") == 0)
-                       wpa_s->setband = WPA_SETBAND_5G;
-               else if (os_strcmp(value, "2G") == 0)
-                       wpa_s->setband = WPA_SETBAND_2G;
-               else
-                       ret = -1;
+               ret = wpas_ctrl_set_band(wpa_s, value);
        } else {
                value[-1] = '=';
                ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
@@ -3086,7 +3104,8 @@ static int wpa_supplicant_ctrl_iface_get_network(
 
 
 static int wpa_supplicant_ctrl_iface_dup_network(
-       struct wpa_supplicant *wpa_s, char *cmd)
+       struct wpa_supplicant *wpa_s, char *cmd,
+       struct wpa_supplicant *dst_wpa_s)
 {
        struct wpa_ssid *ssid_s, *ssid_d;
        char *name, *id, *value;
@@ -3105,8 +3124,10 @@ static int wpa_supplicant_ctrl_iface_dup_network(
 
        id_s = atoi(cmd);
        id_d = atoi(id);
-       wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
-                  id_s, id_d, name);
+
+       wpa_printf(MSG_DEBUG,
+                  "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
+                  wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
 
        ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
        if (ssid_s == NULL) {
@@ -3115,7 +3136,7 @@ static int wpa_supplicant_ctrl_iface_dup_network(
                return -1;
        }
 
-       ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
+       ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
        if (ssid_d == NULL) {
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
                           "network id=%d", id_d);
@@ -3129,7 +3150,7 @@ static int wpa_supplicant_ctrl_iface_dup_network(
                return -1;
        }
 
-       ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
+       ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
                                                       value);
 
        os_free(value);
@@ -4648,6 +4669,48 @@ static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
 }
 
 
+static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
+{
+       const char *last = NULL;
+       const char *token;
+       long int token_len;
+       unsigned int i;
+
+       /* Expected predefined CPT names delimited by ':' */
+       for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
+               if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
+                       wpa_printf(MSG_ERROR,
+                                  "P2PS: CPT name list is too long, expected up to %d names",
+                                  P2PS_FEATURE_CAPAB_CPT_MAX);
+                       cpt[0] = 0;
+                       return -1;
+               }
+
+               token_len = last - token;
+
+               if (token_len  == 3 &&
+                   os_memcmp(token, "UDP", token_len) == 0) {
+                       cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
+               } else if (token_len == 3 &&
+                          os_memcmp(token, "MAC", token_len) == 0) {
+                       cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
+               } else {
+                       wpa_printf(MSG_ERROR,
+                                  "P2PS: Unsupported CPT name '%s'", token);
+                       cpt[0] = 0;
+                       return -1;
+               }
+
+               if (isblank(*last)) {
+                       i++;
+                       break;
+               }
+       }
+       cpt[i] = 0;
+       return 0;
+}
+
+
 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
 {
        struct p2ps_provision *p2ps_prov;
@@ -4656,6 +4719,7 @@ static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
        char *info = NULL;
        u8 role = P2PS_SETUP_NONE;
        long long unsigned val;
+       int i;
 
        pos = os_strstr(cmd, "info=");
        if (pos) {
@@ -4714,6 +4778,18 @@ static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
        if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
                goto invalid_args;
 
+       pos = os_strstr(cmd, "cpt=");
+       if (pos) {
+               if (p2ps_ctrl_parse_cpt_priority(pos + 4,
+                                                p2ps_prov->cpt_priority))
+                       goto invalid_args;
+       } else {
+               p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
+       }
+
+       for (i = 0; p2ps_prov->cpt_priority[i]; i++)
+               p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
+
        /* force conncap with tstCap (no sanity checks) */
        pos = os_strstr(cmd, "tstCap=");
        if (pos) {
@@ -5209,6 +5285,8 @@ static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
        char *adv_str;
        u32 auto_accept, adv_id, svc_state, config_methods;
        char *svc_info = NULL;
+       char *cpt_prio_str;
+       u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
 
        pos = os_strchr(cmd, ' ');
        if (pos == NULL)
@@ -5281,6 +5359,19 @@ static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
        if (pos != NULL)
                *pos++ = '\0';
 
+       cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
+       if (cpt_prio_str) {
+               pos = os_strchr(pos, ' ');
+               if (pos != NULL)
+                       *pos++ = '\0';
+
+               if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
+                       return -1;
+       } else {
+               cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
+               cpt_prio[1] = 0;
+       }
+
        /* Service and Response Information are optional */
        if (pos && pos[0]) {
                size_t len;
@@ -5298,7 +5389,7 @@ static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
 
        return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
                                        (u8) svc_state, (u16) config_methods,
-                                       svc_info);
+                                       svc_info, cpt_prio);
 }
 
 
@@ -8459,7 +8550,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                reply_len = wpa_supplicant_ctrl_iface_get_network(
                        wpa_s, buf + 12, reply, reply_size);
        } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
-               if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
+               if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
+                                                         wpa_s))
                        reply_len = -1;
        } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
                reply_len = wpa_supplicant_ctrl_iface_list_creds(
@@ -9059,6 +9151,41 @@ static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
 }
 
 
+static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
+                                             char *cmd)
+{
+       struct wpa_supplicant *wpa_s[2]; /* src, dst */
+       char *p;
+       unsigned int i;
+
+       /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
+        * <variable name> */
+
+       for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
+               p = os_strchr(cmd, ' ');
+               if (p == NULL)
+                       return -1;
+               *p = '\0';
+
+               wpa_s[i] = global->ifaces;
+               for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
+                       if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
+                               break;
+               }
+
+               if (!wpa_s[i]) {
+                       wpa_printf(MSG_DEBUG,
+                                  "CTRL_IFACE: Could not find iface=%s", cmd);
+                       return -1;
+               }
+
+               cmd = p + 1;
+       }
+
+       return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
+}
+
+
 #ifndef CONFIG_NO_CONFIG_WRITE
 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
 {
@@ -9154,6 +9281,10 @@ static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
        if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
                wpa_s = wpa_supplicant_get_iface(global, ifname);
                if (wpa_s) {
+                       if (wpa_s->fst) {
+                               wpa_printf(MSG_INFO, "FST: Already attached");
+                               return -1;
+                       }
                        fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
                        wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
                                                &iface_obj, &cfg);
@@ -9272,6 +9403,9 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
 #endif /* CONFIG_P2P */
                        reply_len = -1;
                }
+       } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
+               if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
+                       reply_len = -1;
 #ifndef CONFIG_NO_CONFIG_WRITE
        } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
                if (wpas_global_ctrl_iface_save_config(global))