p2p_go_neg.c revision 9e3f8ee32a0c11c56b11985805b5492d04886a99
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	const int op_classes_5ghz[] = { 124, 115, 0 };
352	const int op_classes_ht40[] = { 126, 127, 116, 117, 0 };
353	const int op_classes_vht[] = { 128, 0 };
354
355	if (p2p->own_freq_preference > 0 &&
356	    p2p_freq_to_channel(p2p->own_freq_preference,
357				&op_reg_class, &op_channel) == 0 &&
358	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
359		p2p_dbg(p2p, "Pick own channel preference (reg_class %u channel %u) from intersection",
360			op_reg_class, op_channel);
361		p2p->op_reg_class = op_reg_class;
362		p2p->op_channel = op_channel;
363		return;
364	}
365
366	if (p2p->best_freq_overall > 0 &&
367	    p2p_freq_to_channel(p2p->best_freq_overall,
368				&op_reg_class, &op_channel) == 0 &&
369	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
370		p2p_dbg(p2p, "Pick best overall channel (reg_class %u channel %u) from intersection",
371			op_reg_class, op_channel);
372		p2p->op_reg_class = op_reg_class;
373		p2p->op_channel = op_channel;
374		return;
375	}
376
377	/* First, try to pick the best channel from another band */
378	freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel);
379	if (freq >= 2400 && freq < 2500 && p2p->best_freq_5 > 0 &&
380	    !p2p_channels_includes(intersection, p2p->op_reg_class,
381				   p2p->op_channel) &&
382	    p2p_freq_to_channel(p2p->best_freq_5,
383				&op_reg_class, &op_channel) == 0 &&
384	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
385		p2p_dbg(p2p, "Pick best 5 GHz channel (reg_class %u channel %u) from intersection",
386			op_reg_class, op_channel);
387		p2p->op_reg_class = op_reg_class;
388		p2p->op_channel = op_channel;
389		return;
390	}
391
392	if (freq >= 4900 && freq < 6000 && p2p->best_freq_24 > 0 &&
393	    !p2p_channels_includes(intersection, p2p->op_reg_class,
394				   p2p->op_channel) &&
395	    p2p_freq_to_channel(p2p->best_freq_24,
396				&op_reg_class, &op_channel) == 0 &&
397	    p2p_channels_includes(intersection, op_reg_class, op_channel)) {
398		p2p_dbg(p2p, "Pick best 2.4 GHz channel (reg_class %u channel %u) from intersection",
399			op_reg_class, op_channel);
400		p2p->op_reg_class = op_reg_class;
401		p2p->op_channel = op_channel;
402		return;
403	}
404
405	/* Select channel with highest preference if the peer supports it */
406	for (i = 0; p2p->cfg->pref_chan && i < p2p->cfg->num_pref_chan; i++) {
407		if (p2p_channels_includes(intersection,
408					  p2p->cfg->pref_chan[i].op_class,
409					  p2p->cfg->pref_chan[i].chan)) {
410			p2p->op_reg_class = p2p->cfg->pref_chan[i].op_class;
411			p2p->op_channel = p2p->cfg->pref_chan[i].chan;
412			p2p_dbg(p2p, "Pick highest preferred channel (op_class %u channel %u) from intersection",
413				p2p->op_reg_class, p2p->op_channel);
414			return;
415		}
416	}
417
418	/* Try a channel where we might be able to use VHT */
419	if (p2p_channel_select(intersection, op_classes_vht,
420			       &p2p->op_reg_class, &p2p->op_channel) == 0) {
421		p2p_dbg(p2p, "Pick possible VHT channel (op_class %u channel %u) from intersection",
422			p2p->op_reg_class, p2p->op_channel);
423		return;
424	}
425
426	/* Try a channel where we might be able to use HT40 */
427	if (p2p_channel_select(intersection, op_classes_ht40,
428			       &p2p->op_reg_class, &p2p->op_channel) == 0) {
429		p2p_dbg(p2p, "Pick possible HT40 channel (op_class %u channel %u) from intersection",
430			p2p->op_reg_class, p2p->op_channel);
431		return;
432	}
433
434	/* Prefer a 5 GHz channel */
435	if (p2p_channel_select(intersection, op_classes_5ghz,
436			       &p2p->op_reg_class, &p2p->op_channel) == 0) {
437		p2p_dbg(p2p, "Pick possible 5 GHz channel (op_class %u channel %u) from intersection",
438			p2p->op_reg_class, p2p->op_channel);
439		return;
440	}
441
442	/*
443	 * Try to see if the original channel is in the intersection. If
444	 * so, no need to change anything, as it already contains some
445	 * randomness.
446	 */
447	if (p2p_channels_includes(intersection, p2p->op_reg_class,
448				  p2p->op_channel)) {
449		p2p_dbg(p2p, "Using original operating class and channel (op_class %u channel %u) from intersection",
450			p2p->op_reg_class, p2p->op_channel);
451		return;
452	}
453
454	/*
455	 * Fall back to whatever is included in the channel intersection since
456	 * no better options seems to be available.
457	 */
458	cl = &intersection->reg_class[0];
459	p2p_dbg(p2p, "Pick another channel (reg_class %u channel %u) from intersection",
460		cl->reg_class, cl->channel[0]);
461	p2p->op_reg_class = cl->reg_class;
462	p2p->op_channel = cl->channel[0];
463}
464
465
466static int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev,
467				 u8 *status)
468{
469	struct p2p_channels tmp, intersection;
470
471	p2p_channels_dump(p2p, "own channels", &p2p->channels);
472	p2p_channels_dump(p2p, "peer channels", &dev->channels);
473	p2p_channels_intersect(&p2p->channels, &dev->channels, &tmp);
474	p2p_channels_dump(p2p, "intersection", &tmp);
475	p2p_channels_remove_freqs(&tmp, &p2p->no_go_freq);
476	p2p_channels_dump(p2p, "intersection after no-GO removal", &tmp);
477	p2p_channels_intersect(&tmp, &p2p->cfg->channels, &intersection);
478	p2p_channels_dump(p2p, "intersection with local channel list",
479			  &intersection);
480	if (intersection.reg_classes == 0 ||
481	    intersection.reg_class[0].channels == 0) {
482		*status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
483		p2p_dbg(p2p, "No common channels found");
484		return -1;
485	}
486
487	if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
488				   p2p->op_channel)) {
489		if (dev->flags & P2P_DEV_FORCE_FREQ) {
490			*status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
491			p2p_dbg(p2p, "Peer does not support the forced channel");
492			return -1;
493		}
494
495		p2p_dbg(p2p, "Selected operating channel (op_class %u channel %u) not acceptable to the peer",
496			p2p->op_reg_class, p2p->op_channel);
497		p2p_reselect_channel(p2p, &intersection);
498	} else if (!(dev->flags & P2P_DEV_FORCE_FREQ) &&
499		   !p2p->cfg->cfg_op_channel) {
500		p2p_dbg(p2p, "Try to optimize channel selection with peer information received; previously selected op_class %u channel %u",
501			p2p->op_reg_class, p2p->op_channel);
502		p2p_reselect_channel(p2p, &intersection);
503	}
504
505	if (!p2p->ssid_set) {
506		p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
507		p2p->ssid_set = 1;
508	}
509
510	return 0;
511}
512
513
514void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
515			    const u8 *data, size_t len, int rx_freq)
516{
517	struct p2p_device *dev = NULL;
518	struct wpabuf *resp;
519	struct p2p_message msg;
520	u8 status = P2P_SC_FAIL_INVALID_PARAMS;
521	int tie_breaker = 0;
522	int freq;
523
524	p2p_dbg(p2p, "Received GO Negotiation Request from " MACSTR "(freq=%d)",
525		MAC2STR(sa), rx_freq);
526
527	if (p2p_parse(data, len, &msg))
528		return;
529
530	if (!msg.capability) {
531		p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Request");
532#ifdef CONFIG_P2P_STRICT
533		goto fail;
534#endif /* CONFIG_P2P_STRICT */
535	}
536
537	if (msg.go_intent)
538		tie_breaker = *msg.go_intent & 0x01;
539	else {
540		p2p_dbg(p2p, "Mandatory GO Intent attribute missing from GO Negotiation Request");
541#ifdef CONFIG_P2P_STRICT
542		goto fail;
543#endif /* CONFIG_P2P_STRICT */
544	}
545
546	if (!msg.config_timeout) {
547		p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Request");
548#ifdef CONFIG_P2P_STRICT
549		goto fail;
550#endif /* CONFIG_P2P_STRICT */
551	}
552
553	if (!msg.listen_channel) {
554		p2p_dbg(p2p, "No Listen Channel attribute received");
555		goto fail;
556	}
557	if (!msg.operating_channel) {
558		p2p_dbg(p2p, "No Operating Channel attribute received");
559		goto fail;
560	}
561	if (!msg.channel_list) {
562		p2p_dbg(p2p, "No Channel List attribute received");
563		goto fail;
564	}
565	if (!msg.intended_addr) {
566		p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
567		goto fail;
568	}
569	if (!msg.p2p_device_info) {
570		p2p_dbg(p2p, "No P2P Device Info attribute received");
571		goto fail;
572	}
573
574	if (os_memcmp(msg.p2p_device_addr, sa, ETH_ALEN) != 0) {
575		p2p_dbg(p2p, "Unexpected GO Negotiation Request SA=" MACSTR
576			" != dev_addr=" MACSTR,
577			MAC2STR(sa), MAC2STR(msg.p2p_device_addr));
578		goto fail;
579	}
580
581	dev = p2p_get_device(p2p, sa);
582
583	if (msg.status && *msg.status) {
584		p2p_dbg(p2p, "Unexpected Status attribute (%d) in GO Negotiation Request",
585			*msg.status);
586		goto fail;
587	}
588
589	if (dev == NULL)
590		dev = p2p_add_dev_from_go_neg_req(p2p, sa, &msg);
591	else if (dev->flags & P2P_DEV_PROBE_REQ_ONLY)
592		p2p_add_dev_info(p2p, sa, dev, &msg);
593	else if (!dev->listen_freq && !dev->oper_freq) {
594		/*
595		 * This may happen if the peer entry was added based on PD
596		 * Request and no Probe Request/Response frame has been received
597		 * from this peer (or that information has timed out).
598		 */
599		p2p_dbg(p2p, "Update peer " MACSTR
600			" based on GO Neg Req since listen/oper freq not known",
601			MAC2STR(dev->info.p2p_device_addr));
602		p2p_add_dev_info(p2p, sa, dev, &msg);
603	}
604
605	if (dev && dev->flags & P2P_DEV_USER_REJECTED) {
606		p2p_dbg(p2p, "User has rejected this peer");
607		status = P2P_SC_FAIL_REJECTED_BY_USER;
608	} else if (dev == NULL || dev->wps_method == WPS_NOT_READY) {
609		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
610			MAC2STR(sa));
611		status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
612		p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa,
613					msg.dev_password_id);
614	} else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
615		p2p_dbg(p2p, "Already in Group Formation with another peer");
616		status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
617	} else {
618		int go;
619
620		if (!p2p->go_neg_peer) {
621			p2p_dbg(p2p, "Starting GO Negotiation with previously authorized peer");
622			if (!(dev->flags & P2P_DEV_FORCE_FREQ)) {
623				p2p_dbg(p2p, "Use default channel settings");
624				p2p->op_reg_class = p2p->cfg->op_reg_class;
625				p2p->op_channel = p2p->cfg->op_channel;
626				os_memcpy(&p2p->channels, &p2p->cfg->channels,
627					  sizeof(struct p2p_channels));
628			} else {
629				p2p_dbg(p2p, "Use previously configured forced channel settings");
630			}
631		}
632
633		dev->flags &= ~P2P_DEV_NOT_YET_READY;
634
635		if (!msg.go_intent) {
636			p2p_dbg(p2p, "No GO Intent attribute received");
637			goto fail;
638		}
639		if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
640			p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
641				*msg.go_intent >> 1);
642			goto fail;
643		}
644
645		if (dev->go_neg_req_sent &&
646		    os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) > 0) {
647			p2p_dbg(p2p, "Do not reply since peer has higher address and GO Neg Request already sent");
648			p2p_parse_free(&msg);
649			return;
650		}
651
652		go = p2p_go_det(p2p->go_intent, *msg.go_intent);
653		if (go < 0) {
654			p2p_dbg(p2p, "Incompatible GO Intent");
655			status = P2P_SC_FAIL_BOTH_GO_INTENT_15;
656			goto fail;
657		}
658
659		if (p2p_peer_channels(p2p, dev, msg.channel_list,
660				      msg.channel_list_len) < 0) {
661			p2p_dbg(p2p, "No common channels found");
662			status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
663			goto fail;
664		}
665
666		switch (msg.dev_password_id) {
667		case DEV_PW_REGISTRAR_SPECIFIED:
668			p2p_dbg(p2p, "PIN from peer Display");
669			if (dev->wps_method != WPS_PIN_KEYPAD) {
670				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
671					p2p_wps_method_str(dev->wps_method));
672				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
673				goto fail;
674			}
675			break;
676		case DEV_PW_USER_SPECIFIED:
677			p2p_dbg(p2p, "Peer entered PIN on Keypad");
678			if (dev->wps_method != WPS_PIN_DISPLAY) {
679				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
680					p2p_wps_method_str(dev->wps_method));
681				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
682				goto fail;
683			}
684			break;
685		case DEV_PW_PUSHBUTTON:
686			p2p_dbg(p2p, "Peer using pushbutton");
687			if (dev->wps_method != WPS_PBC) {
688				p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
689					p2p_wps_method_str(dev->wps_method));
690				status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
691				goto fail;
692			}
693			break;
694		default:
695			p2p_dbg(p2p, "Unsupported Device Password ID %d",
696				msg.dev_password_id);
697			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
698			goto fail;
699		}
700
701		if (go && p2p_go_select_channel(p2p, dev, &status) < 0)
702			goto fail;
703
704		dev->go_state = go ? LOCAL_GO : REMOTE_GO;
705		dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
706						     msg.operating_channel[4]);
707		p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
708			dev->oper_freq);
709
710		if (msg.config_timeout) {
711			dev->go_timeout = msg.config_timeout[0];
712			dev->client_timeout = msg.config_timeout[1];
713		}
714
715		p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
716		if (p2p->state != P2P_IDLE)
717			p2p_stop_find_for_freq(p2p, rx_freq);
718		p2p_set_state(p2p, P2P_GO_NEG);
719		p2p_clear_timeout(p2p);
720		dev->dialog_token = msg.dialog_token;
721		os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
722		p2p->go_neg_peer = dev;
723		status = P2P_SC_SUCCESS;
724	}
725
726fail:
727	if (dev)
728		dev->status = status;
729	resp = p2p_build_go_neg_resp(p2p, dev, msg.dialog_token, status,
730				     !tie_breaker);
731	p2p_parse_free(&msg);
732	if (resp == NULL)
733		return;
734	p2p_dbg(p2p, "Sending GO Negotiation Response");
735	if (rx_freq > 0)
736		freq = rx_freq;
737	else
738		freq = p2p_channel_to_freq(p2p->cfg->reg_class,
739					   p2p->cfg->channel);
740	if (freq < 0) {
741		p2p_dbg(p2p, "Unknown regulatory class/channel");
742		wpabuf_free(resp);
743		return;
744	}
745	if (status == P2P_SC_SUCCESS) {
746		p2p->pending_action_state = P2P_PENDING_GO_NEG_RESPONSE;
747		dev->flags |= P2P_DEV_WAIT_GO_NEG_CONFIRM;
748		if (os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) < 0) {
749			/*
750			 * Peer has smaller address, so the GO Negotiation
751			 * Response from us is expected to complete
752			 * negotiation. Ignore a GO Negotiation Response from
753			 * the peer if it happens to be received after this
754			 * point due to a race condition in GO Negotiation
755			 * Request transmission and processing.
756			 */
757			dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
758		}
759	} else
760		p2p->pending_action_state =
761			P2P_PENDING_GO_NEG_RESPONSE_FAILURE;
762	if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
763			    p2p->cfg->dev_addr,
764			    wpabuf_head(resp), wpabuf_len(resp), 500) < 0) {
765		p2p_dbg(p2p, "Failed to send Action frame");
766	}
767
768	wpabuf_free(resp);
769}
770
771
772static struct wpabuf * p2p_build_go_neg_conf(struct p2p_data *p2p,
773					     struct p2p_device *peer,
774					     u8 dialog_token, u8 status,
775					     const u8 *resp_chan, int go)
776{
777	struct wpabuf *buf;
778	u8 *len;
779	struct p2p_channels res;
780	u8 group_capab;
781	size_t extra = 0;
782
783	p2p_dbg(p2p, "Building GO Negotiation Confirm");
784
785#ifdef CONFIG_WIFI_DISPLAY
786	if (p2p->wfd_ie_go_neg)
787		extra = wpabuf_len(p2p->wfd_ie_go_neg);
788#endif /* CONFIG_WIFI_DISPLAY */
789
790	buf = wpabuf_alloc(1000 + extra);
791	if (buf == NULL)
792		return NULL;
793
794	p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_CONF, dialog_token);
795
796	len = p2p_buf_add_ie_hdr(buf);
797	p2p_buf_add_status(buf, status);
798	group_capab = 0;
799	if (peer->go_state == LOCAL_GO) {
800		if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
801			group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
802			if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
803				group_capab |=
804					P2P_GROUP_CAPAB_PERSISTENT_RECONN;
805		}
806		if (p2p->cross_connect)
807			group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
808		if (p2p->cfg->p2p_intra_bss)
809			group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
810	}
811	p2p_buf_add_capability(buf, p2p->dev_capab &
812			       ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
813			       group_capab);
814	if (go || resp_chan == NULL)
815		p2p_buf_add_operating_channel(buf, p2p->cfg->country,
816					      p2p->op_reg_class,
817					      p2p->op_channel);
818	else
819		p2p_buf_add_operating_channel(buf, (const char *) resp_chan,
820					      resp_chan[3], resp_chan[4]);
821	p2p_channels_intersect(&p2p->channels, &peer->channels, &res);
822	p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
823	if (go) {
824		p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
825				     p2p->ssid_len);
826	}
827	p2p_buf_update_ie_hdr(buf, len);
828
829#ifdef CONFIG_WIFI_DISPLAY
830	if (p2p->wfd_ie_go_neg)
831		wpabuf_put_buf(buf, p2p->wfd_ie_go_neg);
832#endif /* CONFIG_WIFI_DISPLAY */
833
834	return buf;
835}
836
837
838void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
839			     const u8 *data, size_t len, int rx_freq)
840{
841	struct p2p_device *dev;
842	struct wpabuf *conf;
843	int go = -1;
844	struct p2p_message msg;
845	u8 status = P2P_SC_SUCCESS;
846	int freq;
847
848	p2p_dbg(p2p, "Received GO Negotiation Response from " MACSTR
849		" (freq=%d)", MAC2STR(sa), rx_freq);
850	dev = p2p_get_device(p2p, sa);
851	if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
852	    dev != p2p->go_neg_peer) {
853		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
854			MAC2STR(sa));
855		return;
856	}
857
858	if (p2p_parse(data, len, &msg))
859		return;
860
861	if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE)) {
862		p2p_dbg(p2p, "Was not expecting GO Negotiation Response - ignore");
863		p2p_parse_free(&msg);
864		return;
865	}
866	dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
867
868	if (msg.dialog_token != dev->dialog_token) {
869		p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
870			msg.dialog_token, dev->dialog_token);
871		p2p_parse_free(&msg);
872		return;
873	}
874
875	if (!msg.status) {
876		p2p_dbg(p2p, "No Status attribute received");
877		status = P2P_SC_FAIL_INVALID_PARAMS;
878		goto fail;
879	}
880	if (*msg.status) {
881		p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
882		dev->go_neg_req_sent = 0;
883		if (*msg.status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
884			p2p_dbg(p2p, "Wait for the peer to become ready for GO Negotiation");
885			dev->flags |= P2P_DEV_NOT_YET_READY;
886			dev->wait_count = 0;
887			p2p_set_state(p2p, P2P_WAIT_PEER_IDLE);
888			p2p_set_timeout(p2p, 0, 0);
889		} else {
890			p2p_dbg(p2p, "Stop GO Negotiation attempt");
891			p2p_go_neg_failed(p2p, dev, *msg.status);
892		}
893		p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
894		p2p_parse_free(&msg);
895		return;
896	}
897
898	if (!msg.capability) {
899		p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Response");
900#ifdef CONFIG_P2P_STRICT
901		status = P2P_SC_FAIL_INVALID_PARAMS;
902		goto fail;
903#endif /* CONFIG_P2P_STRICT */
904	}
905
906	if (!msg.p2p_device_info) {
907		p2p_dbg(p2p, "Mandatory P2P Device Info attribute missing from GO Negotiation Response");
908#ifdef CONFIG_P2P_STRICT
909		status = P2P_SC_FAIL_INVALID_PARAMS;
910		goto fail;
911#endif /* CONFIG_P2P_STRICT */
912	}
913
914	if (!msg.intended_addr) {
915		p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
916		status = P2P_SC_FAIL_INVALID_PARAMS;
917		goto fail;
918	}
919
920	if (!msg.go_intent) {
921		p2p_dbg(p2p, "No GO Intent attribute received");
922		status = P2P_SC_FAIL_INVALID_PARAMS;
923		goto fail;
924	}
925	if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
926		p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
927			*msg.go_intent >> 1);
928		status = P2P_SC_FAIL_INVALID_PARAMS;
929		goto fail;
930	}
931
932	go = p2p_go_det(p2p->go_intent, *msg.go_intent);
933	if (go < 0) {
934		p2p_dbg(p2p, "Incompatible GO Intent");
935		status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
936		goto fail;
937	}
938
939	if (!go && msg.group_id) {
940		/* Store SSID for Provisioning step */
941		p2p->ssid_len = msg.group_id_len - ETH_ALEN;
942		os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
943	} else if (!go) {
944		p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Response");
945		p2p->ssid_len = 0;
946		status = P2P_SC_FAIL_INVALID_PARAMS;
947		goto fail;
948	}
949
950	if (!msg.config_timeout) {
951		p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Response");
952#ifdef CONFIG_P2P_STRICT
953		status = P2P_SC_FAIL_INVALID_PARAMS;
954		goto fail;
955#endif /* CONFIG_P2P_STRICT */
956	} else {
957		dev->go_timeout = msg.config_timeout[0];
958		dev->client_timeout = msg.config_timeout[1];
959	}
960
961	if (!msg.operating_channel && !go) {
962		/*
963		 * Note: P2P Client may omit Operating Channel attribute to
964		 * indicate it does not have a preference.
965		 */
966		p2p_dbg(p2p, "No Operating Channel attribute received");
967		status = P2P_SC_FAIL_INVALID_PARAMS;
968		goto fail;
969	}
970	if (!msg.channel_list) {
971		p2p_dbg(p2p, "No Channel List attribute received");
972		status = P2P_SC_FAIL_INVALID_PARAMS;
973		goto fail;
974	}
975
976	if (p2p_peer_channels(p2p, dev, msg.channel_list,
977			      msg.channel_list_len) < 0) {
978		p2p_dbg(p2p, "No common channels found");
979		status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
980		goto fail;
981	}
982
983	if (msg.operating_channel) {
984		dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
985						     msg.operating_channel[4]);
986		p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
987			dev->oper_freq);
988	} else
989		dev->oper_freq = 0;
990
991	switch (msg.dev_password_id) {
992	case DEV_PW_REGISTRAR_SPECIFIED:
993		p2p_dbg(p2p, "PIN from peer Display");
994		if (dev->wps_method != WPS_PIN_KEYPAD) {
995			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
996				p2p_wps_method_str(dev->wps_method));
997			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
998			goto fail;
999		}
1000		break;
1001	case DEV_PW_USER_SPECIFIED:
1002		p2p_dbg(p2p, "Peer entered PIN on Keypad");
1003		if (dev->wps_method != WPS_PIN_DISPLAY) {
1004			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
1005				p2p_wps_method_str(dev->wps_method));
1006			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1007			goto fail;
1008		}
1009		break;
1010	case DEV_PW_PUSHBUTTON:
1011		p2p_dbg(p2p, "Peer using pushbutton");
1012		if (dev->wps_method != WPS_PBC) {
1013			p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
1014				p2p_wps_method_str(dev->wps_method));
1015			status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1016			goto fail;
1017		}
1018		break;
1019	default:
1020		p2p_dbg(p2p, "Unsupported Device Password ID %d",
1021			msg.dev_password_id);
1022		status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
1023		goto fail;
1024	}
1025
1026	if (go && p2p_go_select_channel(p2p, dev, &status) < 0)
1027		goto fail;
1028
1029	p2p_set_state(p2p, P2P_GO_NEG);
1030	p2p_clear_timeout(p2p);
1031
1032	p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
1033	os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
1034
1035fail:
1036	conf = p2p_build_go_neg_conf(p2p, dev, msg.dialog_token, status,
1037				     msg.operating_channel, go);
1038	p2p_parse_free(&msg);
1039	if (conf == NULL)
1040		return;
1041	p2p_dbg(p2p, "Sending GO Negotiation Confirm");
1042	if (status == P2P_SC_SUCCESS) {
1043		p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM;
1044		dev->go_state = go ? LOCAL_GO : REMOTE_GO;
1045	} else
1046		p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1047	if (rx_freq > 0)
1048		freq = rx_freq;
1049	else
1050		freq = dev->listen_freq;
1051	if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, sa,
1052			    wpabuf_head(conf), wpabuf_len(conf), 200) < 0) {
1053		p2p_dbg(p2p, "Failed to send Action frame");
1054		p2p_go_neg_failed(p2p, dev, -1);
1055		p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
1056	}
1057	wpabuf_free(conf);
1058	if (status != P2P_SC_SUCCESS) {
1059		p2p_dbg(p2p, "GO Negotiation failed");
1060		p2p_go_neg_failed(p2p, dev, status);
1061	}
1062}
1063
1064
1065void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
1066			     const u8 *data, size_t len)
1067{
1068	struct p2p_device *dev;
1069	struct p2p_message msg;
1070
1071	p2p_dbg(p2p, "Received GO Negotiation Confirm from " MACSTR,
1072		MAC2STR(sa));
1073	dev = p2p_get_device(p2p, sa);
1074	if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
1075	    dev != p2p->go_neg_peer) {
1076		p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
1077			MAC2STR(sa));
1078		return;
1079	}
1080
1081	if (p2p->pending_action_state == P2P_PENDING_GO_NEG_RESPONSE) {
1082		p2p_dbg(p2p, "Stopped waiting for TX status on GO Negotiation Response since we already received Confirmation");
1083		p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1084	}
1085
1086	if (p2p_parse(data, len, &msg))
1087		return;
1088
1089	if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
1090		p2p_dbg(p2p, "Was not expecting GO Negotiation Confirm - ignore");
1091		return;
1092	}
1093	dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM;
1094	p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
1095
1096	if (msg.dialog_token != dev->dialog_token) {
1097		p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
1098			msg.dialog_token, dev->dialog_token);
1099		p2p_parse_free(&msg);
1100		return;
1101	}
1102
1103	if (!msg.status) {
1104		p2p_dbg(p2p, "No Status attribute received");
1105		p2p_parse_free(&msg);
1106		return;
1107	}
1108	if (*msg.status) {
1109		p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
1110		p2p_go_neg_failed(p2p, dev, *msg.status);
1111		p2p_parse_free(&msg);
1112		return;
1113	}
1114
1115	if (dev->go_state == REMOTE_GO && msg.group_id) {
1116		/* Store SSID for Provisioning step */
1117		p2p->ssid_len = msg.group_id_len - ETH_ALEN;
1118		os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
1119	} else if (dev->go_state == REMOTE_GO) {
1120		p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Confirmation");
1121		p2p->ssid_len = 0;
1122		p2p_go_neg_failed(p2p, dev, P2P_SC_FAIL_INVALID_PARAMS);
1123		p2p_parse_free(&msg);
1124		return;
1125	}
1126
1127	if (!msg.operating_channel) {
1128		p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
1129#ifdef CONFIG_P2P_STRICT
1130		p2p_parse_free(&msg);
1131		return;
1132#endif /* CONFIG_P2P_STRICT */
1133	} else if (dev->go_state == REMOTE_GO) {
1134		int oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
1135						    msg.operating_channel[4]);
1136		if (oper_freq != dev->oper_freq) {
1137			p2p_dbg(p2p, "Updated peer (GO) operating channel preference from %d MHz to %d MHz",
1138				dev->oper_freq, oper_freq);
1139			dev->oper_freq = oper_freq;
1140		}
1141	}
1142
1143	if (!msg.channel_list) {
1144		p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
1145#ifdef CONFIG_P2P_STRICT
1146		p2p_parse_free(&msg);
1147		return;
1148#endif /* CONFIG_P2P_STRICT */
1149	}
1150
1151	p2p_parse_free(&msg);
1152
1153	if (dev->go_state == UNKNOWN_GO) {
1154		/*
1155		 * This should not happen since GO negotiation has already
1156		 * been completed.
1157		 */
1158		p2p_dbg(p2p, "Unexpected GO Neg state - do not know which end becomes GO");
1159		return;
1160	}
1161
1162	/*
1163	 * The peer could have missed our ctrl::ack frame for GO Negotiation
1164	 * Confirm and continue retransmitting the frame. To reduce the
1165	 * likelihood of the peer not getting successful TX status for the
1166	 * GO Negotiation Confirm frame, wait a short time here before starting
1167	 * the group so that we will remain on the current channel to
1168	 * acknowledge any possible retransmission from the peer.
1169	 */
1170	p2p_dbg(p2p, "20 ms wait on current channel before starting group");
1171	os_sleep(0, 20000);
1172
1173	p2p_go_complete(p2p, dev);
1174}
1175