blob: 3bbce164514c46fba7c9ac2aa2e8be15a076a83a [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"
13#include "wps/wps_defs.h"
14#include "p2p_i.h"
15#include "p2p.h"
16
17
Jouni Malinen75ecf522011-06-27 15:19:46 -070018/*
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070019 * Number of retries to attempt for provision discovery requests
20 * in case the peer is not listening.
Jouni Malinen75ecf522011-06-27 15:19:46 -070021 */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080022#define MAX_PROV_DISC_REQ_RETRIES 120
Jouni Malinen75ecf522011-06-27 15:19:46 -070023
24
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025static void p2p_build_wps_ie_config_methods(struct wpabuf *buf,
26 u16 config_methods)
27{
28 u8 *len;
29 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
30 len = wpabuf_put(buf, 1);
31 wpabuf_put_be32(buf, WPS_DEV_OUI_WFA);
32
33 /* Config Methods */
34 wpabuf_put_be16(buf, ATTR_CONFIG_METHODS);
35 wpabuf_put_be16(buf, 2);
36 wpabuf_put_be16(buf, config_methods);
37
38 p2p_buf_update_ie_hdr(buf, len);
39}
40
41
42static struct wpabuf * p2p_build_prov_disc_req(struct p2p_data *p2p,
43 u8 dialog_token,
44 u16 config_methods,
45 struct p2p_device *go)
46{
47 struct wpabuf *buf;
48 u8 *len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049 size_t extra = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070051#ifdef CONFIG_WIFI_DISPLAY
52 if (p2p->wfd_ie_prov_disc_req)
53 extra = wpabuf_len(p2p->wfd_ie_prov_disc_req);
54#endif /* CONFIG_WIFI_DISPLAY */
55
56 buf = wpabuf_alloc(1000 + extra);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070057 if (buf == NULL)
58 return NULL;
59
60 p2p_buf_add_public_action_hdr(buf, P2P_PROV_DISC_REQ, dialog_token);
61
62 len = p2p_buf_add_ie_hdr(buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -070063 p2p_buf_add_capability(buf, p2p->dev_capab &
64 ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070065 p2p_buf_add_device_info(buf, p2p, NULL);
66 if (go) {
67 p2p_buf_add_group_id(buf, go->info.p2p_device_addr,
68 go->oper_ssid, go->oper_ssid_len);
69 }
70 p2p_buf_update_ie_hdr(buf, len);
71
72 /* WPS IE with Config Methods attribute */
73 p2p_build_wps_ie_config_methods(buf, config_methods);
74
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070075#ifdef CONFIG_WIFI_DISPLAY
76 if (p2p->wfd_ie_prov_disc_req)
77 wpabuf_put_buf(buf, p2p->wfd_ie_prov_disc_req);
78#endif /* CONFIG_WIFI_DISPLAY */
79
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080 return buf;
81}
82
83
84static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
85 u8 dialog_token,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070086 u16 config_methods,
87 const u8 *group_id,
88 size_t group_id_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089{
90 struct wpabuf *buf;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070091 size_t extra = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070093#ifdef CONFIG_WIFI_DISPLAY
94 struct wpabuf *wfd_ie = p2p->wfd_ie_prov_disc_resp;
95 if (wfd_ie && group_id) {
96 size_t i;
97 for (i = 0; i < p2p->num_groups; i++) {
98 struct p2p_group *g = p2p->groups[i];
99 struct wpabuf *ie;
100 if (!p2p_group_is_group_id_match(g, group_id,
101 group_id_len))
102 continue;
103 ie = p2p_group_get_wfd_ie(g);
104 if (ie) {
105 wfd_ie = ie;
106 break;
107 }
108 }
109 }
110 if (wfd_ie)
111 extra = wpabuf_len(wfd_ie);
112#endif /* CONFIG_WIFI_DISPLAY */
113
114 buf = wpabuf_alloc(100 + extra);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 if (buf == NULL)
116 return NULL;
117
118 p2p_buf_add_public_action_hdr(buf, P2P_PROV_DISC_RESP, dialog_token);
119
120 /* WPS IE with Config Methods attribute */
121 p2p_build_wps_ie_config_methods(buf, config_methods);
122
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700123#ifdef CONFIG_WIFI_DISPLAY
124 if (wfd_ie)
125 wpabuf_put_buf(buf, wfd_ie);
126#endif /* CONFIG_WIFI_DISPLAY */
127
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 return buf;
129}
130
131
132void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
133 const u8 *data, size_t len, int rx_freq)
134{
135 struct p2p_message msg;
136 struct p2p_device *dev;
137 int freq;
138 int reject = 1;
139 struct wpabuf *resp;
140
141 if (p2p_parse(data, len, &msg))
142 return;
143
144 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
145 "P2P: Received Provision Discovery Request from " MACSTR
146 " with config methods 0x%x (freq=%d)",
147 MAC2STR(sa), msg.wps_config_methods, rx_freq);
148
149 dev = p2p_get_device(p2p, sa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800150 if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700151 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
152 "P2P: Provision Discovery Request from "
153 "unknown peer " MACSTR, MAC2STR(sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800154
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800155 if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800156 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
158 "P2P: Provision Discovery Request add device "
159 "failed " MACSTR, MAC2STR(sa));
160 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700161 } else if (msg.wfd_subelems) {
162 wpabuf_free(dev->info.wfd_subelems);
163 dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700164 }
165
166 if (!(msg.wps_config_methods &
167 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD |
168 WPS_CONFIG_PUSHBUTTON))) {
169 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unsupported "
170 "Config Methods in Provision Discovery Request");
171 goto out;
172 }
173
Dmitry Shmidt04949592012-07-19 12:16:46 -0700174 if (msg.group_id) {
175 size_t i;
176 for (i = 0; i < p2p->num_groups; i++) {
177 if (p2p_group_is_group_id_match(p2p->groups[i],
178 msg.group_id,
179 msg.group_id_len))
180 break;
181 }
182 if (i == p2p->num_groups) {
183 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: PD "
184 "request for unknown P2P Group ID - reject");
185 goto out;
186 }
187 }
188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 if (dev)
190 dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY |
191 P2P_DEV_PD_PEER_KEYPAD);
192 if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) {
193 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
194 " requested us to show a PIN on display", MAC2STR(sa));
195 if (dev)
196 dev->flags |= P2P_DEV_PD_PEER_KEYPAD;
197 } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) {
198 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
199 " requested us to write its PIN using keypad",
200 MAC2STR(sa));
201 if (dev)
202 dev->flags |= P2P_DEV_PD_PEER_DISPLAY;
203 }
204
205 reject = 0;
206
207out:
208 resp = p2p_build_prov_disc_resp(p2p, msg.dialog_token,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700209 reject ? 0 : msg.wps_config_methods,
210 msg.group_id, msg.group_id_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211 if (resp == NULL) {
212 p2p_parse_free(&msg);
213 return;
214 }
215 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
216 "P2P: Sending Provision Discovery Response");
217 if (rx_freq > 0)
218 freq = rx_freq;
219 else
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700220 freq = p2p_channel_to_freq(p2p->cfg->reg_class,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 p2p->cfg->channel);
222 if (freq < 0) {
223 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
224 "P2P: Unknown regulatory class/channel");
225 wpabuf_free(resp);
226 p2p_parse_free(&msg);
227 return;
228 }
229 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
230 if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
231 p2p->cfg->dev_addr,
232 wpabuf_head(resp), wpabuf_len(resp), 200) < 0) {
233 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
234 "P2P: Failed to send Action frame");
235 }
236
237 wpabuf_free(resp);
238
239 if (!reject && p2p->cfg->prov_disc_req) {
240 const u8 *dev_addr = sa;
241 if (msg.p2p_device_addr)
242 dev_addr = msg.p2p_device_addr;
243 p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa,
244 msg.wps_config_methods,
245 dev_addr, msg.pri_dev_type,
246 msg.device_name, msg.config_methods,
247 msg.capability ? msg.capability[0] : 0,
248 msg.capability ? msg.capability[1] :
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800249 0,
250 msg.group_id, msg.group_id_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251 }
252 p2p_parse_free(&msg);
253}
254
255
256void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
257 const u8 *data, size_t len)
258{
259 struct p2p_message msg;
260 struct p2p_device *dev;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700261 u16 report_config_methods = 0, req_config_methods;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700262 int success = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263
264 if (p2p_parse(data, len, &msg))
265 return;
266
267 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800268 "P2P: Received Provision Discovery Response from " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 " with config methods 0x%x",
270 MAC2STR(sa), msg.wps_config_methods);
271
272 dev = p2p_get_device(p2p, sa);
273 if (dev == NULL || !dev->req_config_methods) {
274 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275 "P2P: Ignore Provision Discovery Response from "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276 MACSTR " with no pending request", MAC2STR(sa));
277 p2p_parse_free(&msg);
278 return;
279 }
280
281 if (dev->dialog_token != msg.dialog_token) {
282 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800283 "P2P: Ignore Provision Discovery Response with "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284 "unexpected Dialog Token %u (expected %u)",
285 msg.dialog_token, dev->dialog_token);
286 p2p_parse_free(&msg);
287 return;
288 }
289
Dmitry Shmidt91c40cd2012-09-25 14:23:53 -0700290 if (p2p->pending_action_state == P2P_PENDING_PD) {
291 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
292 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
293 }
294
Jouni Malinen75ecf522011-06-27 15:19:46 -0700295 /*
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700296 * Use a local copy of the requested config methods since
297 * p2p_reset_pending_pd() can clear this in the peer entry.
298 */
299 req_config_methods = dev->req_config_methods;
300
301 /*
Jouni Malinen75ecf522011-06-27 15:19:46 -0700302 * If the response is from the peer to whom a user initiated request
303 * was sent earlier, we reset that state info here.
304 */
305 if (p2p->user_initiated_pd &&
306 os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0)
307 p2p_reset_pending_pd(p2p);
308
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700309 if (msg.wps_config_methods != req_config_methods) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer rejected "
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700311 "our Provision Discovery Request (received "
312 "config_methods 0x%x expected 0x%x",
313 msg.wps_config_methods, req_config_methods);
Jouni Malinen75ecf522011-06-27 15:19:46 -0700314 if (p2p->cfg->prov_disc_fail)
315 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa,
316 P2P_PROV_DISC_REJECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317 p2p_parse_free(&msg);
318 goto out;
319 }
320
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700321 report_config_methods = req_config_methods;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY |
323 P2P_DEV_PD_PEER_KEYPAD);
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700324 if (req_config_methods & WPS_CONFIG_DISPLAY) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
326 " accepted to show a PIN on display", MAC2STR(sa));
327 dev->flags |= P2P_DEV_PD_PEER_DISPLAY;
328 } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) {
329 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
330 " accepted to write our PIN using keypad",
331 MAC2STR(sa));
332 dev->flags |= P2P_DEV_PD_PEER_KEYPAD;
333 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800334
335 /* Store the provisioning info */
336 dev->wps_prov_info = msg.wps_config_methods;
337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 p2p_parse_free(&msg);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700339 success = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340
341out:
342 dev->req_config_methods = 0;
343 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700344 if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
345 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
346 "P2P: Start GO Neg after the PD-before-GO-Neg "
347 "workaround with " MACSTR,
348 MAC2STR(dev->info.p2p_device_addr));
349 dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG;
350 p2p_connect_send(p2p, dev);
351 return;
352 }
353 if (success && p2p->cfg->prov_disc_resp)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa,
355 report_config_methods);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -0700356
357 if (p2p->state == P2P_PD_DURING_FIND) {
358 p2p_clear_timeout(p2p);
359 p2p_continue_find(p2p);
360 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361}
362
363
364int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800365 int join, int force_freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366{
367 struct wpabuf *req;
368 int freq;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700369
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800370 if (force_freq > 0)
371 freq = force_freq;
372 else
373 freq = dev->listen_freq > 0 ? dev->listen_freq :
374 dev->oper_freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375 if (freq <= 0) {
376 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
377 "P2P: No Listen/Operating frequency known for the "
378 "peer " MACSTR " to send Provision Discovery Request",
379 MAC2STR(dev->info.p2p_device_addr));
380 return -1;
381 }
382
383 if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
384 if (!(dev->info.dev_capab &
385 P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
386 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
387 "P2P: Cannot use PD with P2P Device " MACSTR
388 " that is in a group and is not discoverable",
389 MAC2STR(dev->info.p2p_device_addr));
390 return -1;
391 }
392 /* TODO: use device discoverability request through GO */
393 }
394
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700395 req = p2p_build_prov_disc_req(p2p, dev->dialog_token,
396 dev->req_config_methods,
397 join ? dev : NULL);
398 if (req == NULL)
399 return -1;
400
Dmitry Shmidt04949592012-07-19 12:16:46 -0700401 if (p2p->state != P2P_IDLE)
402 p2p_stop_listen_for_freq(p2p, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 p2p->pending_action_state = P2P_PENDING_PD;
404 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
405 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
406 wpabuf_head(req), wpabuf_len(req), 200) < 0) {
407 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
408 "P2P: Failed to send Action frame");
409 wpabuf_free(req);
410 return -1;
411 }
412
Jouni Malinen75ecf522011-06-27 15:19:46 -0700413 os_memcpy(p2p->pending_pd_devaddr, dev->info.p2p_device_addr, ETH_ALEN);
414
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 wpabuf_free(req);
416 return 0;
417}
418
419
420int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800421 u16 config_methods, int join, int force_freq,
422 int user_initiated_pd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423{
424 struct p2p_device *dev;
425
426 dev = p2p_get_device(p2p, peer_addr);
427 if (dev == NULL)
428 dev = p2p_get_device_interface(p2p, peer_addr);
429 if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
430 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision "
431 "Discovery Request destination " MACSTR
432 " not yet known", MAC2STR(peer_addr));
433 return -1;
434 }
435
436 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision Discovery "
437 "Request with " MACSTR " (config methods 0x%x)",
438 MAC2STR(peer_addr), config_methods);
439 if (config_methods == 0)
440 return -1;
441
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442 /* Reset provisioning info */
443 dev->wps_prov_info = 0;
444
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 dev->req_config_methods = config_methods;
446 if (join)
447 dev->flags |= P2P_DEV_PD_FOR_JOIN;
448 else
449 dev->flags &= ~P2P_DEV_PD_FOR_JOIN;
450
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800451 if (p2p->state != P2P_IDLE && p2p->state != P2P_SEARCH &&
452 p2p->state != P2P_LISTEN_ONLY) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Busy with other "
454 "operations; postpone Provision Discovery Request "
455 "with " MACSTR " (config methods 0x%x)",
456 MAC2STR(peer_addr), config_methods);
457 return 0;
458 }
459
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800460 p2p->user_initiated_pd = user_initiated_pd;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700461
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700462 if (p2p->user_initiated_pd)
Jouni Malinen75ecf522011-06-27 15:19:46 -0700463 p2p->pd_retries = MAX_PROV_DISC_REQ_RETRIES;
464
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800465 /*
466 * Assign dialog token here to use the same value in each retry within
467 * the same PD exchange.
468 */
469 dev->dialog_token++;
470 if (dev->dialog_token == 0)
471 dev->dialog_token = 1;
472
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473 return p2p_send_prov_disc_req(p2p, dev, join, force_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474}
Jouni Malinen75ecf522011-06-27 15:19:46 -0700475
476
477void p2p_reset_pending_pd(struct p2p_data *p2p)
478{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800479 struct p2p_device *dev;
480
481 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) {
482 if (os_memcmp(p2p->pending_pd_devaddr,
483 dev->info.p2p_device_addr, ETH_ALEN))
484 continue;
485 if (!dev->req_config_methods)
486 continue;
487 if (dev->flags & P2P_DEV_PD_FOR_JOIN)
488 continue;
489 /* Reset the config methods of the device */
490 dev->req_config_methods = 0;
491 }
492
Jouni Malinen75ecf522011-06-27 15:19:46 -0700493 p2p->user_initiated_pd = 0;
494 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
495 p2p->pd_retries = 0;
496}