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