Lines Matching refs:p2p
2 * Wi-Fi Direct - P2P provision discovery
16 #include "p2p.h"
43 static void p2ps_add_new_group_info(struct p2p_data *p2p,
54 if (!p2p->cfg->get_go_info)
57 found = p2p->cfg->get_go_info(
58 p2p->cfg->cb_ctx, intended_addr, ssid,
62 p2p->p2ps_prov->force_freq = force_freq;
63 p2p->p2ps_prov->pref_freq = 0;
66 p2p_prepare_channel(p2p, dev, force_freq, 0, 0);
68 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr,
72 p2p_buf_add_intended_addr(buf, p2p->intended_addr);
76 if (!p2p->ssid_set) {
77 p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
78 p2p->ssid_set = 1;
81 /* Add pre-composed P2P Group ID */
82 p2p_buf_add_group_id(buf, p2p->cfg->dev_addr,
83 p2p->ssid, p2p->ssid_len);
87 buf, p2p->intended_addr);
90 buf, p2p->cfg->dev_addr);
95 static void p2ps_add_pd_req_attrs(struct p2p_data *p2p, struct p2p_device *dev,
98 struct p2ps_provision *prov = p2p->p2ps_prov;
111 p2ps_add_new_group_info(p2p, dev, buf);
119 if (p2p->cfg->get_persistent_group) {
120 shared_group = p2p->cfg->get_persistent_group(
121 p2p->cfg->cb_ctx, dev->info.p2p_device_addr,
128 p2p_buf_add_channel_list(buf, p2p->cfg->country,
129 &p2p->channels);
133 p2p_buf_add_operating_channel(buf, p2p->cfg->country,
134 p2p->op_reg_class,
135 p2p->op_channel);
153 p2p_buf_add_config_timeout(buf, p2p->go_timeout,
154 p2p->client_timeout);
157 p2p_buf_add_listen_channel(buf, p2p->cfg->country,
158 p2p->cfg->reg_class,
159 p2p->cfg->channel);
178 static struct wpabuf * p2p_build_prov_disc_req(struct p2p_data *p2p,
191 if (p2p->wfd_ie_prov_disc_req)
192 extra = wpabuf_len(p2p->wfd_ie_prov_disc_req);
195 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ])
196 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ]);
198 if (p2p->p2ps_prov)
199 extra += os_strlen(p2p->p2ps_prov->info) + 1 +
211 if (p2p->p2ps_prov) {
214 if (p2p->cross_connect)
216 if (p2p->cfg->p2p_intra_bss)
219 p2p_buf_add_capability(buf, p2p->dev_capab &
222 p2p_buf_add_device_info(buf, p2p, NULL);
223 if (p2p->p2ps_prov) {
224 p2ps_add_pd_req_attrs(p2p, dev, buf, config_methods);
235 if (p2p->wfd_ie_prov_disc_req)
236 wpabuf_put_buf(buf, p2p->wfd_ie_prov_disc_req);
239 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ])
240 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_PD_REQ]);
246 static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
264 struct wpabuf *wfd_ie = p2p->wfd_ie_prov_disc_resp;
267 for (i = 0; i < p2p->num_groups; i++) {
268 struct p2p_group *g = p2p->groups[i];
284 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP])
285 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP]);
293 /* Add P2P IE for P2PS */
294 if (p2p->p2ps_prov && p2p->p2ps_prov->adv_id == adv_id) {
296 struct p2ps_provision *prov = p2p->p2ps_prov;
310 if (p2p->cross_connect)
312 if (p2p->cfg->p2p_intra_bss)
314 p2p_buf_add_capability(buf, p2p->dev_capab &
317 p2p_buf_add_device_info(buf, p2p, NULL);
319 if (persist_ssid && p2p->cfg->get_persistent_group && dev &&
327 persist = p2p->cfg->get_persistent_group(
328 p2p->cfg->cb_ctx,
342 p2ps_add_new_group_info(p2p, dev, buf);
346 if (p2p->op_reg_class && p2p->op_channel)
348 buf, p2p->cfg->country,
349 p2p->op_reg_class,
350 p2p->op_channel);
353 buf, p2p->cfg->country,
354 p2p->cfg->op_reg_class,
355 p2p->cfg->op_channel);
360 p2p_buf_add_channel_list(buf, p2p->cfg->country,
361 &p2p->channels);
370 p2p_buf_add_config_timeout(buf, p2p->go_timeout,
371 p2p->client_timeout);
383 if (p2p->p2ps_prov)
385 p2p->p2ps_prov->adv_mac);
398 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP])
399 wpabuf_put_buf(buf, p2p->vendor_elem[VENDOR_ELEM_P2P_PD_RESP]);
405 static int p2ps_setup_p2ps_prov(struct p2p_data *p2p, u32 adv_id,
411 if (!p2p->p2ps_prov) {
412 p2p->p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + 1);
413 if (!p2p->p2ps_prov)
416 os_memset(p2p->p2ps_prov, 0, sizeof(struct p2ps_provision) + 1);
419 tmp = p2p->p2ps_prov;
444 static int p2ps_validate_pd_req(struct p2p_data *p2p, struct p2p_message *msg,
457 p2p_dbg(p2p, "Not P2PS PD Request. Missing %s", #_attr); \
491 p2p_dbg(p2p, "P2PS: Invalid feature capability len");
528 p2p_dbg(p2p, "Invalid P2PS PD connection capability");
554 void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
581 p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR
586 dev = p2p_get_device(p2p, sa);
588 p2p_dbg(p2p, "Provision Discovery Request from unknown peer "
591 if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1,
593 p2p_dbg(p2p, "Provision Discovery Request add device failed "
599 dev = p2p_get_device(p2p, sa);
601 p2p_dbg(p2p,
615 p2p_dbg(p2p,
624 for (i = 0; i < p2p->num_groups; i++) {
626 p2p->groups[i],
630 if (i == p2p->num_groups) {
631 p2p_dbg(p2p,
632 "PD request for unknown P2P Group ID - reject");
644 if (p2ps_validate_pd_req(p2p, &msg, sa) < 0) {
666 p2p_dbg(p2p,
682 p2p_dbg(p2p, "Peer " MACSTR
687 p2p_dbg(p2p, "Peer " MACSTR
693 p2p_dbg(p2p, "Peer " MACSTR " requesting P2PS PIN",
700 if (p2p->cfg->remove_stale_groups) {
701 p2p->cfg->remove_stale_groups(
702 p2p->cfg->cb_ctx, dev->info.p2p_device_addr,
710 * End of a legacy P2P PD Request processing, from this point continue
721 if (os_memcmp(p2p->cfg->dev_addr, msg.adv_mac, ETH_ALEN)) {
722 p2p_dbg(p2p,
728 p2ps_adv = p2p_service_p2ps_id(p2p, adv_id);
730 p2p_dbg(p2p, "P2PS PD invalid adv_id=0x%X", adv_id);
734 p2p_dbg(p2p, "adv_id: 0x%X, p2ps_adv: %p", adv_id, p2ps_adv);
737 conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
742 p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d",
745 p2p_prepare_channel(p2p, dev, forced_freq, pref_freq, 0);
750 p2p_dbg(p2p, "cpt: service:0x%x remote:0x%x result:0x%x",
754 p2p_dbg(p2p,
760 p2p_dbg(p2p,
766 p2p_dbg(p2p, "P2PS state unavailable");
769 p2p_dbg(p2p, "Conncap resolution failed");
774 p2p_dbg(p2p, "Keypad - always defer");
781 p2p_peer_channels_check(p2p, &p2p->channels, dev,
784 p2p_dbg(p2p,
814 p2p_channels_intersect(&p2p->channels, &dev->channels,
818 p2p_dbg(p2p,
827 if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id,
834 tmp = p2p->p2ps_prov;
851 (!p2p->p2ps_prov || p2p->p2ps_prov->adv_id != adv_id)) {
859 if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id,
865 tmp = p2p->p2ps_prov;
879 if (*msg.status != P2P_SC_SUCCESS_DEFERRED || !p2p->p2ps_prov)
882 if (p2p->p2ps_prov->adv_id != adv_id ||
883 os_memcmp(p2p->p2ps_prov->adv_mac, msg.adv_mac, ETH_ALEN)) {
884 p2p_dbg(p2p,
889 if (p2p->p2ps_prov->session_id != session_id ||
890 os_memcmp(p2p->p2ps_prov->session_mac, msg.session_mac, ETH_ALEN)) {
891 p2p_dbg(p2p, "P2PS Follow-on PD with mismatch Session ID/MAC");
895 method = p2p->p2ps_prov->method;
897 conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
899 p2p->p2ps_prov->conncap,
900 &p2p->p2ps_prov->force_freq,
901 &p2p->p2ps_prov->pref_freq);
903 resp_fcap.cpt = p2ps_own_preferred_cpt(p2p->p2ps_prov->cpt_priority,
906 p2p_dbg(p2p, "cpt: local:0x%x remote:0x%x result:0x%x",
907 p2p->p2ps_prov->cpt_mask, req_fcap->cpt, resp_fcap.cpt);
909 p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq,
910 p2p->p2ps_prov->pref_freq, 0);
928 p2p_dbg(p2p,
934 p2p_peer_channels_check(p2p, &p2p->channels, dev,
937 p2p_dbg(p2p,
954 p2p_go_select_channel(p2p, dev, &tmp) < 0)
958 p2p->p2ps_prov->status = reject;
959 p2p->p2ps_prov->conncap = conncap;
973 resp = p2p_build_prov_disc_resp(p2p, dev, msg.dialog_token,
984 p2p_dbg(p2p, "Sending Provision Discovery Response");
988 freq = p2p_channel_to_freq(p2p->cfg->reg_class,
989 p2p->cfg->channel);
991 p2p_dbg(p2p, "Unknown regulatory class/channel");
996 p2p->pending_action_state = P2P_PENDING_PD_RESPONSE;
997 if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
998 p2p->cfg->dev_addr,
1001 p2p_dbg(p2p, "Failed to send Action frame");
1003 p2p->send_action_in_progress = 1;
1015 freq = p2p_channel_to_freq(p2p->op_reg_class,
1016 p2p->op_channel);
1021 if (!p2p->cfg->p2ps_prov_complete) {
1026 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject,
1034 p2p->p2ps_prov) {
1035 p2p->p2ps_prov->status = reject;
1036 p2p->p2ps_prov->conncap = conncap;
1039 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject,
1048 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx,
1060 } else if (msg.status && p2p->p2ps_prov) {
1061 p2p->p2ps_prov->status = P2P_SC_SUCCESS;
1062 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa,
1073 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS,
1088 p2p->p2ps_prov->method = msg.wps_config_methods;
1090 p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS,
1104 p2p->p2ps_prov->method = msg.wps_config_methods;
1109 p2p->cfg->p2ps_prov_complete(
1110 p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa,
1123 * prov_disc_req callback is used to generate P2P-PROV-DISC-ENTER-PIN,
1124 * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events.
1125 * Call it either on legacy P2P PD or on P2PS PD only if we need to
1129 * 1. Legacy P2P PD request, response status SUCCESS
1140 if (p2p->cfg->prov_disc_req &&
1156 p2p->cfg->prov_disc_req(p2p
1193 static int p2p_validate_p2ps_pd_resp(struct p2p_data *p2p,
1204 p2p_dbg(p2p, "P2PS PD Response missing " #_attr); \
1221 if (p2p->p2ps_prov->session_id != session_id) {
1222 p2p_dbg(p2p,
1227 if (os_memcmp(p2p->p2ps_prov->session_mac, msg->session_mac,
1229 p2p_dbg(p2p,
1234 if (p2p->p2ps_prov->adv_id != adv_id) {
1235 p2p_dbg(p2p,
1240 if (os_memcmp(p2p->p2ps_prov->adv_mac, msg->adv_mac, ETH_ALEN) != 0) {
1241 p2p_dbg(p2p,
1247 p2p_dbg(p2p,
1254 p2p_dbg(p2p,
1260 p2p_dbg(p2p,
1292 void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
1309 if (p2p->p2ps_prov && p2p_validate_p2ps_pd_resp(p2p, &msg)) {
1342 p2p_dbg(p2p, "Received Provision Discovery Response from " MACSTR
1346 dev = p2p_get_device(p2p, sa);
1348 p2p_dbg(p2p, "Ignore Provision Discovery Response from " MACSTR
1358 p2p_dbg(p2p, "Ignore Provision Discovery Response with unexpected Dialog Token %u (expected %u)",
1364 if (p2p->pending_action_state == P2P_PENDING_PD) {
1365 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
1366 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
1369 p2ps_seeker = p2p->p2ps_prov && p2p->p2ps_prov->pd_seeker;
1381 if (p2p->user_initiated_pd &&
1382 os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0)
1383 p2p_reset_pending_pd(p2p);
1386 p2p_dbg(p2p, "Peer rejected our Provision Discovery Request (received config_methods 0x%x expected 0x%x",
1388 if (p2p->cfg->prov_disc_fail)
1389 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa,
1393 p2ps_prov_free(p2p);
1402 p2p_dbg(p2p, "Peer " MACSTR
1407 p2p_dbg(p2p, "Peer " MACSTR
1413 p2p_dbg(p2p, "Peer " MACSTR " accepted P2PS PIN",
1420 p2p->p2ps_prov) {
1432 p2p_peer_channels_check(p2p, &p2p->channels, dev,
1435 p2p_dbg(p2p, "P2PS PD Response - no common channels");
1438 if (p2p_channels_includes(&p2p->channels,
1449 p2p_dbg(p2p,
1454 if (p2p->cfg->p2ps_prov_complete) {
1465 if (p2p_go_select_channel(p2p, dev, &tmp) < 0)
1466 p2p_dbg(p2p,
1469 freq = p2p_channel_to_freq(p2p->op_reg_class,
1470 p2p->op_channel);
1475 p2p->cfg->p2ps_prov_complete(
1476 p2p->cfg->cb_ctx, status, sa, adv_mac,
1477 p2p->p2ps_prov->session_mac,
1478 group_mac, adv_id, p2p->p2ps_prov->session_id,
1485 p2ps_prov_free(p2p);
1488 status != P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) {
1489 if (p2p->cfg->p2ps_prov_complete)
1490 p2p->cfg->p2ps_prov_complete(
1491 p2p->cfg->cb_ctx, status, sa, adv_mac,
1492 p2p->p2ps_prov->session_mac,
1493 group_mac, adv_id, p2p->p2ps_prov->session_id,
1495 p2ps_prov_free(p2p);
1499 if (p2p->cfg->remove_stale_groups) {
1500 p2p->cfg->remove_stale_groups(p2p->cfg->cb_ctx,
1511 p2ps_prov_free(p2p);
1517 if (p2p->cfg->prov_disc_fail)
1518 p2p->cfg->prov_disc_fail(
1519 p2p->cfg->cb_ctx, sa,
1525 if (p2p->cfg->prov_disc_fail)
1526 p2p->cfg->prov_disc_fail(
1527 p2p->cfg->cb_ctx, sa,
1531 p2p_dbg(p2p, "Peer rejected our Provision Discovery Request");
1532 if (p2p->cfg->prov_disc_fail)
1533 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa,
1537 p2ps_prov_free(p2p);
1550 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
1552 p2p_dbg(p2p, "Start GO Neg after the PD-before-GO-Neg workaround with "
1555 p2p_connect_send(p2p, dev);
1560 * prov_disc_resp callback is used to generate P2P-PROV-DISC-ENTER-PIN,
1561 * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events.
1562 * Call it only for a legacy P2P PD or for P2PS PD scenarios where
1566 * 1. Legacy P2P PD response with a status SUCCESS
1573 if (p2p->cfg->prov_disc_resp &&
1580 p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa,
1583 if (p2p->state == P2P_PD_DURING_FIND) {
1584 p2p_clear_timeout(p2p);
1585 p2p_continue_find(p2p);
1590 int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
1602 p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
1611 p2p_dbg(p2p, "Cannot use PD with P2P Device " MACSTR
1619 if (p2p->p2ps_prov) {
1620 if (p2p->p2ps_prov->status == P2P_SC_SUCCESS_DEFERRED) {
1621 if (p2p->p2ps_prov->method == WPS_CONFIG_DISPLAY)
1623 else if (p2p->p2ps_prov->method == WPS_CONFIG_KEYPAD)
1629 if (p2p->p2ps_prov->method)
1631 p2p->p2ps_prov->method;
1639 p2p_dbg(p2p,
1641 p2p->p2ps_prov->method, p2p->p2ps_prov->status,
1644 if (p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq,
1645 p2p->p2ps_prov->pref_freq, 1) < 0)
1649 req = p2p_build_prov_disc_req(p2p, dev, join);
1653 if (p2p->state != P2P_IDLE)
1654 p2p_stop_listen_for_freq(p2p, freq);
1655 p2p->pending_action_state = P2P_PENDING_PD;
1656 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
1657 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
1659 p2p_dbg(p2p, "Failed to send Action frame");
1664 os_memcpy(p2p->pending_pd_devaddr, dev->info.p2p_device_addr, ETH_ALEN);
1671 int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
1678 dev = p2p_get_device(p2p, peer_addr);
1680 dev = p2p_get_device_interface(p2p, peer_addr);
1682 p2p_dbg(p2p, "Provision Discovery Request destination " MACSTR
1688 p2p_dbg(p2p, "Provision Discovery Request with " MACSTR
1697 p2p->p2ps_prov) {
1699 p2ps_prov->method = p2p->p2ps_prov->method;
1704 p2ps_prov_free(p2p);
1705 p2p->p2ps_prov = p2ps_prov;
1713 if (p2p->state != P2P_IDLE && p2p->state != P2P_SEARCH &&
1714 p2p->state != P2P_LISTEN_ONLY) {
1715 p2p_dbg(p2p, "Busy with other operations; postpone Provision Discovery Request with "
1721 p2p->user_initiated_pd = user_initiated_pd;
1722 p2p->pd_force_freq = force_freq;
1724 if (p2p->user_initiated_pd)
1725 p2p->pd_retries = MAX_PROV_DISC_REQ_RETRIES;
1735 return p2p_send_prov_disc_req(p2p, dev, join, force_freq);
1739 void p2p_reset_pending_pd(struct p2p_data *p2p)
1743 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) {
1744 if (os_memcmp(p2p->pending_pd_devaddr,
1755 p2p->user_initiated_pd = 0;
1756 os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN);
1757 p2p->pd_retries = 0;
1758 p2p->pd_force_freq = 0;
1762 void p2ps_prov_free(struct p2p_data *p2p)
1764 os_free(p2p->p2ps_prov);
1765 p2p->p2ps_prov = NULL;