scan.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. /**
  2. * Functions implementing wlan scan IOCTL and firmware command APIs
  3. *
  4. * IOCTL handlers as well as command preperation and response routines
  5. * for sending scan commands to the firmware.
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/etherdevice.h>
  10. #include <linux/if_arp.h>
  11. #include <asm/unaligned.h>
  12. #include <net/lib80211.h>
  13. #include "host.h"
  14. #include "decl.h"
  15. #include "dev.h"
  16. #include "scan.h"
  17. #include "cmd.h"
  18. //! Approximate amount of data needed to pass a scan result back to iwlist
  19. #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
  20. + IEEE80211_MAX_SSID_LEN \
  21. + IW_EV_UINT_LEN \
  22. + IW_EV_FREQ_LEN \
  23. + IW_EV_QUAL_LEN \
  24. + IEEE80211_MAX_SSID_LEN \
  25. + IW_EV_PARAM_LEN \
  26. + 40) /* 40 for WPAIE */
  27. //! Memory needed to store a max sized channel List TLV for a firmware scan
  28. #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvl_ie_header) \
  29. + (MRVDRV_MAX_CHANNELS_PER_SCAN \
  30. * sizeof(struct chanscanparamset)))
  31. //! Memory needed to store a max number/size SSID TLV for a firmware scan
  32. #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvl_ie_ssid_param_set))
  33. //! Maximum memory needed for a cmd_ds_802_11_scan with all TLVs at max
  34. #define MAX_SCAN_CFG_ALLOC (sizeof(struct cmd_ds_802_11_scan) \
  35. + CHAN_TLV_MAX_SIZE + SSID_TLV_MAX_SIZE)
  36. //! The maximum number of channels the firmware can scan per command
  37. #define MRVDRV_MAX_CHANNELS_PER_SCAN 14
  38. /**
  39. * @brief Number of channels to scan per firmware scan command issuance.
  40. *
  41. * Number restricted to prevent hitting the limit on the amount of scan data
  42. * returned in a single firmware scan command.
  43. */
  44. #define MRVDRV_CHANNELS_PER_SCAN_CMD 4
  45. //! Scan time specified in the channel TLV for each channel for passive scans
  46. #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
  47. //! Scan time specified in the channel TLV for each channel for active scans
  48. #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
  49. #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
  50. static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy,
  51. struct cmd_header *resp);
  52. /*********************************************************************/
  53. /* */
  54. /* Misc helper functions */
  55. /* */
  56. /*********************************************************************/
  57. /**
  58. * @brief Unsets the MSB on basic rates
  59. *
  60. * Scan through an array and unset the MSB for basic data rates.
  61. *
  62. * @param rates buffer of data rates
  63. * @param len size of buffer
  64. */
  65. static void lbs_unset_basic_rate_flags(u8 *rates, size_t len)
  66. {
  67. int i;
  68. for (i = 0; i < len; i++)
  69. rates[i] &= 0x7f;
  70. }
  71. static inline void clear_bss_descriptor(struct bss_descriptor *bss)
  72. {
  73. /* Don't blow away ->list, just BSS data */
  74. memset(bss, 0, offsetof(struct bss_descriptor, list));
  75. }
  76. /**
  77. * @brief Compare two SSIDs
  78. *
  79. * @param ssid1 A pointer to ssid to compare
  80. * @param ssid2 A pointer to ssid to compare
  81. *
  82. * @return 0: ssid is same, otherwise is different
  83. */
  84. int lbs_ssid_cmp(uint8_t *ssid1, uint8_t ssid1_len, uint8_t *ssid2,
  85. uint8_t ssid2_len)
  86. {
  87. if (ssid1_len != ssid2_len)
  88. return -1;
  89. return memcmp(ssid1, ssid2, ssid1_len);
  90. }
  91. static inline int is_same_network(struct bss_descriptor *src,
  92. struct bss_descriptor *dst)
  93. {
  94. /* A network is only a duplicate if the channel, BSSID, and ESSID
  95. * all match. We treat all <hidden> with the same BSSID and channel
  96. * as one network */
  97. return ((src->ssid_len == dst->ssid_len) &&
  98. (src->channel == dst->channel) &&
  99. !compare_ether_addr(src->bssid, dst->bssid) &&
  100. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  101. }
  102. /*********************************************************************/
  103. /* */
  104. /* Main scanning support */
  105. /* */
  106. /*********************************************************************/
  107. /**
  108. * @brief Create a channel list for the driver to scan based on region info
  109. *
  110. * Only used from lbs_scan_setup_scan_config()
  111. *
  112. * Use the driver region/band information to construct a comprehensive list
  113. * of channels to scan. This routine is used for any scan that is not
  114. * provided a specific channel list to scan.
  115. *
  116. * @param priv A pointer to struct lbs_private structure
  117. * @param scanchanlist Output parameter: resulting channel list to scan
  118. *
  119. * @return void
  120. */
  121. static int lbs_scan_create_channel_list(struct lbs_private *priv,
  122. struct chanscanparamset *scanchanlist)
  123. {
  124. struct region_channel *scanregion;
  125. struct chan_freq_power *cfp;
  126. int rgnidx;
  127. int chanidx;
  128. int nextchan;
  129. uint8_t scantype;
  130. chanidx = 0;
  131. /* Set the default scan type to the user specified type, will later
  132. * be changed to passive on a per channel basis if restricted by
  133. * regulatory requirements (11d or 11h)
  134. */
  135. scantype = CMD_SCAN_TYPE_ACTIVE;
  136. for (rgnidx = 0; rgnidx < ARRAY_SIZE(priv->region_channel); rgnidx++) {
  137. if (!priv->region_channel[rgnidx].valid)
  138. continue;
  139. scanregion = &priv->region_channel[rgnidx];
  140. for (nextchan = 0; nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
  141. struct chanscanparamset *chan = &scanchanlist[chanidx];
  142. cfp = scanregion->CFP + nextchan;
  143. if (scanregion->band == BAND_B || scanregion->band == BAND_G)
  144. chan->radiotype = CMD_SCAN_RADIO_TYPE_BG;
  145. if (scantype == CMD_SCAN_TYPE_PASSIVE) {
  146. chan->maxscantime = cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME);
  147. chan->chanscanmode.passivescan = 1;
  148. } else {
  149. chan->maxscantime = cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME);
  150. chan->chanscanmode.passivescan = 0;
  151. }
  152. chan->channumber = cfp->channel;
  153. }
  154. }
  155. return chanidx;
  156. }
  157. /*
  158. * Add SSID TLV of the form:
  159. *
  160. * TLV-ID SSID 00 00
  161. * length 06 00
  162. * ssid 4d 4e 54 45 53 54
  163. */
  164. static int lbs_scan_add_ssid_tlv(struct lbs_private *priv, u8 *tlv)
  165. {
  166. struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
  167. ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
  168. ssid_tlv->header.len = cpu_to_le16(priv->scan_ssid_len);
  169. memcpy(ssid_tlv->ssid, priv->scan_ssid, priv->scan_ssid_len);
  170. return sizeof(ssid_tlv->header) + priv->scan_ssid_len;
  171. }
  172. /*
  173. * Add CHANLIST TLV of the form
  174. *
  175. * TLV-ID CHANLIST 01 01
  176. * length 5b 00
  177. * channel 1 00 01 00 00 00 64 00
  178. * radio type 00
  179. * channel 01
  180. * scan type 00
  181. * min scan time 00 00
  182. * max scan time 64 00
  183. * channel 2 00 02 00 00 00 64 00
  184. * channel 3 00 03 00 00 00 64 00
  185. * channel 4 00 04 00 00 00 64 00
  186. * channel 5 00 05 00 00 00 64 00
  187. * channel 6 00 06 00 00 00 64 00
  188. * channel 7 00 07 00 00 00 64 00
  189. * channel 8 00 08 00 00 00 64 00
  190. * channel 9 00 09 00 00 00 64 00
  191. * channel 10 00 0a 00 00 00 64 00
  192. * channel 11 00 0b 00 00 00 64 00
  193. * channel 12 00 0c 00 00 00 64 00
  194. * channel 13 00 0d 00 00 00 64 00
  195. *
  196. */
  197. static int lbs_scan_add_chanlist_tlv(uint8_t *tlv,
  198. struct chanscanparamset *chan_list,
  199. int chan_count)
  200. {
  201. size_t size = sizeof(struct chanscanparamset) *chan_count;
  202. struct mrvl_ie_chanlist_param_set *chan_tlv = (void *)tlv;
  203. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  204. memcpy(chan_tlv->chanscanparam, chan_list, size);
  205. chan_tlv->header.len = cpu_to_le16(size);
  206. return sizeof(chan_tlv->header) + size;
  207. }
  208. /*
  209. * Add RATES TLV of the form
  210. *
  211. * TLV-ID RATES 01 00
  212. * length 0e 00
  213. * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
  214. *
  215. * The rates are in lbs_bg_rates[], but for the 802.11b
  216. * rates the high bit isn't set.
  217. */
  218. static int lbs_scan_add_rates_tlv(uint8_t *tlv)
  219. {
  220. int i;
  221. struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
  222. rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
  223. tlv += sizeof(rate_tlv->header);
  224. for (i = 0; i < MAX_RATES; i++) {
  225. *tlv = lbs_bg_rates[i];
  226. if (*tlv == 0)
  227. break;
  228. /* This code makes sure that the 802.11b rates (1 MBit/s, 2
  229. MBit/s, 5.5 MBit/s and 11 MBit/s get's the high bit set.
  230. Note that the values are MBit/s * 2, to mark them as
  231. basic rates so that the firmware likes it better */
  232. if (*tlv == 0x02 || *tlv == 0x04 ||
  233. *tlv == 0x0b || *tlv == 0x16)
  234. *tlv |= 0x80;
  235. tlv++;
  236. }
  237. rate_tlv->header.len = cpu_to_le16(i);
  238. return sizeof(rate_tlv->header) + i;
  239. }
  240. /*
  241. * Generate the CMD_802_11_SCAN command with the proper tlv
  242. * for a bunch of channels.
  243. */
  244. static int lbs_do_scan(struct lbs_private *priv, uint8_t bsstype,
  245. struct chanscanparamset *chan_list, int chan_count)
  246. {
  247. int ret = -ENOMEM;
  248. struct cmd_ds_802_11_scan *scan_cmd;
  249. uint8_t *tlv; /* pointer into our current, growing TLV storage area */
  250. lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, chan_count %d",
  251. bsstype, chan_list ? chan_list[0].channumber : -1,
  252. chan_count);
  253. /* create the fixed part for scan command */
  254. scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
  255. if (scan_cmd == NULL)
  256. goto out;
  257. tlv = scan_cmd->tlvbuffer;
  258. /* TODO: do we need to scan for a specific BSSID?
  259. memcpy(scan_cmd->bssid, priv->scan_bssid, ETH_ALEN); */
  260. scan_cmd->bsstype = bsstype;
  261. /* add TLVs */
  262. if (priv->scan_ssid_len)
  263. tlv += lbs_scan_add_ssid_tlv(priv, tlv);
  264. if (chan_list && chan_count)
  265. tlv += lbs_scan_add_chanlist_tlv(tlv, chan_list, chan_count);
  266. tlv += lbs_scan_add_rates_tlv(tlv);
  267. /* This is the final data we are about to send */
  268. scan_cmd->hdr.size = cpu_to_le16(tlv - (uint8_t *)scan_cmd);
  269. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
  270. sizeof(*scan_cmd));
  271. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
  272. tlv - scan_cmd->tlvbuffer);
  273. ret = __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
  274. le16_to_cpu(scan_cmd->hdr.size),
  275. lbs_ret_80211_scan, 0);
  276. out:
  277. kfree(scan_cmd);
  278. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  279. return ret;
  280. }
  281. /**
  282. * @brief Internal function used to start a scan based on an input config
  283. *
  284. * Use the input user scan configuration information when provided in
  285. * order to send the appropriate scan commands to firmware to populate or
  286. * update the internal driver scan table
  287. *
  288. * @param priv A pointer to struct lbs_private structure
  289. * @param full_scan Do a full-scan (blocking)
  290. *
  291. * @return 0 or < 0 if error
  292. */
  293. int lbs_scan_networks(struct lbs_private *priv, int full_scan)
  294. {
  295. int ret = -ENOMEM;
  296. struct chanscanparamset *chan_list;
  297. struct chanscanparamset *curr_chans;
  298. int chan_count;
  299. uint8_t bsstype = CMD_BSS_TYPE_ANY;
  300. int numchannels = MRVDRV_CHANNELS_PER_SCAN_CMD;
  301. union iwreq_data wrqu;
  302. #ifdef CONFIG_LIBERTAS_DEBUG
  303. struct bss_descriptor *iter;
  304. int i = 0;
  305. DECLARE_SSID_BUF(ssid);
  306. #endif
  307. lbs_deb_enter_args(LBS_DEB_SCAN, "full_scan %d", full_scan);
  308. /* Cancel any partial outstanding partial scans if this scan
  309. * is a full scan.
  310. */
  311. if (full_scan && delayed_work_pending(&priv->scan_work))
  312. cancel_delayed_work(&priv->scan_work);
  313. /* User-specified bsstype or channel list
  314. TODO: this can be implemented if some user-space application
  315. need the feature. Formerly, it was accessible from debugfs,
  316. but then nowhere used.
  317. if (user_cfg) {
  318. if (user_cfg->bsstype)
  319. bsstype = user_cfg->bsstype;
  320. } */
  321. lbs_deb_scan("numchannels %d, bsstype %d\n", numchannels, bsstype);
  322. /* Create list of channels to scan */
  323. chan_list = kzalloc(sizeof(struct chanscanparamset) *
  324. LBS_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
  325. if (!chan_list) {
  326. lbs_pr_alert("SCAN: chan_list empty\n");
  327. goto out;
  328. }
  329. /* We want to scan all channels */
  330. chan_count = lbs_scan_create_channel_list(priv, chan_list);
  331. netif_stop_queue(priv->dev);
  332. netif_carrier_off(priv->dev);
  333. if (priv->mesh_dev) {
  334. netif_stop_queue(priv->mesh_dev);
  335. netif_carrier_off(priv->mesh_dev);
  336. }
  337. /* Prepare to continue an interrupted scan */
  338. lbs_deb_scan("chan_count %d, scan_channel %d\n",
  339. chan_count, priv->scan_channel);
  340. curr_chans = chan_list;
  341. /* advance channel list by already-scanned-channels */
  342. if (priv->scan_channel > 0) {
  343. curr_chans += priv->scan_channel;
  344. chan_count -= priv->scan_channel;
  345. }
  346. /* Send scan command(s)
  347. * numchannels contains the number of channels we should maximally scan
  348. * chan_count is the total number of channels to scan
  349. */
  350. while (chan_count) {
  351. int to_scan = min(numchannels, chan_count);
  352. lbs_deb_scan("scanning %d of %d channels\n",
  353. to_scan, chan_count);
  354. ret = lbs_do_scan(priv, bsstype, curr_chans,
  355. to_scan);
  356. if (ret) {
  357. lbs_pr_err("SCAN_CMD failed\n");
  358. goto out2;
  359. }
  360. curr_chans += to_scan;
  361. chan_count -= to_scan;
  362. /* somehow schedule the next part of the scan */
  363. if (chan_count && !full_scan &&
  364. !priv->surpriseremoved) {
  365. /* -1 marks just that we're currently scanning */
  366. if (priv->scan_channel < 0)
  367. priv->scan_channel = to_scan;
  368. else
  369. priv->scan_channel += to_scan;
  370. cancel_delayed_work(&priv->scan_work);
  371. queue_delayed_work(priv->work_thread, &priv->scan_work,
  372. msecs_to_jiffies(300));
  373. /* skip over GIWSCAN event */
  374. goto out;
  375. }
  376. }
  377. memset(&wrqu, 0, sizeof(union iwreq_data));
  378. wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
  379. #ifdef CONFIG_LIBERTAS_DEBUG
  380. /* Dump the scan table */
  381. mutex_lock(&priv->lock);
  382. lbs_deb_scan("scan table:\n");
  383. list_for_each_entry(iter, &priv->network_list, list)
  384. lbs_deb_scan("%02d: BSSID %pM, RSSI %d, SSID '%s'\n",
  385. i++, iter->bssid, iter->rssi,
  386. print_ssid(ssid, iter->ssid, iter->ssid_len));
  387. mutex_unlock(&priv->lock);
  388. #endif
  389. out2:
  390. priv->scan_channel = 0;
  391. out:
  392. if (priv->connect_status == LBS_CONNECTED) {
  393. netif_carrier_on(priv->dev);
  394. if (!priv->tx_pending_len)
  395. netif_wake_queue(priv->dev);
  396. }
  397. if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED)) {
  398. netif_carrier_on(priv->mesh_dev);
  399. if (!priv->tx_pending_len)
  400. netif_wake_queue(priv->mesh_dev);
  401. }
  402. kfree(chan_list);
  403. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  404. return ret;
  405. }
  406. void lbs_scan_worker(struct work_struct *work)
  407. {
  408. struct lbs_private *priv =
  409. container_of(work, struct lbs_private, scan_work.work);
  410. lbs_deb_enter(LBS_DEB_SCAN);
  411. lbs_scan_networks(priv, 0);
  412. lbs_deb_leave(LBS_DEB_SCAN);
  413. }
  414. /*********************************************************************/
  415. /* */
  416. /* Result interpretation */
  417. /* */
  418. /*********************************************************************/
  419. /**
  420. * @brief Interpret a BSS scan response returned from the firmware
  421. *
  422. * Parse the various fixed fields and IEs passed back for a a BSS probe
  423. * response or beacon from the scan command. Record information as needed
  424. * in the scan table struct bss_descriptor for that entry.
  425. *
  426. * @param bss Output parameter: Pointer to the BSS Entry
  427. *
  428. * @return 0 or -1
  429. */
  430. static int lbs_process_bss(struct bss_descriptor *bss,
  431. uint8_t **pbeaconinfo, int *bytesleft)
  432. {
  433. struct ieee_ie_fh_param_set *fh;
  434. struct ieee_ie_ds_param_set *ds;
  435. struct ieee_ie_cf_param_set *cf;
  436. struct ieee_ie_ibss_param_set *ibss;
  437. DECLARE_SSID_BUF(ssid);
  438. uint8_t *pos, *end, *p;
  439. uint8_t n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0;
  440. uint16_t beaconsize = 0;
  441. int ret;
  442. lbs_deb_enter(LBS_DEB_SCAN);
  443. if (*bytesleft >= sizeof(beaconsize)) {
  444. /* Extract & convert beacon size from the command buffer */
  445. beaconsize = get_unaligned_le16(*pbeaconinfo);
  446. *bytesleft -= sizeof(beaconsize);
  447. *pbeaconinfo += sizeof(beaconsize);
  448. }
  449. if (beaconsize == 0 || beaconsize > *bytesleft) {
  450. *pbeaconinfo += *bytesleft;
  451. *bytesleft = 0;
  452. ret = -1;
  453. goto done;
  454. }
  455. /* Initialize the current working beacon pointer for this BSS iteration */
  456. pos = *pbeaconinfo;
  457. end = pos + beaconsize;
  458. /* Advance the return beacon pointer past the current beacon */
  459. *pbeaconinfo += beaconsize;
  460. *bytesleft -= beaconsize;
  461. memcpy(bss->bssid, pos, ETH_ALEN);
  462. lbs_deb_scan("process_bss: BSSID %pM\n", bss->bssid);
  463. pos += ETH_ALEN;
  464. if ((end - pos) < 12) {
  465. lbs_deb_scan("process_bss: Not enough bytes left\n");
  466. ret = -1;
  467. goto done;
  468. }
  469. /*
  470. * next 4 fields are RSSI, time stamp, beacon interval,
  471. * and capability information
  472. */
  473. /* RSSI is 1 byte long */
  474. bss->rssi = *pos;
  475. lbs_deb_scan("process_bss: RSSI %d\n", *pos);
  476. pos++;
  477. /* time stamp is 8 bytes long */
  478. pos += 8;
  479. /* beacon interval is 2 bytes long */
  480. bss->beaconperiod = get_unaligned_le16(pos);
  481. pos += 2;
  482. /* capability information is 2 bytes long */
  483. bss->capability = get_unaligned_le16(pos);
  484. lbs_deb_scan("process_bss: capabilities 0x%04x\n", bss->capability);
  485. pos += 2;
  486. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  487. lbs_deb_scan("process_bss: WEP enabled\n");
  488. if (bss->capability & WLAN_CAPABILITY_IBSS)
  489. bss->mode = IW_MODE_ADHOC;
  490. else
  491. bss->mode = IW_MODE_INFRA;
  492. /* rest of the current buffer are IE's */
  493. lbs_deb_scan("process_bss: IE len %zd\n", end - pos);
  494. lbs_deb_hex(LBS_DEB_SCAN, "process_bss: IE info", pos, end - pos);
  495. /* process variable IE */
  496. while (pos <= end - 2) {
  497. if (pos + pos[1] > end) {
  498. lbs_deb_scan("process_bss: error in processing IE, "
  499. "bytes left < IE length\n");
  500. break;
  501. }
  502. switch (pos[0]) {
  503. case WLAN_EID_SSID:
  504. bss->ssid_len = min_t(int, IEEE80211_MAX_SSID_LEN, pos[1]);
  505. memcpy(bss->ssid, pos + 2, bss->ssid_len);
  506. lbs_deb_scan("got SSID IE: '%s', len %u\n",
  507. print_ssid(ssid, bss->ssid, bss->ssid_len),
  508. bss->ssid_len);
  509. break;
  510. case WLAN_EID_SUPP_RATES:
  511. n_basic_rates = min_t(uint8_t, MAX_RATES, pos[1]);
  512. memcpy(bss->rates, pos + 2, n_basic_rates);
  513. got_basic_rates = 1;
  514. lbs_deb_scan("got RATES IE\n");
  515. break;
  516. case WLAN_EID_FH_PARAMS:
  517. fh = (struct ieee_ie_fh_param_set *) pos;
  518. memcpy(&bss->phy.fh, fh, sizeof(*fh));
  519. lbs_deb_scan("got FH IE\n");
  520. break;
  521. case WLAN_EID_DS_PARAMS:
  522. ds = (struct ieee_ie_ds_param_set *) pos;
  523. bss->channel = ds->channel;
  524. memcpy(&bss->phy.ds, ds, sizeof(*ds));
  525. lbs_deb_scan("got DS IE, channel %d\n", bss->channel);
  526. break;
  527. case WLAN_EID_CF_PARAMS:
  528. cf = (struct ieee_ie_cf_param_set *) pos;
  529. memcpy(&bss->ss.cf, cf, sizeof(*cf));
  530. lbs_deb_scan("got CF IE\n");
  531. break;
  532. case WLAN_EID_IBSS_PARAMS:
  533. ibss = (struct ieee_ie_ibss_param_set *) pos;
  534. bss->atimwindow = ibss->atimwindow;
  535. memcpy(&bss->ss.ibss, ibss, sizeof(*ibss));
  536. lbs_deb_scan("got IBSS IE\n");
  537. break;
  538. case WLAN_EID_EXT_SUPP_RATES:
  539. /* only process extended supported rate if data rate is
  540. * already found. Data rate IE should come before
  541. * extended supported rate IE
  542. */
  543. lbs_deb_scan("got RATESEX IE\n");
  544. if (!got_basic_rates) {
  545. lbs_deb_scan("... but ignoring it\n");
  546. break;
  547. }
  548. n_ex_rates = pos[1];
  549. if (n_basic_rates + n_ex_rates > MAX_RATES)
  550. n_ex_rates = MAX_RATES - n_basic_rates;
  551. p = bss->rates + n_basic_rates;
  552. memcpy(p, pos + 2, n_ex_rates);
  553. break;
  554. case WLAN_EID_GENERIC:
  555. if (pos[1] >= 4 &&
  556. pos[2] == 0x00 && pos[3] == 0x50 &&
  557. pos[4] == 0xf2 && pos[5] == 0x01) {
  558. bss->wpa_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN);
  559. memcpy(bss->wpa_ie, pos, bss->wpa_ie_len);
  560. lbs_deb_scan("got WPA IE\n");
  561. lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie,
  562. bss->wpa_ie_len);
  563. } else if (pos[1] >= MARVELL_MESH_IE_LENGTH &&
  564. pos[2] == 0x00 && pos[3] == 0x50 &&
  565. pos[4] == 0x43 && pos[5] == 0x04) {
  566. lbs_deb_scan("got mesh IE\n");
  567. bss->mesh = 1;
  568. } else {
  569. lbs_deb_scan("got generic IE: %02x:%02x:%02x:%02x, len %d\n",
  570. pos[2], pos[3],
  571. pos[4], pos[5],
  572. pos[1]);
  573. }
  574. break;
  575. case WLAN_EID_RSN:
  576. lbs_deb_scan("got RSN IE\n");
  577. bss->rsn_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN);
  578. memcpy(bss->rsn_ie, pos, bss->rsn_ie_len);
  579. lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE",
  580. bss->rsn_ie, bss->rsn_ie_len);
  581. break;
  582. default:
  583. lbs_deb_scan("got IE 0x%04x, len %d\n",
  584. pos[0], pos[1]);
  585. break;
  586. }
  587. pos += pos[1] + 2;
  588. }
  589. /* Timestamp */
  590. bss->last_scanned = jiffies;
  591. lbs_unset_basic_rate_flags(bss->rates, sizeof(bss->rates));
  592. ret = 0;
  593. done:
  594. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  595. return ret;
  596. }
  597. /**
  598. * @brief Send a scan command for all available channels filtered on a spec
  599. *
  600. * Used in association code and from debugfs
  601. *
  602. * @param priv A pointer to struct lbs_private structure
  603. * @param ssid A pointer to the SSID to scan for
  604. * @param ssid_len Length of the SSID
  605. *
  606. * @return 0-success, otherwise fail
  607. */
  608. int lbs_send_specific_ssid_scan(struct lbs_private *priv, uint8_t *ssid,
  609. uint8_t ssid_len)
  610. {
  611. DECLARE_SSID_BUF(ssid_buf);
  612. int ret = 0;
  613. lbs_deb_enter_args(LBS_DEB_SCAN, "SSID '%s'\n",
  614. print_ssid(ssid_buf, ssid, ssid_len));
  615. if (!ssid_len)
  616. goto out;
  617. memcpy(priv->scan_ssid, ssid, ssid_len);
  618. priv->scan_ssid_len = ssid_len;
  619. lbs_scan_networks(priv, 1);
  620. if (priv->surpriseremoved) {
  621. ret = -1;
  622. goto out;
  623. }
  624. out:
  625. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  626. return ret;
  627. }
  628. /*********************************************************************/
  629. /* */
  630. /* Support for Wireless Extensions */
  631. /* */
  632. /*********************************************************************/
  633. #define MAX_CUSTOM_LEN 64
  634. static inline char *lbs_translate_scan(struct lbs_private *priv,
  635. struct iw_request_info *info,
  636. char *start, char *stop,
  637. struct bss_descriptor *bss)
  638. {
  639. struct chan_freq_power *cfp;
  640. char *current_val; /* For rates */
  641. struct iw_event iwe; /* Temporary buffer */
  642. int j;
  643. #define PERFECT_RSSI ((uint8_t)50)
  644. #define WORST_RSSI ((uint8_t)0)
  645. #define RSSI_DIFF ((uint8_t)(PERFECT_RSSI - WORST_RSSI))
  646. uint8_t rssi;
  647. lbs_deb_enter(LBS_DEB_SCAN);
  648. cfp = lbs_find_cfp_by_band_and_channel(priv, 0, bss->channel);
  649. if (!cfp) {
  650. lbs_deb_scan("Invalid channel number %d\n", bss->channel);
  651. start = NULL;
  652. goto out;
  653. }
  654. /* First entry *MUST* be the BSSID */
  655. iwe.cmd = SIOCGIWAP;
  656. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  657. memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN);
  658. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
  659. /* SSID */
  660. iwe.cmd = SIOCGIWESSID;
  661. iwe.u.data.flags = 1;
  662. iwe.u.data.length = min((uint32_t) bss->ssid_len, (uint32_t) IEEE80211_MAX_SSID_LEN);
  663. start = iwe_stream_add_point(info, start, stop, &iwe, bss->ssid);
  664. /* Mode */
  665. iwe.cmd = SIOCGIWMODE;
  666. iwe.u.mode = bss->mode;
  667. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
  668. /* Frequency */
  669. iwe.cmd = SIOCGIWFREQ;
  670. iwe.u.freq.m = (long)cfp->freq * 100000;
  671. iwe.u.freq.e = 1;
  672. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
  673. /* Add quality statistics */
  674. iwe.cmd = IWEVQUAL;
  675. iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
  676. iwe.u.qual.level = SCAN_RSSI(bss->rssi);
  677. rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
  678. iwe.u.qual.qual =
  679. (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
  680. (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
  681. (RSSI_DIFF * RSSI_DIFF);
  682. if (iwe.u.qual.qual > 100)
  683. iwe.u.qual.qual = 100;
  684. if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  685. iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  686. } else {
  687. iwe.u.qual.noise = CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
  688. }
  689. /* Locally created ad-hoc BSSs won't have beacons if this is the
  690. * only station in the adhoc network; so get signal strength
  691. * from receive statistics.
  692. */
  693. if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate
  694. && !lbs_ssid_cmp(priv->curbssparams.ssid,
  695. priv->curbssparams.ssid_len,
  696. bss->ssid, bss->ssid_len)) {
  697. int snr, nf;
  698. snr = priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
  699. nf = priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
  700. iwe.u.qual.level = CAL_RSSI(snr, nf);
  701. }
  702. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
  703. /* Add encryption capability */
  704. iwe.cmd = SIOCGIWENCODE;
  705. if (bss->capability & WLAN_CAPABILITY_PRIVACY) {
  706. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  707. } else {
  708. iwe.u.data.flags = IW_ENCODE_DISABLED;
  709. }
  710. iwe.u.data.length = 0;
  711. start = iwe_stream_add_point(info, start, stop, &iwe, bss->ssid);
  712. current_val = start + iwe_stream_lcp_len(info);
  713. iwe.cmd = SIOCGIWRATE;
  714. iwe.u.bitrate.fixed = 0;
  715. iwe.u.bitrate.disabled = 0;
  716. iwe.u.bitrate.value = 0;
  717. for (j = 0; j < ARRAY_SIZE(bss->rates) && bss->rates[j]; j++) {
  718. /* Bit rate given in 500 kb/s units */
  719. iwe.u.bitrate.value = bss->rates[j] * 500000;
  720. current_val = iwe_stream_add_value(info, start, current_val,
  721. stop, &iwe, IW_EV_PARAM_LEN);
  722. }
  723. if ((bss->mode == IW_MODE_ADHOC) && priv->adhoccreate
  724. && !lbs_ssid_cmp(priv->curbssparams.ssid,
  725. priv->curbssparams.ssid_len,
  726. bss->ssid, bss->ssid_len)) {
  727. iwe.u.bitrate.value = 22 * 500000;
  728. current_val = iwe_stream_add_value(info, start, current_val,
  729. stop, &iwe, IW_EV_PARAM_LEN);
  730. }
  731. /* Check if we added any event */
  732. if ((current_val - start) > iwe_stream_lcp_len(info))
  733. start = current_val;
  734. memset(&iwe, 0, sizeof(iwe));
  735. if (bss->wpa_ie_len) {
  736. char buf[MAX_WPA_IE_LEN];
  737. memcpy(buf, bss->wpa_ie, bss->wpa_ie_len);
  738. iwe.cmd = IWEVGENIE;
  739. iwe.u.data.length = bss->wpa_ie_len;
  740. start = iwe_stream_add_point(info, start, stop, &iwe, buf);
  741. }
  742. memset(&iwe, 0, sizeof(iwe));
  743. if (bss->rsn_ie_len) {
  744. char buf[MAX_WPA_IE_LEN];
  745. memcpy(buf, bss->rsn_ie, bss->rsn_ie_len);
  746. iwe.cmd = IWEVGENIE;
  747. iwe.u.data.length = bss->rsn_ie_len;
  748. start = iwe_stream_add_point(info, start, stop, &iwe, buf);
  749. }
  750. if (bss->mesh) {
  751. char custom[MAX_CUSTOM_LEN];
  752. char *p = custom;
  753. iwe.cmd = IWEVCUSTOM;
  754. p += snprintf(p, MAX_CUSTOM_LEN, "mesh-type: olpc");
  755. iwe.u.data.length = p - custom;
  756. if (iwe.u.data.length)
  757. start = iwe_stream_add_point(info, start, stop,
  758. &iwe, custom);
  759. }
  760. out:
  761. lbs_deb_leave_args(LBS_DEB_SCAN, "start %p", start);
  762. return start;
  763. }
  764. /**
  765. * @brief Handle Scan Network ioctl
  766. *
  767. * @param dev A pointer to net_device structure
  768. * @param info A pointer to iw_request_info structure
  769. * @param vwrq A pointer to iw_param structure
  770. * @param extra A pointer to extra data buf
  771. *
  772. * @return 0 --success, otherwise fail
  773. */
  774. int lbs_set_scan(struct net_device *dev, struct iw_request_info *info,
  775. union iwreq_data *wrqu, char *extra)
  776. {
  777. DECLARE_SSID_BUF(ssid);
  778. struct lbs_private *priv = dev->ml_priv;
  779. int ret = 0;
  780. lbs_deb_enter(LBS_DEB_WEXT);
  781. if (!priv->radio_on) {
  782. ret = -EINVAL;
  783. goto out;
  784. }
  785. if (!netif_running(dev)) {
  786. ret = -ENETDOWN;
  787. goto out;
  788. }
  789. /* mac80211 does this:
  790. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  791. if (sdata->type != IEEE80211_IF_TYPE_xxx) {
  792. ret = -EOPNOTSUPP;
  793. goto out;
  794. }
  795. */
  796. if (wrqu->data.length == sizeof(struct iw_scan_req) &&
  797. wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  798. struct iw_scan_req *req = (struct iw_scan_req *)extra;
  799. priv->scan_ssid_len = req->essid_len;
  800. memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
  801. lbs_deb_wext("set_scan, essid '%s'\n",
  802. print_ssid(ssid, priv->scan_ssid, priv->scan_ssid_len));
  803. } else {
  804. priv->scan_ssid_len = 0;
  805. }
  806. if (!delayed_work_pending(&priv->scan_work))
  807. queue_delayed_work(priv->work_thread, &priv->scan_work,
  808. msecs_to_jiffies(50));
  809. /* set marker that currently a scan is taking place */
  810. priv->scan_channel = -1;
  811. if (priv->surpriseremoved)
  812. ret = -EIO;
  813. out:
  814. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  815. return ret;
  816. }
  817. /**
  818. * @brief Handle Retrieve scan table ioctl
  819. *
  820. * @param dev A pointer to net_device structure
  821. * @param info A pointer to iw_request_info structure
  822. * @param dwrq A pointer to iw_point structure
  823. * @param extra A pointer to extra data buf
  824. *
  825. * @return 0 --success, otherwise fail
  826. */
  827. int lbs_get_scan(struct net_device *dev, struct iw_request_info *info,
  828. struct iw_point *dwrq, char *extra)
  829. {
  830. #define SCAN_ITEM_SIZE 128
  831. struct lbs_private *priv = dev->ml_priv;
  832. int err = 0;
  833. char *ev = extra;
  834. char *stop = ev + dwrq->length;
  835. struct bss_descriptor *iter_bss;
  836. struct bss_descriptor *safe;
  837. lbs_deb_enter(LBS_DEB_WEXT);
  838. /* iwlist should wait until the current scan is finished */
  839. if (priv->scan_channel)
  840. return -EAGAIN;
  841. /* Update RSSI if current BSS is a locally created ad-hoc BSS */
  842. if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate) {
  843. err = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  844. CMD_OPTION_WAITFORRSP, 0, NULL);
  845. if (err)
  846. goto out;
  847. }
  848. mutex_lock(&priv->lock);
  849. list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) {
  850. char *next_ev;
  851. unsigned long stale_time;
  852. if (stop - ev < SCAN_ITEM_SIZE) {
  853. err = -E2BIG;
  854. break;
  855. }
  856. /* For mesh device, list only mesh networks */
  857. if (dev == priv->mesh_dev && !iter_bss->mesh)
  858. continue;
  859. /* Prune old an old scan result */
  860. stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
  861. if (time_after(jiffies, stale_time)) {
  862. list_move_tail(&iter_bss->list, &priv->network_free_list);
  863. clear_bss_descriptor(iter_bss);
  864. continue;
  865. }
  866. /* Translate to WE format this entry */
  867. next_ev = lbs_translate_scan(priv, info, ev, stop, iter_bss);
  868. if (next_ev == NULL)
  869. continue;
  870. ev = next_ev;
  871. }
  872. mutex_unlock(&priv->lock);
  873. dwrq->length = (ev - extra);
  874. dwrq->flags = 0;
  875. out:
  876. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", err);
  877. return err;
  878. }
  879. /*********************************************************************/
  880. /* */
  881. /* Command execution */
  882. /* */
  883. /*********************************************************************/
  884. /**
  885. * @brief This function handles the command response of scan
  886. *
  887. * Called from handle_cmd_response() in cmdrespc.
  888. *
  889. * The response buffer for the scan command has the following
  890. * memory layout:
  891. *
  892. * .-----------------------------------------------------------.
  893. * | header (4 * sizeof(u16)): Standard command response hdr |
  894. * .-----------------------------------------------------------.
  895. * | bufsize (u16) : sizeof the BSS Description data |
  896. * .-----------------------------------------------------------.
  897. * | NumOfSet (u8) : Number of BSS Descs returned |
  898. * .-----------------------------------------------------------.
  899. * | BSSDescription data (variable, size given in bufsize) |
  900. * .-----------------------------------------------------------.
  901. * | TLV data (variable, size calculated using header->size, |
  902. * | bufsize and sizeof the fixed fields above) |
  903. * .-----------------------------------------------------------.
  904. *
  905. * @param priv A pointer to struct lbs_private structure
  906. * @param resp A pointer to cmd_ds_command
  907. *
  908. * @return 0 or -1
  909. */
  910. static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy,
  911. struct cmd_header *resp)
  912. {
  913. struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
  914. struct bss_descriptor *iter_bss;
  915. struct bss_descriptor *safe;
  916. uint8_t *bssinfo;
  917. uint16_t scanrespsize;
  918. int bytesleft;
  919. int idx;
  920. int tlvbufsize;
  921. int ret;
  922. lbs_deb_enter(LBS_DEB_SCAN);
  923. /* Prune old entries from scan table */
  924. list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) {
  925. unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
  926. if (time_before(jiffies, stale_time))
  927. continue;
  928. list_move_tail (&iter_bss->list, &priv->network_free_list);
  929. clear_bss_descriptor(iter_bss);
  930. }
  931. if (scanresp->nr_sets > MAX_NETWORK_COUNT) {
  932. lbs_deb_scan("SCAN_RESP: too many scan results (%d, max %d)\n",
  933. scanresp->nr_sets, MAX_NETWORK_COUNT);
  934. ret = -1;
  935. goto done;
  936. }
  937. bytesleft = get_unaligned_le16(&scanresp->bssdescriptsize);
  938. lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft);
  939. scanrespsize = le16_to_cpu(resp->size);
  940. lbs_deb_scan("SCAN_RESP: scan results %d\n", scanresp->nr_sets);
  941. bssinfo = scanresp->bssdesc_and_tlvbuffer;
  942. /* The size of the TLV buffer is equal to the entire command response
  943. * size (scanrespsize) minus the fixed fields (sizeof()'s), the
  944. * BSS Descriptions (bssdescriptsize as bytesLef) and the command
  945. * response header (S_DS_GEN)
  946. */
  947. tlvbufsize = scanrespsize - (bytesleft + sizeof(scanresp->bssdescriptsize)
  948. + sizeof(scanresp->nr_sets)
  949. + S_DS_GEN);
  950. /*
  951. * Process each scan response returned (scanresp->nr_sets). Save
  952. * the information in the newbssentry and then insert into the
  953. * driver scan table either as an update to an existing entry
  954. * or as an addition at the end of the table
  955. */
  956. for (idx = 0; idx < scanresp->nr_sets && bytesleft; idx++) {
  957. struct bss_descriptor new;
  958. struct bss_descriptor *found = NULL;
  959. struct bss_descriptor *oldest = NULL;
  960. /* Process the data fields and IEs returned for this BSS */
  961. memset(&new, 0, sizeof (struct bss_descriptor));
  962. if (lbs_process_bss(&new, &bssinfo, &bytesleft) != 0) {
  963. /* error parsing the scan response, skipped */
  964. lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n");
  965. continue;
  966. }
  967. /* Try to find this bss in the scan table */
  968. list_for_each_entry (iter_bss, &priv->network_list, list) {
  969. if (is_same_network(iter_bss, &new)) {
  970. found = iter_bss;
  971. break;
  972. }
  973. if ((oldest == NULL) ||
  974. (iter_bss->last_scanned < oldest->last_scanned))
  975. oldest = iter_bss;
  976. }
  977. if (found) {
  978. /* found, clear it */
  979. clear_bss_descriptor(found);
  980. } else if (!list_empty(&priv->network_free_list)) {
  981. /* Pull one from the free list */
  982. found = list_entry(priv->network_free_list.next,
  983. struct bss_descriptor, list);
  984. list_move_tail(&found->list, &priv->network_list);
  985. } else if (oldest) {
  986. /* If there are no more slots, expire the oldest */
  987. found = oldest;
  988. clear_bss_descriptor(found);
  989. list_move_tail(&found->list, &priv->network_list);
  990. } else {
  991. continue;
  992. }
  993. lbs_deb_scan("SCAN_RESP: BSSID %pM\n", new.bssid);
  994. /* Copy the locally created newbssentry to the scan table */
  995. memcpy(found, &new, offsetof(struct bss_descriptor, list));
  996. }
  997. ret = 0;
  998. done:
  999. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  1000. return ret;
  1001. }