scan.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  1. /* -*- mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
  2. /* vi: set expandtab shiftwidth=4 tabstop=4 textwidth=78: */
  3. /**
  4. * Functions implementing wlan scan IOCTL and firmware command APIs
  5. *
  6. * IOCTL handlers as well as command preperation and response routines
  7. * for sending scan commands to the firmware.
  8. */
  9. #include <linux/ctype.h>
  10. #include <linux/if.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/wireless.h>
  13. #include <net/ieee80211.h>
  14. #include <net/iw_handler.h>
  15. #include "host.h"
  16. #include "decl.h"
  17. #include "dev.h"
  18. #include "scan.h"
  19. //! Approximate amount of data needed to pass a scan result back to iwlist
  20. #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
  21. + IW_ESSID_MAX_SIZE \
  22. + IW_EV_UINT_LEN \
  23. + IW_EV_FREQ_LEN \
  24. + IW_EV_QUAL_LEN \
  25. + IW_ESSID_MAX_SIZE \
  26. + IW_EV_PARAM_LEN \
  27. + 40) /* 40 for WPAIE */
  28. //! Memory needed to store a max sized channel List TLV for a firmware scan
  29. #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \
  30. + (MRVDRV_MAX_CHANNELS_PER_SCAN \
  31. * sizeof(struct chanscanparamset)))
  32. //! Memory needed to store a max number/size SSID TLV for a firmware scan
  33. #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset))
  34. //! Maximum memory needed for a wlan_scan_cmd_config with all TLVs at max
  35. #define MAX_SCAN_CFG_ALLOC (sizeof(struct wlan_scan_cmd_config) \
  36. + sizeof(struct mrvlietypes_numprobes) \
  37. + CHAN_TLV_MAX_SIZE \
  38. + SSID_TLV_MAX_SIZE)
  39. //! The maximum number of channels the firmware can scan per command
  40. #define MRVDRV_MAX_CHANNELS_PER_SCAN 14
  41. /**
  42. * @brief Number of channels to scan per firmware scan command issuance.
  43. *
  44. * Number restricted to prevent hitting the limit on the amount of scan data
  45. * returned in a single firmware scan command.
  46. */
  47. #define MRVDRV_CHANNELS_PER_SCAN_CMD 4
  48. //! Scan time specified in the channel TLV for each channel for passive scans
  49. #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
  50. //! Scan time specified in the channel TLV for each channel for active scans
  51. #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
  52. //! Macro to enable/disable SSID checking before storing a scan table
  53. #ifdef DISCARD_BAD_SSID
  54. #define CHECK_SSID_IS_VALID(x) ssid_valid(&bssidEntry.ssid)
  55. #else
  56. #define CHECK_SSID_IS_VALID(x) 1
  57. #endif
  58. /**
  59. * @brief Check if a scanned network compatible with the driver settings
  60. *
  61. * WEP WPA WPA2 ad-hoc encrypt Network
  62. * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
  63. * 0 0 0 0 NONE 0 0 0 yes No security
  64. * 1 0 0 0 NONE 1 0 0 yes Static WEP
  65. * 0 1 0 0 x 1x 1 x yes WPA
  66. * 0 0 1 0 x 1x x 1 yes WPA2
  67. * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
  68. * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
  69. *
  70. *
  71. * @param adapter A pointer to wlan_adapter
  72. * @param index Index in scantable to check against current driver settings
  73. * @param mode Network mode: Infrastructure or IBSS
  74. *
  75. * @return Index in scantable, or error code if negative
  76. */
  77. static int is_network_compatible(wlan_adapter * adapter, int index, int mode)
  78. {
  79. ENTER();
  80. if (adapter->scantable[index].inframode == mode) {
  81. if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled
  82. && !adapter->secinfo.WPAenabled
  83. && !adapter->secinfo.WPA2enabled
  84. && adapter->scantable[index].wpa_supplicant.wpa_ie[0] !=
  85. WPA_IE
  86. && adapter->scantable[index].wpa2_supplicant.wpa_ie[0] !=
  87. WPA2_IE && adapter->secinfo.Encryptionmode == CIPHER_NONE
  88. && !adapter->scantable[index].privacy) {
  89. /* no security */
  90. LEAVE();
  91. return index;
  92. } else if (adapter->secinfo.WEPstatus == wlan802_11WEPenabled
  93. && !adapter->secinfo.WPAenabled
  94. && !adapter->secinfo.WPA2enabled
  95. && adapter->scantable[index].privacy) {
  96. /* static WEP enabled */
  97. LEAVE();
  98. return index;
  99. } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled
  100. && adapter->secinfo.WPAenabled
  101. && !adapter->secinfo.WPA2enabled
  102. && (adapter->scantable[index].wpa_supplicant.
  103. wpa_ie[0]
  104. == WPA_IE)
  105. /* privacy bit may NOT be set in some APs like LinkSys WRT54G
  106. && adapter->scantable[index].privacy */
  107. ) {
  108. /* WPA enabled */
  109. lbs_pr_debug(1,
  110. "is_network_compatible() WPA: index=%d wpa_ie=%#x "
  111. "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x "
  112. "privacy=%#x\n", index,
  113. adapter->scantable[index].wpa_supplicant.
  114. wpa_ie[0],
  115. adapter->scantable[index].wpa2_supplicant.
  116. wpa_ie[0],
  117. (adapter->secinfo.WEPstatus ==
  118. wlan802_11WEPenabled) ? "e" : "d",
  119. (adapter->secinfo.WPAenabled) ? "e" : "d",
  120. (adapter->secinfo.WPA2enabled) ? "e" : "d",
  121. adapter->secinfo.Encryptionmode,
  122. adapter->scantable[index].privacy);
  123. LEAVE();
  124. return index;
  125. } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled
  126. && !adapter->secinfo.WPAenabled
  127. && adapter->secinfo.WPA2enabled
  128. && (adapter->scantable[index].wpa2_supplicant.
  129. wpa_ie[0]
  130. == WPA2_IE)
  131. /* privacy bit may NOT be set in some APs like LinkSys WRT54G
  132. && adapter->scantable[index].privacy */
  133. ) {
  134. /* WPA2 enabled */
  135. lbs_pr_debug(1,
  136. "is_network_compatible() WPA2: index=%d wpa_ie=%#x "
  137. "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x "
  138. "privacy=%#x\n", index,
  139. adapter->scantable[index].wpa_supplicant.
  140. wpa_ie[0],
  141. adapter->scantable[index].wpa2_supplicant.
  142. wpa_ie[0],
  143. (adapter->secinfo.WEPstatus ==
  144. wlan802_11WEPenabled) ? "e" : "d",
  145. (adapter->secinfo.WPAenabled) ? "e" : "d",
  146. (adapter->secinfo.WPA2enabled) ? "e" : "d",
  147. adapter->secinfo.Encryptionmode,
  148. adapter->scantable[index].privacy);
  149. LEAVE();
  150. return index;
  151. } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled
  152. && !adapter->secinfo.WPAenabled
  153. && !adapter->secinfo.WPA2enabled
  154. && (adapter->scantable[index].wpa_supplicant.
  155. wpa_ie[0]
  156. != WPA_IE)
  157. && (adapter->scantable[index].wpa2_supplicant.
  158. wpa_ie[0]
  159. != WPA2_IE)
  160. && adapter->secinfo.Encryptionmode != CIPHER_NONE
  161. && adapter->scantable[index].privacy) {
  162. /* dynamic WEP enabled */
  163. lbs_pr_debug(1,
  164. "is_network_compatible() dynamic WEP: index=%d "
  165. "wpa_ie=%#x wpa2_ie=%#x Encmode=%#x privacy=%#x\n",
  166. index,
  167. adapter->scantable[index].wpa_supplicant.
  168. wpa_ie[0],
  169. adapter->scantable[index].wpa2_supplicant.
  170. wpa_ie[0], adapter->secinfo.Encryptionmode,
  171. adapter->scantable[index].privacy);
  172. LEAVE();
  173. return index;
  174. }
  175. /* security doesn't match */
  176. lbs_pr_debug(1,
  177. "is_network_compatible() FAILED: index=%d wpa_ie=%#x "
  178. "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x privacy=%#x\n",
  179. index,
  180. adapter->scantable[index].wpa_supplicant.wpa_ie[0],
  181. adapter->scantable[index].wpa2_supplicant.wpa_ie[0],
  182. (adapter->secinfo.WEPstatus ==
  183. wlan802_11WEPenabled) ? "e" : "d",
  184. (adapter->secinfo.WPAenabled) ? "e" : "d",
  185. (adapter->secinfo.WPA2enabled) ? "e" : "d",
  186. adapter->secinfo.Encryptionmode,
  187. adapter->scantable[index].privacy);
  188. LEAVE();
  189. return -ECONNREFUSED;
  190. }
  191. /* mode doesn't match */
  192. LEAVE();
  193. return -ENETUNREACH;
  194. }
  195. /**
  196. * @brief This function validates a SSID as being able to be printed
  197. *
  198. * @param pssid SSID structure to validate
  199. *
  200. * @return TRUE or FALSE
  201. */
  202. static u8 ssid_valid(struct WLAN_802_11_SSID *pssid)
  203. {
  204. int ssididx;
  205. for (ssididx = 0; ssididx < pssid->ssidlength; ssididx++) {
  206. if (!isprint(pssid->ssid[ssididx])) {
  207. return 0;
  208. }
  209. }
  210. return 1;
  211. }
  212. /**
  213. * @brief Post process the scan table after a new scan command has completed
  214. *
  215. * Inspect each entry of the scan table and try to find an entry that
  216. * matches our current associated/joined network from the scan. If
  217. * one is found, update the stored copy of the bssdescriptor for our
  218. * current network.
  219. *
  220. * Debug dump the current scan table contents if compiled accordingly.
  221. *
  222. * @param priv A pointer to wlan_private structure
  223. *
  224. * @return void
  225. */
  226. static void wlan_scan_process_results(wlan_private * priv)
  227. {
  228. wlan_adapter *adapter = priv->adapter;
  229. int foundcurrent;
  230. int i;
  231. foundcurrent = 0;
  232. if (adapter->connect_status == libertas_connected) {
  233. /* try to find the current BSSID in the new scan list */
  234. for (i = 0; i < adapter->numinscantable; i++) {
  235. if (!libertas_SSID_cmp(&adapter->scantable[i].ssid,
  236. &adapter->curbssparams.ssid) &&
  237. !memcmp(adapter->curbssparams.bssid,
  238. adapter->scantable[i].macaddress,
  239. ETH_ALEN)) {
  240. foundcurrent = 1;
  241. }
  242. }
  243. if (foundcurrent) {
  244. /* Make a copy of current BSSID descriptor */
  245. memcpy(&adapter->curbssparams.bssdescriptor,
  246. &adapter->scantable[i],
  247. sizeof(adapter->curbssparams.bssdescriptor));
  248. }
  249. }
  250. for (i = 0; i < adapter->numinscantable; i++) {
  251. lbs_pr_debug(1, "Scan:(%02d) %02x:%02x:%02x:%02x:%02x:%02x, "
  252. "RSSI[%03d], SSID[%s]\n",
  253. i,
  254. adapter->scantable[i].macaddress[0],
  255. adapter->scantable[i].macaddress[1],
  256. adapter->scantable[i].macaddress[2],
  257. adapter->scantable[i].macaddress[3],
  258. adapter->scantable[i].macaddress[4],
  259. adapter->scantable[i].macaddress[5],
  260. (s32) adapter->scantable[i].rssi,
  261. adapter->scantable[i].ssid.ssid);
  262. }
  263. }
  264. /**
  265. * @brief Create a channel list for the driver to scan based on region info
  266. *
  267. * Use the driver region/band information to construct a comprehensive list
  268. * of channels to scan. This routine is used for any scan that is not
  269. * provided a specific channel list to scan.
  270. *
  271. * @param priv A pointer to wlan_private structure
  272. * @param scanchanlist Output parameter: resulting channel list to scan
  273. * @param filteredscan Flag indicating whether or not a BSSID or SSID filter
  274. * is being sent in the command to firmware. Used to
  275. * increase the number of channels sent in a scan
  276. * command and to disable the firmware channel scan
  277. * filter.
  278. *
  279. * @return void
  280. */
  281. static void wlan_scan_create_channel_list(wlan_private * priv,
  282. struct chanscanparamset * scanchanlist,
  283. u8 filteredscan)
  284. {
  285. wlan_adapter *adapter = priv->adapter;
  286. struct region_channel *scanregion;
  287. struct chan_freq_power *cfp;
  288. int rgnidx;
  289. int chanidx;
  290. int nextchan;
  291. u8 scantype;
  292. chanidx = 0;
  293. /* Set the default scan type to the user specified type, will later
  294. * be changed to passive on a per channel basis if restricted by
  295. * regulatory requirements (11d or 11h)
  296. */
  297. scantype = adapter->scantype;
  298. for (rgnidx = 0; rgnidx < ARRAY_SIZE(adapter->region_channel); rgnidx++) {
  299. if (priv->adapter->enable11d &&
  300. adapter->connect_status != libertas_connected) {
  301. /* Scan all the supported chan for the first scan */
  302. if (!adapter->universal_channel[rgnidx].valid)
  303. continue;
  304. scanregion = &adapter->universal_channel[rgnidx];
  305. /* clear the parsed_region_chan for the first scan */
  306. memset(&adapter->parsed_region_chan, 0x00,
  307. sizeof(adapter->parsed_region_chan));
  308. } else {
  309. if (!adapter->region_channel[rgnidx].valid)
  310. continue;
  311. scanregion = &adapter->region_channel[rgnidx];
  312. }
  313. for (nextchan = 0;
  314. nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
  315. cfp = scanregion->CFP + nextchan;
  316. if (priv->adapter->enable11d) {
  317. scantype =
  318. libertas_get_scan_type_11d(cfp->channel,
  319. &adapter->
  320. parsed_region_chan);
  321. }
  322. switch (scanregion->band) {
  323. case BAND_B:
  324. case BAND_G:
  325. default:
  326. scanchanlist[chanidx].radiotype =
  327. cmd_scan_radio_type_bg;
  328. break;
  329. }
  330. if (scantype == cmd_scan_type_passive) {
  331. scanchanlist[chanidx].maxscantime =
  332. cpu_to_le16
  333. (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
  334. scanchanlist[chanidx].chanscanmode.passivescan =
  335. 1;
  336. } else {
  337. scanchanlist[chanidx].maxscantime =
  338. cpu_to_le16
  339. (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
  340. scanchanlist[chanidx].chanscanmode.passivescan =
  341. 0;
  342. }
  343. scanchanlist[chanidx].channumber = cfp->channel;
  344. if (filteredscan) {
  345. scanchanlist[chanidx].chanscanmode.
  346. disablechanfilt = 1;
  347. }
  348. }
  349. }
  350. }
  351. /**
  352. * @brief Construct a wlan_scan_cmd_config structure to use in issue scan cmds
  353. *
  354. * Application layer or other functions can invoke wlan_scan_networks
  355. * with a scan configuration supplied in a wlan_ioctl_user_scan_cfg struct.
  356. * This structure is used as the basis of one or many wlan_scan_cmd_config
  357. * commands that are sent to the command processing module and sent to
  358. * firmware.
  359. *
  360. * Create a wlan_scan_cmd_config based on the following user supplied
  361. * parameters (if present):
  362. * - SSID filter
  363. * - BSSID filter
  364. * - Number of Probes to be sent
  365. * - channel list
  366. *
  367. * If the SSID or BSSID filter is not present, disable/clear the filter.
  368. * If the number of probes is not set, use the adapter default setting
  369. * Qualify the channel
  370. *
  371. * @param priv A pointer to wlan_private structure
  372. * @param puserscanin NULL or pointer to scan configuration parameters
  373. * @param ppchantlvout Output parameter: Pointer to the start of the
  374. * channel TLV portion of the output scan config
  375. * @param pscanchanlist Output parameter: Pointer to the resulting channel
  376. * list to scan
  377. * @param pmaxchanperscan Output parameter: Number of channels to scan for
  378. * each issuance of the firmware scan command
  379. * @param pfilteredscan Output parameter: Flag indicating whether or not
  380. * a BSSID or SSID filter is being sent in the
  381. * command to firmware. Used to increase the number
  382. * of channels sent in a scan command and to
  383. * disable the firmware channel scan filter.
  384. * @param pscancurrentonly Output parameter: Flag indicating whether or not
  385. * we are only scanning our current active channel
  386. *
  387. * @return resulting scan configuration
  388. */
  389. static struct wlan_scan_cmd_config *
  390. wlan_scan_setup_scan_config(wlan_private * priv,
  391. const struct wlan_ioctl_user_scan_cfg * puserscanin,
  392. struct mrvlietypes_chanlistparamset ** ppchantlvout,
  393. struct chanscanparamset * pscanchanlist,
  394. int *pmaxchanperscan,
  395. u8 * pfilteredscan,
  396. u8 * pscancurrentonly)
  397. {
  398. wlan_adapter *adapter = priv->adapter;
  399. const u8 zeromac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  400. struct mrvlietypes_numprobes *pnumprobestlv;
  401. struct mrvlietypes_ssidparamset *pssidtlv;
  402. struct wlan_scan_cmd_config * pscancfgout = NULL;
  403. u8 *ptlvpos;
  404. u16 numprobes;
  405. u16 ssidlen;
  406. int chanidx;
  407. int scantype;
  408. int scandur;
  409. int channel;
  410. int radiotype;
  411. pscancfgout = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
  412. if (pscancfgout == NULL)
  413. goto out;
  414. /* The tlvbufferlen is calculated for each scan command. The TLVs added
  415. * in this routine will be preserved since the routine that sends
  416. * the command will append channelTLVs at *ppchantlvout. The difference
  417. * between the *ppchantlvout and the tlvbuffer start will be used
  418. * to calculate the size of anything we add in this routine.
  419. */
  420. pscancfgout->tlvbufferlen = 0;
  421. /* Running tlv pointer. Assigned to ppchantlvout at end of function
  422. * so later routines know where channels can be added to the command buf
  423. */
  424. ptlvpos = pscancfgout->tlvbuffer;
  425. /*
  426. * Set the initial scan paramters for progressive scanning. If a specific
  427. * BSSID or SSID is used, the number of channels in the scan command
  428. * will be increased to the absolute maximum
  429. */
  430. *pmaxchanperscan = MRVDRV_CHANNELS_PER_SCAN_CMD;
  431. /* Initialize the scan as un-filtered by firmware, set to TRUE below if
  432. * a SSID or BSSID filter is sent in the command
  433. */
  434. *pfilteredscan = 0;
  435. /* Initialize the scan as not being only on the current channel. If
  436. * the channel list is customized, only contains one channel, and
  437. * is the active channel, this is set true and data flow is not halted.
  438. */
  439. *pscancurrentonly = 0;
  440. if (puserscanin) {
  441. /* Set the bss type scan filter, use adapter setting if unset */
  442. pscancfgout->bsstype =
  443. (puserscanin->bsstype ? puserscanin->bsstype : adapter->
  444. scanmode);
  445. /* Set the number of probes to send, use adapter setting if unset */
  446. numprobes = (puserscanin->numprobes ? puserscanin->numprobes :
  447. adapter->scanprobes);
  448. /*
  449. * Set the BSSID filter to the incoming configuration,
  450. * if non-zero. If not set, it will remain disabled (all zeros).
  451. */
  452. memcpy(pscancfgout->specificBSSID,
  453. puserscanin->specificBSSID,
  454. sizeof(pscancfgout->specificBSSID));
  455. ssidlen = strlen(puserscanin->specificSSID);
  456. if (ssidlen) {
  457. pssidtlv =
  458. (struct mrvlietypes_ssidparamset *) pscancfgout->
  459. tlvbuffer;
  460. pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
  461. pssidtlv->header.len = cpu_to_le16(ssidlen);
  462. memcpy(pssidtlv->ssid, puserscanin->specificSSID,
  463. ssidlen);
  464. ptlvpos += sizeof(pssidtlv->header) + ssidlen;
  465. }
  466. /*
  467. * The default number of channels sent in the command is low to
  468. * ensure the response buffer from the firmware does not truncate
  469. * scan results. That is not an issue with an SSID or BSSID
  470. * filter applied to the scan results in the firmware.
  471. */
  472. if (ssidlen || (memcmp(pscancfgout->specificBSSID,
  473. &zeromac, sizeof(zeromac)) != 0)) {
  474. *pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN;
  475. *pfilteredscan = 1;
  476. }
  477. } else {
  478. pscancfgout->bsstype = adapter->scanmode;
  479. numprobes = adapter->scanprobes;
  480. }
  481. /* If the input config or adapter has the number of Probes set, add tlv */
  482. if (numprobes) {
  483. pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos;
  484. pnumprobestlv->header.type =
  485. cpu_to_le16(TLV_TYPE_NUMPROBES);
  486. pnumprobestlv->header.len = sizeof(pnumprobestlv->numprobes);
  487. pnumprobestlv->numprobes = cpu_to_le16(numprobes);
  488. ptlvpos +=
  489. sizeof(pnumprobestlv->header) + pnumprobestlv->header.len;
  490. pnumprobestlv->header.len =
  491. cpu_to_le16(pnumprobestlv->header.len);
  492. }
  493. /*
  494. * Set the output for the channel TLV to the address in the tlv buffer
  495. * past any TLVs that were added in this fuction (SSID, numprobes).
  496. * channel TLVs will be added past this for each scan command, preserving
  497. * the TLVs that were previously added.
  498. */
  499. *ppchantlvout = (struct mrvlietypes_chanlistparamset *) ptlvpos;
  500. if (puserscanin && puserscanin->chanlist[0].channumber) {
  501. lbs_pr_debug(1, "Scan: Using supplied channel list\n");
  502. for (chanidx = 0;
  503. chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX
  504. && puserscanin->chanlist[chanidx].channumber; chanidx++) {
  505. channel = puserscanin->chanlist[chanidx].channumber;
  506. (pscanchanlist + chanidx)->channumber = channel;
  507. radiotype = puserscanin->chanlist[chanidx].radiotype;
  508. (pscanchanlist + chanidx)->radiotype = radiotype;
  509. scantype = puserscanin->chanlist[chanidx].scantype;
  510. if (scantype == cmd_scan_type_passive) {
  511. (pscanchanlist +
  512. chanidx)->chanscanmode.passivescan = 1;
  513. } else {
  514. (pscanchanlist +
  515. chanidx)->chanscanmode.passivescan = 0;
  516. }
  517. if (puserscanin->chanlist[chanidx].scantime) {
  518. scandur =
  519. puserscanin->chanlist[chanidx].scantime;
  520. } else {
  521. if (scantype == cmd_scan_type_passive) {
  522. scandur = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
  523. } else {
  524. scandur = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
  525. }
  526. }
  527. (pscanchanlist + chanidx)->minscantime =
  528. cpu_to_le16(scandur);
  529. (pscanchanlist + chanidx)->maxscantime =
  530. cpu_to_le16(scandur);
  531. }
  532. /* Check if we are only scanning the current channel */
  533. if ((chanidx == 1) && (puserscanin->chanlist[0].channumber
  534. ==
  535. priv->adapter->curbssparams.channel)) {
  536. *pscancurrentonly = 1;
  537. lbs_pr_debug(1, "Scan: Scanning current channel only");
  538. }
  539. } else {
  540. lbs_pr_debug(1, "Scan: Creating full region channel list\n");
  541. wlan_scan_create_channel_list(priv, pscanchanlist,
  542. *pfilteredscan);
  543. }
  544. out:
  545. return pscancfgout;
  546. }
  547. /**
  548. * @brief Construct and send multiple scan config commands to the firmware
  549. *
  550. * Previous routines have created a wlan_scan_cmd_config with any requested
  551. * TLVs. This function splits the channel TLV into maxchanperscan lists
  552. * and sends the portion of the channel TLV along with the other TLVs
  553. * to the wlan_cmd routines for execution in the firmware.
  554. *
  555. * @param priv A pointer to wlan_private structure
  556. * @param maxchanperscan Maximum number channels to be included in each
  557. * scan command sent to firmware
  558. * @param filteredscan Flag indicating whether or not a BSSID or SSID
  559. * filter is being used for the firmware command
  560. * scan command sent to firmware
  561. * @param pscancfgout Scan configuration used for this scan.
  562. * @param pchantlvout Pointer in the pscancfgout where the channel TLV
  563. * should start. This is past any other TLVs that
  564. * must be sent down in each firmware command.
  565. * @param pscanchanlist List of channels to scan in maxchanperscan segments
  566. *
  567. * @return 0 or error return otherwise
  568. */
  569. static int wlan_scan_channel_list(wlan_private * priv,
  570. int maxchanperscan,
  571. u8 filteredscan,
  572. struct wlan_scan_cmd_config * pscancfgout,
  573. struct mrvlietypes_chanlistparamset * pchantlvout,
  574. struct chanscanparamset * pscanchanlist)
  575. {
  576. struct chanscanparamset *ptmpchan;
  577. struct chanscanparamset *pstartchan;
  578. u8 scanband;
  579. int doneearly;
  580. int tlvidx;
  581. int ret = 0;
  582. ENTER();
  583. if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) {
  584. lbs_pr_debug(1, "Scan: Null detect: %p, %p, %p\n",
  585. pscancfgout, pchantlvout, pscanchanlist);
  586. return -1;
  587. }
  588. pchantlvout->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  589. /* Set the temp channel struct pointer to the start of the desired list */
  590. ptmpchan = pscanchanlist;
  591. /* Loop through the desired channel list, sending a new firmware scan
  592. * commands for each maxchanperscan channels (or for 1,6,11 individually
  593. * if configured accordingly)
  594. */
  595. while (ptmpchan->channumber) {
  596. tlvidx = 0;
  597. pchantlvout->header.len = 0;
  598. scanband = ptmpchan->radiotype;
  599. pstartchan = ptmpchan;
  600. doneearly = 0;
  601. /* Construct the channel TLV for the scan command. Continue to
  602. * insert channel TLVs until:
  603. * - the tlvidx hits the maximum configured per scan command
  604. * - the next channel to insert is 0 (end of desired channel list)
  605. * - doneearly is set (controlling individual scanning of 1,6,11)
  606. */
  607. while (tlvidx < maxchanperscan && ptmpchan->channumber
  608. && !doneearly) {
  609. lbs_pr_debug(1,
  610. "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n",
  611. ptmpchan->channumber, ptmpchan->radiotype,
  612. ptmpchan->chanscanmode.passivescan,
  613. ptmpchan->chanscanmode.disablechanfilt,
  614. ptmpchan->maxscantime);
  615. /* Copy the current channel TLV to the command being prepared */
  616. memcpy(pchantlvout->chanscanparam + tlvidx,
  617. ptmpchan, sizeof(pchantlvout->chanscanparam));
  618. /* Increment the TLV header length by the size appended */
  619. pchantlvout->header.len +=
  620. sizeof(pchantlvout->chanscanparam);
  621. /*
  622. * The tlv buffer length is set to the number of bytes of the
  623. * between the channel tlv pointer and the start of the
  624. * tlv buffer. This compensates for any TLVs that were appended
  625. * before the channel list.
  626. */
  627. pscancfgout->tlvbufferlen = ((u8 *) pchantlvout
  628. - pscancfgout->tlvbuffer);
  629. /* Add the size of the channel tlv header and the data length */
  630. pscancfgout->tlvbufferlen +=
  631. (sizeof(pchantlvout->header)
  632. + pchantlvout->header.len);
  633. /* Increment the index to the channel tlv we are constructing */
  634. tlvidx++;
  635. doneearly = 0;
  636. /* Stop the loop if the *current* channel is in the 1,6,11 set
  637. * and we are not filtering on a BSSID or SSID.
  638. */
  639. if (!filteredscan && (ptmpchan->channumber == 1
  640. || ptmpchan->channumber == 6
  641. || ptmpchan->channumber == 11)) {
  642. doneearly = 1;
  643. }
  644. /* Increment the tmp pointer to the next channel to be scanned */
  645. ptmpchan++;
  646. /* Stop the loop if the *next* channel is in the 1,6,11 set.
  647. * This will cause it to be the only channel scanned on the next
  648. * interation
  649. */
  650. if (!filteredscan && (ptmpchan->channumber == 1
  651. || ptmpchan->channumber == 6
  652. || ptmpchan->channumber == 11)) {
  653. doneearly = 1;
  654. }
  655. }
  656. /* Send the scan command to the firmware with the specified cfg */
  657. ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0,
  658. 0, 0, pscancfgout);
  659. }
  660. LEAVE();
  661. return ret;
  662. }
  663. /**
  664. * @brief Internal function used to start a scan based on an input config
  665. *
  666. * Use the input user scan configuration information when provided in
  667. * order to send the appropriate scan commands to firmware to populate or
  668. * update the internal driver scan table
  669. *
  670. * @param priv A pointer to wlan_private structure
  671. * @param puserscanin Pointer to the input configuration for the requested
  672. * scan.
  673. *
  674. * @return 0 or < 0 if error
  675. */
  676. int wlan_scan_networks(wlan_private * priv,
  677. const struct wlan_ioctl_user_scan_cfg * puserscanin)
  678. {
  679. wlan_adapter *adapter = priv->adapter;
  680. struct mrvlietypes_chanlistparamset *pchantlvout;
  681. struct chanscanparamset * scan_chan_list = NULL;
  682. struct wlan_scan_cmd_config * scan_cfg = NULL;
  683. u8 keeppreviousscan;
  684. u8 filteredscan;
  685. u8 scancurrentchanonly;
  686. int maxchanperscan;
  687. int ret;
  688. ENTER();
  689. scan_chan_list = kzalloc(sizeof(struct chanscanparamset) *
  690. WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
  691. if (scan_chan_list == NULL) {
  692. ret = -ENOMEM;
  693. goto out;
  694. }
  695. scan_cfg = wlan_scan_setup_scan_config(priv,
  696. puserscanin,
  697. &pchantlvout,
  698. scan_chan_list,
  699. &maxchanperscan,
  700. &filteredscan,
  701. &scancurrentchanonly);
  702. if (scan_cfg == NULL) {
  703. ret = -ENOMEM;
  704. goto out;
  705. }
  706. keeppreviousscan = 0;
  707. if (puserscanin) {
  708. keeppreviousscan = puserscanin->keeppreviousscan;
  709. }
  710. if (!keeppreviousscan) {
  711. memset(adapter->scantable, 0x00,
  712. sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST);
  713. adapter->numinscantable = 0;
  714. }
  715. /* Keep the data path active if we are only scanning our current channel */
  716. if (!scancurrentchanonly) {
  717. netif_stop_queue(priv->wlan_dev.netdev);
  718. netif_carrier_off(priv->wlan_dev.netdev);
  719. }
  720. ret = wlan_scan_channel_list(priv,
  721. maxchanperscan,
  722. filteredscan,
  723. scan_cfg,
  724. pchantlvout,
  725. scan_chan_list);
  726. /* Process the resulting scan table:
  727. * - Remove any bad ssids
  728. * - Update our current BSS information from scan data
  729. */
  730. wlan_scan_process_results(priv);
  731. if (priv->adapter->connect_status == libertas_connected) {
  732. netif_carrier_on(priv->wlan_dev.netdev);
  733. netif_wake_queue(priv->wlan_dev.netdev);
  734. }
  735. out:
  736. if (scan_cfg)
  737. kfree(scan_cfg);
  738. if (scan_chan_list)
  739. kfree(scan_chan_list);
  740. LEAVE();
  741. return ret;
  742. }
  743. /**
  744. * @brief Inspect the scan response buffer for pointers to expected TLVs
  745. *
  746. * TLVs can be included at the end of the scan response BSS information.
  747. * Parse the data in the buffer for pointers to TLVs that can potentially
  748. * be passed back in the response
  749. *
  750. * @param ptlv Pointer to the start of the TLV buffer to parse
  751. * @param tlvbufsize size of the TLV buffer
  752. * @param ptsftlv Output parameter: Pointer to the TSF TLV if found
  753. *
  754. * @return void
  755. */
  756. static
  757. void wlan_ret_802_11_scan_get_tlv_ptrs(struct mrvlietypes_data * ptlv,
  758. int tlvbufsize,
  759. struct mrvlietypes_tsftimestamp ** ptsftlv)
  760. {
  761. struct mrvlietypes_data *pcurrenttlv;
  762. int tlvbufleft;
  763. u16 tlvtype;
  764. u16 tlvlen;
  765. pcurrenttlv = ptlv;
  766. tlvbufleft = tlvbufsize;
  767. *ptsftlv = NULL;
  768. lbs_pr_debug(1, "SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
  769. lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize);
  770. while (tlvbufleft >= sizeof(struct mrvlietypesheader)) {
  771. tlvtype = le16_to_cpu(pcurrenttlv->header.type);
  772. tlvlen = le16_to_cpu(pcurrenttlv->header.len);
  773. switch (tlvtype) {
  774. case TLV_TYPE_TSFTIMESTAMP:
  775. *ptsftlv = (struct mrvlietypes_tsftimestamp *) pcurrenttlv;
  776. break;
  777. default:
  778. lbs_pr_debug(1, "SCAN_RESP: Unhandled TLV = %d\n",
  779. tlvtype);
  780. /* Give up, this seems corrupted */
  781. return;
  782. } /* switch */
  783. tlvbufleft -= (sizeof(ptlv->header) + tlvlen);
  784. pcurrenttlv =
  785. (struct mrvlietypes_data *) (pcurrenttlv->Data + tlvlen);
  786. } /* while */
  787. }
  788. /**
  789. * @brief Interpret a BSS scan response returned from the firmware
  790. *
  791. * Parse the various fixed fields and IEs passed back for a a BSS probe
  792. * response or beacon from the scan command. Record information as needed
  793. * in the scan table struct bss_descriptor for that entry.
  794. *
  795. * @param pBSSIDEntry Output parameter: Pointer to the BSS Entry
  796. *
  797. * @return 0 or -1
  798. */
  799. static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
  800. u8 ** pbeaconinfo, int *bytesleft)
  801. {
  802. enum ieeetypes_elementid elemID;
  803. struct ieeetypes_fhparamset *pFH;
  804. struct ieeetypes_dsparamset *pDS;
  805. struct ieeetypes_cfparamset *pCF;
  806. struct ieeetypes_ibssparamset *pibss;
  807. struct ieeetypes_capinfo *pcap;
  808. struct WLAN_802_11_FIXED_IEs fixedie;
  809. u8 *pcurrentptr;
  810. u8 *pRate;
  811. u8 elemlen;
  812. u8 bytestocopy;
  813. u8 ratesize;
  814. u16 beaconsize;
  815. u8 founddatarateie;
  816. int bytesleftforcurrentbeacon;
  817. struct WPA_SUPPLICANT *pwpa_supplicant;
  818. struct WPA_SUPPLICANT *pwpa2_supplicant;
  819. struct IE_WPA *pIe;
  820. const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
  821. struct ieeetypes_countryinfoset *pcountryinfo;
  822. ENTER();
  823. founddatarateie = 0;
  824. ratesize = 0;
  825. beaconsize = 0;
  826. if (*bytesleft >= sizeof(beaconsize)) {
  827. /* Extract & convert beacon size from the command buffer */
  828. memcpy(&beaconsize, *pbeaconinfo, sizeof(beaconsize));
  829. beaconsize = le16_to_cpu(beaconsize);
  830. *bytesleft -= sizeof(beaconsize);
  831. *pbeaconinfo += sizeof(beaconsize);
  832. }
  833. if (beaconsize == 0 || beaconsize > *bytesleft) {
  834. *pbeaconinfo += *bytesleft;
  835. *bytesleft = 0;
  836. return -1;
  837. }
  838. /* Initialize the current working beacon pointer for this BSS iteration */
  839. pcurrentptr = *pbeaconinfo;
  840. /* Advance the return beacon pointer past the current beacon */
  841. *pbeaconinfo += beaconsize;
  842. *bytesleft -= beaconsize;
  843. bytesleftforcurrentbeacon = beaconsize;
  844. pwpa_supplicant = &pBSSEntry->wpa_supplicant;
  845. pwpa2_supplicant = &pBSSEntry->wpa2_supplicant;
  846. memcpy(pBSSEntry->macaddress, pcurrentptr, ETH_ALEN);
  847. lbs_pr_debug(1, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
  848. pBSSEntry->macaddress[0], pBSSEntry->macaddress[1],
  849. pBSSEntry->macaddress[2], pBSSEntry->macaddress[3],
  850. pBSSEntry->macaddress[4], pBSSEntry->macaddress[5]);
  851. pcurrentptr += ETH_ALEN;
  852. bytesleftforcurrentbeacon -= ETH_ALEN;
  853. if (bytesleftforcurrentbeacon < 12) {
  854. lbs_pr_debug(1, "InterpretIE: Not enough bytes left\n");
  855. return -1;
  856. }
  857. /*
  858. * next 4 fields are RSSI, time stamp, beacon interval,
  859. * and capability information
  860. */
  861. /* RSSI is 1 byte long */
  862. pBSSEntry->rssi = le32_to_cpu((long)(*pcurrentptr));
  863. lbs_pr_debug(1, "InterpretIE: RSSI=%02X\n", *pcurrentptr);
  864. pcurrentptr += 1;
  865. bytesleftforcurrentbeacon -= 1;
  866. /* time stamp is 8 bytes long */
  867. memcpy(fixedie.timestamp, pcurrentptr, 8);
  868. memcpy(pBSSEntry->timestamp, pcurrentptr, 8);
  869. pcurrentptr += 8;
  870. bytesleftforcurrentbeacon -= 8;
  871. /* beacon interval is 2 bytes long */
  872. memcpy(&fixedie.beaconinterval, pcurrentptr, 2);
  873. pBSSEntry->beaconperiod = le16_to_cpu(fixedie.beaconinterval);
  874. pcurrentptr += 2;
  875. bytesleftforcurrentbeacon -= 2;
  876. /* capability information is 2 bytes long */
  877. memcpy(&fixedie.capabilities, pcurrentptr, 2);
  878. lbs_pr_debug(1, "InterpretIE: fixedie.capabilities=0x%X\n",
  879. fixedie.capabilities);
  880. fixedie.capabilities = le16_to_cpu(fixedie.capabilities);
  881. pcap = (struct ieeetypes_capinfo *) & fixedie.capabilities;
  882. memcpy(&pBSSEntry->cap, pcap, sizeof(struct ieeetypes_capinfo));
  883. pcurrentptr += 2;
  884. bytesleftforcurrentbeacon -= 2;
  885. /* rest of the current buffer are IE's */
  886. lbs_pr_debug(1, "InterpretIE: IElength for this AP = %d\n",
  887. bytesleftforcurrentbeacon);
  888. lbs_dbg_hex("InterpretIE: IE info", (u8 *) pcurrentptr,
  889. bytesleftforcurrentbeacon);
  890. if (pcap->privacy) {
  891. lbs_pr_debug(1, "InterpretIE: AP WEP enabled\n");
  892. pBSSEntry->privacy = wlan802_11privfilter8021xWEP;
  893. } else {
  894. pBSSEntry->privacy = wlan802_11privfilteracceptall;
  895. }
  896. if (pcap->ibss == 1) {
  897. pBSSEntry->inframode = wlan802_11ibss;
  898. } else {
  899. pBSSEntry->inframode = wlan802_11infrastructure;
  900. }
  901. /* process variable IE */
  902. while (bytesleftforcurrentbeacon >= 2) {
  903. elemID = (enum ieeetypes_elementid) (*((u8 *) pcurrentptr));
  904. elemlen = *((u8 *) pcurrentptr + 1);
  905. if (bytesleftforcurrentbeacon < elemlen) {
  906. lbs_pr_debug(1, "InterpretIE: error in processing IE, "
  907. "bytes left < IE length\n");
  908. bytesleftforcurrentbeacon = 0;
  909. continue;
  910. }
  911. switch (elemID) {
  912. case SSID:
  913. pBSSEntry->ssid.ssidlength = elemlen;
  914. memcpy(pBSSEntry->ssid.ssid, (pcurrentptr + 2),
  915. elemlen);
  916. lbs_pr_debug(1, "ssid: %32s", pBSSEntry->ssid.ssid);
  917. break;
  918. case SUPPORTED_RATES:
  919. memcpy(pBSSEntry->datarates, (pcurrentptr + 2),
  920. elemlen);
  921. memmove(pBSSEntry->libertas_supported_rates, (pcurrentptr + 2),
  922. elemlen);
  923. ratesize = elemlen;
  924. founddatarateie = 1;
  925. break;
  926. case EXTRA_IE:
  927. lbs_pr_debug(1, "InterpretIE: EXTRA_IE Found!\n");
  928. pBSSEntry->extra_ie = 1;
  929. break;
  930. case FH_PARAM_SET:
  931. pFH = (struct ieeetypes_fhparamset *) pcurrentptr;
  932. memmove(&pBSSEntry->phyparamset.fhparamset, pFH,
  933. sizeof(struct ieeetypes_fhparamset));
  934. pBSSEntry->phyparamset.fhparamset.dwelltime
  935. =
  936. le16_to_cpu(pBSSEntry->phyparamset.fhparamset.
  937. dwelltime);
  938. break;
  939. case DS_PARAM_SET:
  940. pDS = (struct ieeetypes_dsparamset *) pcurrentptr;
  941. pBSSEntry->channel = pDS->currentchan;
  942. memcpy(&pBSSEntry->phyparamset.dsparamset, pDS,
  943. sizeof(struct ieeetypes_dsparamset));
  944. break;
  945. case CF_PARAM_SET:
  946. pCF = (struct ieeetypes_cfparamset *) pcurrentptr;
  947. memcpy(&pBSSEntry->ssparamset.cfparamset, pCF,
  948. sizeof(struct ieeetypes_cfparamset));
  949. break;
  950. case IBSS_PARAM_SET:
  951. pibss = (struct ieeetypes_ibssparamset *) pcurrentptr;
  952. pBSSEntry->atimwindow =
  953. le32_to_cpu(pibss->atimwindow);
  954. memmove(&pBSSEntry->ssparamset.ibssparamset, pibss,
  955. sizeof(struct ieeetypes_ibssparamset));
  956. pBSSEntry->ssparamset.ibssparamset.atimwindow
  957. =
  958. le16_to_cpu(pBSSEntry->ssparamset.ibssparamset.
  959. atimwindow);
  960. break;
  961. /* Handle Country Info IE */
  962. case COUNTRY_INFO:
  963. pcountryinfo =
  964. (struct ieeetypes_countryinfoset *) pcurrentptr;
  965. if (pcountryinfo->len <
  966. sizeof(pcountryinfo->countrycode)
  967. || pcountryinfo->len > 254) {
  968. lbs_pr_debug(1, "InterpretIE: 11D- Err "
  969. "CountryInfo len =%d min=%d max=254\n",
  970. pcountryinfo->len,
  971. sizeof(pcountryinfo->countrycode));
  972. LEAVE();
  973. return -1;
  974. }
  975. memcpy(&pBSSEntry->countryinfo,
  976. pcountryinfo, pcountryinfo->len + 2);
  977. lbs_dbg_hex("InterpretIE: 11D- CountryInfo:",
  978. (u8 *) pcountryinfo,
  979. (u32) (pcountryinfo->len + 2));
  980. break;
  981. case EXTENDED_SUPPORTED_RATES:
  982. /*
  983. * only process extended supported rate
  984. * if data rate is already found.
  985. * data rate IE should come before
  986. * extended supported rate IE
  987. */
  988. if (founddatarateie) {
  989. if ((elemlen + ratesize) > WLAN_SUPPORTED_RATES) {
  990. bytestocopy =
  991. (WLAN_SUPPORTED_RATES - ratesize);
  992. } else {
  993. bytestocopy = elemlen;
  994. }
  995. pRate = (u8 *) pBSSEntry->datarates;
  996. pRate += ratesize;
  997. memmove(pRate, (pcurrentptr + 2), bytestocopy);
  998. pRate = (u8 *) pBSSEntry->libertas_supported_rates;
  999. pRate += ratesize;
  1000. memmove(pRate, (pcurrentptr + 2), bytestocopy);
  1001. }
  1002. break;
  1003. case VENDOR_SPECIFIC_221:
  1004. #define IE_ID_LEN_FIELDS_BYTES 2
  1005. pIe = (struct IE_WPA *)pcurrentptr;
  1006. if (!memcmp(pIe->oui, oui01, sizeof(oui01))) {
  1007. pwpa_supplicant->wpa_ie_len
  1008. = min_t(size_t, elemlen + IE_ID_LEN_FIELDS_BYTES,
  1009. sizeof(pwpa_supplicant->wpa_ie));
  1010. memcpy(pwpa_supplicant->wpa_ie,
  1011. pcurrentptr,
  1012. pwpa_supplicant->wpa_ie_len);
  1013. lbs_dbg_hex("InterpretIE: Resp WPA_IE",
  1014. pwpa_supplicant->wpa_ie, elemlen);
  1015. }
  1016. break;
  1017. case WPA2_IE:
  1018. pIe = (struct IE_WPA *)pcurrentptr;
  1019. pwpa2_supplicant->wpa_ie_len
  1020. = min_t(size_t, elemlen + IE_ID_LEN_FIELDS_BYTES,
  1021. sizeof(pwpa2_supplicant->wpa_ie));
  1022. memcpy(pwpa2_supplicant->wpa_ie,
  1023. pcurrentptr, pwpa2_supplicant->wpa_ie_len);
  1024. lbs_dbg_hex("InterpretIE: Resp WPA2_IE",
  1025. pwpa2_supplicant->wpa_ie, elemlen);
  1026. break;
  1027. case TIM:
  1028. break;
  1029. case CHALLENGE_TEXT:
  1030. break;
  1031. }
  1032. pcurrentptr += elemlen + 2;
  1033. /* need to account for IE ID and IE len */
  1034. bytesleftforcurrentbeacon -= (elemlen + 2);
  1035. } /* while (bytesleftforcurrentbeacon > 2) */
  1036. return 0;
  1037. }
  1038. /**
  1039. * @brief Compare two SSIDs
  1040. *
  1041. * @param ssid1 A pointer to ssid to compare
  1042. * @param ssid2 A pointer to ssid to compare
  1043. *
  1044. * @return 0--ssid is same, otherwise is different
  1045. */
  1046. int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *ssid2)
  1047. {
  1048. if (!ssid1 || !ssid2)
  1049. return -1;
  1050. if (ssid1->ssidlength != ssid2->ssidlength)
  1051. return -1;
  1052. return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssidlength);
  1053. }
  1054. /**
  1055. * @brief This function finds a specific compatible BSSID in the scan list
  1056. *
  1057. * @param adapter A pointer to wlan_adapter
  1058. * @param bssid BSSID to find in the scan list
  1059. * @param mode Network mode: Infrastructure or IBSS
  1060. *
  1061. * @return index in BSSID list, or error return code (< 0)
  1062. */
  1063. int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, int mode)
  1064. {
  1065. int ret = -ENETUNREACH;
  1066. int i;
  1067. if (!bssid)
  1068. return -EFAULT;
  1069. lbs_pr_debug(1, "FindBSSID: Num of BSSIDs = %d\n",
  1070. adapter->numinscantable);
  1071. /* Look through the scan table for a compatible match. The ret return
  1072. * variable will be equal to the index in the scan table (greater
  1073. * than zero) if the network is compatible. The loop will continue
  1074. * past a matched bssid that is not compatible in case there is an
  1075. * AP with multiple SSIDs assigned to the same BSSID
  1076. */
  1077. for (i = 0; ret < 0 && i < adapter->numinscantable; i++) {
  1078. if (!memcmp(adapter->scantable[i].macaddress, bssid, ETH_ALEN)) {
  1079. switch (mode) {
  1080. case wlan802_11infrastructure:
  1081. case wlan802_11ibss:
  1082. ret = is_network_compatible(adapter, i, mode);
  1083. break;
  1084. default:
  1085. ret = i;
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. return ret;
  1091. }
  1092. /**
  1093. * @brief This function finds ssid in ssid list.
  1094. *
  1095. * @param adapter A pointer to wlan_adapter
  1096. * @param ssid SSID to find in the list
  1097. * @param bssid BSSID to qualify the SSID selection (if provided)
  1098. * @param mode Network mode: Infrastructure or IBSS
  1099. *
  1100. * @return index in BSSID list
  1101. */
  1102. int libertas_find_SSID_in_list(wlan_adapter * adapter,
  1103. struct WLAN_802_11_SSID *ssid, u8 * bssid, int mode)
  1104. {
  1105. int net = -ENETUNREACH;
  1106. u8 bestrssi = 0;
  1107. int i;
  1108. int j;
  1109. lbs_pr_debug(1, "Num of Entries in Table = %d\n", adapter->numinscantable);
  1110. for (i = 0; i < adapter->numinscantable; i++) {
  1111. if (!libertas_SSID_cmp(&adapter->scantable[i].ssid, ssid) &&
  1112. (!bssid ||
  1113. !memcmp(adapter->scantable[i].
  1114. macaddress, bssid, ETH_ALEN))) {
  1115. switch (mode) {
  1116. case wlan802_11infrastructure:
  1117. case wlan802_11ibss:
  1118. j = is_network_compatible(adapter, i, mode);
  1119. if (j >= 0) {
  1120. if (bssid) {
  1121. return i;
  1122. }
  1123. if (SCAN_RSSI
  1124. (adapter->scantable[i].rssi)
  1125. > bestrssi) {
  1126. bestrssi =
  1127. SCAN_RSSI(adapter->
  1128. scantable[i].
  1129. rssi);
  1130. net = i;
  1131. }
  1132. } else {
  1133. if (net == -ENETUNREACH) {
  1134. net = j;
  1135. }
  1136. }
  1137. break;
  1138. case wlan802_11autounknown:
  1139. default:
  1140. if (SCAN_RSSI(adapter->scantable[i].rssi)
  1141. > bestrssi) {
  1142. bestrssi =
  1143. SCAN_RSSI(adapter->scantable[i].
  1144. rssi);
  1145. net = i;
  1146. }
  1147. break;
  1148. }
  1149. }
  1150. }
  1151. return net;
  1152. }
  1153. /**
  1154. * @brief This function finds the best SSID in the Scan List
  1155. *
  1156. * Search the scan table for the best SSID that also matches the current
  1157. * adapter network preference (infrastructure or adhoc)
  1158. *
  1159. * @param adapter A pointer to wlan_adapter
  1160. *
  1161. * @return index in BSSID list
  1162. */
  1163. int libertas_find_best_SSID_in_list(wlan_adapter * adapter,
  1164. enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode)
  1165. {
  1166. int bestnet = -ENETUNREACH;
  1167. u8 bestrssi = 0;
  1168. int i;
  1169. ENTER();
  1170. lbs_pr_debug(1, "Num of BSSIDs = %d\n", adapter->numinscantable);
  1171. for (i = 0; i < adapter->numinscantable; i++) {
  1172. switch (mode) {
  1173. case wlan802_11infrastructure:
  1174. case wlan802_11ibss:
  1175. if (is_network_compatible(adapter, i, mode) >= 0) {
  1176. if (SCAN_RSSI(adapter->scantable[i].rssi) >
  1177. bestrssi) {
  1178. bestrssi =
  1179. SCAN_RSSI(adapter->scantable[i].
  1180. rssi);
  1181. bestnet = i;
  1182. }
  1183. }
  1184. break;
  1185. case wlan802_11autounknown:
  1186. default:
  1187. if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) {
  1188. bestrssi =
  1189. SCAN_RSSI(adapter->scantable[i].rssi);
  1190. bestnet = i;
  1191. }
  1192. break;
  1193. }
  1194. }
  1195. LEAVE();
  1196. return bestnet;
  1197. }
  1198. /**
  1199. * @brief Find the AP with specific ssid in the scan list
  1200. *
  1201. * @param priv A pointer to wlan_private structure
  1202. * @param pSSID A pointer to AP's ssid
  1203. *
  1204. * @return 0--success, otherwise--fail
  1205. */
  1206. int libertas_find_best_network_SSID(wlan_private * priv,
  1207. struct WLAN_802_11_SSID *pSSID,
  1208. enum WLAN_802_11_NETWORK_INFRASTRUCTURE preferred_mode,
  1209. enum WLAN_802_11_NETWORK_INFRASTRUCTURE *out_mode)
  1210. {
  1211. wlan_adapter *adapter = priv->adapter;
  1212. int ret = 0;
  1213. struct bss_descriptor *preqbssid;
  1214. int i;
  1215. ENTER();
  1216. memset(pSSID, 0, sizeof(struct WLAN_802_11_SSID));
  1217. wlan_scan_networks(priv, NULL);
  1218. if (adapter->surpriseremoved)
  1219. return -1;
  1220. wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
  1221. i = libertas_find_best_SSID_in_list(adapter, preferred_mode);
  1222. if (i < 0) {
  1223. ret = -1;
  1224. goto out;
  1225. }
  1226. preqbssid = &adapter->scantable[i];
  1227. memcpy(pSSID, &preqbssid->ssid,
  1228. sizeof(struct WLAN_802_11_SSID));
  1229. *out_mode = preqbssid->inframode;
  1230. if (!pSSID->ssidlength) {
  1231. ret = -1;
  1232. }
  1233. out:
  1234. LEAVE();
  1235. return ret;
  1236. }
  1237. /**
  1238. * @brief Scan Network
  1239. *
  1240. * @param dev A pointer to net_device structure
  1241. * @param info A pointer to iw_request_info structure
  1242. * @param vwrq A pointer to iw_param structure
  1243. * @param extra A pointer to extra data buf
  1244. *
  1245. * @return 0 --success, otherwise fail
  1246. */
  1247. int libertas_set_scan(struct net_device *dev, struct iw_request_info *info,
  1248. struct iw_param *vwrq, char *extra)
  1249. {
  1250. wlan_private *priv = dev->priv;
  1251. wlan_adapter *adapter = priv->adapter;
  1252. union iwreq_data wrqu;
  1253. ENTER();
  1254. if (!wlan_scan_networks(priv, NULL)) {
  1255. memset(&wrqu, 0, sizeof(union iwreq_data));
  1256. wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu,
  1257. NULL);
  1258. }
  1259. if (adapter->surpriseremoved)
  1260. return -1;
  1261. LEAVE();
  1262. return 0;
  1263. }
  1264. /**
  1265. * @brief Send a scan command for all available channels filtered on a spec
  1266. *
  1267. * @param priv A pointer to wlan_private structure
  1268. * @param prequestedssid A pointer to AP's ssid
  1269. * @param keeppreviousscan Flag used to save/clear scan table before scan
  1270. *
  1271. * @return 0-success, otherwise fail
  1272. */
  1273. int libertas_send_specific_SSID_scan(wlan_private * priv,
  1274. struct WLAN_802_11_SSID *prequestedssid,
  1275. u8 keeppreviousscan)
  1276. {
  1277. wlan_adapter *adapter = priv->adapter;
  1278. struct wlan_ioctl_user_scan_cfg scancfg;
  1279. ENTER();
  1280. if (prequestedssid == NULL) {
  1281. return -1;
  1282. }
  1283. memset(&scancfg, 0x00, sizeof(scancfg));
  1284. memcpy(scancfg.specificSSID, prequestedssid->ssid,
  1285. prequestedssid->ssidlength);
  1286. scancfg.keeppreviousscan = keeppreviousscan;
  1287. wlan_scan_networks(priv, &scancfg);
  1288. if (adapter->surpriseremoved)
  1289. return -1;
  1290. wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
  1291. LEAVE();
  1292. return 0;
  1293. }
  1294. /**
  1295. * @brief scan an AP with specific BSSID
  1296. *
  1297. * @param priv A pointer to wlan_private structure
  1298. * @param bssid A pointer to AP's bssid
  1299. * @param keeppreviousscan Flag used to save/clear scan table before scan
  1300. *
  1301. * @return 0-success, otherwise fail
  1302. */
  1303. int libertas_send_specific_BSSID_scan(wlan_private * priv, u8 * bssid, u8 keeppreviousscan)
  1304. {
  1305. struct wlan_ioctl_user_scan_cfg scancfg;
  1306. ENTER();
  1307. if (bssid == NULL) {
  1308. return -1;
  1309. }
  1310. memset(&scancfg, 0x00, sizeof(scancfg));
  1311. memcpy(scancfg.specificBSSID, bssid, sizeof(scancfg.specificBSSID));
  1312. scancfg.keeppreviousscan = keeppreviousscan;
  1313. wlan_scan_networks(priv, &scancfg);
  1314. if (priv->adapter->surpriseremoved)
  1315. return -1;
  1316. wait_event_interruptible(priv->adapter->cmd_pending,
  1317. !priv->adapter->nr_cmd_pending);
  1318. LEAVE();
  1319. return 0;
  1320. }
  1321. /**
  1322. * @brief Retrieve the scan table entries via wireless tools IOCTL call
  1323. *
  1324. * @param dev A pointer to net_device structure
  1325. * @param info A pointer to iw_request_info structure
  1326. * @param dwrq A pointer to iw_point structure
  1327. * @param extra A pointer to extra data buf
  1328. *
  1329. * @return 0 --success, otherwise fail
  1330. */
  1331. int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
  1332. struct iw_point *dwrq, char *extra)
  1333. {
  1334. wlan_private *priv = dev->priv;
  1335. wlan_adapter *adapter = priv->adapter;
  1336. int ret = 0;
  1337. char *current_ev = extra;
  1338. char *end_buf = extra + IW_SCAN_MAX_DATA;
  1339. struct chan_freq_power *cfp;
  1340. struct bss_descriptor *pscantable;
  1341. char *current_val; /* For rates */
  1342. struct iw_event iwe; /* Temporary buffer */
  1343. int i;
  1344. int j;
  1345. int rate;
  1346. #define PERFECT_RSSI ((u8)50)
  1347. #define WORST_RSSI ((u8)0)
  1348. #define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
  1349. u8 rssi;
  1350. u8 buf[16 + 256 * 2];
  1351. u8 *ptr;
  1352. ENTER();
  1353. /*
  1354. * if there's either commands in the queue or one being
  1355. * processed return -EAGAIN for iwlist to retry later.
  1356. */
  1357. if (adapter->nr_cmd_pending)
  1358. return -EAGAIN;
  1359. if (adapter->connect_status == libertas_connected)
  1360. lbs_pr_debug(1, "Current ssid: %32s\n",
  1361. adapter->curbssparams.ssid.ssid);
  1362. lbs_pr_debug(1, "Scan: Get: numinscantable = %d\n",
  1363. adapter->numinscantable);
  1364. /* The old API using SIOCGIWAPLIST had a hard limit of IW_MAX_AP.
  1365. * The new API using SIOCGIWSCAN is only limited by buffer size
  1366. * WE-14 -> WE-16 the buffer is limited to IW_SCAN_MAX_DATA bytes
  1367. * which is 4096.
  1368. */
  1369. for (i = 0; i < adapter->numinscantable; i++) {
  1370. if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) {
  1371. lbs_pr_debug(1, "i=%d break out: current_ev=%p end_buf=%p "
  1372. "MAX_SCAN_CELL_SIZE=%d\n",
  1373. i, current_ev, end_buf, MAX_SCAN_CELL_SIZE);
  1374. break;
  1375. }
  1376. pscantable = &adapter->scantable[i];
  1377. lbs_pr_debug(1, "i=%d ssid: %32s\n", i, pscantable->ssid.ssid);
  1378. cfp =
  1379. libertas_find_cfp_by_band_and_channel(adapter, 0,
  1380. pscantable->channel);
  1381. if (!cfp) {
  1382. lbs_pr_debug(1, "Invalid channel number %d\n",
  1383. pscantable->channel);
  1384. continue;
  1385. }
  1386. if (!ssid_valid(&adapter->scantable[i].ssid)) {
  1387. continue;
  1388. }
  1389. /* First entry *MUST* be the AP MAC address */
  1390. iwe.cmd = SIOCGIWAP;
  1391. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1392. memcpy(iwe.u.ap_addr.sa_data,
  1393. &adapter->scantable[i].macaddress, ETH_ALEN);
  1394. iwe.len = IW_EV_ADDR_LEN;
  1395. current_ev =
  1396. iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
  1397. //Add the ESSID
  1398. iwe.u.data.length = adapter->scantable[i].ssid.ssidlength;
  1399. if (iwe.u.data.length > 32) {
  1400. iwe.u.data.length = 32;
  1401. }
  1402. iwe.cmd = SIOCGIWESSID;
  1403. iwe.u.data.flags = 1;
  1404. iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
  1405. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
  1406. adapter->scantable[i].ssid.
  1407. ssid);
  1408. //Add mode
  1409. iwe.cmd = SIOCGIWMODE;
  1410. iwe.u.mode = adapter->scantable[i].inframode + 1;
  1411. iwe.len = IW_EV_UINT_LEN;
  1412. current_ev =
  1413. iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
  1414. //frequency
  1415. iwe.cmd = SIOCGIWFREQ;
  1416. iwe.u.freq.m = (long)cfp->freq * 100000;
  1417. iwe.u.freq.e = 1;
  1418. iwe.len = IW_EV_FREQ_LEN;
  1419. current_ev =
  1420. iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
  1421. /* Add quality statistics */
  1422. iwe.cmd = IWEVQUAL;
  1423. iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
  1424. iwe.u.qual.level = SCAN_RSSI(adapter->scantable[i].rssi);
  1425. rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
  1426. iwe.u.qual.qual =
  1427. (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
  1428. (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
  1429. (RSSI_DIFF * RSSI_DIFF);
  1430. if (iwe.u.qual.qual > 100)
  1431. iwe.u.qual.qual = 100;
  1432. else if (iwe.u.qual.qual < 1)
  1433. iwe.u.qual.qual = 0;
  1434. if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  1435. iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  1436. } else {
  1437. iwe.u.qual.noise =
  1438. CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  1439. }
  1440. if ((adapter->inframode == wlan802_11ibss) &&
  1441. !libertas_SSID_cmp(&adapter->curbssparams.ssid,
  1442. &adapter->scantable[i].ssid)
  1443. && adapter->adhoccreate) {
  1444. ret = libertas_prepare_and_send_command(priv,
  1445. cmd_802_11_rssi,
  1446. 0,
  1447. cmd_option_waitforrsp,
  1448. 0, NULL);
  1449. if (!ret) {
  1450. iwe.u.qual.level =
  1451. CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] /
  1452. AVG_SCALE,
  1453. adapter->NF[TYPE_RXPD][TYPE_AVG] /
  1454. AVG_SCALE);
  1455. }
  1456. }
  1457. iwe.len = IW_EV_QUAL_LEN;
  1458. current_ev =
  1459. iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
  1460. /* Add encryption capability */
  1461. iwe.cmd = SIOCGIWENCODE;
  1462. if (adapter->scantable[i].privacy) {
  1463. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1464. } else {
  1465. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1466. }
  1467. iwe.u.data.length = 0;
  1468. iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
  1469. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
  1470. adapter->scantable->ssid.
  1471. ssid);
  1472. current_val = current_ev + IW_EV_LCP_LEN;
  1473. iwe.cmd = SIOCGIWRATE;
  1474. iwe.u.bitrate.fixed = 0;
  1475. iwe.u.bitrate.disabled = 0;
  1476. iwe.u.bitrate.value = 0;
  1477. /* Bit rate given in 500 kb/s units (+ 0x80) */
  1478. for (j = 0; j < sizeof(adapter->scantable[i].libertas_supported_rates);
  1479. j++) {
  1480. if (adapter->scantable[i].libertas_supported_rates[j] == 0) {
  1481. break;
  1482. }
  1483. rate =
  1484. (adapter->scantable[i].libertas_supported_rates[j] & 0x7F) *
  1485. 500000;
  1486. if (rate > iwe.u.bitrate.value) {
  1487. iwe.u.bitrate.value = rate;
  1488. }
  1489. iwe.u.bitrate.value =
  1490. (adapter->scantable[i].libertas_supported_rates[j]
  1491. & 0x7f) * 500000;
  1492. iwe.len = IW_EV_PARAM_LEN;
  1493. current_ev =
  1494. iwe_stream_add_value(current_ev, current_val,
  1495. end_buf, &iwe, iwe.len);
  1496. }
  1497. if ((adapter->scantable[i].inframode == wlan802_11ibss)
  1498. && !libertas_SSID_cmp(&adapter->curbssparams.ssid,
  1499. &adapter->scantable[i].ssid)
  1500. && adapter->adhoccreate) {
  1501. iwe.u.bitrate.value = 22 * 500000;
  1502. }
  1503. iwe.len = IW_EV_PARAM_LEN;
  1504. current_ev =
  1505. iwe_stream_add_value(current_ev, current_val, end_buf, &iwe,
  1506. iwe.len);
  1507. /* Add new value to event */
  1508. current_val = current_ev + IW_EV_LCP_LEN;
  1509. if (adapter->scantable[i].wpa2_supplicant.wpa_ie[0] == WPA2_IE) {
  1510. memset(&iwe, 0, sizeof(iwe));
  1511. memset(buf, 0, sizeof(buf));
  1512. memcpy(buf, adapter->scantable[i].
  1513. wpa2_supplicant.wpa_ie,
  1514. adapter->scantable[i].wpa2_supplicant.
  1515. wpa_ie_len);
  1516. iwe.cmd = IWEVGENIE;
  1517. iwe.u.data.length = adapter->scantable[i].
  1518. wpa2_supplicant.wpa_ie_len;
  1519. iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
  1520. current_ev = iwe_stream_add_point(current_ev, end_buf,
  1521. &iwe, buf);
  1522. }
  1523. if (adapter->scantable[i].wpa_supplicant.wpa_ie[0] == WPA_IE) {
  1524. memset(&iwe, 0, sizeof(iwe));
  1525. memset(buf, 0, sizeof(buf));
  1526. memcpy(buf, adapter->scantable[i].
  1527. wpa_supplicant.wpa_ie,
  1528. adapter->scantable[i].wpa_supplicant.
  1529. wpa_ie_len);
  1530. iwe.cmd = IWEVGENIE;
  1531. iwe.u.data.length = adapter->scantable[i].
  1532. wpa_supplicant.wpa_ie_len;
  1533. iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
  1534. current_ev = iwe_stream_add_point(current_ev, end_buf,
  1535. &iwe, buf);
  1536. }
  1537. if (adapter->scantable[i].extra_ie != 0) {
  1538. memset(&iwe, 0, sizeof(iwe));
  1539. memset(buf, 0, sizeof(buf));
  1540. ptr = buf;
  1541. ptr += sprintf(ptr, "extra_ie");
  1542. iwe.u.data.length = strlen(buf);
  1543. lbs_pr_debug(1, "iwe.u.data.length %d\n",
  1544. iwe.u.data.length);
  1545. lbs_pr_debug(1, "BUF: %s \n", buf);
  1546. iwe.cmd = IWEVCUSTOM;
  1547. iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
  1548. current_ev =
  1549. iwe_stream_add_point(current_ev, end_buf, &iwe,
  1550. buf);
  1551. }
  1552. current_val = current_ev + IW_EV_LCP_LEN;
  1553. /*
  1554. * Check if we added any event
  1555. */
  1556. if ((current_val - current_ev) > IW_EV_LCP_LEN)
  1557. current_ev = current_val;
  1558. }
  1559. dwrq->length = (current_ev - extra);
  1560. dwrq->flags = 0;
  1561. LEAVE();
  1562. return 0;
  1563. }
  1564. /**
  1565. * @brief Prepare a scan command to be sent to the firmware
  1566. *
  1567. * Use the wlan_scan_cmd_config sent to the command processing module in
  1568. * the libertas_prepare_and_send_command to configure a cmd_ds_802_11_scan command
  1569. * struct to send to firmware.
  1570. *
  1571. * The fixed fields specifying the BSS type and BSSID filters as well as a
  1572. * variable number/length of TLVs are sent in the command to firmware.
  1573. *
  1574. * @param priv A pointer to wlan_private structure
  1575. * @param cmd A pointer to cmd_ds_command structure to be sent to
  1576. * firmware with the cmd_DS_801_11_SCAN structure
  1577. * @param pdata_buf Void pointer cast of a wlan_scan_cmd_config struct used
  1578. * to set the fields/TLVs for the command sent to firmware
  1579. *
  1580. * @return 0 or -1
  1581. *
  1582. * @sa wlan_scan_create_channel_list
  1583. */
  1584. int libertas_cmd_80211_scan(wlan_private * priv,
  1585. struct cmd_ds_command *cmd, void *pdata_buf)
  1586. {
  1587. struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
  1588. struct wlan_scan_cmd_config *pscancfg;
  1589. ENTER();
  1590. pscancfg = pdata_buf;
  1591. /* Set fixed field variables in scan command */
  1592. pscan->bsstype = pscancfg->bsstype;
  1593. memcpy(pscan->BSSID, pscancfg->specificBSSID, sizeof(pscan->BSSID));
  1594. memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
  1595. cmd->command = cpu_to_le16(cmd_802_11_scan);
  1596. /* size is equal to the sizeof(fixed portions) + the TLV len + header */
  1597. cmd->size = cpu_to_le16(sizeof(pscan->bsstype)
  1598. + sizeof(pscan->BSSID)
  1599. + pscancfg->tlvbufferlen + S_DS_GEN);
  1600. lbs_pr_debug(1, "SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
  1601. cmd->command, cmd->size, cmd->seqnum);
  1602. LEAVE();
  1603. return 0;
  1604. }
  1605. /**
  1606. * @brief This function handles the command response of scan
  1607. *
  1608. * The response buffer for the scan command has the following
  1609. * memory layout:
  1610. *
  1611. * .-----------------------------------------------------------.
  1612. * | header (4 * sizeof(u16)): Standard command response hdr |
  1613. * .-----------------------------------------------------------.
  1614. * | bufsize (u16) : sizeof the BSS Description data |
  1615. * .-----------------------------------------------------------.
  1616. * | NumOfSet (u8) : Number of BSS Descs returned |
  1617. * .-----------------------------------------------------------.
  1618. * | BSSDescription data (variable, size given in bufsize) |
  1619. * .-----------------------------------------------------------.
  1620. * | TLV data (variable, size calculated using header->size, |
  1621. * | bufsize and sizeof the fixed fields above) |
  1622. * .-----------------------------------------------------------.
  1623. *
  1624. * @param priv A pointer to wlan_private structure
  1625. * @param resp A pointer to cmd_ds_command
  1626. *
  1627. * @return 0 or -1
  1628. */
  1629. int libertas_ret_80211_scan(wlan_private * priv, struct cmd_ds_command *resp)
  1630. {
  1631. wlan_adapter *adapter = priv->adapter;
  1632. struct cmd_ds_802_11_scan_rsp *pscan;
  1633. struct bss_descriptor newbssentry;
  1634. struct mrvlietypes_data *ptlv;
  1635. struct mrvlietypes_tsftimestamp *ptsftlv;
  1636. u8 *pbssinfo;
  1637. u16 scanrespsize;
  1638. int bytesleft;
  1639. int numintable;
  1640. int bssIdx;
  1641. int idx;
  1642. int tlvbufsize;
  1643. u64 tsfval;
  1644. ENTER();
  1645. pscan = &resp->params.scanresp;
  1646. if (pscan->nr_sets > MRVDRV_MAX_BSSID_LIST) {
  1647. lbs_pr_debug(1,
  1648. "SCAN_RESP: Invalid number of AP returned (%d)!!\n",
  1649. pscan->nr_sets);
  1650. LEAVE();
  1651. return -1;
  1652. }
  1653. bytesleft = le16_to_cpu(pscan->bssdescriptsize);
  1654. lbs_pr_debug(1, "SCAN_RESP: bssdescriptsize %d\n", bytesleft);
  1655. scanrespsize = le16_to_cpu(resp->size);
  1656. lbs_pr_debug(1, "SCAN_RESP: returned %d AP before parsing\n",
  1657. pscan->nr_sets);
  1658. numintable = adapter->numinscantable;
  1659. pbssinfo = pscan->bssdesc_and_tlvbuffer;
  1660. /* The size of the TLV buffer is equal to the entire command response
  1661. * size (scanrespsize) minus the fixed fields (sizeof()'s), the
  1662. * BSS Descriptions (bssdescriptsize as bytesLef) and the command
  1663. * response header (S_DS_GEN)
  1664. */
  1665. tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize)
  1666. + sizeof(pscan->nr_sets)
  1667. + S_DS_GEN);
  1668. ptlv = (struct mrvlietypes_data *) (pscan->bssdesc_and_tlvbuffer + bytesleft);
  1669. /* Search the TLV buffer space in the scan response for any valid TLVs */
  1670. wlan_ret_802_11_scan_get_tlv_ptrs(ptlv, tlvbufsize, &ptsftlv);
  1671. /*
  1672. * Process each scan response returned (pscan->nr_sets). Save
  1673. * the information in the newbssentry and then insert into the
  1674. * driver scan table either as an update to an existing entry
  1675. * or as an addition at the end of the table
  1676. */
  1677. for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
  1678. /* Zero out the newbssentry we are about to store info in */
  1679. memset(&newbssentry, 0x00, sizeof(newbssentry));
  1680. /* Process the data fields and IEs returned for this BSS */
  1681. if ((InterpretBSSDescriptionWithIE(&newbssentry,
  1682. &pbssinfo,
  1683. &bytesleft) ==
  1684. 0)
  1685. && CHECK_SSID_IS_VALID(&newbssentry.ssid)) {
  1686. lbs_pr_debug(1,
  1687. "SCAN_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
  1688. newbssentry.macaddress[0],
  1689. newbssentry.macaddress[1],
  1690. newbssentry.macaddress[2],
  1691. newbssentry.macaddress[3],
  1692. newbssentry.macaddress[4],
  1693. newbssentry.macaddress[5]);
  1694. /*
  1695. * Search the scan table for the same bssid
  1696. */
  1697. for (bssIdx = 0; bssIdx < numintable; bssIdx++) {
  1698. if (memcmp(newbssentry.macaddress,
  1699. adapter->scantable[bssIdx].
  1700. macaddress,
  1701. sizeof(newbssentry.macaddress)) ==
  1702. 0) {
  1703. /*
  1704. * If the SSID matches as well, it is a duplicate of
  1705. * this entry. Keep the bssIdx set to this
  1706. * entry so we replace the old contents in the table
  1707. */
  1708. if ((newbssentry.ssid.ssidlength ==
  1709. adapter->scantable[bssIdx].ssid.
  1710. ssidlength)
  1711. &&
  1712. (memcmp
  1713. (newbssentry.ssid.ssid,
  1714. adapter->scantable[bssIdx].ssid.
  1715. ssid,
  1716. newbssentry.ssid.ssidlength) ==
  1717. 0)) {
  1718. lbs_pr_debug(1,
  1719. "SCAN_RESP: Duplicate of index: %d\n",
  1720. bssIdx);
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. /*
  1726. * If the bssIdx is equal to the number of entries in the table,
  1727. * the new entry was not a duplicate; append it to the scan
  1728. * table
  1729. */
  1730. if (bssIdx == numintable) {
  1731. /* Range check the bssIdx, keep it limited to the last entry */
  1732. if (bssIdx == MRVDRV_MAX_BSSID_LIST) {
  1733. bssIdx--;
  1734. } else {
  1735. numintable++;
  1736. }
  1737. }
  1738. /*
  1739. * If the TSF TLV was appended to the scan results, save the
  1740. * this entries TSF value in the networktsf field. The
  1741. * networktsf is the firmware's TSF value at the time the
  1742. * beacon or probe response was received.
  1743. */
  1744. if (ptsftlv) {
  1745. memcpy(&tsfval, &ptsftlv->tsftable[idx],
  1746. sizeof(tsfval));
  1747. tsfval = le64_to_cpu(tsfval);
  1748. memcpy(&newbssentry.networktsf,
  1749. &tsfval, sizeof(newbssentry.networktsf));
  1750. }
  1751. /* Copy the locally created newbssentry to the scan table */
  1752. memcpy(&adapter->scantable[bssIdx],
  1753. &newbssentry,
  1754. sizeof(adapter->scantable[bssIdx]));
  1755. } else {
  1756. /* error parsing/interpreting the scan response, skipped */
  1757. lbs_pr_debug(1, "SCAN_RESP: "
  1758. "InterpretBSSDescriptionWithIE returned ERROR\n");
  1759. }
  1760. }
  1761. lbs_pr_debug(1, "SCAN_RESP: Scanned %2d APs, %d valid, %d total\n",
  1762. pscan->nr_sets, numintable - adapter->numinscantable,
  1763. numintable);
  1764. /* Update the total number of BSSIDs in the scan table */
  1765. adapter->numinscantable = numintable;
  1766. LEAVE();
  1767. return 0;
  1768. }