PageRenderTime 41ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/freebsd/contrib/wpa/wpa_supplicant/scan.c

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
C | 689 lines | 507 code | 115 blank | 67 comment | 171 complexity | e3179145fb79eab290305412136487d6 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. * WPA Supplicant - Scanning
  3. * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
  4. *
  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.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "utils/eloop.h"
  17. #include "common/ieee802_11_defs.h"
  18. #include "config.h"
  19. #include "wpa_supplicant_i.h"
  20. #include "driver_i.h"
  21. #include "mlme.h"
  22. #include "wps_supplicant.h"
  23. #include "notify.h"
  24. #include "bss.h"
  25. #include "scan.h"
  26. static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
  27. {
  28. struct wpa_ssid *ssid;
  29. union wpa_event_data data;
  30. ssid = wpa_supplicant_get_ssid(wpa_s);
  31. if (ssid == NULL)
  32. return;
  33. if (wpa_s->current_ssid == NULL) {
  34. wpa_s->current_ssid = ssid;
  35. if (wpa_s->current_ssid != NULL)
  36. wpas_notify_network_changed(wpa_s);
  37. }
  38. wpa_supplicant_initiate_eapol(wpa_s);
  39. wpa_printf(MSG_DEBUG, "Already associated with a configured network - "
  40. "generating associated event");
  41. os_memset(&data, 0, sizeof(data));
  42. wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
  43. }
  44. #ifdef CONFIG_WPS
  45. static int wpas_wps_in_use(struct wpa_config *conf,
  46. enum wps_request_type *req_type)
  47. {
  48. struct wpa_ssid *ssid;
  49. int wps = 0;
  50. for (ssid = conf->ssid; ssid; ssid = ssid->next) {
  51. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  52. continue;
  53. wps = 1;
  54. *req_type = wpas_wps_get_req_type(ssid);
  55. if (!ssid->eap.phase1)
  56. continue;
  57. if (os_strstr(ssid->eap.phase1, "pbc=1"))
  58. return 2;
  59. }
  60. return wps;
  61. }
  62. #endif /* CONFIG_WPS */
  63. int wpa_supplicant_enabled_networks(struct wpa_config *conf)
  64. {
  65. struct wpa_ssid *ssid = conf->ssid;
  66. while (ssid) {
  67. if (!ssid->disabled)
  68. return 1;
  69. ssid = ssid->next;
  70. }
  71. return 0;
  72. }
  73. static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
  74. struct wpa_ssid *ssid)
  75. {
  76. while (ssid) {
  77. if (!ssid->disabled)
  78. break;
  79. ssid = ssid->next;
  80. }
  81. /* ap_scan=2 mode - try to associate with each SSID. */
  82. if (ssid == NULL) {
  83. wpa_printf(MSG_DEBUG, "wpa_supplicant_scan: Reached "
  84. "end of scan list - go back to beginning");
  85. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  86. wpa_supplicant_req_scan(wpa_s, 0, 0);
  87. return;
  88. }
  89. if (ssid->next) {
  90. /* Continue from the next SSID on the next attempt. */
  91. wpa_s->prev_scan_ssid = ssid;
  92. } else {
  93. /* Start from the beginning of the SSID list. */
  94. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  95. }
  96. wpa_supplicant_associate(wpa_s, NULL, ssid);
  97. }
  98. static int int_array_len(const int *a)
  99. {
  100. int i;
  101. for (i = 0; a && a[i]; i++)
  102. ;
  103. return i;
  104. }
  105. static void int_array_concat(int **res, const int *a)
  106. {
  107. int reslen, alen, i;
  108. int *n;
  109. reslen = int_array_len(*res);
  110. alen = int_array_len(a);
  111. n = os_realloc(*res, (reslen + alen + 1) * sizeof(int));
  112. if (n == NULL) {
  113. os_free(*res);
  114. *res = NULL;
  115. return;
  116. }
  117. for (i = 0; i <= alen; i++)
  118. n[reslen + i] = a[i];
  119. *res = n;
  120. }
  121. static int freq_cmp(const void *a, const void *b)
  122. {
  123. int _a = *(int *) a;
  124. int _b = *(int *) b;
  125. if (_a == 0)
  126. return 1;
  127. if (_b == 0)
  128. return -1;
  129. return _a - _b;
  130. }
  131. static void int_array_sort_unique(int *a)
  132. {
  133. int alen;
  134. int i, j;
  135. if (a == NULL)
  136. return;
  137. alen = int_array_len(a);
  138. qsort(a, alen, sizeof(int), freq_cmp);
  139. i = 0;
  140. j = 1;
  141. while (a[i] && a[j]) {
  142. if (a[i] == a[j]) {
  143. j++;
  144. continue;
  145. }
  146. a[++i] = a[j++];
  147. }
  148. if (a[i])
  149. i++;
  150. a[i] = 0;
  151. }
  152. int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
  153. struct wpa_driver_scan_params *params)
  154. {
  155. int ret;
  156. wpa_supplicant_notify_scanning(wpa_s, 1);
  157. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  158. ret = ieee80211_sta_req_scan(wpa_s, params);
  159. else
  160. ret = wpa_drv_scan(wpa_s, params);
  161. if (ret) {
  162. wpa_supplicant_notify_scanning(wpa_s, 0);
  163. wpas_notify_scan_done(wpa_s, 0);
  164. } else
  165. wpa_s->scan_runs++;
  166. return ret;
  167. }
  168. static struct wpa_driver_scan_filter *
  169. wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
  170. {
  171. struct wpa_driver_scan_filter *ssids;
  172. struct wpa_ssid *ssid;
  173. size_t count;
  174. *num_ssids = 0;
  175. if (!conf->filter_ssids)
  176. return NULL;
  177. for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
  178. if (ssid->ssid && ssid->ssid_len)
  179. count++;
  180. }
  181. if (count == 0)
  182. return NULL;
  183. ssids = os_zalloc(count * sizeof(struct wpa_driver_scan_filter));
  184. if (ssids == NULL)
  185. return NULL;
  186. for (ssid = conf->ssid; ssid; ssid = ssid->next) {
  187. if (!ssid->ssid || !ssid->ssid_len)
  188. continue;
  189. os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
  190. ssids[*num_ssids].ssid_len = ssid->ssid_len;
  191. (*num_ssids)++;
  192. }
  193. return ssids;
  194. }
  195. static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
  196. {
  197. struct wpa_supplicant *wpa_s = eloop_ctx;
  198. struct wpa_ssid *ssid;
  199. int scan_req = 0, ret;
  200. struct wpabuf *wps_ie = NULL;
  201. #ifdef CONFIG_WPS
  202. int wps = 0;
  203. enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
  204. #endif /* CONFIG_WPS */
  205. struct wpa_driver_scan_params params;
  206. size_t max_ssids;
  207. enum wpa_states prev_state;
  208. if (wpa_s->disconnected && !wpa_s->scan_req) {
  209. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  210. return;
  211. }
  212. if (!wpa_supplicant_enabled_networks(wpa_s->conf) &&
  213. !wpa_s->scan_req) {
  214. wpa_printf(MSG_DEBUG, "No enabled networks - do not scan");
  215. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  216. return;
  217. }
  218. if (wpa_s->conf->ap_scan != 0 &&
  219. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
  220. wpa_printf(MSG_DEBUG, "Using wired authentication - "
  221. "overriding ap_scan configuration");
  222. wpa_s->conf->ap_scan = 0;
  223. wpas_notify_ap_scan_changed(wpa_s);
  224. }
  225. if (wpa_s->conf->ap_scan == 0) {
  226. wpa_supplicant_gen_assoc_event(wpa_s);
  227. return;
  228. }
  229. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  230. wpa_s->conf->ap_scan == 2)
  231. max_ssids = 1;
  232. else {
  233. max_ssids = wpa_s->max_scan_ssids;
  234. if (max_ssids > WPAS_MAX_SCAN_SSIDS)
  235. max_ssids = WPAS_MAX_SCAN_SSIDS;
  236. }
  237. #ifdef CONFIG_WPS
  238. wps = wpas_wps_in_use(wpa_s->conf, &req_type);
  239. #endif /* CONFIG_WPS */
  240. scan_req = wpa_s->scan_req;
  241. wpa_s->scan_req = 0;
  242. os_memset(&params, 0, sizeof(params));
  243. prev_state = wpa_s->wpa_state;
  244. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  245. wpa_s->wpa_state == WPA_INACTIVE)
  246. wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
  247. /* Find the starting point from which to continue scanning */
  248. ssid = wpa_s->conf->ssid;
  249. if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
  250. while (ssid) {
  251. if (ssid == wpa_s->prev_scan_ssid) {
  252. ssid = ssid->next;
  253. break;
  254. }
  255. ssid = ssid->next;
  256. }
  257. }
  258. if (scan_req != 2 && (wpa_s->conf->ap_scan == 2 ||
  259. wpa_s->connect_without_scan)) {
  260. wpa_s->connect_without_scan = 0;
  261. wpa_supplicant_assoc_try(wpa_s, ssid);
  262. return;
  263. } else if (wpa_s->conf->ap_scan == 2) {
  264. /*
  265. * User-initiated scan request in ap_scan == 2; scan with
  266. * wildcard SSID.
  267. */
  268. ssid = NULL;
  269. } else {
  270. struct wpa_ssid *start = ssid, *tssid;
  271. int freqs_set = 0;
  272. if (ssid == NULL && max_ssids > 1)
  273. ssid = wpa_s->conf->ssid;
  274. while (ssid) {
  275. if (!ssid->disabled && ssid->scan_ssid) {
  276. wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
  277. ssid->ssid, ssid->ssid_len);
  278. params.ssids[params.num_ssids].ssid =
  279. ssid->ssid;
  280. params.ssids[params.num_ssids].ssid_len =
  281. ssid->ssid_len;
  282. params.num_ssids++;
  283. if (params.num_ssids + 1 >= max_ssids)
  284. break;
  285. }
  286. ssid = ssid->next;
  287. if (ssid == start)
  288. break;
  289. if (ssid == NULL && max_ssids > 1 &&
  290. start != wpa_s->conf->ssid)
  291. ssid = wpa_s->conf->ssid;
  292. }
  293. for (tssid = wpa_s->conf->ssid; tssid; tssid = tssid->next) {
  294. if (tssid->disabled)
  295. continue;
  296. if ((params.freqs || !freqs_set) && tssid->scan_freq) {
  297. int_array_concat(&params.freqs,
  298. tssid->scan_freq);
  299. } else {
  300. os_free(params.freqs);
  301. params.freqs = NULL;
  302. }
  303. freqs_set = 1;
  304. }
  305. int_array_sort_unique(params.freqs);
  306. }
  307. if (ssid) {
  308. wpa_s->prev_scan_ssid = ssid;
  309. if (max_ssids > 1) {
  310. wpa_printf(MSG_DEBUG, "Include wildcard SSID in the "
  311. "scan request");
  312. params.num_ssids++;
  313. }
  314. wpa_printf(MSG_DEBUG, "Starting AP scan for specific SSID(s)");
  315. } else {
  316. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  317. params.num_ssids++;
  318. wpa_printf(MSG_DEBUG, "Starting AP scan for wildcard SSID");
  319. }
  320. #ifdef CONFIG_WPS
  321. if (params.freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
  322. /*
  323. * Optimize post-provisioning scan based on channel used
  324. * during provisioning.
  325. */
  326. wpa_printf(MSG_DEBUG, "WPS: Scan only frequency %u MHz that "
  327. "was used during provisioning", wpa_s->wps_freq);
  328. params.freqs = os_zalloc(2 * sizeof(int));
  329. if (params.freqs)
  330. params.freqs[0] = wpa_s->wps_freq;
  331. wpa_s->after_wps--;
  332. }
  333. if (wps) {
  334. wps_ie = wps_build_probe_req_ie(wps == 2, &wpa_s->wps->dev,
  335. wpa_s->wps->uuid, req_type);
  336. if (wps_ie) {
  337. params.extra_ies = wpabuf_head(wps_ie);
  338. params.extra_ies_len = wpabuf_len(wps_ie);
  339. }
  340. }
  341. #endif /* CONFIG_WPS */
  342. params.filter_ssids = wpa_supplicant_build_filter_ssids(
  343. wpa_s->conf, &params.num_filter_ssids);
  344. ret = wpa_supplicant_trigger_scan(wpa_s, &params);
  345. wpabuf_free(wps_ie);
  346. os_free(params.freqs);
  347. os_free(params.filter_ssids);
  348. if (ret) {
  349. wpa_printf(MSG_WARNING, "Failed to initiate AP scan.");
  350. if (prev_state != wpa_s->wpa_state)
  351. wpa_supplicant_set_state(wpa_s, prev_state);
  352. wpa_supplicant_req_scan(wpa_s, 1, 0);
  353. }
  354. }
  355. /**
  356. * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
  357. * @wpa_s: Pointer to wpa_supplicant data
  358. * @sec: Number of seconds after which to scan
  359. * @usec: Number of microseconds after which to scan
  360. *
  361. * This function is used to schedule a scan for neighboring access points after
  362. * the specified time.
  363. */
  364. void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec)
  365. {
  366. /* If there's at least one network that should be specifically scanned
  367. * then don't cancel the scan and reschedule. Some drivers do
  368. * background scanning which generates frequent scan results, and that
  369. * causes the specific SSID scan to get continually pushed back and
  370. * never happen, which causes hidden APs to never get probe-scanned.
  371. */
  372. if (eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL) &&
  373. wpa_s->conf->ap_scan == 1) {
  374. struct wpa_ssid *ssid = wpa_s->conf->ssid;
  375. while (ssid) {
  376. if (!ssid->disabled && ssid->scan_ssid)
  377. break;
  378. ssid = ssid->next;
  379. }
  380. if (ssid) {
  381. wpa_msg(wpa_s, MSG_DEBUG, "Not rescheduling scan to "
  382. "ensure that specific SSID scans occur");
  383. return;
  384. }
  385. }
  386. wpa_msg(wpa_s, MSG_DEBUG, "Setting scan request: %d sec %d usec",
  387. sec, usec);
  388. eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
  389. eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL);
  390. }
  391. /**
  392. * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
  393. * @wpa_s: Pointer to wpa_supplicant data
  394. *
  395. * This function is used to cancel a scan request scheduled with
  396. * wpa_supplicant_req_scan().
  397. */
  398. void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
  399. {
  400. wpa_msg(wpa_s, MSG_DEBUG, "Cancelling scan request");
  401. eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
  402. }
  403. void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
  404. int scanning)
  405. {
  406. if (wpa_s->scanning != scanning) {
  407. wpa_s->scanning = scanning;
  408. wpas_notify_scanning(wpa_s);
  409. }
  410. }
  411. static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
  412. {
  413. int rate = 0;
  414. const u8 *ie;
  415. int i;
  416. ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
  417. for (i = 0; ie && i < ie[1]; i++) {
  418. if ((ie[i + 2] & 0x7f) > rate)
  419. rate = ie[i + 2] & 0x7f;
  420. }
  421. ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
  422. for (i = 0; ie && i < ie[1]; i++) {
  423. if ((ie[i + 2] & 0x7f) > rate)
  424. rate = ie[i + 2] & 0x7f;
  425. }
  426. return rate;
  427. }
  428. const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
  429. {
  430. const u8 *end, *pos;
  431. pos = (const u8 *) (res + 1);
  432. end = pos + res->ie_len;
  433. while (pos + 1 < end) {
  434. if (pos + 2 + pos[1] > end)
  435. break;
  436. if (pos[0] == ie)
  437. return pos;
  438. pos += 2 + pos[1];
  439. }
  440. return NULL;
  441. }
  442. const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
  443. u32 vendor_type)
  444. {
  445. const u8 *end, *pos;
  446. pos = (const u8 *) (res + 1);
  447. end = pos + res->ie_len;
  448. while (pos + 1 < end) {
  449. if (pos + 2 + pos[1] > end)
  450. break;
  451. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  452. vendor_type == WPA_GET_BE32(&pos[2]))
  453. return pos;
  454. pos += 2 + pos[1];
  455. }
  456. return NULL;
  457. }
  458. struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
  459. u32 vendor_type)
  460. {
  461. struct wpabuf *buf;
  462. const u8 *end, *pos;
  463. buf = wpabuf_alloc(res->ie_len);
  464. if (buf == NULL)
  465. return NULL;
  466. pos = (const u8 *) (res + 1);
  467. end = pos + res->ie_len;
  468. while (pos + 1 < end) {
  469. if (pos + 2 + pos[1] > end)
  470. break;
  471. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  472. vendor_type == WPA_GET_BE32(&pos[2]))
  473. wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
  474. pos += 2 + pos[1];
  475. }
  476. if (wpabuf_len(buf) == 0) {
  477. wpabuf_free(buf);
  478. buf = NULL;
  479. }
  480. return buf;
  481. }
  482. /* Compare function for sorting scan results. Return >0 if @b is considered
  483. * better. */
  484. static int wpa_scan_result_compar(const void *a, const void *b)
  485. {
  486. struct wpa_scan_res **_wa = (void *) a;
  487. struct wpa_scan_res **_wb = (void *) b;
  488. struct wpa_scan_res *wa = *_wa;
  489. struct wpa_scan_res *wb = *_wb;
  490. int wpa_a, wpa_b, maxrate_a, maxrate_b;
  491. /* WPA/WPA2 support preferred */
  492. wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
  493. wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
  494. wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
  495. wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
  496. if (wpa_b && !wpa_a)
  497. return 1;
  498. if (!wpa_b && wpa_a)
  499. return -1;
  500. /* privacy support preferred */
  501. if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
  502. (wb->caps & IEEE80211_CAP_PRIVACY))
  503. return 1;
  504. if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
  505. (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
  506. return -1;
  507. /* best/max rate preferred if signal level close enough XXX */
  508. if ((wa->level && wb->level && abs(wb->level - wa->level) < 5) ||
  509. (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
  510. maxrate_a = wpa_scan_get_max_rate(wa);
  511. maxrate_b = wpa_scan_get_max_rate(wb);
  512. if (maxrate_a != maxrate_b)
  513. return maxrate_b - maxrate_a;
  514. }
  515. /* use freq for channel preference */
  516. /* all things being equal, use signal level; if signal levels are
  517. * identical, use quality values since some drivers may only report
  518. * that value and leave the signal level zero */
  519. if (wb->level == wa->level)
  520. return wb->qual - wa->qual;
  521. return wb->level - wa->level;
  522. }
  523. /**
  524. * wpa_supplicant_get_scan_results - Get scan results
  525. * @wpa_s: Pointer to wpa_supplicant data
  526. * @info: Information about what was scanned or %NULL if not available
  527. * @new_scan: Whether a new scan was performed
  528. * Returns: Scan results, %NULL on failure
  529. *
  530. * This function request the current scan results from the driver and updates
  531. * the local BSS list wpa_s->bss. The caller is responsible for freeing the
  532. * results with wpa_scan_results_free().
  533. */
  534. struct wpa_scan_results *
  535. wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
  536. struct scan_info *info, int new_scan)
  537. {
  538. struct wpa_scan_results *scan_res;
  539. size_t i;
  540. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  541. scan_res = ieee80211_sta_get_scan_results(wpa_s);
  542. else
  543. scan_res = wpa_drv_get_scan_results2(wpa_s);
  544. if (scan_res == NULL) {
  545. wpa_printf(MSG_DEBUG, "Failed to get scan results");
  546. return NULL;
  547. }
  548. qsort(scan_res->res, scan_res->num, sizeof(struct wpa_scan_res *),
  549. wpa_scan_result_compar);
  550. wpa_bss_update_start(wpa_s);
  551. for (i = 0; i < scan_res->num; i++)
  552. wpa_bss_update_scan_res(wpa_s, scan_res->res[i]);
  553. wpa_bss_update_end(wpa_s, info, new_scan);
  554. return scan_res;
  555. }
  556. int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
  557. {
  558. struct wpa_scan_results *scan_res;
  559. scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
  560. if (scan_res == NULL)
  561. return -1;
  562. wpa_scan_results_free(scan_res);
  563. return 0;
  564. }
  565. void wpa_scan_results_free(struct wpa_scan_results *res)
  566. {
  567. size_t i;
  568. if (res == NULL)
  569. return;
  570. for (i = 0; i < res->num; i++)
  571. os_free(res->res[i]);
  572. os_free(res->res);
  573. os_free(res);
  574. }