2 * Wi-Fi Direct - P2P Group Owner Negotiation
3 * Copyright (c) 2009-2010, Atheros Communications
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "common/ieee802_11_defs.h"
19 #include "wps/wps_defs.h"
24 static int p2p_go_det(u8 own_intent, u8 peer_value)
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 */
31 /* Use tie breaker bit to determine GO */
32 return (peer_value & 0x01) ? 0 : 1;
35 return own_intent > peer_intent;
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)
44 struct p2p_channels *ch;
46 struct p2p_channels intersection;
49 os_memset(ch, 0, sizeof(*ch));
51 end = channel_list + channel_list_len;
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],
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");
75 cl->channels = channels > P2P_MAX_REG_CLASS_CHANNELS ?
76 P2P_MAX_REG_CLASS_CHANNELS : channels;
77 os_memcpy(cl->channel, pos, cl->channels);
80 if (ch->reg_classes == P2P_MAX_REG_CLASSES)
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");
99 static int p2p_peer_channels(struct p2p_data *p2p, struct p2p_device *dev,
100 const u8 *channel_list, size_t channel_list_len)
102 return p2p_peer_channels_check(p2p, &p2p->channels, dev,
103 channel_list, channel_list_len);
107 static u16 p2p_wps_method_pw_id(enum p2p_wps_method wps_method)
109 switch (wps_method) {
111 return DEV_PW_DEFAULT;
112 case WPS_PIN_DISPLAY:
113 return DEV_PW_REGISTRAR_SPECIFIED;
115 return DEV_PW_USER_SPECIFIED;
117 return DEV_PW_PUSHBUTTON;
119 return DEV_PW_DEFAULT;
124 static const char * p2p_wps_method_str(enum p2p_wps_method wps_method)
126 switch (wps_method) {
129 case WPS_PIN_DISPLAY:
141 static struct wpabuf * p2p_build_go_neg_req(struct p2p_data *p2p,
142 struct p2p_device *peer)
148 buf = wpabuf_alloc(1000);
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);
157 len = p2p_buf_add_ie_hdr(buf);
159 if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP)
160 group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
161 p2p_buf_add_capability(buf, p2p->dev_capab, group_capab);
162 p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) |
163 p2p->next_tie_breaker);
164 p2p->next_tie_breaker = !p2p->next_tie_breaker;
165 p2p_buf_add_config_timeout(buf, 100, 20);
166 p2p_buf_add_listen_channel(buf, p2p->cfg->country, p2p->cfg->reg_class,
168 if (p2p->ext_listen_interval)
169 p2p_buf_add_ext_listen_timing(buf, p2p->ext_listen_period,
170 p2p->ext_listen_interval);
171 p2p_buf_add_intended_addr(buf, p2p->intended_addr);
172 p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels);
173 p2p_buf_add_device_info(buf, p2p, peer);
174 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
175 p2p->op_reg_class, p2p->op_channel);
176 p2p_buf_update_ie_hdr(buf, len);
178 /* WPS IE with Device Password ID attribute */
179 p2p_build_wps_ie(p2p, buf, p2p_wps_method_pw_id(peer->wps_method), 0);
185 int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
190 freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
192 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
193 "P2P: No Listen/Operating frequency known for the "
194 "peer " MACSTR " to send GO Negotiation Request",
195 MAC2STR(dev->p2p_device_addr));
199 req = p2p_build_go_neg_req(p2p, dev);
202 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
203 "P2P: Sending GO Negotiation Request");
204 p2p_set_state(p2p, P2P_CONNECT);
205 p2p->pending_action_state = P2P_PENDING_GO_NEG_REQUEST;
206 p2p->go_neg_peer = dev;
207 dev->flags |= P2P_DEV_WAIT_GO_NEG_RESPONSE;
208 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq,
209 dev->p2p_device_addr, p2p->cfg->dev_addr,
210 dev->p2p_device_addr,
211 wpabuf_head(req), wpabuf_len(req), 200) < 0)
213 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
214 "P2P: Failed to send Action frame");
215 /* Use P2P find to recover and retry */
216 p2p_set_timeout(p2p, 0, 0);
225 static struct wpabuf * p2p_build_go_neg_resp(struct p2p_data *p2p,
226 struct p2p_device *peer,
227 u8 dialog_token, u8 status,
234 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
235 "P2P: Building GO Negotiation Response");
236 buf = wpabuf_alloc(1000);
240 p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_RESP, dialog_token);
242 len = p2p_buf_add_ie_hdr(buf);
243 p2p_buf_add_status(buf, status);
245 if (peer && (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP))
246 group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
247 p2p_buf_add_capability(buf, p2p->dev_capab, group_capab);
248 p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) | tie_breaker);
249 p2p_buf_add_config_timeout(buf, 100, 20);
250 if (peer && peer->go_state == REMOTE_GO) {
251 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Omit Operating "
252 "Channel attribute");
254 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
258 p2p_buf_add_intended_addr(buf, p2p->intended_addr);
259 if (status || peer == NULL) {
260 p2p_buf_add_channel_list(buf, p2p->cfg->country,
262 } else if (peer->go_state == REMOTE_GO) {
263 p2p_buf_add_channel_list(buf, p2p->cfg->country,
266 struct p2p_channels res;
267 p2p_channels_intersect(&p2p->channels, &peer->channels,
269 p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
271 p2p_buf_add_device_info(buf, p2p, peer);
272 if (peer && peer->go_state == LOCAL_GO) {
273 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
276 p2p_buf_update_ie_hdr(buf, len);
278 /* WPS IE with Device Password ID attribute */
279 p2p_build_wps_ie(p2p, buf,
280 p2p_wps_method_pw_id(peer ? peer->wps_method :
287 void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
288 const u8 *data, size_t len, int rx_freq)
290 struct p2p_device *dev = NULL;
292 struct p2p_message msg;
293 u8 status = P2P_SC_FAIL_INVALID_PARAMS;
297 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
298 "P2P: Received GO Negotiation Request from " MACSTR
299 "(freq=%d)", MAC2STR(sa), rx_freq);
301 if (p2p_parse(data, len, &msg))
304 if (!msg.capability) {
305 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
306 "P2P: Mandatory Capability attribute missing from GO "
307 "Negotiation Request");
308 #ifdef CONFIG_P2P_STRICT
310 #endif /* CONFIG_P2P_STRICT */
314 tie_breaker = *msg.go_intent & 0x01;
316 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
317 "P2P: Mandatory GO Intent attribute missing from GO "
318 "Negotiation Request");
319 #ifdef CONFIG_P2P_STRICT
321 #endif /* CONFIG_P2P_STRICT */
324 if (!msg.config_timeout) {
325 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
326 "P2P: Mandatory Configuration Timeout attribute "
327 "missing from GO Negotiation Request");
328 #ifdef CONFIG_P2P_STRICT
330 #endif /* CONFIG_P2P_STRICT */
333 if (!msg.listen_channel) {
334 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
335 "P2P: No Listen Channel attribute received");
338 if (!msg.operating_channel) {
339 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
340 "P2P: No Operating Channel attribute received");
343 if (!msg.channel_list) {
344 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
345 "P2P: No Channel List attribute received");
348 if (!msg.intended_addr) {
349 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
350 "P2P: No Intended P2P Interface Address attribute "
354 if (!msg.p2p_device_info) {
355 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
356 "P2P: No P2P Device Info attribute received");
360 if (os_memcmp(msg.p2p_device_addr, sa, ETH_ALEN) != 0) {
361 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
362 "P2P: Unexpected GO Negotiation Request SA=" MACSTR
363 " != dev_addr=" MACSTR,
364 MAC2STR(sa), MAC2STR(msg.p2p_device_addr));
368 dev = p2p_get_device(p2p, sa);
370 if (msg.status && *msg.status) {
371 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
372 "P2P: Unexpected Status attribute (%d) in GO "
373 "Negotiation Request", *msg.status);
378 dev = p2p_add_dev_from_go_neg_req(p2p, sa, &msg);
379 else if (dev->flags & P2P_DEV_PROBE_REQ_ONLY)
380 p2p_add_dev_info(p2p, sa, dev, &msg);
381 if (dev && dev->flags & P2P_DEV_USER_REJECTED) {
382 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
383 "P2P: User has rejected this peer");
384 status = P2P_SC_FAIL_REJECTED_BY_USER;
385 } else if (dev == NULL || dev->wps_method == WPS_NOT_READY) {
386 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
387 "P2P: Not ready for GO negotiation with " MACSTR,
389 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
391 dev->flags |= P2P_DEV_PEER_WAITING_RESPONSE;
392 p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa);
393 } else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
394 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
395 "P2P: Already in Group Formation with another peer");
396 status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
400 if (!p2p->go_neg_peer) {
401 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting "
402 "GO Negotiation with previously authorized "
404 if (!(dev->flags & P2P_DEV_FORCE_FREQ)) {
405 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
406 "P2P: Use default channel settings");
407 p2p->op_reg_class = p2p->cfg->op_reg_class;
408 p2p->op_channel = p2p->cfg->op_channel;
409 os_memcpy(&p2p->channels, &p2p->cfg->channels,
410 sizeof(struct p2p_channels));
412 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
413 "P2P: Use previously configured "
414 "forced channel settings");
418 dev->flags &= ~P2P_DEV_NOT_YET_READY;
420 if (!msg.go_intent) {
421 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
422 "P2P: No GO Intent attribute received");
425 if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
426 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
427 "P2P: Invalid GO Intent value (%u) received",
428 *msg.go_intent >> 1);
432 if (dev->go_neg_req_sent &&
433 os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) > 0) {
434 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
435 "P2P: Do not reply since peer has higher "
436 "address and GO Neg Request already sent");
437 p2p_parse_free(&msg);
441 go = p2p_go_det(p2p->go_intent, *msg.go_intent);
443 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
444 "P2P: Incompatible GO Intent");
445 status = P2P_SC_FAIL_BOTH_GO_INTENT_15;
449 if (p2p_peer_channels(p2p, dev, msg.channel_list,
450 msg.channel_list_len) < 0) {
451 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
452 "P2P: No common channels found");
453 status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
457 switch (msg.dev_password_id) {
459 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
460 "P2P: PIN from peer Label");
461 if (dev->wps_method != WPS_PIN_KEYPAD) {
462 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
463 "P2P: We have wps_method=%s -> "
465 p2p_wps_method_str(dev->wps_method));
466 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
470 case DEV_PW_REGISTRAR_SPECIFIED:
471 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
472 "P2P: PIN from peer Display");
473 if (dev->wps_method != WPS_PIN_KEYPAD) {
474 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
475 "P2P: We have wps_method=%s -> "
477 p2p_wps_method_str(dev->wps_method));
478 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
482 case DEV_PW_USER_SPECIFIED:
483 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
484 "P2P: Peer entered PIN on Keypad");
485 if (dev->wps_method != WPS_PIN_LABEL &&
486 dev->wps_method != WPS_PIN_DISPLAY) {
487 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
488 "P2P: We have wps_method=%s -> "
490 p2p_wps_method_str(dev->wps_method));
491 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
495 case DEV_PW_PUSHBUTTON:
496 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
497 "P2P: Peer using pushbutton");
498 if (dev->wps_method != WPS_PBC) {
499 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
500 "P2P: We have wps_method=%s -> "
502 p2p_wps_method_str(dev->wps_method));
503 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
508 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
509 "P2P: Unsupported Device Password ID %d",
510 msg.dev_password_id);
511 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
516 struct p2p_channels intersection;
518 p2p_channels_intersect(&p2p->channels, &dev->channels,
520 if (intersection.reg_classes == 0 ||
521 intersection.reg_class[0].channels == 0) {
522 status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
523 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
524 "P2P: No common channels found");
527 for (i = 0; i < intersection.reg_classes; i++) {
528 struct p2p_reg_class *c;
529 c = &intersection.reg_class[i];
530 wpa_printf(MSG_DEBUG, "P2P: reg_class %u",
532 wpa_hexdump(MSG_DEBUG, "P2P: channels",
533 c->channel, c->channels);
535 if (!p2p_channels_includes(&intersection,
538 struct p2p_reg_class *cl;
539 cl = &intersection.reg_class[0];
540 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
541 "P2P: Selected operating channel "
542 "(reg_class %u channel %u) not "
543 "acceptable to the peer - pick "
544 "another channel (reg_class %u "
546 p2p->op_reg_class, p2p->op_channel,
547 cl->reg_class, cl->channel[0]);
548 p2p->op_reg_class = cl->reg_class;
549 p2p->op_channel = cl->channel[0];
552 p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
555 dev->go_state = go ? LOCAL_GO : REMOTE_GO;
556 dev->oper_freq = p2p_channel_to_freq((const char *)
557 msg.operating_channel,
558 msg.operating_channel[3],
559 msg.operating_channel[4]);
560 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
561 "channel preference: %d MHz", dev->oper_freq);
563 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
564 "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
565 if (p2p->state != P2P_IDLE)
567 p2p_set_state(p2p, P2P_GO_NEG);
568 p2p_clear_timeout(p2p);
569 dev->dialog_token = msg.dialog_token;
570 os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
571 p2p->go_neg_peer = dev;
572 status = P2P_SC_SUCCESS;
576 resp = p2p_build_go_neg_resp(p2p, dev, msg.dialog_token, status,
578 p2p_parse_free(&msg);
581 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
582 "P2P: Sending GO Negotiation Response");
586 freq = p2p_channel_to_freq(p2p->cfg->country,
590 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
591 "P2P: Unknown regulatory class/channel");
595 if (status == P2P_SC_SUCCESS) {
596 p2p->pending_action_state = P2P_PENDING_GO_NEG_RESPONSE;
597 dev->flags |= P2P_DEV_WAIT_GO_NEG_CONFIRM;
599 p2p->pending_action_state =
600 P2P_PENDING_GO_NEG_RESPONSE_FAILURE;
601 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq, sa,
602 p2p->cfg->dev_addr, p2p->cfg->dev_addr,
603 wpabuf_head(resp), wpabuf_len(resp), 200) <
605 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
606 "P2P: Failed to send Action frame");
613 static struct wpabuf * p2p_build_go_neg_conf(struct p2p_data *p2p,
614 struct p2p_device *peer,
615 u8 dialog_token, u8 status,
616 const u8 *resp_chan, int go)
620 struct p2p_channels res;
623 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
624 "P2P: Building GO Negotiation Confirm");
625 buf = wpabuf_alloc(1000);
629 p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_CONF, dialog_token);
631 len = p2p_buf_add_ie_hdr(buf);
632 p2p_buf_add_status(buf, status);
634 if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP)
635 group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
636 p2p_buf_add_capability(buf, p2p->dev_capab, group_capab);
637 if (go || resp_chan == NULL)
638 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
642 p2p_buf_add_operating_channel(buf, (const char *) resp_chan,
643 resp_chan[3], resp_chan[4]);
644 p2p_channels_intersect(&p2p->channels, &peer->channels, &res);
645 p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
647 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
650 p2p_buf_update_ie_hdr(buf, len);
656 void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
657 const u8 *data, size_t len, int rx_freq)
659 struct p2p_device *dev;
662 struct p2p_message msg;
663 u8 status = P2P_SC_SUCCESS;
666 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
667 "P2P: Received GO Negotiation Response from " MACSTR
668 " (freq=%d)", MAC2STR(sa), rx_freq);
669 dev = p2p_get_device(p2p, sa);
670 if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
671 dev != p2p->go_neg_peer) {
672 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
673 "P2P: Not ready for GO negotiation with " MACSTR,
678 if (p2p_parse(data, len, &msg))
681 if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE)) {
682 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
683 "P2P: Was not expecting GO Negotiation Response - "
685 p2p_parse_free(&msg);
688 dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
690 if (msg.dialog_token != dev->dialog_token) {
691 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
692 "P2P: Unexpected Dialog Token %u (expected %u)",
693 msg.dialog_token, dev->dialog_token);
694 p2p_parse_free(&msg);
699 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
700 "P2P: No Status attribute received");
701 status = P2P_SC_FAIL_INVALID_PARAMS;
705 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
706 "P2P: GO Negotiation rejected: status %d",
708 dev->go_neg_req_sent = 0;
709 if (*msg.status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
710 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
711 "P2P: Wait for the peer to become ready for "
713 dev->flags |= P2P_DEV_NOT_YET_READY;
715 p2p_set_state(p2p, P2P_WAIT_PEER_IDLE);
716 p2p_set_timeout(p2p, 0, 0);
718 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
719 "P2P: Stop GO Negotiation attempt");
720 p2p_go_neg_failed(p2p, dev, *msg.status);
722 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
723 p2p_parse_free(&msg);
727 if (!msg.capability) {
728 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
729 "P2P: Mandatory Capability attribute missing from GO "
730 "Negotiation Response");
731 #ifdef CONFIG_P2P_STRICT
732 status = P2P_SC_FAIL_INVALID_PARAMS;
734 #endif /* CONFIG_P2P_STRICT */
737 if (!msg.p2p_device_info) {
738 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
739 "P2P: Mandatory P2P Device Info attribute missing "
740 "from GO Negotiation Response");
741 #ifdef CONFIG_P2P_STRICT
742 status = P2P_SC_FAIL_INVALID_PARAMS;
744 #endif /* CONFIG_P2P_STRICT */
747 if (!msg.intended_addr) {
748 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
749 "P2P: No Intended P2P Interface Address attribute "
751 status = P2P_SC_FAIL_INVALID_PARAMS;
755 if (!msg.go_intent) {
756 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
757 "P2P: No GO Intent attribute received");
758 status = P2P_SC_FAIL_INVALID_PARAMS;
761 if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
762 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
763 "P2P: Invalid GO Intent value (%u) received",
764 *msg.go_intent >> 1);
765 status = P2P_SC_FAIL_INVALID_PARAMS;
769 go = p2p_go_det(p2p->go_intent, *msg.go_intent);
771 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
772 "P2P: Incompatible GO Intent");
773 status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
777 if (!go && msg.group_id) {
778 /* TODO: Store SSID for Provisioning step */
780 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
781 "P2P: Mandatory P2P Group ID attribute missing from "
782 "GO Negotiation Response");
783 #ifdef CONFIG_P2P_STRICT
784 status = P2P_SC_FAIL_INVALID_PARAMS;
786 #endif /* CONFIG_P2P_STRICT */
789 if (!msg.config_timeout) {
790 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
791 "P2P: Mandatory Configuration Timeout attribute "
792 "missing from GO Negotiation Response");
793 #ifdef CONFIG_P2P_STRICT
794 status = P2P_SC_FAIL_INVALID_PARAMS;
796 #endif /* CONFIG_P2P_STRICT */
799 if (!msg.operating_channel && !go) {
801 * Note: P2P Client may omit Operating Channel attribute to
802 * indicate it does not have a preference.
804 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
805 "P2P: No Operating Channel attribute received");
806 status = P2P_SC_FAIL_INVALID_PARAMS;
809 if (!msg.channel_list) {
810 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
811 "P2P: No Channel List attribute received");
812 status = P2P_SC_FAIL_INVALID_PARAMS;
816 if (p2p_peer_channels(p2p, dev, msg.channel_list,
817 msg.channel_list_len) < 0) {
818 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
819 "P2P: No common channels found");
820 status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
824 if (msg.operating_channel) {
825 dev->oper_freq = p2p_channel_to_freq((const char *)
826 msg.operating_channel,
827 msg.operating_channel[3],
828 msg.operating_channel[4]);
829 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
830 "channel preference: %d MHz", dev->oper_freq);
834 switch (msg.dev_password_id) {
836 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
837 "P2P: PIN from peer Label");
838 if (dev->wps_method != WPS_PIN_KEYPAD) {
839 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
840 "P2P: We have wps_method=%s -> "
842 p2p_wps_method_str(dev->wps_method));
843 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
847 case DEV_PW_REGISTRAR_SPECIFIED:
848 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
849 "P2P: PIN from peer Display");
850 if (dev->wps_method != WPS_PIN_KEYPAD) {
851 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
852 "P2P: We have wps_method=%s -> "
854 p2p_wps_method_str(dev->wps_method));
855 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
859 case DEV_PW_USER_SPECIFIED:
860 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
861 "P2P: Peer entered PIN on Keypad");
862 if (dev->wps_method != WPS_PIN_LABEL &&
863 dev->wps_method != WPS_PIN_DISPLAY) {
864 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
865 "P2P: We have wps_method=%s -> "
867 p2p_wps_method_str(dev->wps_method));
868 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
872 case DEV_PW_PUSHBUTTON:
873 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
874 "P2P: Peer using pushbutton");
875 if (dev->wps_method != WPS_PBC) {
876 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
877 "P2P: We have wps_method=%s -> "
879 p2p_wps_method_str(dev->wps_method));
880 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
885 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
886 "P2P: Unsupported Device Password ID %d",
887 msg.dev_password_id);
888 status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
893 struct p2p_channels intersection;
895 p2p_channels_intersect(&p2p->channels, &dev->channels,
897 if (intersection.reg_classes == 0 ||
898 intersection.reg_class[0].channels == 0) {
899 status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
900 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
901 "P2P: No common channels found");
904 for (i = 0; i < intersection.reg_classes; i++) {
905 struct p2p_reg_class *c;
906 c = &intersection.reg_class[i];
907 wpa_printf(MSG_DEBUG, "P2P: reg_class %u",
909 wpa_hexdump(MSG_DEBUG, "P2P: channels",
910 c->channel, c->channels);
912 if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
914 struct p2p_reg_class *cl;
915 cl = &intersection.reg_class[0];
916 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
917 "P2P: Selected operating channel "
918 "(reg_class %u channel %u) not "
919 "acceptable to the peer - pick "
920 "another channel (reg_class %u "
922 p2p->op_reg_class, p2p->op_channel,
923 cl->reg_class, cl->channel[0]);
924 p2p->op_reg_class = cl->reg_class;
925 p2p->op_channel = cl->channel[0];
928 p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
931 p2p_set_state(p2p, P2P_GO_NEG);
932 p2p_clear_timeout(p2p);
934 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
935 "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
936 os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
939 conf = p2p_build_go_neg_conf(p2p, dev, msg.dialog_token, status,
940 msg.operating_channel, go);
941 p2p_parse_free(&msg);
944 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
945 "P2P: Sending GO Negotiation Confirm");
946 if (status == P2P_SC_SUCCESS) {
947 p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM;
948 dev->go_state = go ? LOCAL_GO : REMOTE_GO;
950 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
954 freq = dev->listen_freq;
955 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq, sa,
956 p2p->cfg->dev_addr, sa,
957 wpabuf_head(conf), wpabuf_len(conf), 200) <
959 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
960 "P2P: Failed to send Action frame");
961 p2p_go_neg_failed(p2p, dev, -1);
967 void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
968 const u8 *data, size_t len)
970 struct p2p_device *dev;
971 struct p2p_message msg;
973 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
974 "P2P: Received GO Negotiation Confirm from " MACSTR,
976 dev = p2p_get_device(p2p, sa);
977 if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
978 dev != p2p->go_neg_peer) {
979 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
980 "P2P: Not ready for GO negotiation with " MACSTR,
985 if (p2p->pending_action_state == P2P_PENDING_GO_NEG_RESPONSE) {
986 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Stopped waiting "
987 "for TX status on GO Negotiation Response since we "
988 "already received Confirmation");
989 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
992 if (p2p_parse(data, len, &msg))
995 if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
996 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
997 "P2P: Was not expecting GO Negotiation Confirm - "
1001 dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM;
1003 if (msg.dialog_token != dev->dialog_token) {
1004 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1005 "P2P: Unexpected Dialog Token %u (expected %u)",
1006 msg.dialog_token, dev->dialog_token);
1007 p2p_parse_free(&msg);
1012 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1013 "P2P: No Status attribute received");
1014 p2p_parse_free(&msg);
1018 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1019 "P2P: GO Negotiation rejected: status %d",
1021 p2p_parse_free(&msg);
1025 if (dev->go_state == REMOTE_GO && msg.group_id) {
1026 /* TODO: Store SSID for Provisioning step */
1027 } else if (dev->go_state == REMOTE_GO) {
1028 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1029 "P2P: Mandatory P2P Group ID attribute missing from "
1030 "GO Negotiation Confirmation");
1031 #ifdef CONFIG_P2P_STRICT
1032 p2p_parse_free(&msg);
1034 #endif /* CONFIG_P2P_STRICT */
1037 if (!msg.operating_channel) {
1038 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1039 "P2P: Mandatory Operating Channel attribute missing "
1040 "from GO Negotiation Confirmation");
1041 #ifdef CONFIG_P2P_STRICT
1042 p2p_parse_free(&msg);
1044 #endif /* CONFIG_P2P_STRICT */
1047 if (!msg.channel_list) {
1048 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1049 "P2P: Mandatory Operating Channel attribute missing "
1050 "from GO Negotiation Confirmation");
1051 #ifdef CONFIG_P2P_STRICT
1052 p2p_parse_free(&msg);
1054 #endif /* CONFIG_P2P_STRICT */
1057 p2p_parse_free(&msg);
1059 if (dev->go_state == UNKNOWN_GO) {
1061 * This should not happen since GO negotiation has already
1064 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
1065 "P2P: Unexpected GO Neg state - do not know which end "
1070 p2p_go_complete(p2p, dev);