gas_query.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Generic advertisement service (GAS) query
  3. * Copyright (c) 2009, Atheros Communications
  4. * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "includes.h"
  10. #include "common.h"
  11. #include "utils/eloop.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "common/gas.h"
  14. #include "common/wpa_ctrl.h"
  15. #include "wpa_supplicant_i.h"
  16. #include "driver_i.h"
  17. #include "offchannel.h"
  18. #include "gas_query.h"
  19. /** GAS query timeout in seconds */
  20. #define GAS_QUERY_TIMEOUT_PERIOD 2
  21. /** Retry period for GAS query requests in milliseconds */
  22. #define GAS_SERVICE_RETRY_PERIOD_MS 500
  23. /**
  24. * struct gas_query_pending - Pending GAS query
  25. */
  26. struct gas_query_pending {
  27. struct dl_list list;
  28. u8 addr[ETH_ALEN];
  29. u8 dialog_token;
  30. u8 next_frag_id;
  31. unsigned int wait_comeback:1;
  32. unsigned int offchannel_tx_started:1;
  33. int freq;
  34. u16 status_code;
  35. struct wpabuf *req;
  36. struct wpabuf *adv_proto;
  37. struct wpabuf *resp;
  38. void (*cb)(void *ctx, const u8 *dst, u8 dialog_token,
  39. enum gas_query_result result,
  40. const struct wpabuf *adv_proto,
  41. const struct wpabuf *resp, u16 status_code);
  42. void *ctx;
  43. };
  44. /**
  45. * struct gas_query - Internal GAS query data
  46. */
  47. struct gas_query {
  48. struct wpa_supplicant *wpa_s;
  49. struct dl_list pending; /* struct gas_query_pending */
  50. struct gas_query_pending *current;
  51. };
  52. static void gas_query_tx_comeback_timeout(void *eloop_data, void *user_ctx);
  53. static void gas_query_timeout(void *eloop_data, void *user_ctx);
  54. static void gas_service_timeout(void *eloop_data, void *user_ctx);
  55. /**
  56. * gas_query_init - Initialize GAS query component
  57. * @wpa_s: Pointer to wpa_supplicant data
  58. * Returns: Pointer to GAS query data or %NULL on failure
  59. */
  60. struct gas_query * gas_query_init(struct wpa_supplicant *wpa_s)
  61. {
  62. struct gas_query *gas;
  63. gas = os_zalloc(sizeof(*gas));
  64. if (gas == NULL)
  65. return NULL;
  66. gas->wpa_s = wpa_s;
  67. dl_list_init(&gas->pending);
  68. return gas;
  69. }
  70. static const char * gas_result_txt(enum gas_query_result result)
  71. {
  72. switch (result) {
  73. case GAS_QUERY_SUCCESS:
  74. return "SUCCESS";
  75. case GAS_QUERY_FAILURE:
  76. return "FAILURE";
  77. case GAS_QUERY_TIMEOUT:
  78. return "TIMEOUT";
  79. case GAS_QUERY_PEER_ERROR:
  80. return "PEER_ERROR";
  81. case GAS_QUERY_INTERNAL_ERROR:
  82. return "INTERNAL_ERROR";
  83. case GAS_QUERY_CANCELLED:
  84. return "CANCELLED";
  85. case GAS_QUERY_DELETED_AT_DEINIT:
  86. return "DELETED_AT_DEINIT";
  87. }
  88. return "N/A";
  89. }
  90. static void gas_query_done(struct gas_query *gas,
  91. struct gas_query_pending *query,
  92. enum gas_query_result result)
  93. {
  94. wpa_msg(gas->wpa_s, MSG_INFO, GAS_QUERY_DONE "addr=" MACSTR
  95. " dialog_token=%u freq=%d status_code=%u result=%s",
  96. MAC2STR(query->addr), query->dialog_token, query->freq,
  97. query->status_code, gas_result_txt(result));
  98. if (gas->current == query)
  99. gas->current = NULL;
  100. if (query->offchannel_tx_started)
  101. offchannel_send_action_done(gas->wpa_s);
  102. eloop_cancel_timeout(gas_query_tx_comeback_timeout, gas, query);
  103. eloop_cancel_timeout(gas_query_timeout, gas, query);
  104. eloop_cancel_timeout(gas_service_timeout, gas, query);
  105. dl_list_del(&query->list);
  106. query->cb(query->ctx, query->addr, query->dialog_token, result,
  107. query->adv_proto, query->resp, query->status_code);
  108. wpabuf_free(query->req);
  109. wpabuf_free(query->adv_proto);
  110. wpabuf_free(query->resp);
  111. os_free(query);
  112. }
  113. /**
  114. * gas_query_deinit - Deinitialize GAS query component
  115. * @gas: GAS query data from gas_query_init()
  116. */
  117. void gas_query_deinit(struct gas_query *gas)
  118. {
  119. struct gas_query_pending *query, *next;
  120. if (gas == NULL)
  121. return;
  122. dl_list_for_each_safe(query, next, &gas->pending,
  123. struct gas_query_pending, list)
  124. gas_query_done(gas, query, GAS_QUERY_DELETED_AT_DEINIT);
  125. os_free(gas);
  126. }
  127. static struct gas_query_pending *
  128. gas_query_get_pending(struct gas_query *gas, const u8 *addr, u8 dialog_token)
  129. {
  130. struct gas_query_pending *q;
  131. dl_list_for_each(q, &gas->pending, struct gas_query_pending, list) {
  132. if (os_memcmp(q->addr, addr, ETH_ALEN) == 0 &&
  133. q->dialog_token == dialog_token)
  134. return q;
  135. }
  136. return NULL;
  137. }
  138. static int gas_query_append(struct gas_query_pending *query, const u8 *data,
  139. size_t len)
  140. {
  141. if (wpabuf_resize(&query->resp, len) < 0) {
  142. wpa_printf(MSG_DEBUG, "GAS: No memory to store the response");
  143. return -1;
  144. }
  145. wpabuf_put_data(query->resp, data, len);
  146. return 0;
  147. }
  148. static void gas_query_tx_status(struct wpa_supplicant *wpa_s,
  149. unsigned int freq, const u8 *dst,
  150. const u8 *src, const u8 *bssid,
  151. const u8 *data, size_t data_len,
  152. enum offchannel_send_action_result result)
  153. {
  154. struct gas_query_pending *query;
  155. struct gas_query *gas = wpa_s->gas;
  156. if (gas->current == NULL) {
  157. wpa_printf(MSG_DEBUG, "GAS: Unexpected TX status: freq=%u dst="
  158. MACSTR " result=%d - no query in progress",
  159. freq, MAC2STR(dst), result);
  160. return;
  161. }
  162. query = gas->current;
  163. wpa_printf(MSG_DEBUG, "GAS: TX status: freq=%u dst=" MACSTR
  164. " result=%d query=%p dialog_token=%u",
  165. freq, MAC2STR(dst), result, query, query->dialog_token);
  166. if (os_memcmp(dst, query->addr, ETH_ALEN) != 0) {
  167. wpa_printf(MSG_DEBUG, "GAS: TX status for unexpected destination");
  168. return;
  169. }
  170. if (result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
  171. eloop_cancel_timeout(gas_query_timeout, gas, query);
  172. eloop_register_timeout(GAS_QUERY_TIMEOUT_PERIOD, 0,
  173. gas_query_timeout, gas, query);
  174. }
  175. if (result == OFFCHANNEL_SEND_ACTION_FAILED) {
  176. eloop_cancel_timeout(gas_query_timeout, gas, query);
  177. eloop_register_timeout(0, 0, gas_query_timeout, gas, query);
  178. }
  179. }
  180. static int gas_query_tx(struct gas_query *gas, struct gas_query_pending *query,
  181. struct wpabuf *req)
  182. {
  183. int res;
  184. wpa_printf(MSG_DEBUG, "GAS: Send action frame to " MACSTR " len=%u "
  185. "freq=%d", MAC2STR(query->addr),
  186. (unsigned int) wpabuf_len(req), query->freq);
  187. res = offchannel_send_action(gas->wpa_s, query->freq, query->addr,
  188. gas->wpa_s->own_addr, query->addr,
  189. wpabuf_head(req), wpabuf_len(req), 1000,
  190. gas_query_tx_status, 0);
  191. if (res == 0)
  192. query->offchannel_tx_started = 1;
  193. return res;
  194. }
  195. static void gas_query_tx_comeback_req(struct gas_query *gas,
  196. struct gas_query_pending *query)
  197. {
  198. struct wpabuf *req;
  199. req = gas_build_comeback_req(query->dialog_token);
  200. if (req == NULL) {
  201. gas_query_done(gas, query, GAS_QUERY_INTERNAL_ERROR);
  202. return;
  203. }
  204. if (gas_query_tx(gas, query, req) < 0) {
  205. wpa_printf(MSG_DEBUG, "GAS: Failed to send Action frame to "
  206. MACSTR, MAC2STR(query->addr));
  207. gas_query_done(gas, query, GAS_QUERY_INTERNAL_ERROR);
  208. }
  209. wpabuf_free(req);
  210. }
  211. static void gas_query_tx_comeback_timeout(void *eloop_data, void *user_ctx)
  212. {
  213. struct gas_query *gas = eloop_data;
  214. struct gas_query_pending *query = user_ctx;
  215. wpa_printf(MSG_DEBUG, "GAS: Comeback timeout for request to " MACSTR,
  216. MAC2STR(query->addr));
  217. gas_query_tx_comeback_req(gas, query);
  218. }
  219. static void gas_query_tx_comeback_req_delay(struct gas_query *gas,
  220. struct gas_query_pending *query,
  221. u16 comeback_delay)
  222. {
  223. unsigned int secs, usecs;
  224. secs = (comeback_delay * 1024) / 1000000;
  225. usecs = comeback_delay * 1024 - secs * 1000000;
  226. wpa_printf(MSG_DEBUG, "GAS: Send comeback request to " MACSTR
  227. " in %u secs %u usecs", MAC2STR(query->addr), secs, usecs);
  228. eloop_cancel_timeout(gas_query_tx_comeback_timeout, gas, query);
  229. eloop_register_timeout(secs, usecs, gas_query_tx_comeback_timeout,
  230. gas, query);
  231. }
  232. static void gas_query_rx_initial(struct gas_query *gas,
  233. struct gas_query_pending *query,
  234. const u8 *adv_proto, const u8 *resp,
  235. size_t len, u16 comeback_delay)
  236. {
  237. wpa_printf(MSG_DEBUG, "GAS: Received initial response from "
  238. MACSTR " (dialog_token=%u comeback_delay=%u)",
  239. MAC2STR(query->addr), query->dialog_token, comeback_delay);
  240. query->adv_proto = wpabuf_alloc_copy(adv_proto, 2 + adv_proto[1]);
  241. if (query->adv_proto == NULL) {
  242. gas_query_done(gas, query, GAS_QUERY_INTERNAL_ERROR);
  243. return;
  244. }
  245. if (comeback_delay) {
  246. query->wait_comeback = 1;
  247. gas_query_tx_comeback_req_delay(gas, query, comeback_delay);
  248. return;
  249. }
  250. /* Query was completed without comeback mechanism */
  251. if (gas_query_append(query, resp, len) < 0) {
  252. gas_query_done(gas, query, GAS_QUERY_INTERNAL_ERROR);
  253. return;
  254. }
  255. gas_query_done(gas, query, GAS_QUERY_SUCCESS);
  256. }
  257. static void gas_query_rx_comeback(struct gas_query *gas,
  258. struct gas_query_pending *query,
  259. const u8 *adv_proto, const u8 *resp,
  260. size_t len, u8 frag_id, u8 more_frags,
  261. u16 comeback_delay)
  262. {
  263. wpa_printf(MSG_DEBUG, "GAS: Received comeback response from "
  264. MACSTR " (dialog_token=%u frag_id=%u more_frags=%u "
  265. "comeback_delay=%u)",
  266. MAC2STR(query->addr), query->dialog_token, frag_id,
  267. more_frags, comeback_delay);
  268. if ((size_t) 2 + adv_proto[1] != wpabuf_len(query->adv_proto) ||
  269. os_memcmp(adv_proto, wpabuf_head(query->adv_proto),
  270. wpabuf_len(query->adv_proto)) != 0) {
  271. wpa_printf(MSG_DEBUG, "GAS: Advertisement Protocol changed "
  272. "between initial and comeback response from "
  273. MACSTR, MAC2STR(query->addr));
  274. gas_query_done(gas, query, GAS_QUERY_PEER_ERROR);
  275. return;
  276. }
  277. if (comeback_delay) {
  278. if (frag_id) {
  279. wpa_printf(MSG_DEBUG, "GAS: Invalid comeback response "
  280. "with non-zero frag_id and comeback_delay "
  281. "from " MACSTR, MAC2STR(query->addr));
  282. gas_query_done(gas, query, GAS_QUERY_PEER_ERROR);
  283. return;
  284. }
  285. gas_query_tx_comeback_req_delay(gas, query, comeback_delay);
  286. return;
  287. }
  288. if (frag_id != query->next_frag_id) {
  289. wpa_printf(MSG_DEBUG, "GAS: Unexpected frag_id in response "
  290. "from " MACSTR, MAC2STR(query->addr));
  291. if (frag_id + 1 == query->next_frag_id) {
  292. wpa_printf(MSG_DEBUG, "GAS: Drop frame as possible "
  293. "retry of previous fragment");
  294. return;
  295. }
  296. gas_query_done(gas, query, GAS_QUERY_PEER_ERROR);
  297. return;
  298. }
  299. query->next_frag_id++;
  300. if (gas_query_append(query, resp, len) < 0) {
  301. gas_query_done(gas, query, GAS_QUERY_INTERNAL_ERROR);
  302. return;
  303. }
  304. if (more_frags) {
  305. gas_query_tx_comeback_req(gas, query);
  306. return;
  307. }
  308. gas_query_done(gas, query, GAS_QUERY_SUCCESS);
  309. }
  310. /**
  311. * gas_query_rx - Indicate reception of a Public Action frame
  312. * @gas: GAS query data from gas_query_init()
  313. * @da: Destination MAC address of the Action frame
  314. * @sa: Source MAC address of the Action frame
  315. * @bssid: BSSID of the Action frame
  316. * @data: Payload of the Action frame
  317. * @len: Length of @data
  318. * @freq: Frequency (in MHz) on which the frame was received
  319. * Returns: 0 if the Public Action frame was a GAS frame or -1 if not
  320. */
  321. int gas_query_rx(struct gas_query *gas, const u8 *da, const u8 *sa,
  322. const u8 *bssid, const u8 *data, size_t len, int freq)
  323. {
  324. struct gas_query_pending *query;
  325. u8 action, dialog_token, frag_id = 0, more_frags = 0;
  326. u16 comeback_delay, resp_len;
  327. const u8 *pos, *adv_proto;
  328. if (gas == NULL || len < 4)
  329. return -1;
  330. pos = data;
  331. action = *pos++;
  332. dialog_token = *pos++;
  333. if (action != WLAN_PA_GAS_INITIAL_RESP &&
  334. action != WLAN_PA_GAS_COMEBACK_RESP)
  335. return -1; /* Not a GAS response */
  336. query = gas_query_get_pending(gas, sa, dialog_token);
  337. if (query == NULL) {
  338. wpa_printf(MSG_DEBUG, "GAS: No pending query found for " MACSTR
  339. " dialog token %u", MAC2STR(sa), dialog_token);
  340. return -1;
  341. }
  342. if (query->wait_comeback && action == WLAN_PA_GAS_INITIAL_RESP) {
  343. wpa_printf(MSG_DEBUG, "GAS: Unexpected initial response from "
  344. MACSTR " dialog token %u when waiting for comeback "
  345. "response", MAC2STR(sa), dialog_token);
  346. return 0;
  347. }
  348. if (!query->wait_comeback && action == WLAN_PA_GAS_COMEBACK_RESP) {
  349. wpa_printf(MSG_DEBUG, "GAS: Unexpected comeback response from "
  350. MACSTR " dialog token %u when waiting for initial "
  351. "response", MAC2STR(sa), dialog_token);
  352. return 0;
  353. }
  354. query->status_code = WPA_GET_LE16(pos);
  355. pos += 2;
  356. if (query->status_code != WLAN_STATUS_SUCCESS) {
  357. wpa_printf(MSG_DEBUG, "GAS: Query to " MACSTR " dialog token "
  358. "%u failed - status code %u",
  359. MAC2STR(sa), dialog_token, query->status_code);
  360. gas_query_done(gas, query, GAS_QUERY_FAILURE);
  361. return 0;
  362. }
  363. if (action == WLAN_PA_GAS_COMEBACK_RESP) {
  364. if (pos + 1 > data + len)
  365. return 0;
  366. frag_id = *pos & 0x7f;
  367. more_frags = (*pos & 0x80) >> 7;
  368. pos++;
  369. }
  370. /* Comeback Delay */
  371. if (pos + 2 > data + len)
  372. return 0;
  373. comeback_delay = WPA_GET_LE16(pos);
  374. pos += 2;
  375. /* Advertisement Protocol element */
  376. if (pos + 2 > data + len || pos + 2 + pos[1] > data + len) {
  377. wpa_printf(MSG_DEBUG, "GAS: No room for Advertisement "
  378. "Protocol element in the response from " MACSTR,
  379. MAC2STR(sa));
  380. return 0;
  381. }
  382. if (*pos != WLAN_EID_ADV_PROTO) {
  383. wpa_printf(MSG_DEBUG, "GAS: Unexpected Advertisement "
  384. "Protocol element ID %u in response from " MACSTR,
  385. *pos, MAC2STR(sa));
  386. return 0;
  387. }
  388. adv_proto = pos;
  389. pos += 2 + pos[1];
  390. /* Query Response Length */
  391. if (pos + 2 > data + len) {
  392. wpa_printf(MSG_DEBUG, "GAS: No room for GAS Response Length");
  393. return 0;
  394. }
  395. resp_len = WPA_GET_LE16(pos);
  396. pos += 2;
  397. if (pos + resp_len > data + len) {
  398. wpa_printf(MSG_DEBUG, "GAS: Truncated Query Response in "
  399. "response from " MACSTR, MAC2STR(sa));
  400. return 0;
  401. }
  402. if (pos + resp_len < data + len) {
  403. wpa_printf(MSG_DEBUG, "GAS: Ignore %u octets of extra data "
  404. "after Query Response from " MACSTR,
  405. (unsigned int) (data + len - pos - resp_len),
  406. MAC2STR(sa));
  407. }
  408. if (action == WLAN_PA_GAS_COMEBACK_RESP)
  409. gas_query_rx_comeback(gas, query, adv_proto, pos, resp_len,
  410. frag_id, more_frags, comeback_delay);
  411. else
  412. gas_query_rx_initial(gas, query, adv_proto, pos, resp_len,
  413. comeback_delay);
  414. return 0;
  415. }
  416. static void gas_query_timeout(void *eloop_data, void *user_ctx)
  417. {
  418. struct gas_query *gas = eloop_data;
  419. struct gas_query_pending *query = user_ctx;
  420. wpa_printf(MSG_DEBUG, "GAS: No response received for query to " MACSTR
  421. " dialog token %u",
  422. MAC2STR(query->addr), query->dialog_token);
  423. gas_query_done(gas, query, GAS_QUERY_TIMEOUT);
  424. }
  425. static void gas_service_timeout(void *eloop_data, void *user_ctx)
  426. {
  427. struct gas_query *gas = eloop_data;
  428. struct wpa_supplicant *wpa_s = gas->wpa_s;
  429. struct gas_query_pending *query = user_ctx;
  430. int conn;
  431. conn = wpas_wpa_is_in_progress(wpa_s, 1);
  432. if (conn || wpa_s->scanning || gas->current) {
  433. wpa_printf(MSG_DEBUG, "GAS: Delaying GAS query Tx while another operation is in progress:%s%s%s",
  434. conn ? " connection" : "",
  435. wpa_s->scanning ? " scanning" : "",
  436. gas->current ? " gas_query" : "");
  437. eloop_register_timeout(
  438. GAS_SERVICE_RETRY_PERIOD_MS / 1000,
  439. (GAS_SERVICE_RETRY_PERIOD_MS % 1000) * 1000,
  440. gas_service_timeout, gas, query);
  441. return;
  442. }
  443. if (gas_query_tx(gas, query, query->req) < 0) {
  444. wpa_printf(MSG_DEBUG, "GAS: Failed to send Action frame to "
  445. MACSTR, MAC2STR(query->addr));
  446. dl_list_del(&query->list);
  447. wpabuf_free(query->req);
  448. os_free(query);
  449. return;
  450. }
  451. gas->current = query;
  452. wpa_printf(MSG_DEBUG, "GAS: Starting query timeout for dialog token %u",
  453. query->dialog_token);
  454. eloop_register_timeout(GAS_QUERY_TIMEOUT_PERIOD, 0,
  455. gas_query_timeout, gas, query);
  456. }
  457. static int gas_query_dialog_token_available(struct gas_query *gas,
  458. const u8 *dst, u8 dialog_token)
  459. {
  460. struct gas_query_pending *q;
  461. dl_list_for_each(q, &gas->pending, struct gas_query_pending, list) {
  462. if (os_memcmp(dst, q->addr, ETH_ALEN) == 0 &&
  463. dialog_token == q->dialog_token)
  464. return 0;
  465. }
  466. return 1;
  467. }
  468. /**
  469. * gas_query_req - Request a GAS query
  470. * @gas: GAS query data from gas_query_init()
  471. * @dst: Destination MAC address for the query
  472. * @freq: Frequency (in MHz) for the channel on which to send the query
  473. * @req: GAS query payload (to be freed by gas_query module in case of success
  474. * return)
  475. * @cb: Callback function for reporting GAS query result and response
  476. * @ctx: Context pointer to use with the @cb call
  477. * Returns: dialog token (>= 0) on success or -1 on failure
  478. */
  479. int gas_query_req(struct gas_query *gas, const u8 *dst, int freq,
  480. struct wpabuf *req,
  481. void (*cb)(void *ctx, const u8 *dst, u8 dialog_token,
  482. enum gas_query_result result,
  483. const struct wpabuf *adv_proto,
  484. const struct wpabuf *resp, u16 status_code),
  485. void *ctx)
  486. {
  487. struct gas_query_pending *query;
  488. int dialog_token;
  489. static int next_start = 0;
  490. if (wpabuf_len(req) < 3)
  491. return -1;
  492. for (dialog_token = 0; dialog_token < 256; dialog_token++) {
  493. if (gas_query_dialog_token_available(
  494. gas, dst, (next_start + dialog_token) % 256))
  495. break;
  496. }
  497. if (dialog_token == 256)
  498. return -1; /* Too many pending queries */
  499. dialog_token = (next_start + dialog_token) % 256;
  500. next_start = (dialog_token + 1) % 256;
  501. query = os_zalloc(sizeof(*query));
  502. if (query == NULL)
  503. return -1;
  504. os_memcpy(query->addr, dst, ETH_ALEN);
  505. query->dialog_token = dialog_token;
  506. query->freq = freq;
  507. query->cb = cb;
  508. query->ctx = ctx;
  509. query->req = req;
  510. dl_list_add(&gas->pending, &query->list);
  511. *(wpabuf_mhead_u8(req) + 2) = dialog_token;
  512. wpa_msg(gas->wpa_s, MSG_INFO, GAS_QUERY_START "addr=" MACSTR
  513. " dialog_token=%u freq=%d",
  514. MAC2STR(query->addr), query->dialog_token, query->freq);
  515. eloop_register_timeout(0, 0, gas_service_timeout, gas, query);
  516. return dialog_token;
  517. }
  518. /**
  519. * gas_query_cancel - Cancel a pending GAS query
  520. * @gas: GAS query data from gas_query_init()
  521. * @dst: Destination MAC address for the query
  522. * @dialog_token: Dialog token from gas_query_req()
  523. */
  524. void gas_query_cancel(struct gas_query *gas, const u8 *dst, u8 dialog_token)
  525. {
  526. struct gas_query_pending *query;
  527. query = gas_query_get_pending(gas, dst, dialog_token);
  528. if (query)
  529. gas_query_done(gas, query, GAS_QUERY_CANCELLED);
  530. }
  531. int gas_query_in_progress(struct gas_query *gas)
  532. {
  533. return gas->current != NULL;
  534. }