blob: d70a43c2d8d8f3cb1cffaa660f0becb70dfb4648 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Wi-Fi Direct - P2P provision discovery
3 * Copyright (c) 2009-2010, Atheros Communications
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "common/ieee802_11_defs.h"
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070013#include "common/wpa_ctrl.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include "wps/wps_defs.h"
15#include "p2p_i.h"
16#include "p2p.h"
17
18
Jouni Malinen75ecf522011-06-27 15:19:46 -070019/*
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070020 * Number of retries to attempt for provision discovery requests
21 * in case the peer is not listening.
Jouni Malinen75ecf522011-06-27 15:19:46 -070022 */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080023#define MAX_PROV_DISC_REQ_RETRIES 120
Jouni Malinen75ecf522011-06-27 15:19:46 -070024
25
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026static void p2p_build_wps_ie_config_methods(struct wpabuf *buf,
27 u16 config_methods)
28{
29 u8 *len;
30 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
31 len = wpabuf_put(buf, 1);
32 wpabuf_put_be32(buf, WPS_DEV_OUI_WFA);
33
34 /* Config Methods */
35 wpabuf_put_be16(buf, ATTR_CONFIG_METHODS);
36 wpabuf_put_be16(buf, 2);
37 wpabuf_put_be16(buf, config_methods);
38
39 p2p_buf_update_ie_hdr(buf, len);
40}
41
42
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080043static void p2ps_add_new_group_info(struct p2p_data *p2p,
44 struct p2p_device *dev,
45 struct wpabuf *buf)
Dmitry Shmidt216983b2015-02-06 10:50:36 -080046{
47 int found;
48 u8 intended_addr[ETH_ALEN];
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -070049 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt216983b2015-02-06 10:50:36 -080050 size_t ssid_len;
51 int group_iface;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080052 unsigned int force_freq;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080053
54 if (!p2p->cfg->get_go_info)
55 return;
56
57 found = p2p->cfg->get_go_info(
58 p2p->cfg->cb_ctx, intended_addr, ssid,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080059 &ssid_len, &group_iface, &force_freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080060 if (found) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080061 if (force_freq > 0) {
62 p2p->p2ps_prov->force_freq = force_freq;
63 p2p->p2ps_prov->pref_freq = 0;
64
65 if (dev)
66 p2p_prepare_channel(p2p, dev, force_freq, 0, 0);
67 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -080068 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr,
69 ssid, ssid_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080070
71 if (group_iface)
72 p2p_buf_add_intended_addr(buf, p2p->intended_addr);
73 else
74 p2p_buf_add_intended_addr(buf, intended_addr);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080075 } else {
76 if (!p2p->ssid_set) {
77 p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
78 p2p->ssid_set = 1;
79 }
80
81 /* Add pre-composed P2P Group ID */
82 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr,
83 p2p->ssid, p2p->ssid_len);
84
85 if (group_iface)
86 p2p_buf_add_intended_addr(
87 buf, p2p->intended_addr);
88 else
89 p2p_buf_add_intended_addr(
90 buf, p2p->cfg->dev_addr);
91 }
92}
93
94
95static void p2ps_add_pd_req_attrs(struct p2p_data *p2p, struct p2p_device *dev,
96 struct wpabuf *buf, u16 config_methods)
97{
98 struct p2ps_provision *prov = p2p->p2ps_prov;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080099 struct p2ps_feature_capab fcap = { prov->cpt_mask, 0 };
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800100 int shared_group = 0;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700101 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800102 size_t ssid_len;
103 u8 go_dev_addr[ETH_ALEN];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800104 u8 intended_addr[ETH_ALEN];
105 int follow_on_req_fail = prov->status >= 0 &&
106 prov->status != P2P_SC_SUCCESS_DEFERRED;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800107
108 /* If we might be explicite group owner, add GO details */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800109 if (!follow_on_req_fail &&
110 (prov->conncap & (P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW)))
111 p2ps_add_new_group_info(p2p, dev, buf);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800112
113 if (prov->status >= 0)
114 p2p_buf_add_status(buf, (u8) prov->status);
115 else
116 prov->method = config_methods;
117
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800118 if (!follow_on_req_fail) {
119 if (p2p->cfg->get_persistent_group) {
120 shared_group = p2p->cfg->get_persistent_group(
121 p2p->cfg->cb_ctx, dev->info.p2p_device_addr,
122 NULL, 0, go_dev_addr, ssid, &ssid_len,
123 intended_addr);
124 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800125
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800126 if (shared_group ||
127 (prov->conncap & (P2PS_SETUP_CLIENT | P2PS_SETUP_NEW)))
128 p2p_buf_add_channel_list(buf, p2p->cfg->country,
129 &p2p->channels);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800130
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800131 if ((shared_group && !is_zero_ether_addr(intended_addr)) ||
132 (prov->conncap & (P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW)))
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800133 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
134 p2p->op_reg_class,
135 p2p->op_channel);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800136 }
137
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800138 if (prov->status < 0 && prov->info[0])
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800139 p2p_buf_add_session_info(buf, prov->info);
140
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800141 if (!follow_on_req_fail)
142 p2p_buf_add_connection_capability(buf, prov->conncap);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800143
144 p2p_buf_add_advertisement_id(buf, prov->adv_id, prov->adv_mac);
145
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800146 if (!follow_on_req_fail) {
147 if (shared_group || prov->conncap == P2PS_SETUP_NEW ||
148 prov->conncap ==
149 (P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW) ||
150 prov->conncap ==
151 (P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT)) {
152 /* Add Config Timeout */
153 p2p_buf_add_config_timeout(buf, p2p->go_timeout,
154 p2p->client_timeout);
155 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800156
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800157 p2p_buf_add_listen_channel(buf, p2p->cfg->country,
158 p2p->cfg->reg_class,
159 p2p->cfg->channel);
160 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800161
162 p2p_buf_add_session_id(buf, prov->session_id, prov->session_mac);
163
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800164 p2p_buf_add_feature_capability(buf, sizeof(fcap), (const u8 *) &fcap);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800165
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800166 if (shared_group) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800167 p2p_buf_add_persistent_group_info(buf, go_dev_addr,
168 ssid, ssid_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800169 /* Add intended interface address if it is not added yet */
170 if ((prov->conncap == P2PS_SETUP_NONE ||
171 prov->conncap == P2PS_SETUP_CLIENT) &&
172 !is_zero_ether_addr(intended_addr))
173 p2p_buf_add_intended_addr(buf, intended_addr);
174 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800175}
176
177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178static struct wpabuf * p2p_build_prov_disc_req(struct p2p_data *p2p,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800179 struct p2p_device *dev,
180 int join)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181{
182 struct wpabuf *buf;
183 u8 *len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700184 size_t extra = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800185 u8 dialog_token = dev->dialog_token;
186 u16 config_methods = dev->req_config_methods;
187 struct p2p_device *go = join ? dev : NULL;
188 u8 group_capab;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700190#ifdef CONFIG_WIFI_DISPLAY
191 if (p2p->wfd_ie_prov_disc_req)
192 extra = wpabuf_len(p2p->wfd_ie_prov_disc_req);
193#endif /* CONFIG_WIFI_DISPLAY */
194
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700195 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ])
196 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ]);
197
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800198 if (p2p->p2ps_prov)
199 extra += os_strlen(p2p->p2ps_prov->info) + 1 +
200 sizeof(struct p2ps_provision);
201
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700202 buf = wpabuf_alloc(1000 + extra);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 if (buf == NULL)
204 return NULL;
205
206 p2p_buf_add_public_action_hdr(buf, P2P_PROV_DISC_REQ, dialog_token);
207
208 len = p2p_buf_add_ie_hdr(buf);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800209
210 group_capab = 0;
211 if (p2p->p2ps_prov) {
212 group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
213 group_capab |= P2P_GROUP_CAPAB_PERSISTENT_RECONN;
214 if (p2p->cross_connect)
215 group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
216 if (p2p->cfg->p2p_intra_bss)
217 group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
218 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700219 p2p_buf_add_capability(buf, p2p->dev_capab &
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800220 ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
221 group_capab);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 p2p_buf_add_device_info(buf, p2p, NULL);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800223 if (p2p->p2ps_prov) {
224 p2ps_add_pd_req_attrs(p2p, dev, buf, config_methods);
225 } else if (go) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 p2p_buf_add_group_id(buf, go->info.p2p_device_addr,
227 go->oper_ssid, go->oper_ssid_len);
228 }
229 p2p_buf_update_ie_hdr(buf, len);
230
231 /* WPS IE with Config Methods attribute */
232 p2p_build_wps_ie_config_methods(buf, config_methods);
233
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700234#ifdef CONFIG_WIFI_DISPLAY
235 if (p2p->wfd_ie_prov_disc_req)
236 wpabuf_put_buf(buf, p2p->wfd_ie_prov_disc_req);
237#endif /* CONFIG_WIFI_DISPLAY */
238
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700239 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ])
240 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ]);
241
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 return buf;
243}
244
245
246static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800247 struct p2p_device *dev,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 u8 dialog_token,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800249 enum p2p_status_code status,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700250 u16 config_methods,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800251 u32 adv_id,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700252 const u8 *group_id,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800253 size_t group_id_len,
254 const u8 *persist_ssid,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800255 size_t persist_ssid_len,
256 const u8 *fcap,
257 u16 fcap_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258{
259 struct wpabuf *buf;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700260 size_t extra = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800261 int persist = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700263#ifdef CONFIG_WIFI_DISPLAY
264 struct wpabuf *wfd_ie = p2p->wfd_ie_prov_disc_resp;
265 if (wfd_ie && group_id) {
266 size_t i;
267 for (i = 0; i < p2p->num_groups; i++) {
268 struct p2p_group *g = p2p->groups[i];
269 struct wpabuf *ie;
270 if (!p2p_group_is_group_id_match(g, group_id,
271 group_id_len))
272 continue;
273 ie = p2p_group_get_wfd_ie(g);
274 if (ie) {
275 wfd_ie = ie;
276 break;
277 }
278 }
279 }
280 if (wfd_ie)
281 extra = wpabuf_len(wfd_ie);
282#endif /* CONFIG_WIFI_DISPLAY */
283
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700284 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP])
285 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP]);
286
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800287 buf = wpabuf_alloc(1000 + extra);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700288 if (buf == NULL)
289 return NULL;
290
291 p2p_buf_add_public_action_hdr(buf, P2P_PROV_DISC_RESP, dialog_token);
292
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800293 /* Add P2P IE for P2PS */
294 if (p2p->p2ps_prov && p2p->p2ps_prov->adv_id == adv_id) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800295 u8 *len = p2p_buf_add_ie_hdr(buf);
296 struct p2ps_provision *prov = p2p->p2ps_prov;
297 u8 group_capab;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800298 u8 conncap = 0;
299
300 if (status == P2P_SC_SUCCESS ||
301 status == P2P_SC_SUCCESS_DEFERRED)
302 conncap = prov->conncap;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800303
304 if (!status && prov->status != -1)
305 status = prov->status;
306
307 p2p_buf_add_status(buf, status);
308 group_capab = P2P_GROUP_CAPAB_PERSISTENT_GROUP |
309 P2P_GROUP_CAPAB_PERSISTENT_RECONN;
310 if (p2p->cross_connect)
311 group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
312 if (p2p->cfg->p2p_intra_bss)
313 group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
314 p2p_buf_add_capability(buf, p2p->dev_capab &
315 ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
316 group_capab);
317 p2p_buf_add_device_info(buf, p2p, NULL);
318
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800319 if (persist_ssid && p2p->cfg->get_persistent_group && dev &&
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800320 (status == P2P_SC_SUCCESS ||
321 status == P2P_SC_SUCCESS_DEFERRED)) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700322 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800323 size_t ssid_len;
324 u8 go_dev_addr[ETH_ALEN];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800325 u8 intended_addr[ETH_ALEN];
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800326
327 persist = p2p->cfg->get_persistent_group(
328 p2p->cfg->cb_ctx,
329 dev->info.p2p_device_addr,
330 persist_ssid, persist_ssid_len, go_dev_addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800331 ssid, &ssid_len, intended_addr);
332 if (persist) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800333 p2p_buf_add_persistent_group_info(
334 buf, go_dev_addr, ssid, ssid_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800335 if (!is_zero_ether_addr(intended_addr))
336 p2p_buf_add_intended_addr(
337 buf, intended_addr);
338 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800339 }
340
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800341 if (!persist && (conncap & P2PS_SETUP_GROUP_OWNER))
342 p2ps_add_new_group_info(p2p, dev, buf);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800343
344 /* Add Operating Channel if conncap indicates GO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800345 if (persist || (conncap & P2PS_SETUP_GROUP_OWNER)) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800346 if (p2p->op_reg_class && p2p->op_channel)
347 p2p_buf_add_operating_channel(
348 buf, p2p->cfg->country,
349 p2p->op_reg_class,
350 p2p->op_channel);
351 else
352 p2p_buf_add_operating_channel(
353 buf, p2p->cfg->country,
354 p2p->cfg->op_reg_class,
355 p2p->cfg->op_channel);
356 }
357
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800358 if (persist ||
359 (conncap & (P2PS_SETUP_CLIENT | P2PS_SETUP_GROUP_OWNER)))
360 p2p_buf_add_channel_list(buf, p2p->cfg->country,
361 &p2p->channels);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800362
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800363 if (!persist && conncap)
364 p2p_buf_add_connection_capability(buf, conncap);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800365
366 p2p_buf_add_advertisement_id(buf, adv_id, prov->adv_mac);
367
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800368 if (persist ||
369 (conncap & (P2PS_SETUP_CLIENT | P2PS_SETUP_GROUP_OWNER)))
370 p2p_buf_add_config_timeout(buf, p2p->go_timeout,
371 p2p->client_timeout);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800372
373 p2p_buf_add_session_id(buf, prov->session_id,
374 prov->session_mac);
375
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800376 p2p_buf_add_feature_capability(buf, fcap_len, fcap);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800377 p2p_buf_update_ie_hdr(buf, len);
378 } else if (status != P2P_SC_SUCCESS || adv_id) {
379 u8 *len = p2p_buf_add_ie_hdr(buf);
380
381 p2p_buf_add_status(buf, status);
382
383 if (p2p->p2ps_prov)
384 p2p_buf_add_advertisement_id(buf, adv_id,
385 p2p->p2ps_prov->adv_mac);
386
387 p2p_buf_update_ie_hdr(buf, len);
388 }
389
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 /* WPS IE with Config Methods attribute */
391 p2p_build_wps_ie_config_methods(buf, config_methods);
392
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700393#ifdef CONFIG_WIFI_DISPLAY
394 if (wfd_ie)
395 wpabuf_put_buf(buf, wfd_ie);
396#endif /* CONFIG_WIFI_DISPLAY */
397
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700398 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP])
399 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP]);
400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700401 return buf;
402}
403
404
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800405static int p2ps_setup_p2ps_prov(struct p2p_data *p2p, u32 adv_id,
406 u32 session_id, u16 method,
407 const u8 *session_mac, const u8 *adv_mac)
408{
409 struct p2ps_provision *tmp;
410
411 if (!p2p->p2ps_prov) {
412 p2p->p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + 1);
413 if (!p2p->p2ps_prov)
414 return -1;
415 } else {
416 os_memset(p2p->p2ps_prov, 0, sizeof(struct p2ps_provision) + 1);
417 }
418
419 tmp = p2p->p2ps_prov;
420 tmp->adv_id = adv_id;
421 tmp->session_id = session_id;
422 tmp->method = method;
423 os_memcpy(tmp->session_mac, session_mac, ETH_ALEN);
424 os_memcpy(tmp->adv_mac, adv_mac, ETH_ALEN);
425 tmp->info[0] = '\0';
426
427 return 0;
428}
429
430
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800431static u8 p2ps_own_preferred_cpt(const u8 *cpt_priority, u8 req_cpt_mask)
432{
433 int i;
434
435 for (i = 0; cpt_priority[i]; i++)
436 if (req_cpt_mask & cpt_priority[i])
437 return cpt_priority[i];
438
439 return 0;
440}
441
442
443/* Check if the message contains a valid P2PS PD Request */
444static int p2ps_validate_pd_req(struct p2p_data *p2p, struct p2p_message *msg,
445 const u8 *addr)
446{
447 u8 group_id = 0;
448 u8 intended_addr = 0;
449 u8 operating_channel = 0;
450 u8 channel_list = 0;
451 u8 config_timeout = 0;
452 u8 listen_channel = 0;
453
454#define P2PS_PD_REQ_CHECK(_val, _attr) \
455do { \
456 if ((_val) && !msg->_attr) { \
457 p2p_dbg(p2p, "Not P2PS PD Request. Missing %s", #_attr); \
458 return -1; \
459 } \
460} while (0)
461
462 P2PS_PD_REQ_CHECK(1, adv_id);
463 P2PS_PD_REQ_CHECK(1, session_id);
464 P2PS_PD_REQ_CHECK(1, session_mac);
465 P2PS_PD_REQ_CHECK(1, adv_mac);
466 P2PS_PD_REQ_CHECK(1, capability);
467 P2PS_PD_REQ_CHECK(1, p2p_device_info);
468 P2PS_PD_REQ_CHECK(1, feature_cap);
469
470 /*
471 * We don't need to check Connection Capability, Persistent Group,
472 * and related attributes for follow-on PD Request with a status
473 * other than SUCCESS_DEFERRED.
474 */
475 if (msg->status && *msg->status != P2P_SC_SUCCESS_DEFERRED)
476 return 0;
477
478 P2PS_PD_REQ_CHECK(1, conn_cap);
479
480 /*
481 * Note 1: A feature capability attribute structure can be changed
482 * in the future. The assumption is that such modifications are
483 * backward compatible, therefore we allow processing of msg.feature_cap
484 * exceeding the size of the p2ps_feature_capab structure.
485 * Note 2: Verification of msg.feature_cap_len below has to be changed
486 * to allow 2 byte feature capability processing if
487 * struct p2ps_feature_capab is extended to include additional fields
488 * and it affects the structure size.
489 */
490 if (msg->feature_cap_len < sizeof(struct p2ps_feature_capab)) {
491 p2p_dbg(p2p, "P2PS: Invalid feature capability len");
492 return -1;
493 }
494
495 switch (*msg->conn_cap) {
496 case P2PS_SETUP_NEW:
497 group_id = 1;
498 intended_addr = 1;
499 operating_channel = 1;
500 channel_list = 1;
501 config_timeout = 1;
502 listen_channel = 1;
503 break;
504 case P2PS_SETUP_CLIENT:
505 channel_list = 1;
506 listen_channel = 1;
507 break;
508 case P2PS_SETUP_GROUP_OWNER:
509 group_id = 1;
510 intended_addr = 1;
511 operating_channel = 1;
512 break;
513 case P2PS_SETUP_NEW | P2PS_SETUP_GROUP_OWNER:
514 group_id = 1;
515 operating_channel = 1;
516 intended_addr = 1;
517 channel_list = 1;
518 config_timeout = 1;
519 break;
520 case P2PS_SETUP_CLIENT | P2PS_SETUP_GROUP_OWNER:
521 group_id = 1;
522 intended_addr = 1;
523 operating_channel = 1;
524 channel_list = 1;
525 config_timeout = 1;
526 break;
527 default:
528 p2p_dbg(p2p, "Invalid P2PS PD connection capability");
529 return -1;
530 }
531
532 if (msg->persistent_dev) {
533 channel_list = 1;
534 config_timeout = 1;
535 if (os_memcmp(msg->persistent_dev, addr, ETH_ALEN) == 0) {
536 intended_addr = 1;
537 operating_channel = 1;
538 }
539 }
540
541 P2PS_PD_REQ_CHECK(group_id, group_id);
542 P2PS_PD_REQ_CHECK(intended_addr, intended_addr);
543 P2PS_PD_REQ_CHECK(operating_channel, operating_channel);
544 P2PS_PD_REQ_CHECK(channel_list, channel_list);
545 P2PS_PD_REQ_CHECK(config_timeout, config_timeout);
546 P2PS_PD_REQ_CHECK(listen_channel, listen_channel);
547
548#undef P2PS_PD_REQ_CHECK
549
550 return 0;
551}
552
553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
555 const u8 *data, size_t len, int rx_freq)
556{
557 struct p2p_message msg;
558 struct p2p_device *dev;
559 int freq;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800560 enum p2p_status_code reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 struct wpabuf *resp;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800562 u32 adv_id = 0;
563 struct p2ps_advertisement *p2ps_adv = NULL;
564 u8 conncap = P2PS_SETUP_NEW;
565 u8 auto_accept = 0;
566 u32 session_id = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800567 u8 session_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
568 u8 adv_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
569 const u8 *group_mac;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800570 int passwd_id = DEV_PW_DEFAULT;
571 u16 config_methods;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800572 u16 allowed_config_methods = WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
573 struct p2ps_feature_capab resp_fcap = { 0, 0 };
574 struct p2ps_feature_capab *req_fcap = NULL;
575 u8 remote_conncap;
576 u16 method;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577
578 if (p2p_parse(data, len, &msg))
579 return;
580
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700581 p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582 " with config methods 0x%x (freq=%d)",
583 MAC2STR(sa), msg.wps_config_methods, rx_freq);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800584 group_mac = msg.intended_addr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585
586 dev = p2p_get_device(p2p, sa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587 if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700588 p2p_dbg(p2p, "Provision Discovery Request from unknown peer "
589 MACSTR, MAC2STR(sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800590
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800591 if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800592 0)) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700593 p2p_dbg(p2p, "Provision Discovery Request add device failed "
594 MACSTR, MAC2STR(sa));
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800595 goto out;
596 }
597
598 if (!dev) {
599 dev = p2p_get_device(p2p, sa);
600 if (!dev) {
601 p2p_dbg(p2p,
602 "Provision Discovery device not found "
603 MACSTR, MAC2STR(sa));
604 goto out;
605 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700607 } else if (msg.wfd_subelems) {
608 wpabuf_free(dev->info.wfd_subelems);
609 dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 }
611
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800612 if (!msg.adv_id) {
613 allowed_config_methods |= WPS_CONFIG_PUSHBUTTON;
614 if (!(msg.wps_config_methods & allowed_config_methods)) {
615 p2p_dbg(p2p,
616 "Unsupported Config Methods in Provision Discovery Request");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700617 goto out;
618 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700619
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800620 /* Legacy (non-P2PS) - Unknown groups allowed for P2PS */
621 if (msg.group_id) {
622 size_t i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800623
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800624 for (i = 0; i < p2p->num_groups; i++) {
625 if (p2p_group_is_group_id_match(
626 p2p->groups[i],
627 msg.group_id, msg.group_id_len))
628 break;
629 }
630 if (i == p2p->num_groups) {
631 p2p_dbg(p2p,
632 "PD request for unknown P2P Group ID - reject");
633 goto out;
634 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800635 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800636 } else {
637 allowed_config_methods |= WPS_CONFIG_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800639 /*
640 * Set adv_id here, so in case of an error, a P2PS PD Response
641 * will be sent.
642 */
643 adv_id = WPA_GET_LE32(msg.adv_id);
644 if (p2ps_validate_pd_req(p2p, &msg, sa) < 0) {
645 reject = P2P_SC_FAIL_INVALID_PARAMS;
646 goto out;
647 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800648
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800649 req_fcap = (struct p2ps_feature_capab *) msg.feature_cap;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800650
651 os_memcpy(session_mac, msg.session_mac, ETH_ALEN);
652 os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN);
653
654 session_id = WPA_GET_LE32(msg.session_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800655
656 if (msg.conn_cap)
657 conncap = *msg.conn_cap;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800658
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800659 /*
660 * We need to verify a P2PS config methog in an initial PD
661 * request or in a follow-on PD request with the status
662 * SUCCESS_DEFERRED.
663 */
664 if ((!msg.status || *msg.status == P2P_SC_SUCCESS_DEFERRED) &&
665 !(msg.wps_config_methods & allowed_config_methods)) {
666 p2p_dbg(p2p,
667 "Unsupported Config Methods in Provision Discovery Request");
668 goto out;
669 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800670
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800671 /*
672 * TODO: since we don't support multiple PD, reject PD request
673 * if we are in the middle of P2PS PD with some other peer
674 */
675 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800676
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800677 dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY |
678 P2P_DEV_PD_PEER_KEYPAD |
679 P2P_DEV_PD_PEER_P2PS);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800680
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800681 if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) {
682 p2p_dbg(p2p, "Peer " MACSTR
683 " requested us to show a PIN on display", MAC2STR(sa));
684 dev->flags |= P2P_DEV_PD_PEER_KEYPAD;
685 passwd_id = DEV_PW_USER_SPECIFIED;
686 } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) {
687 p2p_dbg(p2p, "Peer " MACSTR
688 " requested us to write its PIN using keypad",
689 MAC2STR(sa));
690 dev->flags |= P2P_DEV_PD_PEER_DISPLAY;
691 passwd_id = DEV_PW_REGISTRAR_SPECIFIED;
692 } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) {
693 p2p_dbg(p2p, "Peer " MACSTR " requesting P2PS PIN",
694 MAC2STR(sa));
695 dev->flags |= P2P_DEV_PD_PEER_P2PS;
696 passwd_id = DEV_PW_P2PS_DEFAULT;
697 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800698
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800699 /* Remove stale persistent groups */
700 if (p2p->cfg->remove_stale_groups) {
701 p2p->cfg->remove_stale_groups(
702 p2p->cfg->cb_ctx, dev->info.p2p_device_addr,
703 msg.persistent_dev,
704 msg.persistent_ssid, msg.persistent_ssid_len);
705 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800706
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800707 reject = P2P_SC_SUCCESS;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800708
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800709 /*
710 * End of a legacy P2P PD Request processing, from this point continue
711 * with P2PS one.
712 */
713 if (!msg.adv_id)
714 goto out;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800715
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800716 remote_conncap = conncap;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800717
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800718 if (!msg.status) {
719 unsigned int forced_freq, pref_freq;
720
721 if (os_memcmp(p2p->cfg->dev_addr, msg.adv_mac, ETH_ALEN)) {
722 p2p_dbg(p2p,
723 "P2PS PD adv mac does not match the local one");
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800724 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
725 goto out;
726 }
727
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800728 p2ps_adv = p2p_service_p2ps_id(p2p, adv_id);
729 if (!p2ps_adv) {
730 p2p_dbg(p2p, "P2PS PD invalid adv_id=0x%X", adv_id);
731 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
732 goto out;
733 }
734 p2p_dbg(p2p, "adv_id: 0x%X, p2ps_adv: %p", adv_id, p2ps_adv);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800735
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800736 auto_accept = p2ps_adv->auto_accept;
737 conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
738 conncap, auto_accept,
739 &forced_freq,
740 &pref_freq);
741
742 p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d",
743 auto_accept, remote_conncap, conncap);
744
745 p2p_prepare_channel(p2p, dev, forced_freq, pref_freq, 0);
746
747 resp_fcap.cpt = p2ps_own_preferred_cpt(p2ps_adv->cpt_priority,
748 req_fcap->cpt);
749
750 p2p_dbg(p2p, "cpt: service:0x%x remote:0x%x result:0x%x",
751 p2ps_adv->cpt_mask, req_fcap->cpt, resp_fcap.cpt);
752
753 if (!resp_fcap.cpt) {
754 p2p_dbg(p2p,
755 "Incompatible P2PS feature capability CPT bitmask");
756 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
757 } else if (p2ps_adv->config_methods &&
758 !(msg.wps_config_methods &
759 p2ps_adv->config_methods)) {
760 p2p_dbg(p2p,
761 "Unsupported config methods in Provision Discovery Request (own=0x%x peer=0x%x)",
762 p2ps_adv->config_methods,
763 msg.wps_config_methods);
764 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
765 } else if (!p2ps_adv->state) {
766 p2p_dbg(p2p, "P2PS state unavailable");
767 reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
768 } else if (!conncap) {
769 p2p_dbg(p2p, "Conncap resolution failed");
770 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
771 }
772
773 if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) {
774 p2p_dbg(p2p, "Keypad - always defer");
775 auto_accept = 0;
776 }
777
778 if ((remote_conncap & (P2PS_SETUP_NEW | P2PS_SETUP_CLIENT) ||
779 msg.persistent_dev) && conncap != P2PS_SETUP_NEW &&
780 msg.channel_list && msg.channel_list_len &&
781 p2p_peer_channels_check(p2p, &p2p->channels, dev,
782 msg.channel_list,
783 msg.channel_list_len) < 0) {
784 p2p_dbg(p2p,
785 "No common channels - force deferred flow");
786 auto_accept = 0;
787 }
788
789 if (((remote_conncap & P2PS_SETUP_GROUP_OWNER) ||
790 msg.persistent_dev) && msg.operating_channel) {
791 struct p2p_channels intersect;
792
793 /*
794 * There are cases where only the operating channel is
795 * provided. This requires saving the channel as the
796 * supported channel list, and verifying that it is
797 * supported.
798 */
799 if (dev->channels.reg_classes == 0 ||
800 !p2p_channels_includes(&dev->channels,
801 msg.operating_channel[3],
802 msg.operating_channel[4])) {
803 struct p2p_channels *ch = &dev->channels;
804
805 os_memset(ch, 0, sizeof(*ch));
806 ch->reg_class[0].reg_class =
807 msg.operating_channel[3];
808 ch->reg_class[0].channel[0] =
809 msg.operating_channel[4];
810 ch->reg_class[0].channels = 1;
811 ch->reg_classes = 1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800812 }
813
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800814 p2p_channels_intersect(&p2p->channels, &dev->channels,
815 &intersect);
816
817 if (intersect.reg_classes == 0) {
818 p2p_dbg(p2p,
819 "No common channels - force deferred flow");
820 auto_accept = 0;
821 }
822 }
823
824 if (auto_accept || reject != P2P_SC_SUCCESS) {
825 struct p2ps_provision *tmp;
826
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800827 if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id,
828 msg.wps_config_methods,
829 session_mac, adv_mac) < 0) {
830 reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
831 goto out;
832 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800833
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800834 tmp = p2p->p2ps_prov;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800835 tmp->force_freq = forced_freq;
836 tmp->pref_freq = pref_freq;
837 if (conncap) {
838 tmp->conncap = conncap;
839 tmp->status = P2P_SC_SUCCESS;
840 } else {
841 tmp->conncap = auto_accept;
842 tmp->status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800843 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800844
845 if (reject != P2P_SC_SUCCESS)
846 goto out;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800847 }
848 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800850 if (!msg.status && !auto_accept &&
851 (!p2p->p2ps_prov || p2p->p2ps_prov->adv_id != adv_id)) {
852 struct p2ps_provision *tmp;
853
854 if (!conncap) {
855 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
856 goto out;
857 }
858
859 if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id,
860 msg.wps_config_methods,
861 session_mac, adv_mac) < 0) {
862 reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
863 goto out;
864 }
865 tmp = p2p->p2ps_prov;
866 reject = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
867 tmp->status = reject;
868 }
869
870 /* Not a P2PS Follow-on PD */
871 if (!msg.status)
872 goto out;
873
874 if (*msg.status && *msg.status != P2P_SC_SUCCESS_DEFERRED) {
875 reject = *msg.status;
876 goto out;
877 }
878
879 if (*msg.status != P2P_SC_SUCCESS_DEFERRED || !p2p->p2ps_prov)
880 goto out;
881
882 if (p2p->p2ps_prov->adv_id != adv_id ||
883 os_memcmp(p2p->p2ps_prov->adv_mac, msg.adv_mac, ETH_ALEN)) {
884 p2p_dbg(p2p,
885 "P2PS Follow-on PD with mismatch Advertisement ID/MAC");
886 goto out;
887 }
888
889 if (p2p->p2ps_prov->session_id != session_id ||
890 os_memcmp(p2p->p2ps_prov->session_mac, msg.session_mac, ETH_ALEN)) {
891 p2p_dbg(p2p, "P2PS Follow-on PD with mismatch Session ID/MAC");
892 goto out;
893 }
894
895 method = p2p->p2ps_prov->method;
896
897 conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
898 remote_conncap,
899 p2p->p2ps_prov->conncap,
900 &p2p->p2ps_prov->force_freq,
901 &p2p->p2ps_prov->pref_freq);
902
903 resp_fcap.cpt = p2ps_own_preferred_cpt(p2p->p2ps_prov->cpt_priority,
904 req_fcap->cpt);
905
906 p2p_dbg(p2p, "cpt: local:0x%x remote:0x%x result:0x%x",
907 p2p->p2ps_prov->cpt_mask, req_fcap->cpt, resp_fcap.cpt);
908
909 p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq,
910 p2p->p2ps_prov->pref_freq, 0);
911
912 /*
913 * Ensure that if we asked for PIN originally, our method is consistent
914 * with original request.
915 */
916 if (method & WPS_CONFIG_DISPLAY)
917 method = WPS_CONFIG_KEYPAD;
918 else if (method & WPS_CONFIG_KEYPAD)
919 method = WPS_CONFIG_DISPLAY;
920
921 if (!conncap || !(msg.wps_config_methods & method)) {
922 /*
923 * Reject this "Deferred Accept*
924 * if incompatible conncap or method
925 */
926 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
927 } else if (!resp_fcap.cpt) {
928 p2p_dbg(p2p,
929 "Incompatible P2PS feature capability CPT bitmask");
930 reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
931 } else if ((remote_conncap & (P2PS_SETUP_NEW | P2PS_SETUP_CLIENT) ||
932 msg.persistent_dev) && conncap != P2PS_SETUP_NEW &&
933 msg.channel_list && msg.channel_list_len &&
934 p2p_peer_channels_check(p2p, &p2p->channels, dev,
935 msg.channel_list,
936 msg.channel_list_len) < 0) {
937 p2p_dbg(p2p,
938 "No common channels in Follow-On Provision Discovery Request");
939 reject = P2P_SC_FAIL_NO_COMMON_CHANNELS;
940 } else {
941 reject = P2P_SC_SUCCESS;
942 }
943
944 dev->oper_freq = 0;
945 if (reject == P2P_SC_SUCCESS || reject == P2P_SC_SUCCESS_DEFERRED) {
946 u8 tmp;
947
948 if (msg.operating_channel)
949 dev->oper_freq =
950 p2p_channel_to_freq(msg.operating_channel[3],
951 msg.operating_channel[4]);
952
953 if ((conncap & P2PS_SETUP_GROUP_OWNER) &&
954 p2p_go_select_channel(p2p, dev, &tmp) < 0)
955 reject = P2P_SC_FAIL_NO_COMMON_CHANNELS;
956 }
957
958 p2p->p2ps_prov->status = reject;
959 p2p->p2ps_prov->conncap = conncap;
960
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961out:
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800962 if (reject == P2P_SC_SUCCESS ||
963 reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
964 config_methods = msg.wps_config_methods;
965 else
966 config_methods = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800968 /*
969 * Send PD Response for an initial PD Request or for follow-on
970 * PD Request with P2P_SC_SUCCESS_DEFERRED status.
971 */
972 if (!msg.status || *msg.status == P2P_SC_SUCCESS_DEFERRED) {
973 resp = p2p_build_prov_disc_resp(p2p, dev, msg.dialog_token,
974 reject, config_methods, adv_id,
975 msg.group_id, msg.group_id_len,
976 msg.persistent_ssid,
977 msg.persistent_ssid_len,
978 (const u8 *) &resp_fcap,
979 sizeof(resp_fcap));
980 if (!resp) {
981 p2p_parse_free(&msg);
982 return;
983 }
984 p2p_dbg(p2p, "Sending Provision Discovery Response");
985 if (rx_freq > 0)
986 freq = rx_freq;
987 else
988 freq = p2p_channel_to_freq(p2p->cfg->reg_class,
989 p2p->cfg->channel);
990 if (freq < 0) {
991 p2p_dbg(p2p, "Unknown regulatory class/channel");
992 wpabuf_free(resp);
993 p2p_parse_free(&msg);
994 return;
995 }
996 p2p->pending_action_state = P2P_PENDING_PD_RESPONSE;
997 if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
998 p2p->cfg->dev_addr,
999 wpabuf_head(resp), wpabuf_len(resp),
1000 200) < 0)
1001 p2p_dbg(p2p, "Failed to send Action frame");
1002 else
1003 p2p->send_action_in_progress = 1;
1004
1005 wpabuf_free(resp);
1006 }
1007
1008 if (!dev) {
1009 p2p_parse_free(&msg);
1010 return;
1011 }
1012
1013 freq = 0;
1014 if (reject == P2P_SC_SUCCESS && conncap == P2PS_SETUP_GROUP_OWNER) {
1015 freq = p2p_channel_to_freq(p2p->op_reg_class,
1016 p2p->op_channel);
1017 if (freq < 0)
1018 freq = 0;
1019 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001021 if (!p2p->cfg->p2ps_prov_complete) {
1022 /* Don't emit anything */
1023 } else if (msg.status && *msg.status != P2P_SC_SUCCESS &&
1024 *msg.status != P2P_SC_SUCCESS_DEFERRED) {
1025 reject = *msg.status;
1026 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject,
1027 sa, adv_mac, session_mac,
1028 NULL, adv_id, session_id,
1029 0, 0, msg.persistent_ssid,
1030 msg.persistent_ssid_len,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001031 0, 0, NULL, NULL, 0, freq,
1032 NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001033 } else if (msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED &&
1034 p2p->p2ps_prov) {
1035 p2p->p2ps_prov->status = reject;
1036 p2p->p2ps_prov->conncap = conncap;
1037
1038 if (reject != P2P_SC_SUCCESS)
1039 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject,
1040 sa, adv_mac, session_mac,
1041 NULL, adv_id,
1042 session_id, conncap, 0,
1043 msg.persistent_ssid,
1044 msg.persistent_ssid_len, 0,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001045 0, NULL, NULL, 0, freq,
1046 NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001047 else
1048 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx,
1049 *msg.status,
1050 sa, adv_mac, session_mac,
1051 group_mac, adv_id,
1052 session_id, conncap,
1053 passwd_id,
1054 msg.persistent_ssid,
1055 msg.persistent_ssid_len, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001056 0, NULL,
1057 (const u8 *) &resp_fcap,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001058 sizeof(resp_fcap), freq,
1059 NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001060 } else if (msg.status && p2p->p2ps_prov) {
1061 p2p->p2ps_prov->status = P2P_SC_SUCCESS;
1062 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa,
1063 adv_mac, session_mac, group_mac,
1064 adv_id, session_id, conncap,
1065 passwd_id,
1066 msg.persistent_ssid,
1067 msg.persistent_ssid_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001068 0, 0, NULL,
1069 (const u8 *) &resp_fcap,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001070 sizeof(resp_fcap), freq, NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001071 } else if (msg.status) {
1072 } else if (auto_accept && reject == P2P_SC_SUCCESS) {
1073 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS,
1074 sa, adv_mac, session_mac,
1075 group_mac, adv_id, session_id,
1076 conncap, passwd_id,
1077 msg.persistent_ssid,
1078 msg.persistent_ssid_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001079 0, 0, NULL,
1080 (const u8 *) &resp_fcap,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001081 sizeof(resp_fcap), freq,
1082 msg.group_id ?
1083 msg.group_id + ETH_ALEN : NULL,
1084 msg.group_id ?
1085 msg.group_id_len - ETH_ALEN : 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001086 } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE &&
1087 (!msg.session_info || !msg.session_info_len)) {
1088 p2p->p2ps_prov->method = msg.wps_config_methods;
1089
1090 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS,
1091 sa, adv_mac, session_mac,
1092 group_mac, adv_id, session_id,
1093 conncap, passwd_id,
1094 msg.persistent_ssid,
1095 msg.persistent_ssid_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001096 0, 1, NULL,
1097 (const u8 *) &resp_fcap,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001098 sizeof(resp_fcap), freq, NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001099 } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
1100 size_t buf_len = msg.session_info_len;
1101 char *buf = os_malloc(2 * buf_len + 1);
1102
1103 if (buf) {
1104 p2p->p2ps_prov->method = msg.wps_config_methods;
1105
1106 utf8_escape((char *) msg.session_info, buf_len,
1107 buf, 2 * buf_len + 1);
1108
1109 p2p->cfg->p2ps_prov_complete(
1110 p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa,
1111 adv_mac, session_mac, group_mac, adv_id,
1112 session_id, conncap, passwd_id,
1113 msg.persistent_ssid, msg.persistent_ssid_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001114 0, 1, buf,
1115 (const u8 *) &resp_fcap, sizeof(resp_fcap),
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001116 freq, NULL, 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001117
1118 os_free(buf);
1119 }
1120 }
1121
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001122 /*
1123 * prov_disc_req callback is used to generate P2P-PROV-DISC-ENTER-PIN,
1124 * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events.
1125 * Call it either on legacy P2P PD or on P2PS PD only if we need to
1126 * enter/show PIN.
1127 *
1128 * The callback is called in the following cases:
1129 * 1. Legacy P2P PD request, response status SUCCESS
1130 * 2. P2PS advertiser, method: DISPLAY, autoaccept: TRUE,
1131 * response status: SUCCESS
1132 * 3. P2PS advertiser, method DISPLAY, autoaccept: FALSE,
1133 * response status: INFO_CURRENTLY_UNAVAILABLE
1134 * 4. P2PS advertiser, method: KEYPAD, autoaccept==any,
1135 * response status: INFO_CURRENTLY_UNAVAILABLE
1136 * 5. P2PS follow-on with SUCCESS_DEFERRED,
1137 * advertiser role: DISPLAY, autoaccept: FALSE,
1138 * seeker: KEYPAD, response status: SUCCESS
1139 */
1140 if (p2p->cfg->prov_disc_req &&
1141 ((reject == P2P_SC_SUCCESS && !msg.adv_id) ||
1142 (!msg.status &&
1143 (reject == P2P_SC_SUCCESS ||
1144 reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) &&
1145 passwd_id == DEV_PW_USER_SPECIFIED) ||
1146 (!msg.status &&
1147 reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE &&
1148 passwd_id == DEV_PW_REGISTRAR_SPECIFIED) ||
1149 (reject == P2P_SC_SUCCESS &&
1150 msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED &&
1151 passwd_id == DEV_PW_REGISTRAR_SPECIFIED))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 const u8 *dev_addr = sa;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154 if (msg.p2p_device_addr)
1155 dev_addr = msg.p2p_device_addr;
1156 p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa,
1157 msg.wps_config_methods,
1158 dev_addr, msg.pri_dev_type,
1159 msg.device_name, msg.config_methods,
1160 msg.capability ? msg.capability[0] : 0,
1161 msg.capability ? msg.capability[1] :
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001162 0,
1163 msg.group_id, msg.group_id_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001165
1166 if (reject == P2P_SC_SUCCESS) {
1167 switch (config_methods) {
1168 case WPS_CONFIG_DISPLAY:
1169 dev->wps_prov_info = WPS_CONFIG_KEYPAD;
1170 break;
1171 case WPS_CONFIG_KEYPAD:
1172 dev->wps_prov_info = WPS_CONFIG_DISPLAY;
1173 break;
1174 case WPS_CONFIG_PUSHBUTTON:
1175 dev->wps_prov_info = WPS_CONFIG_PUSHBUTTON;
1176 break;
1177 case WPS_CONFIG_P2PS:
1178 dev->wps_prov_info = WPS_CONFIG_P2PS;
1179 break;
1180 default:
1181 dev->wps_prov_info = 0;
1182 break;
1183 }
1184
1185 if (msg.intended_addr)
1186 os_memcpy(dev->interface_addr, msg.intended_addr,
1187 ETH_ALEN);
1188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 p2p_parse_free(&msg);
1190}
1191
1192
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001193static int p2p_validate_p2ps_pd_resp(struct p2p_data *p2p,
1194 struct p2p_message *msg)
1195{
1196 u8 conn_cap_go = 0;
1197 u8 conn_cap_cli = 0;
1198 u32 session_id;
1199 u32 adv_id;
1200
1201#define P2PS_PD_RESP_CHECK(_val, _attr) \
1202 do { \
1203 if ((_val) && !msg->_attr) { \
1204 p2p_dbg(p2p, "P2PS PD Response missing " #_attr); \
1205 return -1; \
1206 } \
1207 } while (0)
1208
1209 P2PS_PD_RESP_CHECK(1, status);
1210 P2PS_PD_RESP_CHECK(1, adv_id);
1211 P2PS_PD_RESP_CHECK(1, adv_mac);
1212 P2PS_PD_RESP_CHECK(1, capability);
1213 P2PS_PD_RESP_CHECK(1, p2p_device_info);
1214 P2PS_PD_RESP_CHECK(1, session_id);
1215 P2PS_PD_RESP_CHECK(1, session_mac);
1216 P2PS_PD_RESP_CHECK(1, feature_cap);
1217
1218 session_id = WPA_GET_LE32(msg->session_id);
1219 adv_id = WPA_GET_LE32(msg->adv_id);
1220
1221 if (p2p->p2ps_prov->session_id != session_id) {
1222 p2p_dbg(p2p,
1223 "Ignore PD Response with unexpected Session ID");
1224 return -1;
1225 }
1226
1227 if (os_memcmp(p2p->p2ps_prov->session_mac, msg->session_mac,
1228 ETH_ALEN)) {
1229 p2p_dbg(p2p,
1230 "Ignore PD Response with unexpected Session MAC");
1231 return -1;
1232 }
1233
1234 if (p2p->p2ps_prov->adv_id != adv_id) {
1235 p2p_dbg(p2p,
1236 "Ignore PD Response with unexpected Advertisement ID");
1237 return -1;
1238 }
1239
1240 if (os_memcmp(p2p->p2ps_prov->adv_mac, msg->adv_mac, ETH_ALEN) != 0) {
1241 p2p_dbg(p2p,
1242 "Ignore PD Response with unexpected Advertisement MAC");
1243 return -1;
1244 }
1245
1246 if (msg->listen_channel) {
1247 p2p_dbg(p2p,
1248 "Ignore malformed PD Response - unexpected Listen Channel");
1249 return -1;
1250 }
1251
1252 if (*msg->status == P2P_SC_SUCCESS &&
1253 !(!!msg->conn_cap ^ !!msg->persistent_dev)) {
1254 p2p_dbg(p2p,
1255 "Ignore malformed PD Response - either conn_cap or persistent group should be present");
1256 return -1;
1257 }
1258
1259 if (msg->persistent_dev && *msg->status != P2P_SC_SUCCESS) {
1260 p2p_dbg(p2p,
1261 "Ignore malformed PD Response - persistent group is present, but the status isn't success");
1262 return -1;
1263 }
1264
1265 if (msg->conn_cap) {
1266 conn_cap_go = *msg->conn_cap == P2PS_SETUP_GROUP_OWNER;
1267 conn_cap_cli = *msg->conn_cap == P2PS_SETUP_CLIENT;
1268 }
1269
1270 P2PS_PD_RESP_CHECK(msg->persistent_dev || conn_cap_go || conn_cap_cli,
1271 channel_list);
1272 P2PS_PD_RESP_CHECK(msg->persistent_dev || conn_cap_go || conn_cap_cli,
1273 config_timeout);
1274
1275 P2PS_PD_RESP_CHECK(conn_cap_go, group_id);
1276 P2PS_PD_RESP_CHECK(conn_cap_go, intended_addr);
1277 P2PS_PD_RESP_CHECK(conn_cap_go, operating_channel);
1278 /*
1279 * TODO: Also validate that operating channel is present if the device
1280 * is a GO in a persistent group. We can't do it here since we don't
1281 * know what is the role of the peer. It should be probably done in
1282 * p2ps_prov_complete callback, but currently operating channel isn't
1283 * passed to it.
1284 */
1285
1286#undef P2PS_PD_RESP_CHECK
1287
1288 return 0;
1289}
1290
1291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
1293 const u8 *data, size_t len)
1294{
1295 struct p2p_message msg;
1296 struct p2p_device *dev;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001297 u16 report_config_methods = 0, req_config_methods;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001298 u8 status = P2P_SC_SUCCESS;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001299 u32 adv_id = 0;
1300 u8 conncap = P2PS_SETUP_NEW;
1301 u8 adv_mac[ETH_ALEN];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001302 const u8 *group_mac;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001303 int passwd_id = DEV_PW_DEFAULT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001304 int p2ps_seeker;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001305
1306 if (p2p_parse(data, len, &msg))
1307 return;
1308
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001309 if (p2p->p2ps_prov && p2p_validate_p2ps_pd_resp(p2p, &msg)) {
1310 p2p_parse_free(&msg);
1311 return;
1312 }
1313
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001314 /* Parse the P2PS members present */
1315 if (msg.status)
1316 status = *msg.status;
1317
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001318 group_mac = msg.intended_addr;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001319
1320 if (msg.adv_mac)
1321 os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN);
1322 else
1323 os_memset(adv_mac, 0, ETH_ALEN);
1324
1325 if (msg.adv_id)
1326 adv_id = WPA_GET_LE32(msg.adv_id);
1327
1328 if (msg.conn_cap) {
1329 conncap = *msg.conn_cap;
1330
1331 /* Switch bits to local relative */
1332 switch (conncap) {
1333 case P2PS_SETUP_GROUP_OWNER:
1334 conncap = P2PS_SETUP_CLIENT;
1335 break;
1336 case P2PS_SETUP_CLIENT:
1337 conncap = P2PS_SETUP_GROUP_OWNER;
1338 break;
1339 }
1340 }
1341
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001342 p2p_dbg(p2p, "Received Provision Discovery Response from " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343 " with config methods 0x%x",
1344 MAC2STR(sa), msg.wps_config_methods);
1345
1346 dev = p2p_get_device(p2p, sa);
1347 if (dev == NULL || !dev->req_config_methods) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001348 p2p_dbg(p2p, "Ignore Provision Discovery Response from " MACSTR
1349 " with no pending request", MAC2STR(sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 p2p_parse_free(&msg);
1351 return;
1352 }
1353
1354 if (dev->dialog_token != msg.dialog_token) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001355 p2p_dbg(p2p, "Ignore Provision Discovery Response with unexpected Dialog Token %u (expected %u)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 msg.dialog_token, dev->dialog_token);
1357 p2p_parse_free(&msg);
1358 return;
1359 }
1360
Dmitry Shmidt91c40cd2012-09-25 14:23:53 -07001361 if (p2p->pending_action_state == P2P_PENDING_PD) {
1362 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
1363 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1364 }
1365
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001366 p2ps_seeker = p2p->p2ps_prov && p2p->p2ps_prov->pd_seeker;
1367
Jouni Malinen75ecf522011-06-27 15:19:46 -07001368 /*
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001369 * Use a local copy of the requested config methods since
1370 * p2p_reset_pending_pd() can clear this in the peer entry.
1371 */
1372 req_config_methods = dev->req_config_methods;
1373
1374 /*
Jouni Malinen75ecf522011-06-27 15:19:46 -07001375 * If the response is from the peer to whom a user initiated request
1376 * was sent earlier, we reset that state info here.
1377 */
1378 if (p2p->user_initiated_pd &&
1379 os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0)
1380 p2p_reset_pending_pd(p2p);
1381
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001382 if (msg.wps_config_methods != req_config_methods) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001383 p2p_dbg(p2p, "Peer rejected our Provision Discovery Request (received config_methods 0x%x expected 0x%x",
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001384 msg.wps_config_methods, req_config_methods);
Jouni Malinen75ecf522011-06-27 15:19:46 -07001385 if (p2p->cfg->prov_disc_fail)
1386 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001387 P2P_PROV_DISC_REJECTED,
1388 adv_id, adv_mac, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389 p2p_parse_free(&msg);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001390 p2ps_prov_free(p2p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001391 goto out;
1392 }
1393
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001394 report_config_methods = req_config_methods;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001395 dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY |
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001396 P2P_DEV_PD_PEER_KEYPAD |
1397 P2P_DEV_PD_PEER_P2PS);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001398 if (req_config_methods & WPS_CONFIG_DISPLAY) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001399 p2p_dbg(p2p, "Peer " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001400 " accepted to show a PIN on display", MAC2STR(sa));
1401 dev->flags |= P2P_DEV_PD_PEER_DISPLAY;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001402 passwd_id = DEV_PW_REGISTRAR_SPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403 } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001404 p2p_dbg(p2p, "Peer " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 " accepted to write our PIN using keypad",
1406 MAC2STR(sa));
1407 dev->flags |= P2P_DEV_PD_PEER_KEYPAD;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001408 passwd_id = DEV_PW_USER_SPECIFIED;
1409 } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) {
1410 p2p_dbg(p2p, "Peer " MACSTR " accepted P2PS PIN",
1411 MAC2STR(sa));
1412 dev->flags |= P2P_DEV_PD_PEER_P2PS;
1413 passwd_id = DEV_PW_P2PS_DEFAULT;
1414 }
1415
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001416 if ((status == P2P_SC_SUCCESS || status == P2P_SC_SUCCESS_DEFERRED) &&
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001417 p2p->p2ps_prov) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001418 dev->oper_freq = 0;
1419
1420 /*
1421 * Save the reported channel list and operating frequency.
1422 * Note that the specification mandates that the responder
1423 * should include in the channel list only channels reported by
1424 * the initiator, so this is only a sanity check, and if this
1425 * fails the flow would continue, although it would probably
1426 * fail. Same is true for the operating channel.
1427 */
1428 if (msg.channel_list && msg.channel_list_len &&
1429 p2p_peer_channels_check(p2p, &p2p->channels, dev,
1430 msg.channel_list,
1431 msg.channel_list_len) < 0)
1432 p2p_dbg(p2p, "P2PS PD Response - no common channels");
1433
1434 if (msg.operating_channel) {
1435 if (p2p_channels_includes(&p2p->channels,
1436 msg.operating_channel[3],
1437 msg.operating_channel[4]) &&
1438 p2p_channels_includes(&dev->channels,
1439 msg.operating_channel[3],
1440 msg.operating_channel[4])) {
1441 dev->oper_freq =
1442 p2p_channel_to_freq(
1443 msg.operating_channel[3],
1444 msg.operating_channel[4]);
1445 } else {
1446 p2p_dbg(p2p,
1447 "P2PS PD Response - invalid operating channel");
1448 }
1449 }
1450
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001451 if (p2p->cfg->p2ps_prov_complete) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001452 int freq = 0;
1453
1454 if (conncap == P2PS_SETUP_GROUP_OWNER) {
1455 u8 tmp;
1456
1457 /*
1458 * Re-select the operating channel as it is
1459 * possible that original channel is no longer
1460 * valid. This should not really fail.
1461 */
1462 if (p2p_go_select_channel(p2p, dev, &tmp) < 0)
1463 p2p_dbg(p2p,
1464 "P2PS PD channel selection failed");
1465
1466 freq = p2p_channel_to_freq(p2p->op_reg_class,
1467 p2p->op_channel);
1468 if (freq < 0)
1469 freq = 0;
1470 }
1471
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001472 p2p->cfg->p2ps_prov_complete(
1473 p2p->cfg->cb_ctx, status, sa, adv_mac,
1474 p2p->p2ps_prov->session_mac,
1475 group_mac, adv_id, p2p->p2ps_prov->session_id,
1476 conncap, passwd_id, msg.persistent_ssid,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001477 msg.persistent_ssid_len, 1, 0, NULL,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001478 msg.feature_cap, msg.feature_cap_len, freq,
1479 msg.group_id ? msg.group_id + ETH_ALEN : NULL,
1480 msg.group_id ? msg.group_id_len - ETH_ALEN : 0);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001481 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001482 p2ps_prov_free(p2p);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001483 } else if (status != P2P_SC_SUCCESS &&
1484 status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE &&
1485 status != P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001486 if (p2p->cfg->p2ps_prov_complete)
1487 p2p->cfg->p2ps_prov_complete(
1488 p2p->cfg->cb_ctx, status, sa, adv_mac,
1489 p2p->p2ps_prov->session_mac,
1490 group_mac, adv_id, p2p->p2ps_prov->session_id,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001491 0, 0, NULL, 0, 1, 0, NULL, NULL, 0, 0, NULL, 0);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001492 p2ps_prov_free(p2p);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001493 }
1494
1495 if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
1496 if (p2p->cfg->remove_stale_groups) {
1497 p2p->cfg->remove_stale_groups(p2p->cfg->cb_ctx,
1498 dev->info.p2p_device_addr,
1499 NULL, NULL, 0);
1500 }
1501
1502 if (msg.session_info && msg.session_info_len) {
1503 size_t info_len = msg.session_info_len;
1504 char *deferred_sess_resp = os_malloc(2 * info_len + 1);
1505
1506 if (!deferred_sess_resp) {
1507 p2p_parse_free(&msg);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001508 p2ps_prov_free(p2p);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001509 goto out;
1510 }
1511 utf8_escape((char *) msg.session_info, info_len,
1512 deferred_sess_resp, 2 * info_len + 1);
1513
1514 if (p2p->cfg->prov_disc_fail)
1515 p2p->cfg->prov_disc_fail(
1516 p2p->cfg->cb_ctx, sa,
1517 P2P_PROV_DISC_INFO_UNAVAILABLE,
1518 adv_id, adv_mac,
1519 deferred_sess_resp);
1520 os_free(deferred_sess_resp);
1521 } else
1522 if (p2p->cfg->prov_disc_fail)
1523 p2p->cfg->prov_disc_fail(
1524 p2p->cfg->cb_ctx, sa,
1525 P2P_PROV_DISC_INFO_UNAVAILABLE,
1526 adv_id, adv_mac, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001527 } else if (status != P2P_SC_SUCCESS) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001528 p2p_dbg(p2p, "Peer rejected our Provision Discovery Request");
1529 if (p2p->cfg->prov_disc_fail)
1530 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001531 P2P_PROV_DISC_REJECTED,
1532 adv_id, adv_mac, NULL);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001533 p2p_parse_free(&msg);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001534 p2ps_prov_free(p2p);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001535 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001537
1538 /* Store the provisioning info */
1539 dev->wps_prov_info = msg.wps_config_methods;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001540 if (msg.intended_addr)
1541 os_memcpy(dev->interface_addr, msg.intended_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001543 p2p_parse_free(&msg);
1544
1545out:
1546 dev->req_config_methods = 0;
1547 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001548 if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001549 p2p_dbg(p2p, "Start GO Neg after the PD-before-GO-Neg workaround with "
1550 MACSTR, MAC2STR(dev->info.p2p_device_addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -07001551 dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG;
1552 p2p_connect_send(p2p, dev);
1553 return;
1554 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001555
1556 /*
1557 * prov_disc_resp callback is used to generate P2P-PROV-DISC-ENTER-PIN,
1558 * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events.
1559 * Call it only for a legacy P2P PD or for P2PS PD scenarios where
1560 * show/enter PIN events are needed.
1561 *
1562 * The callback is called in the following cases:
1563 * 1. Legacy P2P PD response with a status SUCCESS
1564 * 2. P2PS, advertiser method: DISPLAY, autoaccept: true,
1565 * response status: SUCCESS, local method KEYPAD
1566 * 3. P2PS, advertiser method: KEYPAD,Seeker side,
1567 * response status: INFO_CURRENTLY_UNAVAILABLE,
1568 * local method: DISPLAY
1569 */
1570 if (p2p->cfg->prov_disc_resp &&
1571 ((status == P2P_SC_SUCCESS && !adv_id) ||
1572 (p2ps_seeker && status == P2P_SC_SUCCESS &&
1573 passwd_id == DEV_PW_REGISTRAR_SPECIFIED) ||
1574 (p2ps_seeker &&
1575 status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE &&
1576 passwd_id == DEV_PW_USER_SPECIFIED)))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001577 p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa,
1578 report_config_methods);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001579
1580 if (p2p->state == P2P_PD_DURING_FIND) {
1581 p2p_clear_timeout(p2p);
1582 p2p_continue_find(p2p);
1583 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001584}
1585
1586
1587int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001588 int join, int force_freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589{
1590 struct wpabuf *req;
1591 int freq;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07001592
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001593 if (force_freq > 0)
1594 freq = force_freq;
1595 else
1596 freq = dev->listen_freq > 0 ? dev->listen_freq :
1597 dev->oper_freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001598 if (freq <= 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001599 p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
1600 MACSTR " to send Provision Discovery Request",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 MAC2STR(dev->info.p2p_device_addr));
1602 return -1;
1603 }
1604
1605 if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
1606 if (!(dev->info.dev_capab &
1607 P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001608 p2p_dbg(p2p, "Cannot use PD with P2P Device " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001609 " that is in a group and is not discoverable",
1610 MAC2STR(dev->info.p2p_device_addr));
1611 return -1;
1612 }
1613 /* TODO: use device discoverability request through GO */
1614 }
1615
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001616 if (p2p->p2ps_prov) {
1617 if (p2p->p2ps_prov->status == P2P_SC_SUCCESS_DEFERRED) {
1618 if (p2p->p2ps_prov->method == WPS_CONFIG_DISPLAY)
1619 dev->req_config_methods = WPS_CONFIG_KEYPAD;
1620 else if (p2p->p2ps_prov->method == WPS_CONFIG_KEYPAD)
1621 dev->req_config_methods = WPS_CONFIG_DISPLAY;
1622 else
1623 dev->req_config_methods = WPS_CONFIG_P2PS;
1624 } else {
1625 /* Order of preference, based on peer's capabilities */
1626 if (p2p->p2ps_prov->method)
1627 dev->req_config_methods =
1628 p2p->p2ps_prov->method;
1629 else if (dev->info.config_methods & WPS_CONFIG_P2PS)
1630 dev->req_config_methods = WPS_CONFIG_P2PS;
1631 else if (dev->info.config_methods & WPS_CONFIG_DISPLAY)
1632 dev->req_config_methods = WPS_CONFIG_DISPLAY;
1633 else
1634 dev->req_config_methods = WPS_CONFIG_KEYPAD;
1635 }
1636 p2p_dbg(p2p,
1637 "Building PD Request based on P2PS config method 0x%x status %d --> req_config_methods 0x%x",
1638 p2p->p2ps_prov->method, p2p->p2ps_prov->status,
1639 dev->req_config_methods);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001640
1641 if (p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq,
1642 p2p->p2ps_prov->pref_freq, 1) < 0)
1643 return -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001644 }
1645
1646 req = p2p_build_prov_disc_req(p2p, dev, join);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 if (req == NULL)
1648 return -1;
1649
Dmitry Shmidt04949592012-07-19 12:16:46 -07001650 if (p2p->state != P2P_IDLE)
1651 p2p_stop_listen_for_freq(p2p, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 p2p->pending_action_state = P2P_PENDING_PD;
1653 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
1654 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
1655 wpabuf_head(req), wpabuf_len(req), 200) < 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001656 p2p_dbg(p2p, "Failed to send Action frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001657 wpabuf_free(req);
1658 return -1;
1659 }
1660
Jouni Malinen75ecf522011-06-27 15:19:46 -07001661 os_memcpy(p2p->pending_pd_devaddr, dev->info.p2p_device_addr, ETH_ALEN);
1662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 wpabuf_free(req);
1664 return 0;
1665}
1666
1667
1668int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001669 struct p2ps_provision *p2ps_prov,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001670 u16 config_methods, int join, int force_freq,
1671 int user_initiated_pd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672{
1673 struct p2p_device *dev;
1674
1675 dev = p2p_get_device(p2p, peer_addr);
1676 if (dev == NULL)
1677 dev = p2p_get_device_interface(p2p, peer_addr);
1678 if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001679 p2p_dbg(p2p, "Provision Discovery Request destination " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 " not yet known", MAC2STR(peer_addr));
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001681 os_free(p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001682 return -1;
1683 }
1684
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001685 p2p_dbg(p2p, "Provision Discovery Request with " MACSTR
1686 " (config methods 0x%x)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001687 MAC2STR(peer_addr), config_methods);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001688 if (config_methods == 0 && !p2ps_prov) {
1689 os_free(p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 return -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001691 }
1692
1693 if (p2ps_prov && p2ps_prov->status == P2P_SC_SUCCESS_DEFERRED &&
1694 p2p->p2ps_prov) {
1695 /* Use cached method from deferred provisioning */
1696 p2ps_prov->method = p2p->p2ps_prov->method;
1697 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001698
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001699 /* Reset provisioning info */
1700 dev->wps_prov_info = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001701 p2ps_prov_free(p2p);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001702 p2p->p2ps_prov = p2ps_prov;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001704 dev->req_config_methods = config_methods;
1705 if (join)
1706 dev->flags |= P2P_DEV_PD_FOR_JOIN;
1707 else
1708 dev->flags &= ~P2P_DEV_PD_FOR_JOIN;
1709
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001710 if (p2p->state != P2P_IDLE && p2p->state != P2P_SEARCH &&
1711 p2p->state != P2P_LISTEN_ONLY) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001712 p2p_dbg(p2p, "Busy with other operations; postpone Provision Discovery Request with "
1713 MACSTR " (config methods 0x%x)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714 MAC2STR(peer_addr), config_methods);
1715 return 0;
1716 }
1717
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001718 p2p->user_initiated_pd = user_initiated_pd;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001719 p2p->pd_force_freq = force_freq;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001720
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001721 if (p2p->user_initiated_pd)
Jouni Malinen75ecf522011-06-27 15:19:46 -07001722 p2p->pd_retries = MAX_PROV_DISC_REQ_RETRIES;
1723
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001724 /*
1725 * Assign dialog token here to use the same value in each retry within
1726 * the same PD exchange.
1727 */
1728 dev->dialog_token++;
1729 if (dev->dialog_token == 0)
1730 dev->dialog_token = 1;
1731
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001732 return p2p_send_prov_disc_req(p2p, dev, join, force_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733}
Jouni Malinen75ecf522011-06-27 15:19:46 -07001734
1735
1736void p2p_reset_pending_pd(struct p2p_data *p2p)
1737{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001738 struct p2p_device *dev;
1739
1740 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) {
1741 if (os_memcmp(p2p->pending_pd_devaddr,
1742 dev->info.p2p_device_addr, ETH_ALEN))
1743 continue;
1744 if (!dev->req_config_methods)
1745 continue;
1746 if (dev->flags & P2P_DEV_PD_FOR_JOIN)
1747 continue;
1748 /* Reset the config methods of the device */
1749 dev->req_config_methods = 0;
1750 }
1751
Jouni Malinen75ecf522011-06-27 15:19:46 -07001752 p2p->user_initiated_pd = 0;
1753 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
1754 p2p->pd_retries = 0;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001755 p2p->pd_force_freq = 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001756}
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001757
1758
1759void p2ps_prov_free(struct p2p_data *p2p)
1760{
1761 os_free(p2p->p2ps_prov);
1762 p2p->p2ps_prov = NULL;
1763}