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