scan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/wireless.h>
  14. #include <linux/if_arp.h>
  15. #include <net/mac80211.h>
  16. #include <net/iw_handler.h>
  17. #include "ieee80211_i.h"
  18. #define IEEE80211_PROBE_DELAY (HZ / 33)
  19. #define IEEE80211_CHANNEL_TIME (HZ / 33)
  20. #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
  21. ieee80211_rx_result
  22. ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  23. struct ieee80211_rx_status *rx_status)
  24. {
  25. struct ieee80211_mgmt *mgmt;
  26. struct ieee80211_sta_bss *bss;
  27. u8 *elements;
  28. struct ieee80211_channel *channel;
  29. size_t baselen;
  30. int freq;
  31. __le16 fc;
  32. bool presp, beacon = false;
  33. struct ieee802_11_elems elems;
  34. if (skb->len < 2)
  35. return RX_DROP_UNUSABLE;
  36. mgmt = (struct ieee80211_mgmt *) skb->data;
  37. fc = mgmt->frame_control;
  38. if (ieee80211_is_ctl(fc))
  39. return RX_CONTINUE;
  40. if (skb->len < 24)
  41. return RX_DROP_MONITOR;
  42. presp = ieee80211_is_probe_resp(fc);
  43. if (presp) {
  44. /* ignore ProbeResp to foreign address */
  45. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  46. return RX_DROP_MONITOR;
  47. presp = true;
  48. elements = mgmt->u.probe_resp.variable;
  49. baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  50. } else {
  51. beacon = ieee80211_is_beacon(fc);
  52. baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  53. elements = mgmt->u.beacon.variable;
  54. }
  55. if (!presp && !beacon)
  56. return RX_CONTINUE;
  57. if (baselen > skb->len)
  58. return RX_DROP_MONITOR;
  59. ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
  60. if (elems.ds_params && elems.ds_params_len == 1)
  61. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  62. else
  63. freq = rx_status->freq;
  64. channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
  65. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  66. return RX_DROP_MONITOR;
  67. bss = ieee80211_bss_info_update(sdata->local, rx_status,
  68. mgmt, skb->len, &elems,
  69. freq, beacon);
  70. ieee80211_rx_bss_put(sdata->local, bss);
  71. dev_kfree_skb(skb);
  72. return RX_QUEUED;
  73. }
  74. static void ieee80211_send_nullfunc(struct ieee80211_local *local,
  75. struct ieee80211_sub_if_data *sdata,
  76. int powersave)
  77. {
  78. struct sk_buff *skb;
  79. struct ieee80211_hdr *nullfunc;
  80. __le16 fc;
  81. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
  82. if (!skb) {
  83. printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
  84. "frame\n", sdata->dev->name);
  85. return;
  86. }
  87. skb_reserve(skb, local->hw.extra_tx_headroom);
  88. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
  89. memset(nullfunc, 0, 24);
  90. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  91. IEEE80211_FCTL_TODS);
  92. if (powersave)
  93. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  94. nullfunc->frame_control = fc;
  95. memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
  96. memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
  97. memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
  98. ieee80211_sta_tx(sdata, skb, 0);
  99. }
  100. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  101. {
  102. if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  103. ieee80211_vif_is_mesh(&sdata->vif))
  104. ieee80211_sta_timer((unsigned long)sdata);
  105. }
  106. void ieee80211_scan_completed(struct ieee80211_hw *hw)
  107. {
  108. struct ieee80211_local *local = hw_to_local(hw);
  109. struct ieee80211_sub_if_data *sdata;
  110. union iwreq_data wrqu;
  111. local->last_scan_completed = jiffies;
  112. memset(&wrqu, 0, sizeof(wrqu));
  113. wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL);
  114. if (local->sta_hw_scanning) {
  115. local->sta_hw_scanning = 0;
  116. if (ieee80211_hw_config(local))
  117. printk(KERN_DEBUG "%s: failed to restore operational "
  118. "channel after scan\n", wiphy_name(local->hw.wiphy));
  119. /* Restart STA timer for HW scan case */
  120. rcu_read_lock();
  121. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  122. ieee80211_restart_sta_timer(sdata);
  123. rcu_read_unlock();
  124. goto done;
  125. }
  126. local->sta_sw_scanning = 0;
  127. if (ieee80211_hw_config(local))
  128. printk(KERN_DEBUG "%s: failed to restore operational "
  129. "channel after scan\n", wiphy_name(local->hw.wiphy));
  130. netif_tx_lock_bh(local->mdev);
  131. netif_addr_lock(local->mdev);
  132. local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
  133. local->ops->configure_filter(local_to_hw(local),
  134. FIF_BCN_PRBRESP_PROMISC,
  135. &local->filter_flags,
  136. local->mdev->mc_count,
  137. local->mdev->mc_list);
  138. netif_addr_unlock(local->mdev);
  139. netif_tx_unlock_bh(local->mdev);
  140. rcu_read_lock();
  141. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  142. /* Tell AP we're back */
  143. if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
  144. if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
  145. ieee80211_send_nullfunc(local, sdata, 0);
  146. netif_tx_wake_all_queues(sdata->dev);
  147. }
  148. } else
  149. netif_tx_wake_all_queues(sdata->dev);
  150. ieee80211_restart_sta_timer(sdata);
  151. }
  152. rcu_read_unlock();
  153. done:
  154. ieee80211_mlme_notify_scan_completed(local);
  155. }
  156. EXPORT_SYMBOL(ieee80211_scan_completed);
  157. void ieee80211_sta_scan_work(struct work_struct *work)
  158. {
  159. struct ieee80211_local *local =
  160. container_of(work, struct ieee80211_local, scan_work.work);
  161. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  162. struct ieee80211_supported_band *sband;
  163. struct ieee80211_channel *chan;
  164. int skip;
  165. unsigned long next_delay = 0;
  166. if (!local->sta_sw_scanning)
  167. return;
  168. switch (local->scan_state) {
  169. case SCAN_SET_CHANNEL:
  170. /*
  171. * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
  172. * after we successfully scanned the last channel of the last
  173. * band (and the last band is supported by the hw)
  174. */
  175. if (local->scan_band < IEEE80211_NUM_BANDS)
  176. sband = local->hw.wiphy->bands[local->scan_band];
  177. else
  178. sband = NULL;
  179. /*
  180. * If we are at an unsupported band and have more bands
  181. * left to scan, advance to the next supported one.
  182. */
  183. while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
  184. local->scan_band++;
  185. sband = local->hw.wiphy->bands[local->scan_band];
  186. local->scan_channel_idx = 0;
  187. }
  188. /* if no more bands/channels left, complete scan */
  189. if (!sband || local->scan_channel_idx >= sband->n_channels) {
  190. ieee80211_scan_completed(local_to_hw(local));
  191. return;
  192. }
  193. skip = 0;
  194. chan = &sband->channels[local->scan_channel_idx];
  195. if (chan->flags & IEEE80211_CHAN_DISABLED ||
  196. (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
  197. chan->flags & IEEE80211_CHAN_NO_IBSS))
  198. skip = 1;
  199. if (!skip) {
  200. local->scan_channel = chan;
  201. if (ieee80211_hw_config(local)) {
  202. printk(KERN_DEBUG "%s: failed to set freq to "
  203. "%d MHz for scan\n", wiphy_name(local->hw.wiphy),
  204. chan->center_freq);
  205. skip = 1;
  206. }
  207. }
  208. /* advance state machine to next channel/band */
  209. local->scan_channel_idx++;
  210. if (local->scan_channel_idx >= sband->n_channels) {
  211. /*
  212. * scan_band may end up == IEEE80211_NUM_BANDS, but
  213. * we'll catch that case above and complete the scan
  214. * if that is the case.
  215. */
  216. local->scan_band++;
  217. local->scan_channel_idx = 0;
  218. }
  219. if (skip)
  220. break;
  221. next_delay = IEEE80211_PROBE_DELAY +
  222. usecs_to_jiffies(local->hw.channel_change_time);
  223. local->scan_state = SCAN_SEND_PROBE;
  224. break;
  225. case SCAN_SEND_PROBE:
  226. next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
  227. local->scan_state = SCAN_SET_CHANNEL;
  228. if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  229. break;
  230. ieee80211_send_probe_req(sdata, NULL, local->scan_ssid,
  231. local->scan_ssid_len);
  232. next_delay = IEEE80211_CHANNEL_TIME;
  233. break;
  234. }
  235. if (local->sta_sw_scanning)
  236. queue_delayed_work(local->hw.workqueue, &local->scan_work,
  237. next_delay);
  238. }
  239. int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata,
  240. u8 *ssid, size_t ssid_len)
  241. {
  242. struct ieee80211_local *local = scan_sdata->local;
  243. struct ieee80211_sub_if_data *sdata;
  244. if (ssid_len > IEEE80211_MAX_SSID_LEN)
  245. return -EINVAL;
  246. /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
  247. * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
  248. * BSSID: MACAddress
  249. * SSID
  250. * ScanType: ACTIVE, PASSIVE
  251. * ProbeDelay: delay (in microseconds) to be used prior to transmitting
  252. * a Probe frame during active scanning
  253. * ChannelList
  254. * MinChannelTime (>= ProbeDelay), in TU
  255. * MaxChannelTime: (>= MinChannelTime), in TU
  256. */
  257. /* MLME-SCAN.confirm
  258. * BSSDescriptionSet
  259. * ResultCode: SUCCESS, INVALID_PARAMETERS
  260. */
  261. if (local->sta_sw_scanning || local->sta_hw_scanning) {
  262. if (local->scan_sdata == scan_sdata)
  263. return 0;
  264. return -EBUSY;
  265. }
  266. if (local->ops->hw_scan) {
  267. int rc = local->ops->hw_scan(local_to_hw(local),
  268. ssid, ssid_len);
  269. if (!rc) {
  270. local->sta_hw_scanning = 1;
  271. local->scan_sdata = scan_sdata;
  272. }
  273. return rc;
  274. }
  275. local->sta_sw_scanning = 1;
  276. rcu_read_lock();
  277. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  278. if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
  279. if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
  280. netif_tx_stop_all_queues(sdata->dev);
  281. ieee80211_send_nullfunc(local, sdata, 1);
  282. }
  283. } else
  284. netif_tx_stop_all_queues(sdata->dev);
  285. }
  286. rcu_read_unlock();
  287. if (ssid) {
  288. local->scan_ssid_len = ssid_len;
  289. memcpy(local->scan_ssid, ssid, ssid_len);
  290. } else
  291. local->scan_ssid_len = 0;
  292. local->scan_state = SCAN_SET_CHANNEL;
  293. local->scan_channel_idx = 0;
  294. local->scan_band = IEEE80211_BAND_2GHZ;
  295. local->scan_sdata = scan_sdata;
  296. netif_addr_lock_bh(local->mdev);
  297. local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
  298. local->ops->configure_filter(local_to_hw(local),
  299. FIF_BCN_PRBRESP_PROMISC,
  300. &local->filter_flags,
  301. local->mdev->mc_count,
  302. local->mdev->mc_list);
  303. netif_addr_unlock_bh(local->mdev);
  304. /* TODO: start scan as soon as all nullfunc frames are ACKed */
  305. queue_delayed_work(local->hw.workqueue, &local->scan_work,
  306. IEEE80211_CHANNEL_TIME);
  307. return 0;
  308. }
  309. int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len)
  310. {
  311. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  312. struct ieee80211_local *local = sdata->local;
  313. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  314. return ieee80211_sta_start_scan(sdata, ssid, ssid_len);
  315. if (local->sta_sw_scanning || local->sta_hw_scanning) {
  316. if (local->scan_sdata == sdata)
  317. return 0;
  318. return -EBUSY;
  319. }
  320. ifsta->scan_ssid_len = ssid_len;
  321. if (ssid_len)
  322. memcpy(ifsta->scan_ssid, ssid, ssid_len);
  323. set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
  324. queue_work(local->hw.workqueue, &ifsta->work);
  325. return 0;
  326. }
  327. static void ieee80211_sta_add_scan_ies(struct iw_request_info *info,
  328. struct ieee80211_sta_bss *bss,
  329. char **current_ev, char *end_buf)
  330. {
  331. u8 *pos, *end, *next;
  332. struct iw_event iwe;
  333. if (bss == NULL || bss->ies == NULL)
  334. return;
  335. /*
  336. * If needed, fragment the IEs buffer (at IE boundaries) into short
  337. * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
  338. */
  339. pos = bss->ies;
  340. end = pos + bss->ies_len;
  341. while (end - pos > IW_GENERIC_IE_MAX) {
  342. next = pos + 2 + pos[1];
  343. while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
  344. next = next + 2 + next[1];
  345. memset(&iwe, 0, sizeof(iwe));
  346. iwe.cmd = IWEVGENIE;
  347. iwe.u.data.length = next - pos;
  348. *current_ev = iwe_stream_add_point(info, *current_ev,
  349. end_buf, &iwe, pos);
  350. pos = next;
  351. }
  352. if (end > pos) {
  353. memset(&iwe, 0, sizeof(iwe));
  354. iwe.cmd = IWEVGENIE;
  355. iwe.u.data.length = end - pos;
  356. *current_ev = iwe_stream_add_point(info, *current_ev,
  357. end_buf, &iwe, pos);
  358. }
  359. }
  360. static char *
  361. ieee80211_sta_scan_result(struct ieee80211_local *local,
  362. struct iw_request_info *info,
  363. struct ieee80211_sta_bss *bss,
  364. char *current_ev, char *end_buf)
  365. {
  366. struct iw_event iwe;
  367. char *buf;
  368. if (time_after(jiffies,
  369. bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
  370. return current_ev;
  371. memset(&iwe, 0, sizeof(iwe));
  372. iwe.cmd = SIOCGIWAP;
  373. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  374. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  375. current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
  376. IW_EV_ADDR_LEN);
  377. memset(&iwe, 0, sizeof(iwe));
  378. iwe.cmd = SIOCGIWESSID;
  379. if (bss_mesh_cfg(bss)) {
  380. iwe.u.data.length = bss_mesh_id_len(bss);
  381. iwe.u.data.flags = 1;
  382. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  383. &iwe, bss_mesh_id(bss));
  384. } else {
  385. iwe.u.data.length = bss->ssid_len;
  386. iwe.u.data.flags = 1;
  387. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  388. &iwe, bss->ssid);
  389. }
  390. if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
  391. || bss_mesh_cfg(bss)) {
  392. memset(&iwe, 0, sizeof(iwe));
  393. iwe.cmd = SIOCGIWMODE;
  394. if (bss_mesh_cfg(bss))
  395. iwe.u.mode = IW_MODE_MESH;
  396. else if (bss->capability & WLAN_CAPABILITY_ESS)
  397. iwe.u.mode = IW_MODE_MASTER;
  398. else
  399. iwe.u.mode = IW_MODE_ADHOC;
  400. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  401. &iwe, IW_EV_UINT_LEN);
  402. }
  403. memset(&iwe, 0, sizeof(iwe));
  404. iwe.cmd = SIOCGIWFREQ;
  405. iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
  406. iwe.u.freq.e = 0;
  407. current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
  408. IW_EV_FREQ_LEN);
  409. memset(&iwe, 0, sizeof(iwe));
  410. iwe.cmd = SIOCGIWFREQ;
  411. iwe.u.freq.m = bss->freq;
  412. iwe.u.freq.e = 6;
  413. current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
  414. IW_EV_FREQ_LEN);
  415. memset(&iwe, 0, sizeof(iwe));
  416. iwe.cmd = IWEVQUAL;
  417. iwe.u.qual.qual = bss->qual;
  418. iwe.u.qual.level = bss->signal;
  419. iwe.u.qual.noise = bss->noise;
  420. iwe.u.qual.updated = local->wstats_flags;
  421. current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
  422. IW_EV_QUAL_LEN);
  423. memset(&iwe, 0, sizeof(iwe));
  424. iwe.cmd = SIOCGIWENCODE;
  425. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  426. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  427. else
  428. iwe.u.data.flags = IW_ENCODE_DISABLED;
  429. iwe.u.data.length = 0;
  430. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  431. &iwe, "");
  432. ieee80211_sta_add_scan_ies(info, bss, &current_ev, end_buf);
  433. if (bss->supp_rates_len > 0) {
  434. /* display all supported rates in readable format */
  435. char *p = current_ev + iwe_stream_lcp_len(info);
  436. int i;
  437. memset(&iwe, 0, sizeof(iwe));
  438. iwe.cmd = SIOCGIWRATE;
  439. /* Those two flags are ignored... */
  440. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  441. for (i = 0; i < bss->supp_rates_len; i++) {
  442. iwe.u.bitrate.value = ((bss->supp_rates[i] &
  443. 0x7f) * 500000);
  444. p = iwe_stream_add_value(info, current_ev, p,
  445. end_buf, &iwe, IW_EV_PARAM_LEN);
  446. }
  447. current_ev = p;
  448. }
  449. buf = kmalloc(30, GFP_ATOMIC);
  450. if (buf) {
  451. memset(&iwe, 0, sizeof(iwe));
  452. iwe.cmd = IWEVCUSTOM;
  453. sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
  454. iwe.u.data.length = strlen(buf);
  455. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  456. &iwe, buf);
  457. memset(&iwe, 0, sizeof(iwe));
  458. iwe.cmd = IWEVCUSTOM;
  459. sprintf(buf, " Last beacon: %dms ago",
  460. jiffies_to_msecs(jiffies - bss->last_update));
  461. iwe.u.data.length = strlen(buf);
  462. current_ev = iwe_stream_add_point(info, current_ev,
  463. end_buf, &iwe, buf);
  464. kfree(buf);
  465. }
  466. if (bss_mesh_cfg(bss)) {
  467. u8 *cfg = bss_mesh_cfg(bss);
  468. buf = kmalloc(50, GFP_ATOMIC);
  469. if (buf) {
  470. memset(&iwe, 0, sizeof(iwe));
  471. iwe.cmd = IWEVCUSTOM;
  472. sprintf(buf, "Mesh network (version %d)", cfg[0]);
  473. iwe.u.data.length = strlen(buf);
  474. current_ev = iwe_stream_add_point(info, current_ev,
  475. end_buf,
  476. &iwe, buf);
  477. sprintf(buf, "Path Selection Protocol ID: "
  478. "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
  479. cfg[4]);
  480. iwe.u.data.length = strlen(buf);
  481. current_ev = iwe_stream_add_point(info, current_ev,
  482. end_buf,
  483. &iwe, buf);
  484. sprintf(buf, "Path Selection Metric ID: "
  485. "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
  486. cfg[8]);
  487. iwe.u.data.length = strlen(buf);
  488. current_ev = iwe_stream_add_point(info, current_ev,
  489. end_buf,
  490. &iwe, buf);
  491. sprintf(buf, "Congestion Control Mode ID: "
  492. "0x%02X%02X%02X%02X", cfg[9], cfg[10],
  493. cfg[11], cfg[12]);
  494. iwe.u.data.length = strlen(buf);
  495. current_ev = iwe_stream_add_point(info, current_ev,
  496. end_buf,
  497. &iwe, buf);
  498. sprintf(buf, "Channel Precedence: "
  499. "0x%02X%02X%02X%02X", cfg[13], cfg[14],
  500. cfg[15], cfg[16]);
  501. iwe.u.data.length = strlen(buf);
  502. current_ev = iwe_stream_add_point(info, current_ev,
  503. end_buf,
  504. &iwe, buf);
  505. kfree(buf);
  506. }
  507. }
  508. return current_ev;
  509. }
  510. int ieee80211_sta_scan_results(struct ieee80211_local *local,
  511. struct iw_request_info *info,
  512. char *buf, size_t len)
  513. {
  514. char *current_ev = buf;
  515. char *end_buf = buf + len;
  516. struct ieee80211_sta_bss *bss;
  517. spin_lock_bh(&local->sta_bss_lock);
  518. list_for_each_entry(bss, &local->sta_bss_list, list) {
  519. if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
  520. spin_unlock_bh(&local->sta_bss_lock);
  521. return -E2BIG;
  522. }
  523. current_ev = ieee80211_sta_scan_result(local, info, bss,
  524. current_ev, end_buf);
  525. }
  526. spin_unlock_bh(&local->sta_bss_lock);
  527. return current_ev - buf;
  528. }