Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /*
  2. * BSS table
  3. * Copyright (c) 2009-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 "drivers/driver.h"
  19. #include "wpa_supplicant_i.h"
  20. #include "config.h"
  21. #include "notify.h"
  22. #include "scan.h"
  23. #include "bss.h"
  24. /**
  25. * WPA_BSS_EXPIRATION_PERIOD - Period of expiration run in seconds
  26. */
  27. #define WPA_BSS_EXPIRATION_PERIOD 10
  28. #define WPA_BSS_FREQ_CHANGED_FLAG BIT(0)
  29. #define WPA_BSS_SIGNAL_CHANGED_FLAG BIT(1)
  30. #define WPA_BSS_PRIVACY_CHANGED_FLAG BIT(2)
  31. #define WPA_BSS_MODE_CHANGED_FLAG BIT(3)
  32. #define WPA_BSS_WPAIE_CHANGED_FLAG BIT(4)
  33. #define WPA_BSS_RSNIE_CHANGED_FLAG BIT(5)
  34. #define WPA_BSS_WPS_CHANGED_FLAG BIT(6)
  35. #define WPA_BSS_RATES_CHANGED_FLAG BIT(7)
  36. #define WPA_BSS_IES_CHANGED_FLAG BIT(8)
  37. static void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  38. {
  39. dl_list_del(&bss->list);
  40. dl_list_del(&bss->list_id);
  41. wpa_s->num_bss--;
  42. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR
  43. " SSID '%s'", bss->id, MAC2STR(bss->bssid),
  44. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  45. wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id);
  46. os_free(bss);
  47. }
  48. struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
  49. const u8 *ssid, size_t ssid_len)
  50. {
  51. struct wpa_bss *bss;
  52. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  53. if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
  54. bss->ssid_len == ssid_len &&
  55. os_memcmp(bss->ssid, ssid, ssid_len) == 0)
  56. return bss;
  57. }
  58. return NULL;
  59. }
  60. static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src)
  61. {
  62. os_time_t usec;
  63. dst->flags = src->flags;
  64. os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
  65. dst->freq = src->freq;
  66. dst->beacon_int = src->beacon_int;
  67. dst->caps = src->caps;
  68. dst->qual = src->qual;
  69. dst->noise = src->noise;
  70. dst->level = src->level;
  71. dst->tsf = src->tsf;
  72. os_get_time(&dst->last_update);
  73. dst->last_update.sec -= src->age / 1000;
  74. usec = (src->age % 1000) * 1000;
  75. if (dst->last_update.usec < usec) {
  76. dst->last_update.sec--;
  77. dst->last_update.usec += 1000000;
  78. }
  79. dst->last_update.usec -= usec;
  80. }
  81. static void wpa_bss_add(struct wpa_supplicant *wpa_s,
  82. const u8 *ssid, size_t ssid_len,
  83. struct wpa_scan_res *res)
  84. {
  85. struct wpa_bss *bss;
  86. bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len);
  87. if (bss == NULL)
  88. return;
  89. bss->id = wpa_s->bss_next_id++;
  90. bss->last_update_idx = wpa_s->bss_update_idx;
  91. wpa_bss_copy_res(bss, res);
  92. os_memcpy(bss->ssid, ssid, ssid_len);
  93. bss->ssid_len = ssid_len;
  94. bss->ie_len = res->ie_len;
  95. bss->beacon_ie_len = res->beacon_ie_len;
  96. os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
  97. dl_list_add_tail(&wpa_s->bss, &bss->list);
  98. dl_list_add_tail(&wpa_s->bss_id, &bss->list_id);
  99. wpa_s->num_bss++;
  100. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR
  101. " SSID '%s'",
  102. bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
  103. wpas_notify_bss_added(wpa_s, bss->bssid, bss->id);
  104. if (wpa_s->num_bss > wpa_s->conf->bss_max_count) {
  105. /* Remove the oldest entry */
  106. wpa_bss_remove(wpa_s, dl_list_first(&wpa_s->bss,
  107. struct wpa_bss, list));
  108. }
  109. }
  110. static int are_ies_equal(const struct wpa_bss *old,
  111. const struct wpa_scan_res *new, u32 ie)
  112. {
  113. const u8 *old_ie, *new_ie;
  114. struct wpabuf *old_ie_buff = NULL;
  115. struct wpabuf *new_ie_buff = NULL;
  116. int new_ie_len, old_ie_len, ret, is_multi;
  117. switch (ie) {
  118. case WPA_IE_VENDOR_TYPE:
  119. old_ie = wpa_bss_get_vendor_ie(old, ie);
  120. new_ie = wpa_scan_get_vendor_ie(new, ie);
  121. is_multi = 0;
  122. break;
  123. case WPS_IE_VENDOR_TYPE:
  124. old_ie_buff = wpa_bss_get_vendor_ie_multi(old, ie);
  125. new_ie_buff = wpa_scan_get_vendor_ie_multi(new, ie);
  126. is_multi = 1;
  127. break;
  128. case WLAN_EID_RSN:
  129. case WLAN_EID_SUPP_RATES:
  130. case WLAN_EID_EXT_SUPP_RATES:
  131. old_ie = wpa_bss_get_ie(old, ie);
  132. new_ie = wpa_scan_get_ie(new, ie);
  133. is_multi = 0;
  134. break;
  135. default:
  136. wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__);
  137. return 0;
  138. }
  139. if (is_multi) {
  140. /* in case of multiple IEs stored in buffer */
  141. old_ie = old_ie_buff ? wpabuf_head_u8(old_ie_buff) : NULL;
  142. new_ie = new_ie_buff ? wpabuf_head_u8(new_ie_buff) : NULL;
  143. old_ie_len = old_ie_buff ? wpabuf_len(old_ie_buff) : 0;
  144. new_ie_len = new_ie_buff ? wpabuf_len(new_ie_buff) : 0;
  145. } else {
  146. /* in case of single IE */
  147. old_ie_len = old_ie ? old_ie[1] + 2 : 0;
  148. new_ie_len = new_ie ? new_ie[1] + 2 : 0;
  149. }
  150. if (!old_ie || !new_ie)
  151. ret = !old_ie && !new_ie;
  152. else
  153. ret = (old_ie_len == new_ie_len &&
  154. os_memcmp(old_ie, new_ie, old_ie_len) == 0);
  155. wpabuf_free(old_ie_buff);
  156. wpabuf_free(new_ie_buff);
  157. return ret;
  158. }
  159. static u32 wpa_bss_compare_res(const struct wpa_bss *old,
  160. const struct wpa_scan_res *new)
  161. {
  162. u32 changes = 0;
  163. int caps_diff = old->caps ^ new->caps;
  164. if (old->freq != new->freq)
  165. changes |= WPA_BSS_FREQ_CHANGED_FLAG;
  166. if (old->level != new->level)
  167. changes |= WPA_BSS_SIGNAL_CHANGED_FLAG;
  168. if (caps_diff & IEEE80211_CAP_PRIVACY)
  169. changes |= WPA_BSS_PRIVACY_CHANGED_FLAG;
  170. if (caps_diff & IEEE80211_CAP_IBSS)
  171. changes |= WPA_BSS_MODE_CHANGED_FLAG;
  172. if (old->ie_len == new->ie_len &&
  173. os_memcmp(old + 1, new + 1, old->ie_len) == 0)
  174. return changes;
  175. changes |= WPA_BSS_IES_CHANGED_FLAG;
  176. if (!are_ies_equal(old, new, WPA_IE_VENDOR_TYPE))
  177. changes |= WPA_BSS_WPAIE_CHANGED_FLAG;
  178. if (!are_ies_equal(old, new, WLAN_EID_RSN))
  179. changes |= WPA_BSS_RSNIE_CHANGED_FLAG;
  180. if (!are_ies_equal(old, new, WPS_IE_VENDOR_TYPE))
  181. changes |= WPA_BSS_WPS_CHANGED_FLAG;
  182. if (!are_ies_equal(old, new, WLAN_EID_SUPP_RATES) ||
  183. !are_ies_equal(old, new, WLAN_EID_EXT_SUPP_RATES))
  184. changes |= WPA_BSS_RATES_CHANGED_FLAG;
  185. return changes;
  186. }
  187. static void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes,
  188. const struct wpa_bss *bss)
  189. {
  190. if (changes & WPA_BSS_FREQ_CHANGED_FLAG)
  191. wpas_notify_bss_freq_changed(wpa_s, bss->id);
  192. if (changes & WPA_BSS_SIGNAL_CHANGED_FLAG)
  193. wpas_notify_bss_signal_changed(wpa_s, bss->id);
  194. if (changes & WPA_BSS_PRIVACY_CHANGED_FLAG)
  195. wpas_notify_bss_privacy_changed(wpa_s, bss->id);
  196. if (changes & WPA_BSS_MODE_CHANGED_FLAG)
  197. wpas_notify_bss_mode_changed(wpa_s, bss->id);
  198. if (changes & WPA_BSS_WPAIE_CHANGED_FLAG)
  199. wpas_notify_bss_wpaie_changed(wpa_s, bss->id);
  200. if (changes & WPA_BSS_RSNIE_CHANGED_FLAG)
  201. wpas_notify_bss_rsnie_changed(wpa_s, bss->id);
  202. if (changes & WPA_BSS_WPS_CHANGED_FLAG)
  203. wpas_notify_bss_wps_changed(wpa_s, bss->id);
  204. if (changes & WPA_BSS_IES_CHANGED_FLAG)
  205. wpas_notify_bss_ies_changed(wpa_s, bss->id);
  206. if (changes & WPA_BSS_RATES_CHANGED_FLAG)
  207. wpas_notify_bss_rates_changed(wpa_s, bss->id);
  208. }
  209. static void wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  210. struct wpa_scan_res *res)
  211. {
  212. u32 changes;
  213. changes = wpa_bss_compare_res(bss, res);
  214. bss->scan_miss_count = 0;
  215. bss->last_update_idx = wpa_s->bss_update_idx;
  216. wpa_bss_copy_res(bss, res);
  217. /* Move the entry to the end of the list */
  218. dl_list_del(&bss->list);
  219. if (bss->ie_len + bss->beacon_ie_len >=
  220. res->ie_len + res->beacon_ie_len) {
  221. os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
  222. bss->ie_len = res->ie_len;
  223. bss->beacon_ie_len = res->beacon_ie_len;
  224. } else {
  225. struct wpa_bss *nbss;
  226. struct dl_list *prev = bss->list_id.prev;
  227. dl_list_del(&bss->list_id);
  228. nbss = os_realloc(bss, sizeof(*bss) + res->ie_len +
  229. res->beacon_ie_len);
  230. if (nbss) {
  231. bss = nbss;
  232. os_memcpy(bss + 1, res + 1,
  233. res->ie_len + res->beacon_ie_len);
  234. bss->ie_len = res->ie_len;
  235. bss->beacon_ie_len = res->beacon_ie_len;
  236. }
  237. dl_list_add(prev, &bss->list_id);
  238. }
  239. dl_list_add_tail(&wpa_s->bss, &bss->list);
  240. notify_bss_changes(wpa_s, changes, bss);
  241. }
  242. static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  243. {
  244. return bss == wpa_s->current_bss ||
  245. os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) == 0 ||
  246. os_memcmp(bss->bssid, wpa_s->pending_bssid, ETH_ALEN) == 0;
  247. }
  248. void wpa_bss_update_start(struct wpa_supplicant *wpa_s)
  249. {
  250. wpa_s->bss_update_idx++;
  251. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Start scan result update %u",
  252. wpa_s->bss_update_idx);
  253. }
  254. void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
  255. struct wpa_scan_res *res)
  256. {
  257. const u8 *ssid, *p2p;
  258. struct wpa_bss *bss;
  259. ssid = wpa_scan_get_ie(res, WLAN_EID_SSID);
  260. if (ssid == NULL) {
  261. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: No SSID IE included for "
  262. MACSTR, MAC2STR(res->bssid));
  263. return;
  264. }
  265. if (ssid[1] > 32) {
  266. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for "
  267. MACSTR, MAC2STR(res->bssid));
  268. return;
  269. }
  270. p2p = wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE);
  271. if (p2p && ssid[1] == P2P_WILDCARD_SSID_LEN &&
  272. os_memcmp(ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == 0)
  273. return; /* Skip P2P listen discovery results here */
  274. /* TODO: add option for ignoring BSSes we are not interested in
  275. * (to save memory) */
  276. bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]);
  277. if (bss == NULL)
  278. wpa_bss_add(wpa_s, ssid + 2, ssid[1], res);
  279. else
  280. wpa_bss_update(wpa_s, bss, res);
  281. }
  282. static int wpa_bss_included_in_scan(const struct wpa_bss *bss,
  283. const struct scan_info *info)
  284. {
  285. int found;
  286. size_t i;
  287. if (info == NULL)
  288. return 1;
  289. if (info->num_freqs) {
  290. found = 0;
  291. for (i = 0; i < info->num_freqs; i++) {
  292. if (bss->freq == info->freqs[i]) {
  293. found = 1;
  294. break;
  295. }
  296. }
  297. if (!found)
  298. return 0;
  299. }
  300. if (info->num_ssids) {
  301. found = 0;
  302. for (i = 0; i < info->num_ssids; i++) {
  303. const struct wpa_driver_scan_ssid *s = &info->ssids[i];
  304. if ((s->ssid == NULL || s->ssid_len == 0) ||
  305. (s->ssid_len == bss->ssid_len &&
  306. os_memcmp(s->ssid, bss->ssid, bss->ssid_len) ==
  307. 0)) {
  308. found = 1;
  309. break;
  310. }
  311. }
  312. if (!found)
  313. return 0;
  314. }
  315. return 1;
  316. }
  317. void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
  318. int new_scan)
  319. {
  320. struct wpa_bss *bss, *n;
  321. if (!new_scan)
  322. return; /* do not expire entries without new scan */
  323. dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
  324. if (wpa_bss_in_use(wpa_s, bss))
  325. continue;
  326. if (!wpa_bss_included_in_scan(bss, info))
  327. continue; /* expire only BSSes that were scanned */
  328. if (bss->last_update_idx < wpa_s->bss_update_idx)
  329. bss->scan_miss_count++;
  330. if (bss->scan_miss_count >=
  331. wpa_s->conf->bss_expiration_scan_count) {
  332. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Expire BSS %u due to "
  333. "no match in scan", bss->id);
  334. wpa_bss_remove(wpa_s, bss);
  335. }
  336. }
  337. }
  338. void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age)
  339. {
  340. struct wpa_bss *bss, *n;
  341. struct os_time t;
  342. if (dl_list_empty(&wpa_s->bss))
  343. return;
  344. os_get_time(&t);
  345. t.sec -= age;
  346. dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
  347. if (wpa_bss_in_use(wpa_s, bss))
  348. continue;
  349. if (os_time_before(&bss->last_update, &t)) {
  350. wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Expire BSS %u due to "
  351. "age", bss->id);
  352. wpa_bss_remove(wpa_s, bss);
  353. } else
  354. break;
  355. }
  356. }
  357. static void wpa_bss_timeout(void *eloop_ctx, void *timeout_ctx)
  358. {
  359. struct wpa_supplicant *wpa_s = eloop_ctx;
  360. wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age);
  361. eloop_register_timeout(WPA_BSS_EXPIRATION_PERIOD, 0,
  362. wpa_bss_timeout, wpa_s, NULL);
  363. }
  364. int wpa_bss_init(struct wpa_supplicant *wpa_s)
  365. {
  366. dl_list_init(&wpa_s->bss);
  367. dl_list_init(&wpa_s->bss_id);
  368. eloop_register_timeout(WPA_BSS_EXPIRATION_PERIOD, 0,
  369. wpa_bss_timeout, wpa_s, NULL);
  370. return 0;
  371. }
  372. void wpa_bss_flush(struct wpa_supplicant *wpa_s)
  373. {
  374. struct wpa_bss *bss, *n;
  375. if (wpa_s->bss.next == NULL)
  376. return; /* BSS table not yet initialized */
  377. dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
  378. if (wpa_bss_in_use(wpa_s, bss))
  379. continue;
  380. wpa_bss_remove(wpa_s, bss);
  381. }
  382. }
  383. void wpa_bss_deinit(struct wpa_supplicant *wpa_s)
  384. {
  385. eloop_cancel_timeout(wpa_bss_timeout, wpa_s, NULL);
  386. wpa_bss_flush(wpa_s);
  387. }
  388. struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
  389. const u8 *bssid)
  390. {
  391. struct wpa_bss *bss;
  392. dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
  393. if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
  394. return bss;
  395. }
  396. return NULL;
  397. }
  398. struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
  399. {
  400. struct wpa_bss *bss;
  401. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  402. if (bss->id == id)
  403. return bss;
  404. }
  405. return NULL;
  406. }
  407. const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
  408. {
  409. const u8 *end, *pos;
  410. pos = (const u8 *) (bss + 1);
  411. end = pos + bss->ie_len;
  412. while (pos + 1 < end) {
  413. if (pos + 2 + pos[1] > end)
  414. break;
  415. if (pos[0] == ie)
  416. return pos;
  417. pos += 2 + pos[1];
  418. }
  419. return NULL;
  420. }
  421. const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type)
  422. {
  423. const u8 *end, *pos;
  424. pos = (const u8 *) (bss + 1);
  425. end = pos + bss->ie_len;
  426. while (pos + 1 < end) {
  427. if (pos + 2 + pos[1] > end)
  428. break;
  429. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  430. vendor_type == WPA_GET_BE32(&pos[2]))
  431. return pos;
  432. pos += 2 + pos[1];
  433. }
  434. return NULL;
  435. }
  436. struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
  437. u32 vendor_type)
  438. {
  439. struct wpabuf *buf;
  440. const u8 *end, *pos;
  441. buf = wpabuf_alloc(bss->ie_len);
  442. if (buf == NULL)
  443. return NULL;
  444. pos = (const u8 *) (bss + 1);
  445. end = pos + bss->ie_len;
  446. while (pos + 1 < end) {
  447. if (pos + 2 + pos[1] > end)
  448. break;
  449. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  450. vendor_type == WPA_GET_BE32(&pos[2]))
  451. wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
  452. pos += 2 + pos[1];
  453. }
  454. if (wpabuf_len(buf) == 0) {
  455. wpabuf_free(buf);
  456. buf = NULL;
  457. }
  458. return buf;
  459. }
  460. int wpa_bss_get_max_rate(const struct wpa_bss *bss)
  461. {
  462. int rate = 0;
  463. const u8 *ie;
  464. int i;
  465. ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
  466. for (i = 0; ie && i < ie[1]; i++) {
  467. if ((ie[i + 2] & 0x7f) > rate)
  468. rate = ie[i + 2] & 0x7f;
  469. }
  470. ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
  471. for (i = 0; ie && i < ie[1]; i++) {
  472. if ((ie[i + 2] & 0x7f) > rate)
  473. rate = ie[i + 2] & 0x7f;
  474. }
  475. return rate;
  476. }
  477. int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates)
  478. {
  479. const u8 *ie, *ie2;
  480. int i, j;
  481. unsigned int len;
  482. u8 *r;
  483. ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
  484. ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
  485. len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0);
  486. r = os_malloc(len);
  487. if (!r)
  488. return -1;
  489. for (i = 0; ie && i < ie[1]; i++)
  490. r[i] = ie[i + 2] & 0x7f;
  491. for (j = 0; ie2 && j < ie2[1]; j++)
  492. r[i + j] = ie2[j + 2] & 0x7f;
  493. *rates = r;
  494. return len;
  495. }