2 * Wi-Fi Direct - P2P service discovery
3 * Copyright (c) 2009, Atheros Communications
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "common/ieee802_11_defs.h"
13 #include "common/gas.h"
18 #ifdef CONFIG_WIFI_DISPLAY
19 static int wfd_wsd_supported(struct wpabuf *wfd)
28 pos = wpabuf_head(wfd);
29 end = pos + wpabuf_len(wfd);
31 while (pos + 3 <= end) {
33 len = WPA_GET_BE16(pos);
38 if (subelem == WFD_SUBELEM_DEVICE_INFO && len >= 6) {
39 u16 info = WPA_GET_BE16(pos);
40 return !!(info & 0x0040);
48 #endif /* CONFIG_WIFI_DISPLAY */
50 struct p2p_sd_query * p2p_pending_sd_req(struct p2p_data *p2p,
51 struct p2p_device *dev)
53 struct p2p_sd_query *q;
56 if (!(dev->info.dev_capab & P2P_DEV_CAPAB_SERVICE_DISCOVERY))
57 return NULL; /* peer does not support SD */
58 #ifdef CONFIG_WIFI_DISPLAY
59 if (wfd_wsd_supported(dev->info.wfd_subelems))
61 #endif /* CONFIG_WIFI_DISPLAY */
63 for (q = p2p->sd_queries; q; q = q->next) {
64 /* Use WSD only if the peer indicates support or it */
67 if (q->for_all_peers && !(dev->flags & P2P_DEV_SD_INFO))
69 if (!q->for_all_peers &&
70 os_memcmp(q->peer, dev->info.p2p_device_addr, ETH_ALEN) ==
79 static int p2p_unlink_sd_query(struct p2p_data *p2p,
80 struct p2p_sd_query *query)
82 struct p2p_sd_query *q, *prev;
90 p2p->sd_queries = q->next;
91 if (p2p->sd_query == query)
102 static void p2p_free_sd_query(struct p2p_sd_query *q)
106 wpabuf_free(q->tlvs);
111 void p2p_free_sd_queries(struct p2p_data *p2p)
113 struct p2p_sd_query *q, *prev;
115 p2p->sd_queries = NULL;
119 p2p_free_sd_query(prev);
124 static struct wpabuf * p2p_build_sd_query(u16 update_indic,
130 buf = gas_anqp_build_initial_req(0, 100 + wpabuf_len(tlvs));
134 /* ANQP Query Request Frame */
135 len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
136 wpabuf_put_be24(buf, OUI_WFA);
137 wpabuf_put_u8(buf, P2P_OUI_TYPE);
138 wpabuf_put_le16(buf, update_indic); /* Service Update Indicator */
139 wpabuf_put_buf(buf, tlvs);
140 gas_anqp_set_element_len(buf, len_pos);
142 gas_anqp_set_len(buf);
148 static void p2p_send_gas_comeback_req(struct p2p_data *p2p, const u8 *dst,
149 u8 dialog_token, int freq)
153 req = gas_build_comeback_req(dialog_token);
157 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
158 if (p2p_send_action(p2p, freq, dst, p2p->cfg->dev_addr, dst,
159 wpabuf_head(req), wpabuf_len(req), 200) < 0)
160 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
161 "P2P: Failed to send Action frame");
167 static struct wpabuf * p2p_build_sd_response(u8 dialog_token, u16 status_code,
170 const struct wpabuf *tlvs)
175 buf = gas_anqp_build_initial_resp(dialog_token, status_code,
177 100 + (tlvs ? wpabuf_len(tlvs) : 0));
182 /* ANQP Query Response Frame */
183 len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
184 wpabuf_put_be24(buf, OUI_WFA);
185 wpabuf_put_u8(buf, P2P_OUI_TYPE);
186 /* Service Update Indicator */
187 wpabuf_put_le16(buf, update_indic);
188 wpabuf_put_buf(buf, tlvs);
189 gas_anqp_set_element_len(buf, len_pos);
192 gas_anqp_set_len(buf);
198 static struct wpabuf * p2p_build_gas_comeback_resp(u8 dialog_token,
201 const u8 *data, size_t len,
207 buf = gas_anqp_build_comeback_resp(dialog_token, status_code, frag_id,
213 /* ANQP Query Response Frame */
214 wpabuf_put_le16(buf, ANQP_VENDOR_SPECIFIC); /* Info ID */
215 wpabuf_put_le16(buf, 3 + 1 + 2 + total_len);
216 wpabuf_put_be24(buf, OUI_WFA);
217 wpabuf_put_u8(buf, P2P_OUI_TYPE);
218 /* Service Update Indicator */
219 wpabuf_put_le16(buf, update_indic);
222 wpabuf_put_data(buf, data, len);
223 gas_anqp_set_len(buf);
229 int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
233 struct p2p_sd_query *query;
236 freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
238 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
239 "P2P: No Listen/Operating frequency known for the "
240 "peer " MACSTR " to send SD Request",
241 MAC2STR(dev->info.p2p_device_addr));
245 query = p2p_pending_sd_req(p2p, dev);
249 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
250 "P2P: Start Service Discovery with " MACSTR,
251 MAC2STR(dev->info.p2p_device_addr));
253 req = p2p_build_sd_query(p2p->srv_update_indic, query->tlvs);
258 p2p->sd_query = query;
259 p2p->pending_action_state = P2P_PENDING_SD;
261 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
262 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
263 wpabuf_head(req), wpabuf_len(req), 5000) < 0) {
264 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
265 "P2P: Failed to send Action frame");
275 void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
276 const u8 *data, size_t len, int rx_freq)
278 const u8 *pos = data;
279 const u8 *end = data + len;
287 if (p2p->cfg->sd_request == NULL)
293 freq = p2p_channel_to_freq(p2p->cfg->country,
302 dialog_token = *pos++;
303 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
304 "P2P: GAS Initial Request from " MACSTR " (dialog token %u, "
306 MAC2STR(sa), dialog_token, rx_freq);
308 if (*pos != WLAN_EID_ADV_PROTO) {
309 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
310 "P2P: Unexpected IE in GAS Initial Request: %u", *pos);
317 if (next > end || slen < 2) {
318 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
319 "P2P: Invalid IE in GAS Initial Request");
322 pos++; /* skip QueryRespLenLimit and PAME-BI */
324 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
325 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
326 "P2P: Unsupported GAS advertisement protocol id %u",
335 slen = WPA_GET_LE16(pos);
337 if (pos + slen > end)
341 /* ANQP Query Request */
344 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
345 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
346 "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
351 slen = WPA_GET_LE16(pos);
353 if (pos + slen > end || slen < 3 + 1) {
354 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
355 "P2P: Invalid ANQP Query Request length");
359 if (WPA_GET_BE24(pos) != OUI_WFA) {
360 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
361 "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
366 if (*pos != P2P_OUI_TYPE) {
367 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
368 "P2P: Unsupported ANQP vendor type %u", *pos);
375 update_indic = WPA_GET_LE16(pos);
376 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
377 "P2P: Service Update Indicator: %u", update_indic);
380 p2p->cfg->sd_request(p2p->cfg->cb_ctx, freq, sa, dialog_token,
381 update_indic, pos, end - pos);
382 /* the response will be indicated with a call to p2p_sd_response() */
386 void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
387 u8 dialog_token, const struct wpabuf *resp_tlvs)
391 /* TODO: fix the length limit to match with the maximum frame length */
392 if (wpabuf_len(resp_tlvs) > 1400) {
393 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response long "
394 "enough to require fragmentation");
397 * TODO: Could consider storing the fragmented response
398 * separately for each peer to avoid having to drop old
399 * one if there is more than one pending SD query.
400 * Though, that would eat more memory, so there are
401 * also benefits to just using a single buffer.
403 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
404 "previous SD response");
405 wpabuf_free(p2p->sd_resp);
407 p2p->sd_resp = wpabuf_dup(resp_tlvs);
408 if (p2p->sd_resp == NULL) {
409 wpa_msg(p2p->cfg->msg_ctx, MSG_ERROR, "P2P: Failed to "
410 "allocate SD response fragmentation area");
413 os_memcpy(p2p->sd_resp_addr, dst, ETH_ALEN);
414 p2p->sd_resp_dialog_token = dialog_token;
415 p2p->sd_resp_pos = 0;
417 resp = p2p_build_sd_response(dialog_token, WLAN_STATUS_SUCCESS,
418 1, p2p->srv_update_indic, NULL);
420 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response fits "
421 "in initial response");
422 resp = p2p_build_sd_response(dialog_token,
423 WLAN_STATUS_SUCCESS, 0,
424 p2p->srv_update_indic, resp_tlvs);
429 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
430 if (p2p_send_action(p2p, freq, dst, p2p->cfg->dev_addr,
432 wpabuf_head(resp), wpabuf_len(resp), 200) < 0)
433 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
434 "P2P: Failed to send Action frame");
440 void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
441 const u8 *data, size_t len, int rx_freq)
443 const u8 *pos = data;
444 const u8 *end = data + len;
452 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
453 os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
454 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
455 "P2P: Ignore unexpected GAS Initial Response from "
456 MACSTR, MAC2STR(sa));
459 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
460 p2p_clear_timeout(p2p);
462 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
463 "P2P: Received GAS Initial Response from " MACSTR " (len=%d)",
464 MAC2STR(sa), (int) len);
467 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
468 "P2P: Too short GAS Initial Response frame");
472 dialog_token = *pos++;
473 /* TODO: check dialog_token match */
474 status_code = WPA_GET_LE16(pos);
476 comeback_delay = WPA_GET_LE16(pos);
478 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
479 "P2P: dialog_token=%u status_code=%u comeback_delay=%u",
480 dialog_token, status_code, comeback_delay);
482 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
483 "P2P: Service Discovery failed: status code %u",
488 if (*pos != WLAN_EID_ADV_PROTO) {
489 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
490 "P2P: Unexpected IE in GAS Initial Response: %u",
498 if (next > end || slen < 2) {
499 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
500 "P2P: Invalid IE in GAS Initial Response");
503 pos++; /* skip QueryRespLenLimit and PAME-BI */
505 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
506 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
507 "P2P: Unsupported GAS advertisement protocol id %u",
515 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
519 slen = WPA_GET_LE16(pos);
521 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
523 if (pos + slen > end) {
524 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
530 if (comeback_delay) {
531 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Fragmented "
532 "response - request fragments");
533 if (p2p->sd_rx_resp) {
534 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
535 "old SD reassembly buffer");
536 wpabuf_free(p2p->sd_rx_resp);
537 p2p->sd_rx_resp = NULL;
539 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
543 /* ANQP Query Response */
546 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
547 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
548 "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
553 slen = WPA_GET_LE16(pos);
555 if (pos + slen > end || slen < 3 + 1) {
556 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
557 "P2P: Invalid ANQP Query Response length");
561 if (WPA_GET_BE24(pos) != OUI_WFA) {
562 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
563 "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
568 if (*pos != P2P_OUI_TYPE) {
569 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
570 "P2P: Unsupported ANQP vendor type %u", *pos);
577 update_indic = WPA_GET_LE16(pos);
578 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
579 "P2P: Service Update Indicator: %u", update_indic);
582 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
583 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
587 if (!p2p->sd_query->for_all_peers) {
588 struct p2p_sd_query *q;
589 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
590 "P2P: Remove completed SD query %p",
593 p2p_unlink_sd_query(p2p, p2p->sd_query);
594 p2p_free_sd_query(q);
596 p2p->sd_query = NULL;
599 if (p2p->cfg->sd_response)
600 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa, update_indic,
602 p2p_continue_find(p2p);
606 void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
607 const u8 *data, size_t len, int rx_freq)
614 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Request", data, len);
617 dialog_token = *data;
618 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Dialog Token: %u",
620 if (dialog_token != p2p->sd_resp_dialog_token) {
621 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
622 "response fragment for dialog token %u", dialog_token);
626 if (p2p->sd_resp == NULL) {
627 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
628 "response fragment available");
631 if (os_memcmp(sa, p2p->sd_resp_addr, ETH_ALEN) != 0) {
632 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
633 "response fragment for " MACSTR, MAC2STR(sa));
637 frag_len = wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos;
638 if (frag_len > 1400) {
642 resp = p2p_build_gas_comeback_resp(dialog_token, WLAN_STATUS_SUCCESS,
643 p2p->srv_update_indic,
644 wpabuf_head_u8(p2p->sd_resp) +
645 p2p->sd_resp_pos, frag_len,
646 p2p->sd_frag_id, more,
647 wpabuf_len(p2p->sd_resp));
650 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send GAS Comeback "
651 "Response (frag_id %d more=%d frag_len=%d)",
652 p2p->sd_frag_id, more, (int) frag_len);
654 p2p->sd_resp_pos += frag_len;
657 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: %d more bytes "
659 (int) (wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos));
661 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: All fragments of "
663 wpabuf_free(p2p->sd_resp);
667 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
668 if (p2p_send_action(p2p, rx_freq, sa, p2p->cfg->dev_addr,
670 wpabuf_head(resp), wpabuf_len(resp), 200) < 0)
671 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
672 "P2P: Failed to send Action frame");
678 void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
679 const u8 *data, size_t len, int rx_freq)
681 const u8 *pos = data;
682 const u8 *end = data + len;
691 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Response", data, len);
693 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
694 os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
695 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
696 "P2P: Ignore unexpected GAS Comeback Response from "
697 MACSTR, MAC2STR(sa));
700 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
701 p2p_clear_timeout(p2p);
703 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
704 "P2P: Received GAS Comeback Response from " MACSTR " (len=%d)",
705 MAC2STR(sa), (int) len);
708 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
709 "P2P: Too short GAS Comeback Response frame");
713 dialog_token = *pos++;
714 /* TODO: check dialog_token match */
715 status_code = WPA_GET_LE16(pos);
717 frag_id = *pos & 0x7f;
718 more_frags = (*pos & 0x80) >> 7;
720 comeback_delay = WPA_GET_LE16(pos);
722 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
723 "P2P: dialog_token=%u status_code=%u frag_id=%d more_frags=%d "
725 dialog_token, status_code, frag_id, more_frags,
727 /* TODO: check frag_id match */
729 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
730 "P2P: Service Discovery failed: status code %u",
735 if (*pos != WLAN_EID_ADV_PROTO) {
736 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
737 "P2P: Unexpected IE in GAS Comeback Response: %u",
745 if (next > end || slen < 2) {
746 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
747 "P2P: Invalid IE in GAS Comeback Response");
750 pos++; /* skip QueryRespLenLimit and PAME-BI */
752 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
753 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
754 "P2P: Unsupported GAS advertisement protocol id %u",
762 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
766 slen = WPA_GET_LE16(pos);
768 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
770 if (pos + slen > end) {
771 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
776 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No Query Response "
782 if (p2p->sd_rx_resp) {
784 * ANQP header is only included in the first fragment; rest of
785 * the fragments start with continue TLVs.
787 goto skip_nqp_header;
790 /* ANQP Query Response */
793 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
794 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
795 "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
800 slen = WPA_GET_LE16(pos);
802 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: ANQP Query Response "
805 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
806 "P2P: Invalid ANQP Query Response length");
812 if (WPA_GET_BE24(pos) != OUI_WFA) {
813 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
814 "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
819 if (*pos != P2P_OUI_TYPE) {
820 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
821 "P2P: Unsupported ANQP vendor type %u", *pos);
828 p2p->sd_rx_update_indic = WPA_GET_LE16(pos);
829 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
830 "P2P: Service Update Indicator: %u", p2p->sd_rx_update_indic);
834 if (wpabuf_resize(&p2p->sd_rx_resp, end - pos) < 0)
836 wpabuf_put_data(p2p->sd_rx_resp, pos, end - pos);
837 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Current SD reassembly "
839 (unsigned int) wpabuf_len(p2p->sd_rx_resp));
842 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: More fragments "
844 /* TODO: what would be a good size limit? */
845 if (wpabuf_len(p2p->sd_rx_resp) > 64000) {
846 wpabuf_free(p2p->sd_rx_resp);
847 p2p->sd_rx_resp = NULL;
848 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too long "
849 "SD response - drop it");
852 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
856 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
857 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
861 if (!p2p->sd_query->for_all_peers) {
862 struct p2p_sd_query *q;
863 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
864 "P2P: Remove completed SD query %p",
867 p2p_unlink_sd_query(p2p, p2p->sd_query);
868 p2p_free_sd_query(q);
870 p2p->sd_query = NULL;
873 if (p2p->cfg->sd_response)
874 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa,
875 p2p->sd_rx_update_indic,
876 wpabuf_head(p2p->sd_rx_resp),
877 wpabuf_len(p2p->sd_rx_resp));
878 wpabuf_free(p2p->sd_rx_resp);
879 p2p->sd_rx_resp = NULL;
881 p2p_continue_find(p2p);
885 void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
886 const struct wpabuf *tlvs)
888 struct p2p_sd_query *q;
890 q = os_zalloc(sizeof(*q));
895 os_memcpy(q->peer, dst, ETH_ALEN);
897 q->for_all_peers = 1;
899 q->tlvs = wpabuf_dup(tlvs);
900 if (q->tlvs == NULL) {
901 p2p_free_sd_query(q);
905 q->next = p2p->sd_queries;
907 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Added SD Query %p", q);
910 struct p2p_device *dev;
911 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list)
912 dev->flags &= ~P2P_DEV_SD_INFO;
919 #ifdef CONFIG_WIFI_DISPLAY
920 void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst,
921 const struct wpabuf *tlvs)
923 struct p2p_sd_query *q;
924 q = p2p_sd_request(p2p, dst, tlvs);
929 #endif /* CONFIG_WIFI_DISPLAY */
932 void p2p_sd_service_update(struct p2p_data *p2p)
934 p2p->srv_update_indic++;
938 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req)
940 if (p2p_unlink_sd_query(p2p, req)) {
941 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
942 "P2P: Cancel pending SD query %p", req);
943 p2p_free_sd_query(req);