blob: 5d9c1bb886fe3c3bf4d637c71b117b6ca7c373e2 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Wi-Fi Direct - P2P service discovery
3 * Copyright (c) 2009, Atheros Communications
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013#include "common/gas.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include "p2p_i.h"
15#include "p2p.h"
16
17
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070018#ifdef CONFIG_WIFI_DISPLAY
19static int wfd_wsd_supported(struct wpabuf *wfd)
20{
21 const u8 *pos, *end;
22 u8 subelem;
23 u16 len;
24
25 if (wfd == NULL)
26 return 0;
27
28 pos = wpabuf_head(wfd);
29 end = pos + wpabuf_len(wfd);
30
31 while (pos + 3 <= end) {
32 subelem = *pos++;
33 len = WPA_GET_BE16(pos);
34 pos += 2;
35 if (pos + len > end)
36 break;
37
38 if (subelem == WFD_SUBELEM_DEVICE_INFO && len >= 6) {
39 u16 info = WPA_GET_BE16(pos);
40 return !!(info & 0x0040);
41 }
42
43 pos += len;
44 }
45
46 return 0;
47}
48#endif /* CONFIG_WIFI_DISPLAY */
49
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050struct p2p_sd_query * p2p_pending_sd_req(struct p2p_data *p2p,
51 struct p2p_device *dev)
52{
53 struct p2p_sd_query *q;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054 int wsd = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070055
56 if (!(dev->info.dev_capab & P2P_DEV_CAPAB_SERVICE_DISCOVERY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080057 return NULL; /* peer does not support SD */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070058#ifdef CONFIG_WIFI_DISPLAY
59 if (wfd_wsd_supported(dev->info.wfd_subelems))
60 wsd = 1;
61#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070062
63 for (q = p2p->sd_queries; q; q = q->next) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070064 /* Use WSD only if the peer indicates support or it */
65 if (q->wsd && !wsd)
66 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067 if (q->for_all_peers && !(dev->flags & P2P_DEV_SD_INFO))
68 return q;
69 if (!q->for_all_peers &&
70 os_memcmp(q->peer, dev->info.p2p_device_addr, ETH_ALEN) ==
71 0)
72 return q;
73 }
74
75 return NULL;
76}
77
78
79static int p2p_unlink_sd_query(struct p2p_data *p2p,
80 struct p2p_sd_query *query)
81{
82 struct p2p_sd_query *q, *prev;
83 q = p2p->sd_queries;
84 prev = NULL;
85 while (q) {
86 if (q == query) {
87 if (prev)
88 prev->next = q->next;
89 else
90 p2p->sd_queries = q->next;
91 if (p2p->sd_query == query)
92 p2p->sd_query = NULL;
93 return 1;
94 }
95 prev = q;
96 q = q->next;
97 }
98 return 0;
99}
100
101
102static void p2p_free_sd_query(struct p2p_sd_query *q)
103{
104 if (q == NULL)
105 return;
106 wpabuf_free(q->tlvs);
107 os_free(q);
108}
109
110
111void p2p_free_sd_queries(struct p2p_data *p2p)
112{
113 struct p2p_sd_query *q, *prev;
114 q = p2p->sd_queries;
115 p2p->sd_queries = NULL;
116 while (q) {
117 prev = q;
118 q = q->next;
119 p2p_free_sd_query(prev);
120 }
121}
122
123
124static struct wpabuf * p2p_build_sd_query(u16 update_indic,
125 struct wpabuf *tlvs)
126{
127 struct wpabuf *buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800128 u8 *len_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700129
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800130 buf = gas_anqp_build_initial_req(0, 100 + wpabuf_len(tlvs));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 if (buf == NULL)
132 return NULL;
133
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800134 /* ANQP Query Request Frame */
135 len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136 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);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800140 gas_anqp_set_element_len(buf, len_pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800142 gas_anqp_set_len(buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700143
144 return buf;
145}
146
147
148static void p2p_send_gas_comeback_req(struct p2p_data *p2p, const u8 *dst,
149 u8 dialog_token, int freq)
150{
151 struct wpabuf *req;
152
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800153 req = gas_build_comeback_req(dialog_token);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 if (req == NULL)
155 return;
156
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)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700160 p2p_dbg(p2p, "Failed to send Action frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161
162 wpabuf_free(req);
163}
164
165
166static struct wpabuf * p2p_build_sd_response(u8 dialog_token, u16 status_code,
167 u16 comeback_delay,
168 u16 update_indic,
169 const struct wpabuf *tlvs)
170{
171 struct wpabuf *buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800172 u8 *len_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800174 buf = gas_anqp_build_initial_resp(dialog_token, status_code,
175 comeback_delay,
176 100 + (tlvs ? wpabuf_len(tlvs) : 0));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177 if (buf == NULL)
178 return NULL;
179
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 if (tlvs) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181 /* ANQP Query Response Frame */
182 len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 wpabuf_put_be24(buf, OUI_WFA);
184 wpabuf_put_u8(buf, P2P_OUI_TYPE);
185 /* Service Update Indicator */
186 wpabuf_put_le16(buf, update_indic);
187 wpabuf_put_buf(buf, tlvs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800188 gas_anqp_set_element_len(buf, len_pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 }
190
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800191 gas_anqp_set_len(buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192
193 return buf;
194}
195
196
197static struct wpabuf * p2p_build_gas_comeback_resp(u8 dialog_token,
198 u16 status_code,
199 u16 update_indic,
200 const u8 *data, size_t len,
201 u8 frag_id, u8 more,
202 u16 total_len)
203{
204 struct wpabuf *buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800206 buf = gas_anqp_build_comeback_resp(dialog_token, status_code, frag_id,
207 more, 0, 100 + len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 if (buf == NULL)
209 return NULL;
210
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211 if (frag_id == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800212 /* ANQP Query Response Frame */
213 wpabuf_put_le16(buf, ANQP_VENDOR_SPECIFIC); /* Info ID */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214 wpabuf_put_le16(buf, 3 + 1 + 2 + total_len);
215 wpabuf_put_be24(buf, OUI_WFA);
216 wpabuf_put_u8(buf, P2P_OUI_TYPE);
217 /* Service Update Indicator */
218 wpabuf_put_le16(buf, update_indic);
219 }
220
221 wpabuf_put_data(buf, data, len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222 gas_anqp_set_len(buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223
224 return buf;
225}
226
227
228int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
229{
230 struct wpabuf *req;
231 int ret = 0;
232 struct p2p_sd_query *query;
233 int freq;
234
235 freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
236 if (freq <= 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700237 p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
238 MACSTR " to send SD Request",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 MAC2STR(dev->info.p2p_device_addr));
240 return -1;
241 }
242
243 query = p2p_pending_sd_req(p2p, dev);
244 if (query == NULL)
245 return -1;
246
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700247 p2p_dbg(p2p, "Start Service Discovery with " MACSTR,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 MAC2STR(dev->info.p2p_device_addr));
249
250 req = p2p_build_sd_query(p2p->srv_update_indic, query->tlvs);
251 if (req == NULL)
252 return -1;
253
254 p2p->sd_peer = dev;
255 p2p->sd_query = query;
256 p2p->pending_action_state = P2P_PENDING_SD;
257
258 if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
259 p2p->cfg->dev_addr, dev->info.p2p_device_addr,
260 wpabuf_head(req), wpabuf_len(req), 5000) < 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700261 p2p_dbg(p2p, "Failed to send Action frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 ret = -1;
263 }
264
265 wpabuf_free(req);
266
267 return ret;
268}
269
270
271void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
272 const u8 *data, size_t len, int rx_freq)
273{
274 const u8 *pos = data;
275 const u8 *end = data + len;
276 const u8 *next;
277 u8 dialog_token;
278 u16 slen;
279 int freq;
280 u16 update_indic;
281
282
283 if (p2p->cfg->sd_request == NULL)
284 return;
285
286 if (rx_freq > 0)
287 freq = rx_freq;
288 else
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700289 freq = p2p_channel_to_freq(p2p->cfg->reg_class,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 p2p->cfg->channel);
291 if (freq < 0)
292 return;
293
294 if (len < 1 + 2)
295 return;
296
297 dialog_token = *pos++;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700298 p2p_dbg(p2p, "GAS Initial Request from " MACSTR
299 " (dialog token %u, freq %d)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 MAC2STR(sa), dialog_token, rx_freq);
301
302 if (*pos != WLAN_EID_ADV_PROTO) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700303 p2p_dbg(p2p, "Unexpected IE in GAS Initial Request: %u", *pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 return;
305 }
306 pos++;
307
308 slen = *pos++;
309 next = pos + slen;
310 if (next > end || slen < 2) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700311 p2p_dbg(p2p, "Invalid IE in GAS Initial Request");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 return;
313 }
314 pos++; /* skip QueryRespLenLimit and PAME-BI */
315
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800316 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700317 p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 *pos);
319 return;
320 }
321
322 pos = next;
323 /* Query Request */
324 if (pos + 2 > end)
325 return;
326 slen = WPA_GET_LE16(pos);
327 pos += 2;
328 if (pos + slen > end)
329 return;
330 end = pos + slen;
331
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800332 /* ANQP Query Request */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 if (pos + 4 > end)
334 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800335 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700336 p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 return;
338 }
339 pos += 2;
340
341 slen = WPA_GET_LE16(pos);
342 pos += 2;
343 if (pos + slen > end || slen < 3 + 1) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700344 p2p_dbg(p2p, "Invalid ANQP Query Request length");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 return;
346 }
347
348 if (WPA_GET_BE24(pos) != OUI_WFA) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700349 p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350 return;
351 }
352 pos += 3;
353
354 if (*pos != P2P_OUI_TYPE) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700355 p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 return;
357 }
358 pos++;
359
360 if (pos + 2 > end)
361 return;
362 update_indic = WPA_GET_LE16(pos);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700363 p2p_dbg(p2p, "Service Update Indicator: %u", update_indic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 pos += 2;
365
366 p2p->cfg->sd_request(p2p->cfg->cb_ctx, freq, sa, dialog_token,
367 update_indic, pos, end - pos);
368 /* the response will be indicated with a call to p2p_sd_response() */
369}
370
371
372void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
373 u8 dialog_token, const struct wpabuf *resp_tlvs)
374{
375 struct wpabuf *resp;
376
377 /* TODO: fix the length limit to match with the maximum frame length */
378 if (wpabuf_len(resp_tlvs) > 1400) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700379 p2p_dbg(p2p, "SD response long enough to require fragmentation");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 if (p2p->sd_resp) {
381 /*
382 * TODO: Could consider storing the fragmented response
383 * separately for each peer to avoid having to drop old
384 * one if there is more than one pending SD query.
385 * Though, that would eat more memory, so there are
386 * also benefits to just using a single buffer.
387 */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700388 p2p_dbg(p2p, "Drop previous SD response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389 wpabuf_free(p2p->sd_resp);
390 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700391 p2p->sd_resp = wpabuf_dup(resp_tlvs);
392 if (p2p->sd_resp == NULL) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700393 p2p_err(p2p, "Failed to allocate SD response fragmentation area");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700394 return;
395 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 os_memcpy(p2p->sd_resp_addr, dst, ETH_ALEN);
397 p2p->sd_resp_dialog_token = dialog_token;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398 p2p->sd_resp_pos = 0;
399 p2p->sd_frag_id = 0;
400 resp = p2p_build_sd_response(dialog_token, WLAN_STATUS_SUCCESS,
401 1, p2p->srv_update_indic, NULL);
402 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700403 p2p_dbg(p2p, "SD response fits in initial response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 resp = p2p_build_sd_response(dialog_token,
405 WLAN_STATUS_SUCCESS, 0,
406 p2p->srv_update_indic, resp_tlvs);
407 }
408 if (resp == NULL)
409 return;
410
411 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
412 if (p2p_send_action(p2p, freq, dst, p2p->cfg->dev_addr,
413 p2p->cfg->dev_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 wpabuf_head(resp), wpabuf_len(resp), 200) < 0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700415 p2p_dbg(p2p, "Failed to send Action frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416
417 wpabuf_free(resp);
418}
419
420
421void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
422 const u8 *data, size_t len, int rx_freq)
423{
424 const u8 *pos = data;
425 const u8 *end = data + len;
426 const u8 *next;
427 u8 dialog_token;
428 u16 status_code;
429 u16 comeback_delay;
430 u16 slen;
431 u16 update_indic;
432
Dmitry Shmidt04949592012-07-19 12:16:46 -0700433#ifdef ANDROID_P2P
434 if (p2p->state != P2P_SD_DURING_FIND) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700435 p2p_dbg(p2p, "P2P: #### Not ignoring unexpected GAS Initial Response from "
Dmitry Shmidt04949592012-07-19 12:16:46 -0700436 MACSTR " state %d", MAC2STR(sa), p2p->state);
437 }
438 if (p2p->sd_peer == NULL ||
439#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
Dmitry Shmidt04949592012-07-19 12:16:46 -0700441#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442 os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700443 p2p_dbg(p2p, "Ignore unexpected GAS Initial Response from "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 MACSTR, MAC2STR(sa));
445 return;
446 }
447 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
448 p2p_clear_timeout(p2p);
449
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700450 p2p_dbg(p2p, "Received GAS Initial Response from " MACSTR " (len=%d)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 MAC2STR(sa), (int) len);
452
453 if (len < 5 + 2) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700454 p2p_dbg(p2p, "Too short GAS Initial Response frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 return;
456 }
457
458 dialog_token = *pos++;
459 /* TODO: check dialog_token match */
460 status_code = WPA_GET_LE16(pos);
461 pos += 2;
462 comeback_delay = WPA_GET_LE16(pos);
463 pos += 2;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700464 p2p_dbg(p2p, "dialog_token=%u status_code=%u comeback_delay=%u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 dialog_token, status_code, comeback_delay);
466 if (status_code) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700467 p2p_dbg(p2p, "Service Discovery failed: status code %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 status_code);
469 return;
470 }
471
472 if (*pos != WLAN_EID_ADV_PROTO) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700473 p2p_dbg(p2p, "Unexpected IE in GAS Initial Response: %u", *pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 return;
475 }
476 pos++;
477
478 slen = *pos++;
479 next = pos + slen;
480 if (next > end || slen < 2) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700481 p2p_dbg(p2p, "Invalid IE in GAS Initial Response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 return;
483 }
484 pos++; /* skip QueryRespLenLimit and PAME-BI */
485
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800486 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700487 p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 *pos);
489 return;
490 }
491
492 pos = next;
493 /* Query Response */
494 if (pos + 2 > end) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700495 p2p_dbg(p2p, "Too short Query Response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 return;
497 }
498 slen = WPA_GET_LE16(pos);
499 pos += 2;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700500 p2p_dbg(p2p, "Query Response Length: %d", slen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 if (pos + slen > end) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700502 p2p_dbg(p2p, "Not enough Query Response data");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503 return;
504 }
505 end = pos + slen;
506
507 if (comeback_delay) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700508 p2p_dbg(p2p, "Fragmented response - request fragments");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 if (p2p->sd_rx_resp) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700510 p2p_dbg(p2p, "Drop old SD reassembly buffer");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 wpabuf_free(p2p->sd_rx_resp);
512 p2p->sd_rx_resp = NULL;
513 }
514 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
515 return;
516 }
517
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800518 /* ANQP Query Response */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 if (pos + 4 > end)
520 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700522 p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 return;
524 }
525 pos += 2;
526
527 slen = WPA_GET_LE16(pos);
528 pos += 2;
529 if (pos + slen > end || slen < 3 + 1) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700530 p2p_dbg(p2p, "Invalid ANQP Query Response length");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700531 return;
532 }
533
534 if (WPA_GET_BE24(pos) != OUI_WFA) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700535 p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 return;
537 }
538 pos += 3;
539
540 if (*pos != P2P_OUI_TYPE) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700541 p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 return;
543 }
544 pos++;
545
546 if (pos + 2 > end)
547 return;
548 update_indic = WPA_GET_LE16(pos);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700549 p2p_dbg(p2p, "Service Update Indicator: %u", update_indic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550 pos += 2;
551
552 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
553 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
554 p2p->sd_peer = NULL;
555
556 if (p2p->sd_query) {
557 if (!p2p->sd_query->for_all_peers) {
558 struct p2p_sd_query *q;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700559 p2p_dbg(p2p, "Remove completed SD query %p",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 p2p->sd_query);
561 q = p2p->sd_query;
562 p2p_unlink_sd_query(p2p, p2p->sd_query);
563 p2p_free_sd_query(q);
564 }
565 p2p->sd_query = NULL;
566 }
567
568 if (p2p->cfg->sd_response)
569 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa, update_indic,
570 pos, end - pos);
571 p2p_continue_find(p2p);
572}
573
574
575void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
576 const u8 *data, size_t len, int rx_freq)
577{
578 struct wpabuf *resp;
579 u8 dialog_token;
580 size_t frag_len;
581 int more = 0;
582
583 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Request", data, len);
584 if (len < 1)
585 return;
586 dialog_token = *data;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700587 p2p_dbg(p2p, "Dialog Token: %u", dialog_token);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 if (dialog_token != p2p->sd_resp_dialog_token) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700589 p2p_dbg(p2p, "No pending SD response fragment for dialog token %u",
590 dialog_token);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 return;
592 }
593
594 if (p2p->sd_resp == NULL) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700595 p2p_dbg(p2p, "No pending SD response fragment available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 return;
597 }
598 if (os_memcmp(sa, p2p->sd_resp_addr, ETH_ALEN) != 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700599 p2p_dbg(p2p, "No pending SD response fragment for " MACSTR,
600 MAC2STR(sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601 return;
602 }
603
604 frag_len = wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos;
605 if (frag_len > 1400) {
606 frag_len = 1400;
607 more = 1;
608 }
609 resp = p2p_build_gas_comeback_resp(dialog_token, WLAN_STATUS_SUCCESS,
610 p2p->srv_update_indic,
611 wpabuf_head_u8(p2p->sd_resp) +
612 p2p->sd_resp_pos, frag_len,
613 p2p->sd_frag_id, more,
614 wpabuf_len(p2p->sd_resp));
615 if (resp == NULL)
616 return;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700617 p2p_dbg(p2p, "Send GAS Comeback Response (frag_id %d more=%d frag_len=%d)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618 p2p->sd_frag_id, more, (int) frag_len);
619 p2p->sd_frag_id++;
620 p2p->sd_resp_pos += frag_len;
621
622 if (more) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700623 p2p_dbg(p2p, "%d more bytes remain to be sent",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 (int) (wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos));
625 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700626 p2p_dbg(p2p, "All fragments of SD response sent");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 wpabuf_free(p2p->sd_resp);
628 p2p->sd_resp = NULL;
629 }
630
631 p2p->pending_action_state = P2P_NO_PENDING_ACTION;
632 if (p2p_send_action(p2p, rx_freq, sa, p2p->cfg->dev_addr,
633 p2p->cfg->dev_addr,
634 wpabuf_head(resp), wpabuf_len(resp), 200) < 0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700635 p2p_dbg(p2p, "Failed to send Action frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636
637 wpabuf_free(resp);
638}
639
640
641void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
642 const u8 *data, size_t len, int rx_freq)
643{
644 const u8 *pos = data;
645 const u8 *end = data + len;
646 const u8 *next;
647 u8 dialog_token;
648 u16 status_code;
649 u8 frag_id;
650 u8 more_frags;
651 u16 comeback_delay;
652 u16 slen;
653
654 wpa_hexdump(MSG_DEBUG, "P2P: RX GAS Comeback Response", data, len);
655
Dmitry Shmidt04949592012-07-19 12:16:46 -0700656#ifdef ANDROID_P2P
657 if (p2p->state != P2P_SD_DURING_FIND) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700658 p2p_dbg(p2p, "P2P: #### Not ignoring unexpected GAS Comeback Response from "
Dmitry Shmidt04949592012-07-19 12:16:46 -0700659 MACSTR " state %d", MAC2STR(sa), p2p->state);
660 }
661 if (p2p->sd_peer == NULL ||
662#else
663 if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
664#endif
665 os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700666 p2p_dbg(p2p, "Ignore unexpected GAS Comeback Response from "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 MACSTR, MAC2STR(sa));
668 return;
669 }
670 p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
671 p2p_clear_timeout(p2p);
672
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700673 p2p_dbg(p2p, "Received GAS Comeback Response from " MACSTR " (len=%d)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 MAC2STR(sa), (int) len);
675
676 if (len < 6 + 2) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700677 p2p_dbg(p2p, "Too short GAS Comeback Response frame");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 return;
679 }
680
681 dialog_token = *pos++;
682 /* TODO: check dialog_token match */
683 status_code = WPA_GET_LE16(pos);
684 pos += 2;
685 frag_id = *pos & 0x7f;
686 more_frags = (*pos & 0x80) >> 7;
687 pos++;
688 comeback_delay = WPA_GET_LE16(pos);
689 pos += 2;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700690 p2p_dbg(p2p, "dialog_token=%u status_code=%u frag_id=%d more_frags=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 "comeback_delay=%u",
692 dialog_token, status_code, frag_id, more_frags,
693 comeback_delay);
694 /* TODO: check frag_id match */
695 if (status_code) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700696 p2p_dbg(p2p, "Service Discovery failed: status code %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697 status_code);
698 return;
699 }
700
701 if (*pos != WLAN_EID_ADV_PROTO) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700702 p2p_dbg(p2p, "Unexpected IE in GAS Comeback Response: %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 *pos);
704 return;
705 }
706 pos++;
707
708 slen = *pos++;
709 next = pos + slen;
710 if (next > end || slen < 2) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700711 p2p_dbg(p2p, "Invalid IE in GAS Comeback Response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 return;
713 }
714 pos++; /* skip QueryRespLenLimit and PAME-BI */
715
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800716 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700717 p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 *pos);
719 return;
720 }
721
722 pos = next;
723 /* Query Response */
724 if (pos + 2 > end) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700725 p2p_dbg(p2p, "Too short Query Response");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726 return;
727 }
728 slen = WPA_GET_LE16(pos);
729 pos += 2;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700730 p2p_dbg(p2p, "Query Response Length: %d", slen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 if (pos + slen > end) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700732 p2p_dbg(p2p, "Not enough Query Response data");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 return;
734 }
735 if (slen == 0) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700736 p2p_dbg(p2p, "No Query Response data");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 return;
738 }
739 end = pos + slen;
740
741 if (p2p->sd_rx_resp) {
742 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800743 * ANQP header is only included in the first fragment; rest of
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 * the fragments start with continue TLVs.
745 */
746 goto skip_nqp_header;
747 }
748
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800749 /* ANQP Query Response */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750 if (pos + 4 > end)
751 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800752 if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700753 p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 return;
755 }
756 pos += 2;
757
758 slen = WPA_GET_LE16(pos);
759 pos += 2;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700760 p2p_dbg(p2p, "ANQP Query Response length: %u", slen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 if (slen < 3 + 1) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700762 p2p_dbg(p2p, "Invalid ANQP Query Response length");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 return;
764 }
765 if (pos + 4 > end)
766 return;
767
768 if (WPA_GET_BE24(pos) != OUI_WFA) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700769 p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 return;
771 }
772 pos += 3;
773
774 if (*pos != P2P_OUI_TYPE) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700775 p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 return;
777 }
778 pos++;
779
780 if (pos + 2 > end)
781 return;
782 p2p->sd_rx_update_indic = WPA_GET_LE16(pos);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700783 p2p_dbg(p2p, "Service Update Indicator: %u", p2p->sd_rx_update_indic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 pos += 2;
785
786skip_nqp_header:
787 if (wpabuf_resize(&p2p->sd_rx_resp, end - pos) < 0)
788 return;
789 wpabuf_put_data(p2p->sd_rx_resp, pos, end - pos);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700790 p2p_dbg(p2p, "Current SD reassembly buffer length: %u",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 (unsigned int) wpabuf_len(p2p->sd_rx_resp));
792
793 if (more_frags) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700794 p2p_dbg(p2p, "More fragments remains");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 /* TODO: what would be a good size limit? */
796 if (wpabuf_len(p2p->sd_rx_resp) > 64000) {
797 wpabuf_free(p2p->sd_rx_resp);
798 p2p->sd_rx_resp = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700799 p2p_dbg(p2p, "Too long SD response - drop it");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 return;
801 }
802 p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
803 return;
804 }
805
806 p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
807 p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
808 p2p->sd_peer = NULL;
809
810 if (p2p->sd_query) {
811 if (!p2p->sd_query->for_all_peers) {
812 struct p2p_sd_query *q;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700813 p2p_dbg(p2p, "Remove completed SD query %p",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 p2p->sd_query);
815 q = p2p->sd_query;
816 p2p_unlink_sd_query(p2p, p2p->sd_query);
817 p2p_free_sd_query(q);
818 }
819 p2p->sd_query = NULL;
820 }
821
822 if (p2p->cfg->sd_response)
823 p2p->cfg->sd_response(p2p->cfg->cb_ctx, sa,
824 p2p->sd_rx_update_indic,
825 wpabuf_head(p2p->sd_rx_resp),
826 wpabuf_len(p2p->sd_rx_resp));
827 wpabuf_free(p2p->sd_rx_resp);
828 p2p->sd_rx_resp = NULL;
829
830 p2p_continue_find(p2p);
831}
832
833
834void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
835 const struct wpabuf *tlvs)
836{
837 struct p2p_sd_query *q;
Irfan Sherifff44b9c42012-06-13 11:09:23 -0700838#ifdef ANDROID_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -0700839 /* Currently, supplicant doesn't support more than one pending broadcast SD request.
Irfan Sherifff44b9c42012-06-13 11:09:23 -0700840 * So reject if application is registering another one before cancelling the existing one.
841 */
842 for (q = p2p->sd_queries; q; q = q->next) {
843 if( (q->for_all_peers == 1) && (!dst)) {
844 wpa_printf(MSG_ERROR, "P2P: Already one pending"
845 " Broadcast request. Please cancel the current one"
846 " before adding a new one");
847 return NULL;
848 }
849 }
850#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851
852 q = os_zalloc(sizeof(*q));
853 if (q == NULL)
854 return NULL;
855
856 if (dst)
857 os_memcpy(q->peer, dst, ETH_ALEN);
858 else
859 q->for_all_peers = 1;
860
861 q->tlvs = wpabuf_dup(tlvs);
862 if (q->tlvs == NULL) {
863 p2p_free_sd_query(q);
864 return NULL;
865 }
866
867 q->next = p2p->sd_queries;
868 p2p->sd_queries = q;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700869 p2p_dbg(p2p, "Added SD Query %p", q);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870
Irfan Sheriff96161872012-04-11 18:07:13 -0700871 if (dst == NULL) {
872 struct p2p_device *dev;
873 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list)
874 dev->flags &= ~P2P_DEV_SD_INFO;
875 }
876
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877 return q;
878}
879
880
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700881#ifdef CONFIG_WIFI_DISPLAY
882void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst,
883 const struct wpabuf *tlvs)
884{
885 struct p2p_sd_query *q;
886 q = p2p_sd_request(p2p, dst, tlvs);
887 if (q)
888 q->wsd = 1;
889 return q;
890}
891#endif /* CONFIG_WIFI_DISPLAY */
892
893
Dmitry Shmidtb5e8f062012-08-08 10:56:33 -0700894#ifdef ANDROID_P2P
895void p2p_sd_service_update(struct p2p_data *p2p, int action)
896#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897void p2p_sd_service_update(struct p2p_data *p2p)
Dmitry Shmidtb5e8f062012-08-08 10:56:33 -0700898#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899{
900 p2p->srv_update_indic++;
Dmitry Shmidtb5e8f062012-08-08 10:56:33 -0700901#ifdef ANDROID_P2P
902 if(action == SRV_FLUSH)
903 p2p->srv_count = 0;
904 else if (action == SRV_DEL)
905 p2p->srv_count--;
906 else if (action == SRV_ADD)
907 p2p->srv_count++;
908
909 if(p2p->cfg->sd_request) {
910 if (p2p->srv_count == 1) {
911 /* First Service Registered. Enable SD capability */
912 p2p->dev_capab |= P2P_DEV_CAPAB_SERVICE_DISCOVERY;
913 } else if (p2p->srv_count == 0 && !p2p->sd_queries) {
914 /* No services remaining + No queries registered .
915 * Remove the SD Capability
916 */
917 p2p->dev_capab &= ~P2P_DEV_CAPAB_SERVICE_DISCOVERY;
918 }
919 }
920#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921}
922
923
924int p2p_sd_cancel_request(struct p2p_data *p2p, void *req)
925{
926 if (p2p_unlink_sd_query(p2p, req)) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700927 p2p_dbg(p2p, "Cancel pending SD query %p", req);
Irfan Sherifff44b9c42012-06-13 11:09:23 -0700928#ifdef ANDROID_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -0700929 p2p->sd_dev_list = NULL;
Irfan Sherifff44b9c42012-06-13 11:09:23 -0700930#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 p2p_free_sd_query(req);
932 return 0;
933 }
934 return -1;
935}