Lines Matching refs:p2p
2 * Wi-Fi Direct - P2P Invitation procedure
15 #include "p2p.h"
18 static struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p,
29 struct wpabuf *wfd_ie = p2p->wfd_ie_invitation;
30 if (wfd_ie && p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) {
32 for (i = 0; i < p2p->num_groups; i++) {
33 struct p2p_group *g = p2p->groups[i];
36 p2p->inv_bssid, ETH_ALEN) != 0)
49 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_INV_REQ])
50 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_INV_REQ]);
63 if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO || !p2p->inv_persistent)
66 p2p_buf_add_config_timeout(buf, p2p->go_timeout,
67 p2p->client_timeout);
68 p2p_buf_add_invitation_flags(buf, p2p->inv_persistent ?
70 if (p2p->inv_role != P2P_INVITE_ROLE_CLIENT ||
72 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
73 p2p->op_reg_class,
74 p2p->op_channel);
75 if (p2p->inv_bssid_set)
76 p2p_buf_add_group_bssid(buf, p2p->inv_bssid);
77 p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels);
80 else if (p2p->inv_role == P2P_INVITE_ROLE_CLIENT)
83 dev_addr = p2p->cfg->dev_addr;
84 p2p_buf_add_group_id(buf, dev_addr, p2p->inv_ssid, p2p->inv_ssid_len);
85 p2p_buf_add_device_info(buf, p2p, peer);
88 p2p_buf_add_pref_channel_list(buf, p2p->pref_freq_list,
89 p2p->num_pref_freq);
96 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_INV_REQ])
97 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_INV_REQ]);
101 p2p_build_wps_ie(p2p, buf, dev_pw_id, 0);
108 static struct wpabuf * p2p_build_invitation_resp(struct p2p_data *p2p,
120 struct wpabuf *wfd_ie = p2p->wfd_ie_invitation;
123 for (i = 0; i < p2p->num_groups; i++) {
124 struct p2p_group *g = p2p->groups[i];
140 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_INV_RESP])
141 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_INV_RESP]);
154 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
159 p2p_buf_add_channel_list(buf, p2p->cfg->country, channels);
167 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_INV_RESP])
168 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_INV_RESP]);
174 void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
191 p2p_dbg(p2p, "Received Invitation Request from " MACSTR " (freq=%d)",
197 dev = p2p_get_device(p2p, sa);
199 p2p_dbg(p2p, "Invitation Request from unknown peer " MACSTR,
202 if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1,
204 p2p_dbg(p2p, "Invitation Request add device failed "
210 dev = p2p_get_device(p2p, sa);
212 p2p_dbg(p2p, "Reject Invitation Request from unknown peer "
220 p2p_dbg(p2p, "Mandatory attribute missing in Invitation Request from "
229 /* Invitation Flags is a mandatory attribute starting from P2P
234 p2p_dbg(p2p, "Mandatory Invitation Flags attribute missing from Invitation Request");
238 p2p_channels_union(&p2p->cfg->channels, &p2p->cfg->cli_channels,
241 if (p2p_peer_channels_check(p2p, &all_channels, dev,
244 p2p_dbg(p2p, "No common channels found");
249 p2p_channels_dump(p2p, "own channels", &p2p->cfg->channels);
250 p2p_channels_dump(p2p, "own client channels", &all_channels);
251 p2p_channels_dump(p2p, "peer channels", &dev->channels);
254 p2p_channels_dump(p2p, "intersection", &intersection);
256 if (p2p->cfg->invitation_process) {
257 status = p2p->cfg->invitation_process(
258 p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id,
265 p2p_channels_intersect(&p2p->cfg->channels, &dev->channels,
267 p2p_channels_dump(p2p, "intersection(GO)", &intersection);
269 p2p_dbg(p2p, "No common channels found (GO)");
276 p2p_dbg(p2p, "Invitation processing forced frequency %d MHz",
279 p2p_dbg(p2p, "Unknown forced freq %d MHz from invitation_process()",
287 p2p_dbg(p2p, "forced freq %d MHz not in the supported channels intersection",
296 p2p_dbg(p2p, "No forced channel from invitation processing - figure out best one to use");
299 p2p->op_reg_class = p2p->cfg->op_reg_class;
300 p2p->op_channel = p2p->cfg->op_channel;
301 p2p_dbg(p2p, "Own default op_class %d channel %d",
302 p2p->op_reg_class, p2p->op_channel);
310 p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
316 p2p->op_reg_class = msg.operating_channel[3];
317 p2p->op_channel = msg.operating_channel[4];
318 p2p_dbg(p2p, "Use peer preference op_class %d channel %d",
319 p2p->op_reg_class, p2p->op_channel);
321 p2p_dbg(p2p, "Cannot use peer channel preference");
327 !p2p_channels_includes(&intersection, p2p->op_reg_class,
328 p2p->op_channel)) {
329 p2p_dbg(p2p, "Initially selected channel (op_class %d channel %d) not in channel intersection - try to reselect",
330 p2p->op_reg_class, p2p->op_channel);
331 p2p_reselect_channel(p2p, &intersection);
332 p2p_dbg(p2p, "Re-selection result: op_class %d channel %d",
333 p2p->op_reg_class, p2p->op_channel);
335 p2p->op_reg_class,
336 p2p->op_channel)) {
337 p2p_dbg(p2p, "Peer does not support selected operating channel (reg_class=%u channel=%u)",
338 p2p->op_reg_class, p2p->op_channel);
343 !p2p->cfg->cfg_op_channel) {
344 p2p_dbg(p2p, "Try to reselect channel selection with peer information received; previously selected op_class %u channel %u",
345 p2p->op_reg_class, p2p->op_channel);
346 p2p_reselect_channel(p2p, &intersection);
353 p2p_check_pref_chan(p2p, go, dev, &msg);
355 op_freq = p2p_channel_to_freq(p2p->op_reg_class,
356 p2p->op_channel);
358 p2p_dbg(p2p, "Unknown operational channel (country=%c%c reg_class=%u channel=%u)",
359 p2p->cfg->country[0], p2p->cfg->country[1],
360 p2p->op_reg_class, p2p->op_channel);
364 p2p_dbg(p2p, "Selected operating channel - %d MHz", op_freq);
367 reg_class = p2p->op_reg_class;
368 channel = p2p->op_channel;
378 resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status,
387 freq = p2p_channel_to_freq(p2p->cfg->reg_class,
388 p2p->cfg->channel);
390 p2p_dbg(p2p, "Unknown regulatory class/channel");
398 os_memcpy(p2p->inv_sa, sa, ETH_ALEN);
400 os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN);
401 p2p->inv_group_bssid_ptr = p2p->inv_group_bssid;
403 p2p->inv_group_bssid_ptr = NULL;
406 os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN,
408 p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN;
410 os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN);
412 p2p->inv_ssid_len = 0;
413 os_memset(p2p->inv_go_dev_addr, 0, ETH_ALEN);
415 p2p->inv_status = status;
416 p2p->inv_op_freq = op_freq;
418 p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE;
419 if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
420 p2p->cfg->dev_addr,
422 p2p_dbg(p2p, "Failed to send Action frame");
431 void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
438 p2p_dbg(p2p, "Received Invitation Response from " MACSTR,
441 dev = p2p_get_device(p2p, sa);
443 p2p_dbg(p2p, "Ignore Invitation Response from unknown peer "
445 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
449 if (dev != p2p->invite_peer) {
450 p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer "
452 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
457 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
462 p2p_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from "
465 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
480 p2p->retry_invite_req_sent &&
482 p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
489 p2p->retry_invite_req &&
490 p2p_channel_random_social(&p2p->cfg->channels, &p2p->op_reg_class,
491 &p2p->op_channel) == 0) {
492 p2p->retry_invite_req = 0;
493 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
494 p2p->cfg->stop_listen(p2p->cfg->cb_ctx);
495 p2p_set_state(p2p, P2P_INVITE);
496 p2p_dbg(p2p, "Resend Invitation Request setting op_class %u channel %u as operating channel",
497 p2p->op_reg_class, p2p->op_channel);
498 p2p->retry_invite_req_sent = 1;
499 p2p_invite_send(p2p, p2p->invite_peer, p2p->invite_go_dev_addr,
500 p2p->invite_dev_pw_id);
504 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
505 p2p->retry_invite_req = 0;
508 p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from "
515 channels = &p2p->channels;
518 channels = &p2p->channels;
519 } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev,
522 p2p_dbg(p2p, "No common channels found");
526 p2p_channels_intersect(&p2p->channels, &dev->channels,
531 if (p2p->cfg->invitation_result) {
533 int freq = p2p_channel_to_freq(p2p->op_reg_class,
534 p2p->op_channel);
550 p2p_check_pref_chan(p2p, 0, dev, &msg);
552 p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status,
559 p2p_clear_timeout(p2p);
560 p2p_set_state(p2p, P2P_IDLE);
561 p2p->invite_peer = NULL;
565 int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
575 p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
581 req = p2p_build_invitation_req(p2p, dev, go_dev_addr, dev_pw_id);
584 if (p2p->state != P2P_IDLE)
585 p2p_stop_listen_for_freq(p2p, freq);
586 p2p_dbg(p2p, "Sending Invitation Request");
587 p2p_set_state(p2p, P2P_INVITE);
588 p2p->pending_action_state = P2P_PENDING_INVITATION_REQUEST;
589 p2p->invite_peer = dev;
591 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
592 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
594 p2p_dbg(p2p, "Failed to send Action frame");
595 /* Use P2P find to recover and retry */
596 p2p_set_timeout(p2p, 0, 0);
607 void p2p_invitation_req_cb(struct p2p_data *p2p, int success)
609 p2p_dbg(p2p, "Invitation Request TX callback: success=%d", success);
611 if (p2p->invite_peer == NULL) {
612 p2p_dbg(p2p, "No pending Invite");
617 p2p->invite_peer->flags &= ~P2P_DEV_WAIT_INV_REQ_ACK;
620 * Use P2P find, if needed, to find the other device from its listen
623 p2p_set_state(p2p, P2P_INVITE);
624 p2p_set_timeout(p2p, 0, success ? 500000 : 100000);
628 void p2p_invitation_resp_cb(struct p2p_data *p2p, int success)
630 p2p_dbg(p2p, "Invitation Response TX callback: success=%d", success);
631 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
634 p2p_dbg(p2p, "Assume Invitation Response was actually received by the peer even though Ack was not reported");
636 if (p2p->cfg->invitation_received) {
637 p2p->cfg->invitation_received(p2p->cfg->cb_ctx,
638 p2p->inv_sa,
639 p2p->inv_group_bssid_ptr,
640 p2p->inv_ssid, p2p->inv_ssid_len,
641 p2p->inv_go_dev_addr,
642 p2p->inv_status,
643 p2p->inv_op_freq);
648 int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
655 p2p_dbg(p2p, "Request to invite peer " MACSTR " role=%d persistent=%d "
659 p2p_dbg(p2p, "Invitation for BSSID " MACSTR, MAC2STR(bssid));
661 p2p_dbg(p2p, "Invitation for GO Device Address " MACSTR,
663 os_memcpy(p2p->invite_go_dev_addr_buf, go_dev_addr, ETH_ALEN);
664 p2p->invite_go_dev_addr = p2p->invite_go_dev_addr_buf;
666 p2p->invite_go_dev_addr = NULL;
670 p2p_dbg(p2p, "Invitation to use Device Password ID %d",
673 p2p->invite_dev_pw_id = dev_pw_id;
674 p2p->retry_invite_req = role == P2P_INVITE_ROLE_GO &&
676 p2p->retry_invite_req_sent = 0;
678 dev = p2p_get_device(p2p, peer);
681 p2p_dbg(p2p, "Cannot invite unknown P2P Device " MACSTR,
686 if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq,
699 p2p_dbg(p2p, "Cannot invite a P2P Device " MACSTR
708 if (p2p->state != P2P_IDLE)
709 p2p_stop_find(p2p);
711 p2p->inv_role = role;
712 p2p->inv_bssid_set = bssid != NULL;
714 os_memcpy(p2p->inv_bssid, bssid, ETH_ALEN);
715 os_memcpy(p2p->inv_ssid, ssid, ssid_len);
716 p2p->inv_ssid_len = ssid_len;
717 p2p->inv_persistent = persistent_group;
718 return p2p_invite_send(p2p, dev, go_dev_addr, dev_pw_id);