p2p_go_neg.c revision 7e6eef4d7cae2a3f6b49744844c20cce3dc2ef28
1/*
2 * Wi-Fi Direct - P2P Group Owner Negotiation
3 * Copyright (c) 2009-2010, Atheros Communications
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
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
18static int p2p_go_det(u8 own_intent, u8 peer_value)
19{
20	u8 peer_intent = peer_value >> 1;
21	if (own_intent == peer_intent) {
22		if (own_intent == P2P_MAX_GO_INTENT)
23			return -1; /* both devices want to become GO */
24
25		/* Use tie breaker bit to determine GO */
26		return (peer_value & 0x01) ? 0 : 1;
27	}
28
29	return own_intent > peer_intent;
30}
31
32
33int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
34			    struct p2p_device *dev,
35			    const u8 *channel_list, size_t channel_list_len)
36{
37	const u8 *pos, *end;
38	struct p2p_channels *ch;
39	size_t channels;
40	struct p2p_channels intersection;
41
42	ch = &dev->channels;
43	os_memset(ch, 0, sizeof(*ch));
44	pos = channel_list;
45	end = channel_list + channel_list_len;
46
47	if (end - pos < 3)
48		return -1;
49	os_memcpy(dev->country, pos, 3);
50	wpa_hexdump_ascii(MSG_DEBUG, "P2P: Peer country", pos, 3);
51	if (pos[2] != 0x04 && os_memcmp(pos, p2p->cfg->country, 2) != 0) {
52		p2p_info(p2p, "Mismatching country (ours=%c%c peer's=%c%c)",
53			p2p->cfg->country[0], p2p->cfg->country[1],
54			pos[0], pos[1]);
55		return -1;
56	}
57	pos += 3;
58
59	while (pos + 2 < end) {
60		struct p2p_reg_class *cl = &ch->reg_class[ch->reg_classes];
61		cl->reg_class = *pos++;
62		if (pos + 1 + pos[0] > end) {
63			p2p_info(p2p, "Invalid peer Channel List");
64			return -1;
65		}
66		channels = *pos++;
67		cl->channels = channels > P2P_MAX_REG_CLASS_CHANNELS ?
68			P2P_MAX_REG_CLASS_CHANNELS : channels;
69		os_memcpy(cl->channel, pos, cl->channels);
70		pos += channels;
71		ch->reg_classes++;
72		if (ch->reg_classes == P2P_MAX_REG_CLASSES)
73			break;
74	}
75
76	p2p_channels_intersect(own, &dev->channels, &intersection);
77	p2p_dbg(p2p, "Own reg_classes %d peer reg_classes %d intersection reg_classes %d",
78		(int) own->reg_classes,
79		(int) dev->channels.reg_classes,
80		(int) intersection.reg_classes);
81	if (intersection.reg_classes == 0) {
82		p2p_info(p2p, "No common channels found");
83		return -1;
84	}
85	return 0;
86}
87
88
89static int p2p_peer_channels(struct p2p_data *p2p, struct p2p_device *dev,
90			     const u8 *channel_list, size_t channel_list_len)
91{
92	return p2p_peer_channels_check(p2p, &p2p->channels, dev,
93				       channel_list, channel_list_len);
94}
95
96
97u16 p2p_wps_method_pw_id(enum p2p_wps_method wps_method)
98{
99	switch (wps_method) {
100	case WPS_PIN_DISPLAY:
101		return DEV_PW_REGISTRAR_SPECIFIED;
102	case WPS_PIN_KEYPAD:
103		return DEV_PW_USER_SPECIFIED;
104	case WPS_PBC:
105		return DEV_PW_PUSHBUTTON;
106	default:
107		return DEV_PW_DEFAULT;
108	}
109}
110
111
112static const char * p2p_wps_method_str(enum p2p_wps_method wps_method)
113{
114	switch (wps_method) {
115	case WPS_PIN_DISPLAY:
116		return "Display";
117	case WPS_PIN_KEYPAD:
118		return "Keypad";
119	case WPS_PBC:
120		return "PBC";
121	default:
122		return "??";
123	}
124}
125
126
127static struct wpabuf * p2p_build_go_neg_req(struct p2p_data *p2p,
128					    struct p2p_device *peer)
129{
130	struct wpabuf *buf;
131	u8 *len;
132	u8 group_capab;
133	size_t extra = 0;
134
135#ifdef CONFIG_WIFI_DISPLAY
136	if (p2p->wfd_ie_go_neg)
137		extra = wpabuf_len(p2p->wfd_ie_go_neg);
138#endif /* CONFIG_WIFI_DISPLAY */
139
140	buf = wpabuf_alloc(1000 + extra);
141	if (buf == NULL)
142		return NULL;
143
144	p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_REQ, peer->dialog_token);
145
146	len = p2p_buf_add_ie_hdr(buf);
147	group_capab = 0;
148	if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
149		group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
150		if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
151			group_capab |= P2P_GROUP_CAPAB_PERSISTENT_RECONN;
152	}
153	if (p2p->cross_connect)
154		group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
155	if (p2p->cfg->p2p_intra_bss)
156		group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
157	p2p_buf_add_capability(buf, p2p->dev_capab &
158			       ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
159			       group_capab);
160	p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) | peer->tie_breaker);
161	p2p_buf_add_config_timeout(buf, p2p->go_timeout, p2p->client_timeout);
162	p2p_buf_add_listen_channel(buf, p2p->cfg->country, p2p->cfg->reg_class,
163				   p2p->cfg->channel);
164	if (p2p->ext_listen_interval)
165		p2p_buf_add_ext_listen_timing(buf, p2p->ext_listen_period,
166					      p2p->ext_listen_interval);
167	p2p_buf_add_intended_addr(buf, p2p->intended_addr);
168	p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels);
169	p2p_buf_add_device_info(buf, p2p, peer);
170	p2p_buf_add_operating_channel(buf, p2p->cfg->country,
171				      p2p->op_reg_class, p2p->op_channel);
172	p2p_buf_update_ie_hdr(buf, len);
173
174	/* WPS IE with Device Password ID attribute */
175	if (p2p_build_wps_ie(p2p, buf, p2p_wps_method_pw_id(peer->wps_method),
176			     0) < 0) {
177		p2p_dbg(p2p, "Failed to build WPS IE for GO Negotiation Request");
178		wpabuf_free(buf);
179		return NULL;
180	}
181
182#ifdef CONFIG_WIFI_DISPLAY
183	if (p2p->wfd_ie_go_neg)
184		wpabuf_put_buf(buf, p2p->wfd_ie_go_neg);
185#endif /* CONFIG_WIFI_DISPLAY */
186
187	return buf;
188}
189
190
191int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
192{
193	struct wpabuf *req;
194	int freq;
195
196	if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
197		u16 config_method;
198		p2p_dbg(p2p, "Use PD-before-GO-Neg workaround for " MACSTR,
199			MAC2STR(dev->info.p2p_device_addr));
200		if (dev->wps_method == WPS_PIN_DISPLAY)
201			config_method = WPS_CONFIG_KEYPAD;
202		else if (dev->wps_method == WPS_PIN_KEYPAD)
203			config_method = WPS_CONFIG_DISPLAY;
204		else if (dev->wps_method == WPS_PBC)
205			config_method = WPS_CONFIG_PUSHBUTTON;
206		else
207			return -1;
208		return p2p_prov_disc_req(p2p, dev->info.p2p_device_addr,
209					 config_method, 0, 0, 1);
210	}
211
212	freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
213	if (freq <= 0) {
214		p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
215			MACSTR " to send GO Negotiation Request",
216			MAC2STR(dev->info.p2p_device_addr));
217		return -1;
218	}
219
220	req = p2p_build_go_neg_req(p2p, dev);
221	if (req == NULL)
222		return -1;
223	p2p_dbg(p2p, "Sending GO Negotiation Request");
224	p2p_set_state(p2p, P2P_CONNECT);
225	p2p->pending_action_state = P2P_PENDING_GO_NEG_REQUEST;
226	p2p->go_neg_peer = dev;
227	dev->flags |= P2P_DEV_WAIT_GO_NEG_RESPONSE;
228	dev->connect_reqs++;
229	if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
230			    p2p->cfg->dev_addr, dev->info.p2p_device_addr,
231			    wpabuf_head(req), wpabuf_len(req), 500) < 0) {
232		p2p_dbg(p2p, "Failed to send Action frame");
233		/* Use P2P find to recover and retry */
234		p2p_set_timeout(p2p, 0, 0);
235	} else
236		dev->go_neg_req_sent++;
237
238	wpabuf_free(req);
239
240	return 0;
241}
242
243
244static struct wpabuf * p2p_build_go_neg_resp(struct p2p_data *p2p,
245					     struct p2p_device *peer,
246					     u8 dialog_token, u8 status,
247					     u8 tie_breaker)
248{
249	struct wpabuf *buf;
250	u8 *len;
251	u8 group_capab;
252	size_t extra = 0;
253
254	p2p_dbg(p2p, "Building GO Negotiation Response");
255
256#ifdef CONFIG_WIFI_DISPLAY
257	if (p2p->wfd_ie_go_neg)
258		extra = wpabuf_len(p2p->wfd_ie_go_neg);
259#endif /* CONFIG_WIFI_DISPLAY */
260
261	buf = wpabuf_alloc(1000 + extra);
262	if (buf == NULL)
263		return NULL;
264
265	p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_RESP, dialog_token);
266
267	len = p2p_buf_add_ie_hdr(buf);
268	p2p_buf_add_status(buf, status);
269	group_capab = 0;
270	if (peer && peer->go_state == LOCAL_GO) {
271		if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
272			group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
273			if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
274				group_capab |=
275					P2P_GROUP_CAPAB_PERSISTENT_RECONN;
276		}
277		if (p2p->cross_connect)
278			group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
279		if (p2p->cfg->p2p_intra_bss)
280			group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
281	}
282	p2p_buf_add_capability(buf, p2p->dev_capab &
283			       ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
284			       group_capab);
285	p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) | tie_breaker);
286	p2p_buf_add_config_timeout(buf, p2p->go_timeout, p2p->client_timeout);
287	if (peer && peer->go_state == REMOTE_GO) {
288		p2p_dbg(p2p, "Omit Operating Channel attribute");
289	} else {
290		p2p_buf_add_operating_channel(buf, p2p->cfg->country,
291					      p2p->op_reg_class,
292					      p2p->op_channel);
293	}
294	p2p_buf_add_intended_addr(buf, p2p->intended_addr);
295	if (status || peer == NULL) {
296		p2p_buf_add_channel_list(buf, p2p->cfg->country,
297					 &p2p->channels);
298	} else if (peer->go_state == REMOTE_GO) {
299		p2p_buf_add_channel_list(buf, p2p->cfg->country,
300					 &p2p->channels);
301	} else {
302		struct p2p_channels res;
303		p2p_channels_intersect(&p2p->channels, &peer->channels,
304				       &res);
305		p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
306	}
307	p2p_buf_add_device_info(buf, p2p, peer);
308	if (peer && peer->go_state == LOCAL_GO) {
309		p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
310				     p2p->ssid_len);
311	}
312	p2p_buf_update_ie_hdr(buf, len);
313
314	/* WPS IE with Device Password ID attribute */
315	if (p2p_build_wps_ie(p2p, buf,
316			     p2p_wps_method_pw_id(peer ? peer->wps_method :
317						  WPS_NOT_READY), 0) < 0) {
318		p2p_dbg(p2p, "Failed to build WPS IE for GO Negotiation Response");
319		wpabuf_free(buf);
320		return NULL;
321	}
322
323#ifdef CONFIG_WIFI_DISPLAY
324	if (p2p->wfd_ie_go_neg)
325		wpabuf_put_buf(buf, p2p->wfd_ie_go_neg);
326#endif /* CONFIG_WIFI_DISPLAY */
327
328
329	return buf;
330}
331
332
333/**
334 * p2p_reselect_channel - Re-select operating channel based on peer information
335 * @p2p: P2P module context from p2p_init()
336 * @intersection: Support channel list intersection from local and peer
337 *
338 * This function is used to re-select the best channel after having received
339 * information from the peer to allow supported channel lists to be intersected.
340 * This can be used to improve initial channel selection done in
341 * p2p_prepare_channel() prior to the start of GO Negotiation. In addition, this
342 * can be used for Invitation case.
343 */
344void p2p_reselect_channel(struct p2p_data *p2p,
345			  struct p2p_channels *intersection)
346{
347	struct p2p_reg_class *cl;
348	int freq;
349	u8 op_reg_class, op_channel;
350	unsigned int i;
351
352	if (p2p->own_freq_preference > 0 &&
353	    p2p_freq_to_channel(p2p->own_freq_preference,
354				&op_reg_class, &op_channel) == 0 &&
355	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
356		p2p_dbg(p2p, "Pick own channel preference (reg_class %u channel %u) from intersection",
357			op_reg_class, op_channel);
358		p2p->op_reg_class = op_reg_class;
359		p2p->op_channel = op_channel;
360		return;
361	}
362
363	if (p2p->best_freq_overall > 0 &&
364	    p2p_freq_to_channel(p2p->best_freq_overall,
365				&op_reg_class, &op_channel) == 0 &&
366	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
367		p2p_dbg(p2p, "Pick best overall channel (reg_class %u channel %u) from intersection",
368			op_reg_class, op_channel);
369		p2p->op_reg_class = op_reg_class;
370		p2p->op_channel = op_channel;
371		return;
372	}
373
374	/* First, try to pick the best channel from another band */
375	freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel);
376	if (freq >= 2400 && freq < 2500 && p2p->best_freq_5 > 0 &&
377	    !p2p_channels_includes(intersection, p2p->op_reg_class,
378				   p2p->op_channel) &&
379	    p2p_freq_to_channel(p2p->best_freq_5,
380				&op_reg_class, &op_channel) == 0 &&
381	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
382		p2p_dbg(p2p, "Pick best 5 GHz channel (reg_class %u channel %u) from intersection",
383			op_reg_class, op_channel);
384		p2p->op_reg_class = op_reg_class;
385		p2p->op_channel = op_channel;
386		return;
387	}
388
389	if (freq >= 4900 && freq < 6000 && p2p->best_freq_24 > 0 &&
390	    !p2p_channels_includes(intersection, p2p->op_reg_class,
391				   p2p->op_channel) &&
392	    p2p_freq_to_channel(p2p->best_freq_24,
393				&op_reg_class, &op_channel) == 0 &&
394	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
395		p2p_dbg(p2p, "Pick best 2.4 GHz channel (reg_class %u channel %u) from intersection",
396			op_reg_class, op_channel);
397		p2p->op_reg_class = op_reg_class;
398		p2p->op_channel = op_channel;
399		return;
400	}
401
402	/* Select channel with highest preference if the peer supports it */
403	for (i = 0; p2p->cfg->pref_chan && i < p2p->cfg->num_pref_chan; i++) {
404		if (p2p_channels_includes(intersection,
405					  p2p->cfg->pref_chan[i].op_class,
406					  p2p->cfg->pref_chan[i].chan)) {
407			p2p->op_reg_class = p2p->cfg->pref_chan[i].op_class;
408			p2p->op_channel = p2p->cfg->pref_chan[i].chan;
409			p2p_dbg(p2p, "Pick highest preferred channel (op_class %u channel %u) from intersection",
410				p2p->op_reg_class, p2p->op_channel);
411			return;
412		}
413	}
414
415	/* Try a channel where we might be able to use VHT */
416	for (i = 0; i < intersection->reg_classes; i++) {
417		struct p2p_reg_class *c = &intersection->reg_class[i];
418		if (c->reg_class == 128) {
419			p2p_dbg(p2p, "Pick possible VHT channel (reg_class %u channel %u) from intersection",
420				c->reg_class, c->channel[0]);
421			p2p->op_reg_class = c->reg_class;
422			p2p->op_channel = c->channel[0];
423			return;
424		}
425	}
426
427	/* Try a channel where we might be able to use HT40 */
428	for (i = 0; i < intersection->reg_classes; i++) {
429		struct p2p_reg_class *c = &intersection->reg_class[i];
430		if (c->reg_class == 116 || c->reg_class == 117 ||
431		    c->reg_class == 126 || c->reg_class == 127) {
432			p2p_dbg(p2p, "Pick possible HT40 channel (reg_class %u channel %u) from intersection",
433				c->reg_class, c->channel[0]);
434			p2p->op_reg_class = c->reg_class;
435			p2p->op_channel = c->channel[0];
436			return;
437		}
438	}
439
440	/* Prefer a 5 GHz channel */
441	for (i = 0; i < intersection->reg_classes; i++) {
442		struct p2p_reg_class *c = &intersection->reg_class[i];
443		if ((c->reg_class == 115 || c->reg_class == 124) &&
444		    c->channels) {
445			unsigned int r;
446
447			/*
448			 * Pick one of the available channels in the operating
449			 * class at random.
450			 */
451			os_get_random((u8 *) &r, sizeof(r));
452			r %= c->channels;
453			p2p_dbg(p2p, "Pick possible 5 GHz channel (op_class %u channel %u) from intersection",
454				c->reg_class, c->channel[r]);
455			p2p->op_reg_class = c->reg_class;
456			p2p->op_channel = c->channel[r];
457			return;
458		}
459	}
460
461	/*
462	 * Try to see if the original channel is in the intersection. If
463	 * so, no need to change anything, as it already contains some
464	 * randomness.
465	 */
466	if (p2p_channels_includes(intersection, p2p->op_reg_class,
467				  p2p->op_channel)) {
468		p2p_dbg(p2p, "Using original operating class and channel (op_class %u channel %u) from intersection",
469			p2p->op_reg_class, p2p->op_channel);
470		return;
471	}
472
473	/*
474	 * Fall back to whatever is included in the channel intersection since
475	 * no better options seems to be available.
476	 */
477	cl = &intersection->reg_class[0];
478	p2p_dbg(p2p, "Pick another channel (reg_class %u channel %u) from intersection",
479		cl->reg_class, cl->channel[0]);
480	p2p->op_reg_class = cl->reg_class;
481	p2p->op_channel = cl->channel[0];
482}
483
484
485static int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev,
486				 u8 *status)
487{
488	struct p2p_channels tmp, intersection;
489
490	p2p_channels_dump(p2p, "own channels", &p2p->channels);
491	p2p_channels_dump(p2p, "peer channels", &dev->channels);
492	p2p_channels_intersect(&p2p->channels, &dev->channels, &tmp);
493	p2p_channels_dump(p2p, "intersection", &tmp);
494	p2p_channels_remove_freqs(&tmp, &p2p->no_go_freq);
495	p2p_channels_dump(p2p, "intersection after no-GO removal", &tmp);
496	p2p_channels_intersect(&tmp, &p2p->cfg->channels, &intersection);
497	p2p_channels_dump(p2p, "intersection with local channel list",
498			  &intersection);
499	if (intersection.reg_classes == 0 ||
500	    intersection.reg_class[0].channels == 0) {
501		*status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
502		p2p_dbg(p2p, "No common channels found");
503		return -1;
504	}
505
506	if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
507				   p2p->op_channel)) {
508		if (dev->flags & P2P_DEV_FORCE_FREQ) {
509			*status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
510			p2p_dbg(p2p, "Peer does not support the forced channel");
511			return -1;
512		}
513
514		p2p_dbg(p2p, "Selected operating channel (op_class %u channel %u) not acceptable to the peer",
515			p2p->op_reg_class, p2p->op_channel);
516		p2p_reselect_channel(p2p, &intersection);
517	} else if (!(dev->flags & P2P_DEV_FORCE_FREQ) &&
518		   !p2p->cfg->cfg_op_channel) {
519		p2p_dbg(p2p, "Try to optimize channel selection with peer information received; previously selected op_class %u channel %u",
520			p2p->op_reg_class, p2p->op_channel);
521		p2p_reselect_channel(p2p, &intersection);
522	}
523
524	if (!p2p->ssid_set) {
525		p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
526		p2p->ssid_set = 1;
527	}
528
529	return 0;
530}
531
532
533void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
534			    const u8 *data, size_t len, int rx_freq)
535{
536	struct p2p_device *dev = NULL;
537	struct wpabuf *resp;
538	struct p2p_message msg;
539	u8 status = P2P_SC_FAIL_INVALID_PARAMS;
540	int tie_breaker = 0;
541	int freq;
542
543	p2p_dbg(p2p, "Received GO Negotiation Request from " MACSTR "(freq=%d)",
544		MAC2STR(sa), rx_freq);
545
546	if (p2p_parse(data, len, &msg))
547		return;
548
549	if (!msg.capability) {
550		p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Request");
551#ifdef CONFIG_P2P_STRICT
552		goto fail;
553#endif /* CONFIG_P2P_STRICT */
554	}
555
556	if (msg.go_intent)
557		tie_breaker = *msg.go_intent & 0x01;
558	else {
559		p2p_dbg(p2p, "Mandatory GO Intent attribute missing from GO Negotiation Request");
560#ifdef CONFIG_P2P_STRICT
561		goto fail;
562#endif /* CONFIG_P2P_STRICT */
563	}
564
565	if (!msg.config_timeout) {
566		p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Request");
567#ifdef CONFIG_P2P_STRICT
568		goto fail;
569#endif /* CONFIG_P2P_STRICT */
570	}
571
572	if (!msg.listen_channel) {
573		p2p_dbg(p2p, "No Listen Channel attribute received");
574		goto fail;
575	}
576	if (!msg.operating_channel) {
577		p2p_dbg(p2p, "No Operating Channel attribute received");
578		goto fail;
579	}
580	if (!msg.channel_list) {
581		p2p_dbg(p2p, "No Channel List attribute received");
582		goto fail;
583	}
584	if (!msg.intended_addr) {
585		p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
586		goto fail;
587	}
588	if (!msg.p2p_device_info) {
589		p2p_dbg(p2p, "No P2P Device Info attribute received");
590		goto fail;
591	}
592
593	if (os_memcmp(msg.p2p_device_addr, sa, ETH_ALEN) != 0) {
594		p2p_dbg(p2p, "Unexpected GO Negotiation Request SA=" MACSTR
595			" != dev_addr=" MACSTR,
596			MAC2STR(sa), MAC2STR(msg.p2p_device_addr));
597		goto fail;
598	}
599
600	dev = p2p_get_device(p2p, sa);
601
602	if (msg.status && *msg.status) {
603		p2p_dbg(p2p, "Unexpected Status attribute (%d) in GO Negotiation Request",
604			*msg.status);
605		goto fail;
606	}
607
608	if (dev == NULL)
609		dev = p2p_add_dev_from_go_neg_req(p2p, sa, &msg);
610	else if (dev->flags & P2P_DEV_PROBE_REQ_ONLY)
611		p2p_add_dev_info(p2p, sa, dev, &msg);
612	if (dev && dev->flags & P2P_DEV_USER_REJECTED) {
613		p2p_dbg(p2p, "User has rejected this peer");
614		status = P2P_SC_FAIL_REJECTED_BY_USER;
615	} else if (dev == NULL || dev->wps_method == WPS_NOT_READY) {
616		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
617			MAC2STR(sa));
618		status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
619		p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa,
620					msg.dev_password_id);
621	} else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
622		p2p_dbg(p2p, "Already in Group Formation with another peer");
623		status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
624	} else {
625		int go;
626
627		if (!p2p->go_neg_peer) {
628			p2p_dbg(p2p, "Starting GO Negotiation with previously authorized peer");
629			if (!(dev->flags & P2P_DEV_FORCE_FREQ)) {
630				p2p_dbg(p2p, "Use default channel settings");
631				p2p->op_reg_class = p2p->cfg->op_reg_class;
632				p2p->op_channel = p2p->cfg->op_channel;
633				os_memcpy(&p2p->channels, &p2p->cfg->channels,
634					  sizeof(struct p2p_channels));
635			} else {
636				p2p_dbg(p2p, "Use previously configured forced channel settings");
637			}
638		}
639
640		dev->flags &= ~P2P_DEV_NOT_YET_READY;
641
642		if (!msg.go_intent) {
643			p2p_dbg(p2p, "No GO Intent attribute received");
644			goto fail;
645		}
646		if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
647			p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
648				*msg.go_intent >> 1);
649			goto fail;
650		}
651
652		if (dev->go_neg_req_sent &&
653		    os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) > 0) {
654			p2p_dbg(p2p, "Do not reply since peer has higher address and GO Neg Request already sent");
655			p2p_parse_free(&msg);
656			return;
657		}
658
659		go = p2p_go_det(p2p->go_intent, *msg.go_intent);
660		if (go < 0) {
661			p2p_dbg(p2p, "Incompatible GO Intent");
662			status = P2P_SC_FAIL_BOTH_GO_INTENT_15;
663			goto fail;
664		}
665
666		if (p2p_peer_channels(p2p, dev, msg.channel_list,
667				      msg.channel_list_len) < 0) {
668			p2p_dbg(p2p, "No common channels found");
669			status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
670			goto fail;
671		}
672
673		switch (msg.dev_password_id) {
674		case DEV_PW_REGISTRAR_SPECIFIED:
675			p2p_dbg(p2p, "PIN from peer Display");
676			if (dev->wps_method != WPS_PIN_KEYPAD) {
677				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
678					p2p_wps_method_str(dev->wps_method));
679				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
680				goto fail;
681			}
682			break;
683		case DEV_PW_USER_SPECIFIED:
684			p2p_dbg(p2p, "Peer entered PIN on Keypad");
685			if (dev->wps_method != WPS_PIN_DISPLAY) {
686				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
687					p2p_wps_method_str(dev->wps_method));
688				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
689				goto fail;
690			}
691			break;
692		case DEV_PW_PUSHBUTTON:
693			p2p_dbg(p2p, "Peer using pushbutton");
694			if (dev->wps_method != WPS_PBC) {
695				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
696					p2p_wps_method_str(dev->wps_method));
697				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
698				goto fail;
699			}
700			break;
701		default:
702			p2p_dbg(p2p, "Unsupported Device Password ID %d",
703				msg.dev_password_id);
704			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
705			goto fail;
706		}
707
708		if (go && p2p_go_select_channel(p2p, dev, &status) < 0)
709			goto fail;
710
711		dev->go_state = go ? LOCAL_GO : REMOTE_GO;
712		dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
713						     msg.operating_channel[4]);
714		p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
715			dev->oper_freq);
716
717		if (msg.config_timeout) {
718			dev->go_timeout = msg.config_timeout[0];
719			dev->client_timeout = msg.config_timeout[1];
720		}
721
722		p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
723		if (p2p->state != P2P_IDLE)
724			p2p_stop_find_for_freq(p2p, rx_freq);
725		p2p_set_state(p2p, P2P_GO_NEG);
726		p2p_clear_timeout(p2p);
727		dev->dialog_token = msg.dialog_token;
728		os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
729		p2p->go_neg_peer = dev;
730		status = P2P_SC_SUCCESS;
731	}
732
733fail:
734	if (dev)
735		dev->status = status;
736	resp = p2p_build_go_neg_resp(p2p, dev, msg.dialog_token, status,
737				     !tie_breaker);
738	p2p_parse_free(&msg);
739	if (resp == NULL)
740		return;
741	p2p_dbg(p2p, "Sending GO Negotiation Response");
742	if (rx_freq > 0)
743		freq = rx_freq;
744	else
745		freq = p2p_channel_to_freq(p2p->cfg->reg_class,
746					   p2p->cfg->channel);
747	if (freq < 0) {
748		p2p_dbg(p2p, "Unknown regulatory class/channel");
749		wpabuf_free(resp);
750		return;
751	}
752	if (status == P2P_SC_SUCCESS) {
753		p2p->pending_action_state = P2P_PENDING_GO_NEG_RESPONSE;
754		dev->flags |= P2P_DEV_WAIT_GO_NEG_CONFIRM;
755		if (os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) < 0) {
756			/*
757			 * Peer has smaller address, so the GO Negotiation
758			 * Response from us is expected to complete
759			 * negotiation. Ignore a GO Negotiation Response from
760			 * the peer if it happens to be received after this
761			 * point due to a race condition in GO Negotiation
762			 * Request transmission and processing.
763			 */
764			dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
765		}
766	} else
767		p2p->pending_action_state =
768			P2P_PENDING_GO_NEG_RESPONSE_FAILURE;
769	if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
770			    p2p->cfg->dev_addr,
771			    wpabuf_head(resp), wpabuf_len(resp), 500) < 0) {
772		p2p_dbg(p2p, "Failed to send Action frame");
773	}
774
775	wpabuf_free(resp);
776}
777
778
779static struct wpabuf * p2p_build_go_neg_conf(struct p2p_data *p2p,
780					     struct p2p_device *peer,
781					     u8 dialog_token, u8 status,
782					     const u8 *resp_chan, int go)
783{
784	struct wpabuf *buf;
785	u8 *len;
786	struct p2p_channels res;
787	u8 group_capab;
788	size_t extra = 0;
789
790	p2p_dbg(p2p, "Building GO Negotiation Confirm");
791
792#ifdef CONFIG_WIFI_DISPLAY
793	if (p2p->wfd_ie_go_neg)
794		extra = wpabuf_len(p2p->wfd_ie_go_neg);
795#endif /* CONFIG_WIFI_DISPLAY */
796
797	buf = wpabuf_alloc(1000 + extra);
798	if (buf == NULL)
799		return NULL;
800
801	p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_CONF, dialog_token);
802
803	len = p2p_buf_add_ie_hdr(buf);
804	p2p_buf_add_status(buf, status);
805	group_capab = 0;
806	if (peer->go_state == LOCAL_GO) {
807		if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
808			group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
809			if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
810				group_capab |=
811					P2P_GROUP_CAPAB_PERSISTENT_RECONN;
812		}
813		if (p2p->cross_connect)
814			group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
815		if (p2p->cfg->p2p_intra_bss)
816			group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
817	}
818	p2p_buf_add_capability(buf, p2p->dev_capab &
819			       ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
820			       group_capab);
821	if (go || resp_chan == NULL)
822		p2p_buf_add_operating_channel(buf, p2p->cfg->country,
823					      p2p->op_reg_class,
824					      p2p->op_channel);
825	else
826		p2p_buf_add_operating_channel(buf, (const char *) resp_chan,
827					      resp_chan[3], resp_chan[4]);
828	p2p_channels_intersect(&p2p->channels, &peer->channels, &res);
829	p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
830	if (go) {
831		p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
832				     p2p->ssid_len);
833	}
834	p2p_buf_update_ie_hdr(buf, len);
835
836#ifdef CONFIG_WIFI_DISPLAY
837	if (p2p->wfd_ie_go_neg)
838		wpabuf_put_buf(buf, p2p->wfd_ie_go_neg);
839#endif /* CONFIG_WIFI_DISPLAY */
840
841	return buf;
842}
843
844
845void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
846			     const u8 *data, size_t len, int rx_freq)
847{
848	struct p2p_device *dev;
849	struct wpabuf *conf;
850	int go = -1;
851	struct p2p_message msg;
852	u8 status = P2P_SC_SUCCESS;
853	int freq;
854
855	p2p_dbg(p2p, "Received GO Negotiation Response from " MACSTR
856		" (freq=%d)", MAC2STR(sa), rx_freq);
857	dev = p2p_get_device(p2p, sa);
858	if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
859	    dev != p2p->go_neg_peer) {
860		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
861			MAC2STR(sa));
862		return;
863	}
864
865	if (p2p_parse(data, len, &msg))
866		return;
867
868	if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE)) {
869		p2p_dbg(p2p, "Was not expecting GO Negotiation Response - ignore");
870		p2p_parse_free(&msg);
871		return;
872	}
873	dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
874
875	if (msg.dialog_token != dev->dialog_token) {
876		p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
877			msg.dialog_token, dev->dialog_token);
878		p2p_parse_free(&msg);
879		return;
880	}
881
882	if (!msg.status) {
883		p2p_dbg(p2p, "No Status attribute received");
884		status = P2P_SC_FAIL_INVALID_PARAMS;
885		goto fail;
886	}
887	if (*msg.status) {
888		p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
889		dev->go_neg_req_sent = 0;
890		if (*msg.status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
891			p2p_dbg(p2p, "Wait for the peer to become ready for GO Negotiation");
892			dev->flags |= P2P_DEV_NOT_YET_READY;
893			dev->wait_count = 0;
894			p2p_set_state(p2p, P2P_WAIT_PEER_IDLE);
895			p2p_set_timeout(p2p, 0, 0);
896		} else {
897			p2p_dbg(p2p, "Stop GO Negotiation attempt");
898			p2p_go_neg_failed(p2p, dev, *msg.status);
899		}
900		p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
901		p2p_parse_free(&msg);
902		return;
903	}
904
905	if (!msg.capability) {
906		p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Response");
907#ifdef CONFIG_P2P_STRICT
908		status = P2P_SC_FAIL_INVALID_PARAMS;
909		goto fail;
910#endif /* CONFIG_P2P_STRICT */
911	}
912
913	if (!msg.p2p_device_info) {
914		p2p_dbg(p2p, "Mandatory P2P Device Info attribute missing from GO Negotiation Response");
915#ifdef CONFIG_P2P_STRICT
916		status = P2P_SC_FAIL_INVALID_PARAMS;
917		goto fail;
918#endif /* CONFIG_P2P_STRICT */
919	}
920
921	if (!msg.intended_addr) {
922		p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
923		status = P2P_SC_FAIL_INVALID_PARAMS;
924		goto fail;
925	}
926
927	if (!msg.go_intent) {
928		p2p_dbg(p2p, "No GO Intent attribute received");
929		status = P2P_SC_FAIL_INVALID_PARAMS;
930		goto fail;
931	}
932	if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
933		p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
934			*msg.go_intent >> 1);
935		status = P2P_SC_FAIL_INVALID_PARAMS;
936		goto fail;
937	}
938
939	go = p2p_go_det(p2p->go_intent, *msg.go_intent);
940	if (go < 0) {
941		p2p_dbg(p2p, "Incompatible GO Intent");
942		status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
943		goto fail;
944	}
945
946	if (!go && msg.group_id) {
947		/* Store SSID for Provisioning step */
948		p2p->ssid_len = msg.group_id_len - ETH_ALEN;
949		os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
950	} else if (!go) {
951		p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Response");
952		p2p->ssid_len = 0;
953		status = P2P_SC_FAIL_INVALID_PARAMS;
954		goto fail;
955	}
956
957	if (!msg.config_timeout) {
958		p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Response");
959#ifdef CONFIG_P2P_STRICT
960		status = P2P_SC_FAIL_INVALID_PARAMS;
961		goto fail;
962#endif /* CONFIG_P2P_STRICT */
963	} else {
964		dev->go_timeout = msg.config_timeout[0];
965		dev->client_timeout = msg.config_timeout[1];
966	}
967
968	if (!msg.operating_channel && !go) {
969		/*
970		 * Note: P2P Client may omit Operating Channel attribute to
971		 * indicate it does not have a preference.
972		 */
973		p2p_dbg(p2p, "No Operating Channel attribute received");
974		status = P2P_SC_FAIL_INVALID_PARAMS;
975		goto fail;
976	}
977	if (!msg.channel_list) {
978		p2p_dbg(p2p, "No Channel List attribute received");
979		status = P2P_SC_FAIL_INVALID_PARAMS;
980		goto fail;
981	}
982
983	if (p2p_peer_channels(p2p, dev, msg.channel_list,
984			      msg.channel_list_len) < 0) {
985		p2p_dbg(p2p, "No common channels found");
986		status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
987		goto fail;
988	}
989
990	if (msg.operating_channel) {
991		dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
992						     msg.operating_channel[4]);
993		p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
994			dev->oper_freq);
995	} else
996		dev->oper_freq = 0;
997
998	switch (msg.dev_password_id) {
999	case DEV_PW_REGISTRAR_SPECIFIED:
1000		p2p_dbg(p2p, "PIN from peer Display");
1001		if (dev->wps_method != WPS_PIN_KEYPAD) {
1002			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
1003				p2p_wps_method_str(dev->wps_method));
1004			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1005			goto fail;
1006		}
1007		break;
1008	case DEV_PW_USER_SPECIFIED:
1009		p2p_dbg(p2p, "Peer entered PIN on Keypad");
1010		if (dev->wps_method != WPS_PIN_DISPLAY) {
1011			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
1012				p2p_wps_method_str(dev->wps_method));
1013			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1014			goto fail;
1015		}
1016		break;
1017	case DEV_PW_PUSHBUTTON:
1018		p2p_dbg(p2p, "Peer using pushbutton");
1019		if (dev->wps_method != WPS_PBC) {
1020			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
1021				p2p_wps_method_str(dev->wps_method));
1022			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1023			goto fail;
1024		}
1025		break;
1026	default:
1027		p2p_dbg(p2p, "Unsupported Device Password ID %d",
1028			msg.dev_password_id);
1029		status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1030		goto fail;
1031	}
1032
1033	if (go && p2p_go_select_channel(p2p, dev, &status) < 0)
1034		goto fail;
1035
1036	p2p_set_state(p2p, P2P_GO_NEG);
1037	p2p_clear_timeout(p2p);
1038
1039	p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
1040	os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
1041
1042fail:
1043	conf = p2p_build_go_neg_conf(p2p, dev, msg.dialog_token, status,
1044				     msg.operating_channel, go);
1045	p2p_parse_free(&msg);
1046	if (conf == NULL)
1047		return;
1048	p2p_dbg(p2p, "Sending GO Negotiation Confirm");
1049	if (status == P2P_SC_SUCCESS) {
1050		p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM;
1051		dev->go_state = go ? LOCAL_GO : REMOTE_GO;
1052	} else
1053		p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1054	if (rx_freq > 0)
1055		freq = rx_freq;
1056	else
1057		freq = dev->listen_freq;
1058	if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, sa,
1059			    wpabuf_head(conf), wpabuf_len(conf), 0) < 0) {
1060		p2p_dbg(p2p, "Failed to send Action frame");
1061		p2p_go_neg_failed(p2p, dev, -1);
1062	}
1063	wpabuf_free(conf);
1064	if (status != P2P_SC_SUCCESS) {
1065		p2p_dbg(p2p, "GO Negotiation failed");
1066		p2p_go_neg_failed(p2p, dev, status);
1067	}
1068}
1069
1070
1071void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
1072			     const u8 *data, size_t len)
1073{
1074	struct p2p_device *dev;
1075	struct p2p_message msg;
1076
1077	p2p_dbg(p2p, "Received GO Negotiation Confirm from " MACSTR,
1078		MAC2STR(sa));
1079	dev = p2p_get_device(p2p, sa);
1080	if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
1081	    dev != p2p->go_neg_peer) {
1082		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
1083			MAC2STR(sa));
1084		return;
1085	}
1086
1087	if (p2p->pending_action_state == P2P_PENDING_GO_NEG_RESPONSE) {
1088		p2p_dbg(p2p, "Stopped waiting for TX status on GO Negotiation Response since we already received Confirmation");
1089		p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1090	}
1091
1092	if (p2p_parse(data, len, &msg))
1093		return;
1094
1095	if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
1096		p2p_dbg(p2p, "Was not expecting GO Negotiation Confirm - ignore");
1097		return;
1098	}
1099	dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM;
1100
1101	if (msg.dialog_token != dev->dialog_token) {
1102		p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
1103			msg.dialog_token, dev->dialog_token);
1104		p2p_parse_free(&msg);
1105		return;
1106	}
1107
1108	if (!msg.status) {
1109		p2p_dbg(p2p, "No Status attribute received");
1110		p2p_parse_free(&msg);
1111		return;
1112	}
1113	if (*msg.status) {
1114		p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
1115		p2p_go_neg_failed(p2p, dev, *msg.status);
1116		p2p_parse_free(&msg);
1117		return;
1118	}
1119
1120	if (dev->go_state == REMOTE_GO && msg.group_id) {
1121		/* Store SSID for Provisioning step */
1122		p2p->ssid_len = msg.group_id_len - ETH_ALEN;
1123		os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
1124	} else if (dev->go_state == REMOTE_GO) {
1125		p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Confirmation");
1126		p2p->ssid_len = 0;
1127		p2p_go_neg_failed(p2p, dev, P2P_SC_FAIL_INVALID_PARAMS);
1128		p2p_parse_free(&msg);
1129		return;
1130	}
1131
1132	if (!msg.operating_channel) {
1133		p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
1134#ifdef CONFIG_P2P_STRICT
1135		p2p_parse_free(&msg);
1136		return;
1137#endif /* CONFIG_P2P_STRICT */
1138	} else if (dev->go_state == REMOTE_GO) {
1139		int oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
1140						    msg.operating_channel[4]);
1141		if (oper_freq != dev->oper_freq) {
1142			p2p_dbg(p2p, "Updated peer (GO) operating channel preference from %d MHz to %d MHz",
1143				dev->oper_freq, oper_freq);
1144			dev->oper_freq = oper_freq;
1145		}
1146	}
1147
1148	if (!msg.channel_list) {
1149		p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
1150#ifdef CONFIG_P2P_STRICT
1151		p2p_parse_free(&msg);
1152		return;
1153#endif /* CONFIG_P2P_STRICT */
1154	}
1155
1156	p2p_parse_free(&msg);
1157
1158	if (dev->go_state == UNKNOWN_GO) {
1159		/*
1160		 * This should not happen since GO negotiation has already
1161		 * been completed.
1162		 */
1163		p2p_dbg(p2p, "Unexpected GO Neg state - do not know which end becomes GO");
1164		return;
1165	}
1166
1167	/*
1168	 * The peer could have missed our ctrl::ack frame for GO Negotiation
1169	 * Confirm and continue retransmitting the frame. To reduce the
1170	 * likelihood of the peer not getting successful TX status for the
1171	 * GO Negotiation Confirm frame, wait a short time here before starting
1172	 * the group so that we will remain on the current channel to
1173	 * acknowledge any possible retransmission from the peer.
1174	 */
1175	p2p_dbg(p2p, "20 ms wait on current channel before starting group");
1176	os_sleep(0, 20000);
1177
1178	p2p_go_complete(p2p, dev);
1179}
1180