1 /* 2 * Wi-Fi Direct - P2P Invitation procedure 3 * Copyright (c) 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 "p2p_i.h" 14 #include "p2p.h" 15 16 17 static struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p, 18 struct p2p_device *peer, 19 const u8 *go_dev_addr) 20 { 21 struct wpabuf *buf; 22 u8 *len; 23 const u8 *dev_addr; 24 size_t extra = 0; 25 26 #ifdef CONFIG_WIFI_DISPLAY 27 struct wpabuf *wfd_ie = p2p->wfd_ie_invitation; 28 if (wfd_ie && p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) { 29 size_t i; 30 for (i = 0; i < p2p->num_groups; i++) { 31 struct p2p_group *g = p2p->groups[i]; 32 struct wpabuf *ie; 33 if (os_memcmp(p2p_group_get_interface_addr(g), 34 p2p->inv_bssid, ETH_ALEN) != 0) 35 continue; 36 ie = p2p_group_get_wfd_ie(g); 37 if (ie) { 38 wfd_ie = ie; 39 break; 40 } 41 } 42 } 43 if (wfd_ie) 44 extra = wpabuf_len(wfd_ie); 45 #endif /* CONFIG_WIFI_DISPLAY */ 46 47 buf = wpabuf_alloc(1000 + extra); 48 if (buf == NULL) 49 return NULL; 50 51 peer->dialog_token++; 52 if (peer->dialog_token == 0) 53 peer->dialog_token = 1; 54 p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_REQ, 55 peer->dialog_token); 56 57 len = p2p_buf_add_ie_hdr(buf); 58 if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO || !p2p->inv_persistent) 59 p2p_buf_add_config_timeout(buf, 0, 0); 60 else 61 p2p_buf_add_config_timeout(buf, p2p->go_timeout, 62 p2p->client_timeout); 63 p2p_buf_add_invitation_flags(buf, p2p->inv_persistent ? 64 P2P_INVITATION_FLAGS_TYPE : 0); 65 if (p2p->inv_role != P2P_INVITE_ROLE_CLIENT || 66 !(peer->flags & P2P_DEV_NO_PREF_CHAN)) 67 p2p_buf_add_operating_channel(buf, p2p->cfg->country, 68 p2p->op_reg_class, 69 p2p->op_channel); 70 if (p2p->inv_bssid_set) 71 p2p_buf_add_group_bssid(buf, p2p->inv_bssid); 72 p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels); 73 if (go_dev_addr) 74 dev_addr = go_dev_addr; 75 else if (p2p->inv_role == P2P_INVITE_ROLE_CLIENT) 76 dev_addr = peer->info.p2p_device_addr; 77 else 78 dev_addr = p2p->cfg->dev_addr; 79 p2p_buf_add_group_id(buf, dev_addr, p2p->inv_ssid, p2p->inv_ssid_len); 80 p2p_buf_add_device_info(buf, p2p, peer); 81 p2p_buf_update_ie_hdr(buf, len); 82 83 #ifdef CONFIG_WIFI_DISPLAY 84 if (wfd_ie) 85 wpabuf_put_buf(buf, wfd_ie); 86 #endif /* CONFIG_WIFI_DISPLAY */ 87 88 return buf; 89 } 90 91 92 static struct wpabuf * p2p_build_invitation_resp(struct p2p_data *p2p, 93 struct p2p_device *peer, 94 u8 dialog_token, u8 status, 95 const u8 *group_bssid, 96 u8 reg_class, u8 channel, 97 struct p2p_channels *channels) 98 { 99 struct wpabuf *buf; 100 u8 *len; 101 size_t extra = 0; 102 103 #ifdef CONFIG_WIFI_DISPLAY 104 struct wpabuf *wfd_ie = p2p->wfd_ie_invitation; 105 if (wfd_ie && group_bssid) { 106 size_t i; 107 for (i = 0; i < p2p->num_groups; i++) { 108 struct p2p_group *g = p2p->groups[i]; 109 struct wpabuf *ie; 110 if (os_memcmp(p2p_group_get_interface_addr(g), 111 group_bssid, ETH_ALEN) != 0) 112 continue; 113 ie = p2p_group_get_wfd_ie(g); 114 if (ie) { 115 wfd_ie = ie; 116 break; 117 } 118 } 119 } 120 if (wfd_ie) 121 extra = wpabuf_len(wfd_ie); 122 #endif /* CONFIG_WIFI_DISPLAY */ 123 124 buf = wpabuf_alloc(1000 + extra); 125 if (buf == NULL) 126 return NULL; 127 128 p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_RESP, 129 dialog_token); 130 131 len = p2p_buf_add_ie_hdr(buf); 132 p2p_buf_add_status(buf, status); 133 p2p_buf_add_config_timeout(buf, 0, 0); /* FIX */ 134 if (reg_class && channel) 135 p2p_buf_add_operating_channel(buf, p2p->cfg->country, 136 reg_class, channel); 137 if (group_bssid) 138 p2p_buf_add_group_bssid(buf, group_bssid); 139 if (channels) 140 p2p_buf_add_channel_list(buf, p2p->cfg->country, channels); 141 p2p_buf_update_ie_hdr(buf, len); 142 143 #ifdef CONFIG_WIFI_DISPLAY 144 if (wfd_ie) 145 wpabuf_put_buf(buf, wfd_ie); 146 #endif /* CONFIG_WIFI_DISPLAY */ 147 148 return buf; 149 } 150 151 152 void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa, 153 const u8 *data, size_t len, int rx_freq) 154 { 155 struct p2p_device *dev; 156 struct p2p_message msg; 157 struct wpabuf *resp = NULL; 158 u8 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; 159 int freq; 160 int go = 0; 161 u8 group_bssid[ETH_ALEN], *bssid; 162 int op_freq = 0; 163 u8 reg_class = 0, channel = 0; 164 struct p2p_channels intersection, *channels = NULL; 165 int persistent; 166 167 os_memset(group_bssid, 0, sizeof(group_bssid)); 168 169 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 170 "P2P: Received Invitation Request from " MACSTR " (freq=%d)", 171 MAC2STR(sa), rx_freq); 172 173 if (p2p_parse(data, len, &msg)) 174 return; 175 176 dev = p2p_get_device(p2p, sa); 177 if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { 178 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 179 "P2P: Invitation Request from unknown peer " 180 MACSTR, MAC2STR(sa)); 181 182 if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 183 0)) { 184 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 185 "P2P: Invitation Request add device failed " 186 MACSTR, MAC2STR(sa)); 187 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; 188 goto fail; 189 } 190 191 dev = p2p_get_device(p2p, sa); 192 if (dev == NULL) { 193 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 194 "P2P: Reject Invitation Request from unknown " 195 "peer " MACSTR, MAC2STR(sa)); 196 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; 197 goto fail; 198 } 199 } 200 201 if (!msg.group_id || !msg.channel_list) { 202 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 203 "P2P: Mandatory attribute missing in Invitation " 204 "Request from " MACSTR, MAC2STR(sa)); 205 status = P2P_SC_FAIL_INVALID_PARAMS; 206 goto fail; 207 } 208 209 if (msg.invitation_flags) 210 persistent = *msg.invitation_flags & P2P_INVITATION_FLAGS_TYPE; 211 else { 212 /* Invitation Flags is a mandatory attribute starting from P2P 213 * spec 1.06. As a backwards compatibility mechanism, assume 214 * the request was for a persistent group if the attribute is 215 * missing. 216 */ 217 wpa_printf(MSG_DEBUG, "P2P: Mandatory Invitation Flags " 218 "attribute missing from Invitation Request"); 219 persistent = 1; 220 } 221 222 if (p2p_peer_channels_check(p2p, &p2p->cfg->channels, dev, 223 msg.channel_list, msg.channel_list_len) < 224 0) { 225 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 226 "P2P: No common channels found"); 227 status = P2P_SC_FAIL_NO_COMMON_CHANNELS; 228 goto fail; 229 } 230 231 if (p2p->cfg->invitation_process) { 232 status = p2p->cfg->invitation_process( 233 p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id, 234 msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN, 235 &go, group_bssid, &op_freq, persistent); 236 } 237 238 if (op_freq) { 239 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invitation " 240 "processing forced frequency %d MHz", op_freq); 241 if (p2p_freq_to_channel(p2p->cfg->country, op_freq, 242 ®_class, &channel) < 0) { 243 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 244 "P2P: Unknown forced freq %d MHz from " 245 "invitation_process()", op_freq); 246 status = P2P_SC_FAIL_NO_COMMON_CHANNELS; 247 goto fail; 248 } 249 250 p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, 251 &intersection); 252 if (!p2p_channels_includes(&intersection, reg_class, channel)) 253 { 254 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 255 "P2P: forced freq %d MHz not in the supported " 256 "channels interaction", op_freq); 257 status = P2P_SC_FAIL_NO_COMMON_CHANNELS; 258 goto fail; 259 } 260 261 if (status == P2P_SC_SUCCESS) 262 channels = &intersection; 263 } else { 264 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 265 "P2P: No forced channel from invitation processing - " 266 "figure out best one to use"); 267 268 p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, 269 &intersection); 270 /* Default to own configuration as a starting point */ 271 p2p->op_reg_class = p2p->cfg->op_reg_class; 272 p2p->op_channel = p2p->cfg->op_channel; 273 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Own default " 274 "op_class %d channel %d", 275 p2p->op_reg_class, p2p->op_channel); 276 277 /* Use peer preference if specified and compatible */ 278 if (msg.operating_channel) { 279 int req_freq; 280 req_freq = p2p_channel_to_freq( 281 (const char *) msg.operating_channel, 282 msg.operating_channel[3], 283 msg.operating_channel[4]); 284 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " 285 "operating channel preference: %d MHz", 286 req_freq); 287 if (req_freq > 0 && 288 p2p_channels_includes(&intersection, 289 msg.operating_channel[3], 290 msg.operating_channel[4])) { 291 p2p->op_reg_class = msg.operating_channel[3]; 292 p2p->op_channel = msg.operating_channel[4]; 293 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 294 "P2P: Use peer preference op_class %d " 295 "channel %d", 296 p2p->op_reg_class, p2p->op_channel); 297 } else { 298 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 299 "P2P: Cannot use peer channel " 300 "preference"); 301 } 302 } 303 304 if (!p2p_channels_includes(&intersection, p2p->op_reg_class, 305 p2p->op_channel)) { 306 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 307 "P2P: Initially selected channel (op_class %d " 308 "channel %d) not in channel intersection - try " 309 "to reselect", 310 p2p->op_reg_class, p2p->op_channel); 311 p2p_reselect_channel(p2p, &intersection); 312 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 313 "P2P: Re-selection result: op_class %d " 314 "channel %d", 315 p2p->op_reg_class, p2p->op_channel); 316 if (!p2p_channels_includes(&intersection, 317 p2p->op_reg_class, 318 p2p->op_channel)) { 319 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 320 "P2P: Peer does not support selected " 321 "operating channel (reg_class=%u " 322 "channel=%u)", 323 p2p->op_reg_class, p2p->op_channel); 324 status = P2P_SC_FAIL_NO_COMMON_CHANNELS; 325 goto fail; 326 } 327 } 328 329 op_freq = p2p_channel_to_freq(p2p->cfg->country, 330 p2p->op_reg_class, 331 p2p->op_channel); 332 if (op_freq < 0) { 333 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 334 "P2P: Unknown operational channel " 335 "(country=%c%c reg_class=%u channel=%u)", 336 p2p->cfg->country[0], p2p->cfg->country[1], 337 p2p->op_reg_class, p2p->op_channel); 338 status = P2P_SC_FAIL_NO_COMMON_CHANNELS; 339 goto fail; 340 } 341 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Selected operating " 342 "channel - %d MHz", op_freq); 343 344 if (status == P2P_SC_SUCCESS) { 345 reg_class = p2p->op_reg_class; 346 channel = p2p->op_channel; 347 channels = &intersection; 348 } 349 } 350 351 fail: 352 if (go && status == P2P_SC_SUCCESS && !is_zero_ether_addr(group_bssid)) 353 bssid = group_bssid; 354 else 355 bssid = NULL; 356 resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status, 357 bssid, reg_class, channel, channels); 358 359 if (resp == NULL) 360 goto out; 361 362 if (rx_freq > 0) 363 freq = rx_freq; 364 else 365 freq = p2p_channel_to_freq(p2p->cfg->country, 366 p2p->cfg->reg_class, 367 p2p->cfg->channel); 368 if (freq < 0) { 369 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 370 "P2P: Unknown regulatory class/channel"); 371 goto out; 372 } 373 374 /* 375 * Store copy of invitation data to be used when processing TX status 376 * callback for the Acton frame. 377 */ 378 os_memcpy(p2p->inv_sa, sa, ETH_ALEN); 379 if (msg.group_bssid) { 380 os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN); 381 p2p->inv_group_bssid_ptr = p2p->inv_group_bssid; 382 } else 383 p2p->inv_group_bssid_ptr = NULL; 384 if (msg.group_id_len - ETH_ALEN <= 32) { 385 os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN, 386 msg.group_id_len - ETH_ALEN); 387 p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN; 388 } 389 os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN); 390 p2p->inv_status = status; 391 p2p->inv_op_freq = op_freq; 392 393 p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE; 394 if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, 395 p2p->cfg->dev_addr, 396 wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { 397 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 398 "P2P: Failed to send Action frame"); 399 } 400 401 out: 402 wpabuf_free(resp); 403 p2p_parse_free(&msg); 404 } 405 406 407 void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, 408 const u8 *data, size_t len) 409 { 410 struct p2p_device *dev; 411 struct p2p_message msg; 412 struct p2p_channels intersection, *channels = NULL; 413 414 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 415 "P2P: Received Invitation Response from " MACSTR, 416 MAC2STR(sa)); 417 418 dev = p2p_get_device(p2p, sa); 419 if (dev == NULL) { 420 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 421 "P2P: Ignore Invitation Response from unknown peer " 422 MACSTR, MAC2STR(sa)); 423 return; 424 } 425 426 if (dev != p2p->invite_peer) { 427 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 428 "P2P: Ignore unexpected Invitation Response from peer " 429 MACSTR, MAC2STR(sa)); 430 return; 431 } 432 433 if (p2p_parse(data, len, &msg)) 434 return; 435 436 if (!msg.status) { 437 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 438 "P2P: Mandatory Status attribute missing in " 439 "Invitation Response from " MACSTR, MAC2STR(sa)); 440 p2p_parse_free(&msg); 441 return; 442 } 443 444 if (!msg.channel_list) { 445 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 446 "P2P: Mandatory Channel List attribute missing in " 447 "Invitation Response from " MACSTR, MAC2STR(sa)); 448 #ifdef CONFIG_P2P_STRICT 449 p2p_parse_free(&msg); 450 return; 451 #endif /* CONFIG_P2P_STRICT */ 452 /* Try to survive without peer channel list */ 453 channels = &p2p->channels; 454 } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev, 455 msg.channel_list, 456 msg.channel_list_len) < 0) { 457 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 458 "P2P: No common channels found"); 459 p2p_parse_free(&msg); 460 return; 461 } else { 462 p2p_channels_intersect(&p2p->channels, &dev->channels, 463 &intersection); 464 channels = &intersection; 465 } 466 467 if (p2p->cfg->invitation_result) 468 p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status, 469 msg.group_bssid, channels, sa); 470 471 p2p_parse_free(&msg); 472 473 p2p_clear_timeout(p2p); 474 p2p_set_state(p2p, P2P_IDLE); 475 p2p->invite_peer = NULL; 476 } 477 478 479 int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev, 480 const u8 *go_dev_addr) 481 { 482 struct wpabuf *req; 483 int freq; 484 485 freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq; 486 if (freq <= 0) { 487 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 488 "P2P: No Listen/Operating frequency known for the " 489 "peer " MACSTR " to send Invitation Request", 490 MAC2STR(dev->info.p2p_device_addr)); 491 return -1; 492 } 493 494 req = p2p_build_invitation_req(p2p, dev, go_dev_addr); 495 if (req == NULL) 496 return -1; 497 if (p2p->state != P2P_IDLE) 498 p2p_stop_listen_for_freq(p2p, freq); 499 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 500 "P2P: Sending Invitation Request"); 501 p2p_set_state(p2p, P2P_INVITE); 502 p2p->pending_action_state = P2P_PENDING_INVITATION_REQUEST; 503 p2p->invite_peer = dev; 504 dev->invitation_reqs++; 505 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr, 506 p2p->cfg->dev_addr, dev->info.p2p_device_addr, 507 wpabuf_head(req), wpabuf_len(req), 200) < 0) { 508 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 509 "P2P: Failed to send Action frame"); 510 /* Use P2P find to recover and retry */ 511 p2p_set_timeout(p2p, 0, 0); 512 } 513 514 wpabuf_free(req); 515 516 return 0; 517 } 518 519 520 void p2p_invitation_req_cb(struct p2p_data *p2p, int success) 521 { 522 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 523 "P2P: Invitation Request TX callback: success=%d", success); 524 525 if (p2p->invite_peer == NULL) { 526 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 527 "P2P: No pending Invite"); 528 return; 529 } 530 531 /* 532 * Use P2P find, if needed, to find the other device from its listen 533 * channel. 534 */ 535 p2p_set_state(p2p, P2P_INVITE); 536 #ifdef ANDROID_P2P 537 p2p_set_timeout(p2p, 0, 350000); 538 #else 539 p2p_set_timeout(p2p, 0, 100000); 540 #endif 541 } 542 543 544 void p2p_invitation_resp_cb(struct p2p_data *p2p, int success) 545 { 546 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 547 "P2P: Invitation Response TX callback: success=%d", success); 548 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); 549 550 if (!success) 551 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 552 "P2P: Assume Invitation Response was actually " 553 "received by the peer even though Ack was not " 554 "reported"); 555 556 if (p2p->cfg->invitation_received) { 557 p2p->cfg->invitation_received(p2p->cfg->cb_ctx, 558 p2p->inv_sa, 559 p2p->inv_group_bssid_ptr, 560 p2p->inv_ssid, p2p->inv_ssid_len, 561 p2p->inv_go_dev_addr, 562 p2p->inv_status, 563 p2p->inv_op_freq); 564 } 565 } 566 567 568 int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role, 569 const u8 *bssid, const u8 *ssid, size_t ssid_len, 570 unsigned int force_freq, const u8 *go_dev_addr, 571 int persistent_group, unsigned int pref_freq) 572 { 573 struct p2p_device *dev; 574 575 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 576 "P2P: Request to invite peer " MACSTR " role=%d persistent=%d " 577 "force_freq=%u", 578 MAC2STR(peer), role, persistent_group, force_freq); 579 if (bssid) 580 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 581 "P2P: Invitation for BSSID " MACSTR, MAC2STR(bssid)); 582 if (go_dev_addr) { 583 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 584 "P2P: Invitation for GO Device Address " MACSTR, 585 MAC2STR(go_dev_addr)); 586 os_memcpy(p2p->invite_go_dev_addr_buf, go_dev_addr, ETH_ALEN); 587 p2p->invite_go_dev_addr = p2p->invite_go_dev_addr_buf; 588 } else 589 p2p->invite_go_dev_addr = NULL; 590 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Invitation for SSID", 591 ssid, ssid_len); 592 593 dev = p2p_get_device(p2p, peer); 594 if (dev == NULL || (dev->listen_freq <= 0 && dev->oper_freq <= 0)) { 595 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 596 "P2P: Cannot invite unknown P2P Device " MACSTR, 597 MAC2STR(peer)); 598 return -1; 599 } 600 601 if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq) < 0) 602 return -1; 603 604 if (persistent_group && role == P2P_INVITE_ROLE_CLIENT && !force_freq && 605 !pref_freq) 606 dev->flags |= P2P_DEV_NO_PREF_CHAN; 607 else 608 dev->flags &= ~P2P_DEV_NO_PREF_CHAN; 609 610 if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) { 611 if (!(dev->info.dev_capab & 612 P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) { 613 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, 614 "P2P: Cannot invite a P2P Device " MACSTR 615 " that is in a group and is not discoverable", 616 MAC2STR(peer)); 617 } 618 /* TODO: use device discoverability request through GO */ 619 } 620 621 dev->invitation_reqs = 0; 622 623 if (p2p->state != P2P_IDLE) 624 p2p_stop_find(p2p); 625 626 p2p->inv_role = role; 627 p2p->inv_bssid_set = bssid != NULL; 628 if (bssid) 629 os_memcpy(p2p->inv_bssid, bssid, ETH_ALEN); 630 os_memcpy(p2p->inv_ssid, ssid, ssid_len); 631 p2p->inv_ssid_len = ssid_len; 632 p2p->inv_persistent = persistent_group; 633 return p2p_invite_send(p2p, dev, go_dev_addr); 634 } 635