2 * Wi-Fi Direct - P2P service discovery
3 * Copyright (c) 2009, Atheros Communications
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "common/ieee802_11_defs.h"
23 struct p2p_sd_query * p2p_pending_sd_req(struct p2p_data *p2p,
24 struct p2p_device *dev)
26 struct p2p_sd_query *q;
28 if (!(dev->dev_capab & P2P_DEV_CAPAB_SERVICE_DISCOVERY))
29 return 0; /* peer does not support SD */
31 for (q = p2p->sd_queries; q; q = q->next) {
32 if (q->for_all_peers && !(dev->flags & P2P_DEV_SD_INFO))
34 if (!q->for_all_peers &&
35 os_memcmp(q->peer, dev->p2p_device_addr, ETH_ALEN) == 0)
43 static int p2p_unlink_sd_query(struct p2p_data *p2p,
44 struct p2p_sd_query *query)
46 struct p2p_sd_query *q, *prev;
54 p2p->sd_queries = q->next;
55 if (p2p->sd_query == query)
66 static void p2p_free_sd_query(struct p2p_sd_query *q)
75 void p2p_free_sd_queries(struct p2p_data *p2p)
77 struct p2p_sd_query *q, *prev;
79 p2p->sd_queries = NULL;
83 p2p_free_sd_query(prev);
88 static struct wpabuf * p2p_build_sd_query(u16 update_indic,
92 u8 *len_pos, *len_pos2;
94 buf = wpabuf_alloc(1000 + wpabuf_len(tlvs));
98 wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC);
99 wpabuf_put_u8(buf, WLAN_PA_GAS_INITIAL_REQ);
100 wpabuf_put_u8(buf, 0); /* Dialog Token */
102 /* Advertisement Protocol IE */
103 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
104 wpabuf_put_u8(buf, 2); /* Length */
105 wpabuf_put_u8(buf, 0); /* QueryRespLenLimit | PAME-BI */
106 wpabuf_put_u8(buf, NATIVE_QUERY_PROTOCOL); /* Advertisement Protocol */
109 len_pos = wpabuf_put(buf, 2); /* Length (to be filled) */
111 /* NQP Query Request Frame */
112 wpabuf_put_le16(buf, NQP_VENDOR_SPECIFIC); /* Info ID */
113 len_pos2 = wpabuf_put(buf, 2); /* Length (to be filled) */
114 wpabuf_put_be24(buf, OUI_WFA);
115 wpabuf_put_u8(buf, P2P_OUI_TYPE);
116 wpabuf_put_le16(buf, update_indic); /* Service Update Indicator */
117 wpabuf_put_buf(buf, tlvs);
119 WPA_PUT_LE16(len_pos2, (u8 *) wpabuf_put(buf, 0) - len_pos2 - 2);
120 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(buf, 0) - len_pos - 2);
126 static struct wpabuf * p2p_build_gas_comeback_req(u8 dialog_token)
130 buf = wpabuf_alloc(3);
134 wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC);
135 wpabuf_put_u8(buf, WLAN_PA_GAS_COMEBACK_REQ);
136 wpabuf_put_u8(buf, dialog_token);
142 static void p2p_send_gas_comeback_req(struct p2p_data *p2p, const u8 *dst,
143 u8 dialog_token, int freq)
147 req = p2p_build_gas_comeback_req(dialog_token);
151 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
152 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq,
153 dst, p2p->cfg->dev_addr, dst,
154 wpabuf_head(req), wpabuf_len(req), 200) < 0)
155 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
156 "P2P: Failed to send Action frame");
162 static struct wpabuf * p2p_build_sd_response(u8 dialog_token, u16 status_code,
165 const struct wpabuf *tlvs)
168 u8 *len_pos, *len_pos2;
170 buf = wpabuf_alloc(1000 + (tlvs ? wpabuf_len(tlvs) : 0));
174 wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC);
175 wpabuf_put_u8(buf, WLAN_PA_GAS_INITIAL_RESP);
176 wpabuf_put_u8(buf, dialog_token);
177 wpabuf_put_le16(buf, status_code);
178 wpabuf_put_le16(buf, comeback_delay);
180 /* Advertisement Protocol IE */
181 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
182 wpabuf_put_u8(buf, 2); /* Length */
183 wpabuf_put_u8(buf, 0x7f); /* QueryRespLenLimit | PAME-BI */
184 wpabuf_put_u8(buf, NATIVE_QUERY_PROTOCOL); /* Advertisement Protocol */
187 len_pos = wpabuf_put(buf, 2); /* Length (to be filled) */
190 /* NQP Query Response Frame */
191 wpabuf_put_le16(buf, NQP_VENDOR_SPECIFIC); /* Info ID */
192 len_pos2 = wpabuf_put(buf, 2); /* Length (to be filled) */
193 wpabuf_put_be24(buf, OUI_WFA);
194 wpabuf_put_u8(buf, P2P_OUI_TYPE);
195 /* Service Update Indicator */
196 wpabuf_put_le16(buf, update_indic);
197 wpabuf_put_buf(buf, tlvs);
199 WPA_PUT_LE16(len_pos2,
200 (u8 *) wpabuf_put(buf, 0) - len_pos2 - 2);
203 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(buf, 0) - len_pos - 2);
209 static struct wpabuf * p2p_build_gas_comeback_resp(u8 dialog_token,
212 const u8 *data, size_t len,
216 u8 *len_pos, *len_pos2;
218 buf = wpabuf_alloc(1000 + len);
222 wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC);
223 wpabuf_put_u8(buf, WLAN_PA_GAS_COMEBACK_RESP);
224 wpabuf_put_u8(buf, dialog_token);
225 wpabuf_put_le16(buf, status_code);
226 wpabuf_put_u8(buf, frag_id | (more ? 0x80 : 0));
227 wpabuf_put_le16(buf, 0); /* Comeback Delay */
229 /* Advertisement Protocol IE */
230 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
231 wpabuf_put_u8(buf, 2); /* Length */
232 wpabuf_put_u8(buf, 0x7f); /* QueryRespLenLimit | PAME-BI */
233 wpabuf_put_u8(buf, NATIVE_QUERY_PROTOCOL); /* Advertisement Protocol */
236 len_pos = wpabuf_put(buf, 2); /* Length (to be filled) */
238 /* NQP Query Response Frame */
239 wpabuf_put_le16(buf, NQP_VENDOR_SPECIFIC); /* Info ID */
240 len_pos2 = wpabuf_put(buf, 2); /* Length (to be filled) */
241 wpabuf_put_be24(buf, OUI_WFA);
242 wpabuf_put_u8(buf, P2P_OUI_TYPE);
243 /* Service Update Indicator */
244 wpabuf_put_le16(buf, update_indic);
246 wpabuf_put_data(buf, data, len);
248 WPA_PUT_LE16(len_pos2, (u8 *) wpabuf_put(buf, 0) - len_pos2 - 2);
249 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(buf, 0) - len_pos - 2);
255 int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
259 struct p2p_sd_query *query;
262 freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
264 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
265 "P2P: No Listen/Operating frequency known for the "
266 "peer " MACSTR " to send SD Request",
267 MAC2STR(dev->p2p_device_addr));
271 query = p2p_pending_sd_req(p2p, dev);
275 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
276 "P2P: Start Service Discovery with " MACSTR,
277 MAC2STR(dev->p2p_device_addr));
279 req = p2p_build_sd_query(p2p->srv_update_indic, query->tlvs);
284 p2p->sd_query = query;
285 p2p->pending_action_state = P2P_PENDING_SD;
287 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq,
288 dev->p2p_device_addr, p2p->cfg->dev_addr,
289 dev->p2p_device_addr,
290 wpabuf_head(req), wpabuf_len(req), 5000) < 0)
292 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
293 "P2P: Failed to send Action frame");
303 void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
304 const u8 *data, size_t len, int rx_freq)
306 const u8 *pos = data;
307 const u8 *end = data + len;
315 if (p2p->cfg->sd_request == NULL)
321 freq = p2p_channel_to_freq(p2p->cfg->country,
330 dialog_token = *pos++;
331 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
332 "P2P: GAS Initial Request from " MACSTR " (dialog token %u, "
334 MAC2STR(sa), dialog_token, rx_freq);
336 if (*pos != WLAN_EID_ADV_PROTO) {
337 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
338 "P2P: Unexpected IE in GAS Initial Request: %u", *pos);
345 if (next > end || slen < 2) {
346 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
347 "P2P: Invalid IE in GAS Initial Request");
350 pos++; /* skip QueryRespLenLimit and PAME-BI */
352 if (*pos != NATIVE_QUERY_PROTOCOL) {
353 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
354 "P2P: Unsupported GAS advertisement protocol id %u",
363 slen = WPA_GET_LE16(pos);
365 if (pos + slen > end)
369 /* NQP Query Request */
372 if (WPA_GET_LE16(pos) != NQP_VENDOR_SPECIFIC) {
373 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
374 "P2P: Unsupported NQP Info ID %u", WPA_GET_LE16(pos));
379 slen = WPA_GET_LE16(pos);
381 if (pos + slen > end || slen < 3 + 1) {
382 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
383 "P2P: Invalid NQP Query Request length");
387 if (WPA_GET_BE24(pos) != OUI_WFA) {
388 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
389 "P2P: Unsupported NQP OUI %06x", WPA_GET_BE24(pos));
394 if (*pos != P2P_OUI_TYPE) {
395 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
396 "P2P: Unsupported NQP vendor type %u", *pos);
403 update_indic = WPA_GET_LE16(pos);
404 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
405 "P2P: Service Update Indicator: %u", update_indic);
408 p2p->cfg->sd_request(p2p->cfg->cb_ctx, freq, sa, dialog_token,
409 update_indic, pos, end - pos);
410 /* the response will be indicated with a call to p2p_sd_response() */
414 void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
415 u8 dialog_token, const struct wpabuf *resp_tlvs)
419 /* TODO: fix the length limit to match with the maximum frame length */
420 if (wpabuf_len(resp_tlvs) > 1400) {
421 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response long "
422 "enough to require fragmentation");
425 * TODO: Could consider storing the fragmented response
426 * separately for each peer to avoid having to drop old
427 * one if there is more than one pending SD query.
428 * Though, that would eat more memory, so there are
429 * also benefits to just using a single buffer.
431 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
432 "previous SD response");
433 wpabuf_free(p2p->sd_resp);
435 os_memcpy(p2p->sd_resp_addr, dst, ETH_ALEN);
436 p2p->sd_resp_dialog_token = dialog_token;
437 p2p->sd_resp = wpabuf_dup(resp_tlvs);
438 p2p->sd_resp_pos = 0;
440 resp = p2p_build_sd_response(dialog_token, WLAN_STATUS_SUCCESS,
441 1, p2p->srv_update_indic, NULL);
443 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response fits "
444 "in initial response");
445 resp = p2p_build_sd_response(dialog_token,
446 WLAN_STATUS_SUCCESS, 0,
447 p2p->srv_update_indic, resp_tlvs);
452 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
453 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, freq,
454 dst, p2p->cfg->dev_addr, p2p->cfg->dev_addr,
455 wpabuf_head(resp), wpabuf_len(resp), 200) <
457 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
458 "P2P: Failed to send Action frame");
464 void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
465 const u8 *data, size_t len, int rx_freq)
467 const u8 *pos = data;
468 const u8 *end = data + len;
476 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
477 os_memcmp(sa, p2p->sd_peer->p2p_device_addr, ETH_ALEN) != 0) {
478 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
479 "P2P: Ignore unexpected GAS Initial Response from "
480 MACSTR, MAC2STR(sa));
483 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
484 p2p_clear_timeout(p2p);
486 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
487 "P2P: Received GAS Initial Response from " MACSTR " (len=%d)",
488 MAC2STR(sa), (int) len);
491 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
492 "P2P: Too short GAS Initial Response frame");
496 dialog_token = *pos++;
497 /* TODO: check dialog_token match */
498 status_code = WPA_GET_LE16(pos);
500 comeback_delay = WPA_GET_LE16(pos);
502 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
503 "P2P: dialog_token=%u status_code=%u comeback_delay=%u",
504 dialog_token, status_code, comeback_delay);
506 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
507 "P2P: Service Discovery failed: status code %u",
512 if (*pos != WLAN_EID_ADV_PROTO) {
513 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
514 "P2P: Unexpected IE in GAS Initial Response: %u",
522 if (next > end || slen < 2) {
523 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
524 "P2P: Invalid IE in GAS Initial Response");
527 pos++; /* skip QueryRespLenLimit and PAME-BI */
529 if (*pos != NATIVE_QUERY_PROTOCOL) {
530 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
531 "P2P: Unsupported GAS advertisement protocol id %u",
539 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
543 slen = WPA_GET_LE16(pos);
545 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
547 if (pos + slen > end) {
548 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
554 if (comeback_delay) {
555 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Fragmented "
556 "response - request fragments");
557 if (p2p->sd_rx_resp) {
558 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
559 "old SD reassembly buffer");
560 wpabuf_free(p2p->sd_rx_resp);
561 p2p->sd_rx_resp = NULL;
563 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
567 /* NQP Query Response */
570 if (WPA_GET_LE16(pos) != NQP_VENDOR_SPECIFIC) {
571 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
572 "P2P: Unsupported NQP Info ID %u", WPA_GET_LE16(pos));
577 slen = WPA_GET_LE16(pos);
579 if (pos + slen > end || slen < 3 + 1) {
580 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
581 "P2P: Invalid NQP Query Response length");
585 if (WPA_GET_BE24(pos) != OUI_WFA) {
586 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
587 "P2P: Unsupported NQP OUI %06x", WPA_GET_BE24(pos));
592 if (*pos != P2P_OUI_TYPE) {
593 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
594 "P2P: Unsupported NQP vendor type %u", *pos);
601 update_indic = WPA_GET_LE16(pos);
602 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
603 "P2P: Service Update Indicator: %u", update_indic);
606 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
607 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
611 if (!p2p->sd_query->for_all_peers) {
612 struct p2p_sd_query *q;
613 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
614 "P2P: Remove completed SD query %p",
617 p2p_unlink_sd_query(p2p, p2p->sd_query);
618 p2p_free_sd_query(q);
620 p2p->sd_query = NULL;
623 if (p2p->cfg->sd_response)
624 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa, update_indic,
626 p2p_continue_find(p2p);
630 void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
631 const u8 *data, size_t len, int rx_freq)
638 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Request", data, len);
641 dialog_token = *data;
642 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Dialog Token: %u",
644 if (dialog_token != p2p->sd_resp_dialog_token) {
645 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
646 "response fragment for dialog token %u", dialog_token);
650 if (p2p->sd_resp == NULL) {
651 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
652 "response fragment available");
655 if (os_memcmp(sa, p2p->sd_resp_addr, ETH_ALEN) != 0) {
656 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
657 "response fragment for " MACSTR, MAC2STR(sa));
661 frag_len = wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos;
662 if (frag_len > 1400) {
666 resp = p2p_build_gas_comeback_resp(dialog_token, WLAN_STATUS_SUCCESS,
667 p2p->srv_update_indic,
668 wpabuf_head_u8(p2p->sd_resp) +
669 p2p->sd_resp_pos, frag_len,
670 p2p->sd_frag_id, more);
673 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send GAS Comeback "
674 "Response (frag_id %d more=%d frag_len=%d)",
675 p2p->sd_frag_id, more, (int) frag_len);
677 p2p->sd_resp_pos += frag_len;
680 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: %d more bytes "
682 (int) (wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos));
684 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: All fragments of "
686 wpabuf_free(p2p->sd_resp);
690 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
691 if (p2p->cfg->send_action(p2p->cfg->cb_ctx, rx_freq,
692 sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr,
693 wpabuf_head(resp), wpabuf_len(resp), 200) <
695 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
696 "P2P: Failed to send Action frame");
702 void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
703 const u8 *data, size_t len, int rx_freq)
705 const u8 *pos = data;
706 const u8 *end = data + len;
716 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Response", data, len);
718 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
719 os_memcmp(sa, p2p->sd_peer->p2p_device_addr, ETH_ALEN) != 0) {
720 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
721 "P2P: Ignore unexpected GAS Comeback Response from "
722 MACSTR, MAC2STR(sa));
725 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
726 p2p_clear_timeout(p2p);
728 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
729 "P2P: Received GAS Comeback Response from " MACSTR " (len=%d)",
730 MAC2STR(sa), (int) len);
733 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
734 "P2P: Too short GAS Comeback Response frame");
738 dialog_token = *pos++;
739 /* TODO: check dialog_token match */
740 status_code = WPA_GET_LE16(pos);
742 frag_id = *pos & 0x7f;
743 more_frags = (*pos & 0x80) >> 7;
745 comeback_delay = WPA_GET_LE16(pos);
747 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
748 "P2P: dialog_token=%u status_code=%u frag_id=%d more_frags=%d "
750 dialog_token, status_code, frag_id, more_frags,
752 /* TODO: check frag_id match */
754 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
755 "P2P: Service Discovery failed: status code %u",
760 if (*pos != WLAN_EID_ADV_PROTO) {
761 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
762 "P2P: Unexpected IE in GAS Comeback Response: %u",
770 if (next > end || slen < 2) {
771 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
772 "P2P: Invalid IE in GAS Comeback Response");
775 pos++; /* skip QueryRespLenLimit and PAME-BI */
777 if (*pos != NATIVE_QUERY_PROTOCOL) {
778 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
779 "P2P: Unsupported GAS advertisement protocol id %u",
787 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
791 slen = WPA_GET_LE16(pos);
793 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
795 if (pos + slen > end) {
796 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
801 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No Query Response "
807 /* NQP Query Response */
810 if (WPA_GET_LE16(pos) != NQP_VENDOR_SPECIFIC) {
811 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
812 "P2P: Unsupported NQP Info ID %u", WPA_GET_LE16(pos));
817 slen = WPA_GET_LE16(pos);
819 if (pos + slen > end || slen < 3 + 1) {
820 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
821 "P2P: Invalid NQP Query Response length");
825 if (WPA_GET_BE24(pos) != OUI_WFA) {
826 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
827 "P2P: Unsupported NQP OUI %06x", WPA_GET_BE24(pos));
832 if (*pos != P2P_OUI_TYPE) {
833 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
834 "P2P: Unsupported NQP vendor type %u", *pos);
841 update_indic = WPA_GET_LE16(pos);
842 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
843 "P2P: Service Update Indicator: %u", update_indic);
846 if (wpabuf_resize(&p2p->sd_rx_resp, end - pos) < 0)
848 wpabuf_put_data(p2p->sd_rx_resp, pos, end - pos);
849 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Current SD reassembly "
851 (unsigned int) wpabuf_len(p2p->sd_rx_resp));
854 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: More fragments "
856 /* TODO: what would be a good size limit? */
857 if (wpabuf_len(p2p->sd_rx_resp) > 64000) {
858 wpabuf_free(p2p->sd_rx_resp);
859 p2p->sd_rx_resp = NULL;
860 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too long "
861 "SD response - drop it");
864 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
868 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
869 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
873 if (!p2p->sd_query->for_all_peers) {
874 struct p2p_sd_query *q;
875 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
876 "P2P: Remove completed SD query %p",
879 p2p_unlink_sd_query(p2p, p2p->sd_query);
880 p2p_free_sd_query(q);
882 p2p->sd_query = NULL;
885 if (p2p->cfg->sd_response)
886 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa, update_indic,
887 wpabuf_head(p2p->sd_rx_resp),
888 wpabuf_len(p2p->sd_rx_resp));
889 wpabuf_free(p2p->sd_rx_resp);
890 p2p->sd_rx_resp = NULL;
892 p2p_continue_find(p2p);
896 void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
897 const struct wpabuf *tlvs)
899 struct p2p_sd_query *q;
901 q = os_zalloc(sizeof(*q));
906 os_memcpy(q->peer, dst, ETH_ALEN);
908 q->for_all_peers = 1;
910 q->tlvs = wpabuf_dup(tlvs);
911 if (q->tlvs == NULL) {
912 p2p_free_sd_query(q);
916 q->next = p2p->sd_queries;
918 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Added SD Query %p", q);
924 void p2p_sd_service_update(struct p2p_data *p2p)
926 p2p->srv_update_indic++;
930 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req)
932 if (p2p_unlink_sd_query(p2p, req)) {
933 wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
934 "P2P: Cancel pending SD query %p", req);
935 p2p_free_sd_query(req);