]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P NFC: Add support for freq option in NFC ctrl_iface commands
authorJouni Malinen <jouni@qca.qualcomm.com>
Wed, 4 Dec 2013 03:44:56 +0000 (05:44 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 27 Jan 2014 19:44:31 +0000 (21:44 +0200)
This can be used to force an operating channel for P2P group formation
triggered by NFC operations.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

wpa_supplicant/ctrl_iface.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/p2p_supplicant.h
wpa_supplicant/wps_supplicant.c
wpa_supplicant/wps_supplicant.h

index eef9da3d0a3a3d941eece4cd7ae027870e653c58..9a3cbeaef8554d564f12c939ea08ba5435aacf25 100644 (file)
@@ -890,6 +890,15 @@ static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
        size_t len;
        struct wpabuf *buf;
        int ret;
+       char *freq;
+       int forced_freq = 0;
+
+       freq = strstr(pos, " freq=");
+       if (freq) {
+               *freq = '\0';
+               freq += 6;
+               forced_freq = atoi(freq);
+       }
 
        len = os_strlen(pos);
        if (len & 0x01)
@@ -904,7 +913,7 @@ static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
                return -1;
        }
 
-       ret = wpas_wps_nfc_tag_read(wpa_s, buf);
+       ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
        wpabuf_free(buf);
 
        return ret;
@@ -1142,6 +1151,15 @@ static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
        struct wpabuf *req, *sel;
        int ret;
        char *pos, *role, *type, *pos2;
+       char *freq;
+       int forced_freq = 0;
+
+       freq = strstr(cmd, " freq=");
+       if (freq) {
+               *freq = '\0';
+               freq += 6;
+               forced_freq = atoi(freq);
+       }
 
        role = cmd;
        pos = os_strchr(role, ' ');
@@ -1217,10 +1235,11 @@ static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
                        ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
        } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
        {
-               ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel);
+               ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
        } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
        {
-               ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel);
+               ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
+                                                  forced_freq);
        } else {
                wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
                           "reported: role=%s type=%s", role, type);
index 29e244a967607a95176c16bf1b931abcd1536168..8d6c381cd4ee5f4e841d595c98c0e36f9a6f87b1 100644 (file)
@@ -7238,18 +7238,20 @@ static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
 
 
 static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s,
-                                   struct p2p_nfc_params *params)
+                                   struct p2p_nfc_params *params,
+                                   int forced_freq)
 {
        wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC "
                   "connection handover");
        return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
                                WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent,
-                               0, -1, 0, 1, 1);
+                               forced_freq, -1, 0, 1, 1);
 }
 
 
 static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
-                                   struct p2p_nfc_params *params)
+                                   struct p2p_nfc_params *params,
+                                   int forced_freq)
 {
        int res;
 
@@ -7257,7 +7259,7 @@ static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
                   "connection handover");
        res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
                               WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent,
-                              0, -1, 0, 1, 1);
+                              forced_freq, -1, 0, 1, 1);
        if (res)
                return res;
 
@@ -7273,7 +7275,7 @@ static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
 
 static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
                                            const struct wpabuf *data,
-                                           int sel, int tag)
+                                           int sel, int tag, int forced_freq)
 {
        const u8 *pos, *end;
        u16 len, id;
@@ -7426,10 +7428,10 @@ static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
        case AUTH_JOIN:
                return wpas_p2p_nfc_auth_join(wpa_s, &params, tag);
        case INIT_GO_NEG:
-               return wpas_p2p_nfc_init_go_neg(wpa_s, &params);
+               return wpas_p2p_nfc_init_go_neg(wpa_s, &params, forced_freq);
        case RESP_GO_NEG:
                /* TODO: use own OOB Dev Pw */
-               return wpas_p2p_nfc_resp_go_neg(wpa_s, &params);
+               return wpas_p2p_nfc_resp_go_neg(wpa_s, &params, forced_freq);
        }
 
        return -1;
@@ -7437,18 +7439,18 @@ static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
 
 
 int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s,
-                            const struct wpabuf *data)
+                            const struct wpabuf *data, int forced_freq)
 {
        if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
                return -1;
 
-       return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1);
+       return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq);
 }
 
 
 int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
                                 const struct wpabuf *req,
-                                const struct wpabuf *sel)
+                                const struct wpabuf *sel, int forced_freq)
 {
        struct wpabuf *tmp;
        int ret;
@@ -7462,13 +7464,16 @@ int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
                          wpabuf_head(req), wpabuf_len(req));
        wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel",
                          wpabuf_head(sel), wpabuf_len(sel));
+       if (forced_freq)
+               wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq);
        tmp = ndef_parse_p2p(init ? sel : req);
        if (tmp == NULL) {
                wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF");
                return -1;
        }
 
-       ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0);
+       ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0,
+                                              forced_freq);
        wpabuf_free(tmp);
 
        return ret;
index 4adea48a2f5966019a4ebe1be9d287bfe1e2e22c..685313c6f181b891ddfba896199e6c34f0247140 100644 (file)
@@ -153,10 +153,10 @@ struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s,
 struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s,
                                          int ndef, int tag);
 int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s,
-                            const struct wpabuf *data);
+                            const struct wpabuf *data, int forced_freq);
 int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
                                 const struct wpabuf *req,
-                                const struct wpabuf *sel);
+                                const struct wpabuf *sel, int forced_freq);
 int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled);
 
 #ifdef CONFIG_P2P
index a4b6da5ca355f543b00884ce2d468784742eac82..537aac391fb08361ed73fd945b1c959238b6db64 100644 (file)
@@ -2289,7 +2289,7 @@ static int wpas_wps_nfc_tag_process(struct wpa_supplicant *wpa_s,
 
 
 int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
-                         const struct wpabuf *data)
+                         const struct wpabuf *data, int forced_freq)
 {
        const struct wpabuf *wps = data;
        struct wpabuf *tmp = NULL;
@@ -2305,7 +2305,8 @@ int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
 #ifdef CONFIG_P2P
                        tmp = ndef_parse_p2p(data);
                        if (tmp) {
-                               ret = wpas_p2p_nfc_tag_process(wpa_s, tmp);
+                               ret = wpas_p2p_nfc_tag_process(wpa_s, tmp,
+                                                              forced_freq);
                                wpabuf_free(tmp);
                                return ret;
                        }
index ef32da73883823f44d4c1e7901516a4ed8b98b5f..86e9d0915419f6d66b73d10a84ff3f26e31abbe3 100644 (file)
@@ -70,7 +70,7 @@ int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *dev_addr,
                       int p2p_group, const u8 *peer_pubkey_hash,
                       const u8 *ssid, size_t ssid_len, int freq);
 int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
-                         const struct wpabuf *data);
+                         const struct wpabuf *data, int forced_freq);
 struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s,
                                          int ndef);
 struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,