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