cfg.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  1. /*
  2. * Implement cfg80211 ("iw") support.
  3. *
  4. * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
  5. * Holger Schurig <hs4233@mail.mn-solutions.de>
  6. *
  7. */
  8. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9. #include <linux/hardirq.h>
  10. #include <linux/sched.h>
  11. #include <linux/wait.h>
  12. #include <linux/slab.h>
  13. #include <linux/ieee80211.h>
  14. #include <net/cfg80211.h>
  15. #include <asm/unaligned.h>
  16. #include "decl.h"
  17. #include "cfg.h"
  18. #include "cmd.h"
  19. #define CHAN2G(_channel, _freq, _flags) { \
  20. .band = IEEE80211_BAND_2GHZ, \
  21. .center_freq = (_freq), \
  22. .hw_value = (_channel), \
  23. .flags = (_flags), \
  24. .max_antenna_gain = 0, \
  25. .max_power = 30, \
  26. }
  27. static struct ieee80211_channel lbs_2ghz_channels[] = {
  28. CHAN2G(1, 2412, 0),
  29. CHAN2G(2, 2417, 0),
  30. CHAN2G(3, 2422, 0),
  31. CHAN2G(4, 2427, 0),
  32. CHAN2G(5, 2432, 0),
  33. CHAN2G(6, 2437, 0),
  34. CHAN2G(7, 2442, 0),
  35. CHAN2G(8, 2447, 0),
  36. CHAN2G(9, 2452, 0),
  37. CHAN2G(10, 2457, 0),
  38. CHAN2G(11, 2462, 0),
  39. CHAN2G(12, 2467, 0),
  40. CHAN2G(13, 2472, 0),
  41. CHAN2G(14, 2484, 0),
  42. };
  43. #define RATETAB_ENT(_rate, _hw_value, _flags) { \
  44. .bitrate = (_rate), \
  45. .hw_value = (_hw_value), \
  46. .flags = (_flags), \
  47. }
  48. /* Table 6 in section 3.2.1.1 */
  49. static struct ieee80211_rate lbs_rates[] = {
  50. RATETAB_ENT(10, 0, 0),
  51. RATETAB_ENT(20, 1, 0),
  52. RATETAB_ENT(55, 2, 0),
  53. RATETAB_ENT(110, 3, 0),
  54. RATETAB_ENT(60, 9, 0),
  55. RATETAB_ENT(90, 6, 0),
  56. RATETAB_ENT(120, 7, 0),
  57. RATETAB_ENT(180, 8, 0),
  58. RATETAB_ENT(240, 9, 0),
  59. RATETAB_ENT(360, 10, 0),
  60. RATETAB_ENT(480, 11, 0),
  61. RATETAB_ENT(540, 12, 0),
  62. };
  63. static struct ieee80211_supported_band lbs_band_2ghz = {
  64. .channels = lbs_2ghz_channels,
  65. .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
  66. .bitrates = lbs_rates,
  67. .n_bitrates = ARRAY_SIZE(lbs_rates),
  68. };
  69. static const u32 cipher_suites[] = {
  70. WLAN_CIPHER_SUITE_WEP40,
  71. WLAN_CIPHER_SUITE_WEP104,
  72. WLAN_CIPHER_SUITE_TKIP,
  73. WLAN_CIPHER_SUITE_CCMP,
  74. };
  75. /* Time to stay on the channel */
  76. #define LBS_DWELL_PASSIVE 100
  77. #define LBS_DWELL_ACTIVE 40
  78. /***************************************************************************
  79. * Misc utility functions
  80. *
  81. * TLVs are Marvell specific. They are very similar to IEs, they have the
  82. * same structure: type, length, data*. The only difference: for IEs, the
  83. * type and length are u8, but for TLVs they're __le16.
  84. */
  85. /*
  86. * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
  87. * in the firmware spec
  88. */
  89. static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
  90. {
  91. int ret = -ENOTSUPP;
  92. switch (auth_type) {
  93. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  94. case NL80211_AUTHTYPE_SHARED_KEY:
  95. ret = auth_type;
  96. break;
  97. case NL80211_AUTHTYPE_AUTOMATIC:
  98. ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
  99. break;
  100. case NL80211_AUTHTYPE_NETWORK_EAP:
  101. ret = 0x80;
  102. break;
  103. default:
  104. /* silence compiler */
  105. break;
  106. }
  107. return ret;
  108. }
  109. /*
  110. * Various firmware commands need the list of supported rates, but with
  111. * the hight-bit set for basic rates
  112. */
  113. static int lbs_add_rates(u8 *rates)
  114. {
  115. size_t i;
  116. for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
  117. u8 rate = lbs_rates[i].bitrate / 5;
  118. if (rate == 0x02 || rate == 0x04 ||
  119. rate == 0x0b || rate == 0x16)
  120. rate |= 0x80;
  121. rates[i] = rate;
  122. }
  123. return ARRAY_SIZE(lbs_rates);
  124. }
  125. /***************************************************************************
  126. * TLV utility functions
  127. *
  128. * TLVs are Marvell specific. They are very similar to IEs, they have the
  129. * same structure: type, length, data*. The only difference: for IEs, the
  130. * type and length are u8, but for TLVs they're __le16.
  131. */
  132. /*
  133. * Add ssid TLV
  134. */
  135. #define LBS_MAX_SSID_TLV_SIZE \
  136. (sizeof(struct mrvl_ie_header) \
  137. + IEEE80211_MAX_SSID_LEN)
  138. static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
  139. {
  140. struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
  141. /*
  142. * TLV-ID SSID 00 00
  143. * length 06 00
  144. * ssid 4d 4e 54 45 53 54
  145. */
  146. ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
  147. ssid_tlv->header.len = cpu_to_le16(ssid_len);
  148. memcpy(ssid_tlv->ssid, ssid, ssid_len);
  149. return sizeof(ssid_tlv->header) + ssid_len;
  150. }
  151. /*
  152. * Add channel list TLV (section 8.4.2)
  153. *
  154. * Actual channel data comes from priv->wdev->wiphy->channels.
  155. */
  156. #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
  157. (sizeof(struct mrvl_ie_header) \
  158. + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
  159. static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
  160. int last_channel, int active_scan)
  161. {
  162. int chanscanparamsize = sizeof(struct chanscanparamset) *
  163. (last_channel - priv->scan_channel);
  164. struct mrvl_ie_header *header = (void *) tlv;
  165. /*
  166. * TLV-ID CHANLIST 01 01
  167. * length 0e 00
  168. * channel 00 01 00 00 00 64 00
  169. * radio type 00
  170. * channel 01
  171. * scan type 00
  172. * min scan time 00 00
  173. * max scan time 64 00
  174. * channel 2 00 02 00 00 00 64 00
  175. *
  176. */
  177. header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
  178. header->len = cpu_to_le16(chanscanparamsize);
  179. tlv += sizeof(struct mrvl_ie_header);
  180. /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
  181. last_channel); */
  182. memset(tlv, 0, chanscanparamsize);
  183. while (priv->scan_channel < last_channel) {
  184. struct chanscanparamset *param = (void *) tlv;
  185. param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
  186. param->channumber =
  187. priv->scan_req->channels[priv->scan_channel]->hw_value;
  188. if (active_scan) {
  189. param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
  190. } else {
  191. param->chanscanmode.passivescan = 1;
  192. param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
  193. }
  194. tlv += sizeof(struct chanscanparamset);
  195. priv->scan_channel++;
  196. }
  197. return sizeof(struct mrvl_ie_header) + chanscanparamsize;
  198. }
  199. /*
  200. * Add rates TLV
  201. *
  202. * The rates are in lbs_bg_rates[], but for the 802.11b
  203. * rates the high bit is set. We add this TLV only because
  204. * there's a firmware which otherwise doesn't report all
  205. * APs in range.
  206. */
  207. #define LBS_MAX_RATES_TLV_SIZE \
  208. (sizeof(struct mrvl_ie_header) \
  209. + (ARRAY_SIZE(lbs_rates)))
  210. /* Adds a TLV with all rates the hardware supports */
  211. static int lbs_add_supported_rates_tlv(u8 *tlv)
  212. {
  213. size_t i;
  214. struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
  215. /*
  216. * TLV-ID RATES 01 00
  217. * length 0e 00
  218. * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
  219. */
  220. rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
  221. tlv += sizeof(rate_tlv->header);
  222. i = lbs_add_rates(tlv);
  223. tlv += i;
  224. rate_tlv->header.len = cpu_to_le16(i);
  225. return sizeof(rate_tlv->header) + i;
  226. }
  227. /* Add common rates from a TLV and return the new end of the TLV */
  228. static u8 *
  229. add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
  230. {
  231. int hw, ap, ap_max = ie[1];
  232. u8 hw_rate;
  233. /* Advance past IE header */
  234. ie += 2;
  235. lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
  236. for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
  237. hw_rate = lbs_rates[hw].bitrate / 5;
  238. for (ap = 0; ap < ap_max; ap++) {
  239. if (hw_rate == (ie[ap] & 0x7f)) {
  240. *tlv++ = ie[ap];
  241. *nrates = *nrates + 1;
  242. }
  243. }
  244. }
  245. return tlv;
  246. }
  247. /*
  248. * Adds a TLV with all rates the hardware *and* BSS supports.
  249. */
  250. static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
  251. {
  252. struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
  253. const u8 *rates_eid, *ext_rates_eid;
  254. int n = 0;
  255. rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
  256. ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
  257. /*
  258. * 01 00 TLV_TYPE_RATES
  259. * 04 00 len
  260. * 82 84 8b 96 rates
  261. */
  262. rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
  263. tlv += sizeof(rate_tlv->header);
  264. /* Add basic rates */
  265. if (rates_eid) {
  266. tlv = add_ie_rates(tlv, rates_eid, &n);
  267. /* Add extended rates, if any */
  268. if (ext_rates_eid)
  269. tlv = add_ie_rates(tlv, ext_rates_eid, &n);
  270. } else {
  271. lbs_deb_assoc("assoc: bss had no basic rate IE\n");
  272. /* Fallback: add basic 802.11b rates */
  273. *tlv++ = 0x82;
  274. *tlv++ = 0x84;
  275. *tlv++ = 0x8b;
  276. *tlv++ = 0x96;
  277. n = 4;
  278. }
  279. rate_tlv->header.len = cpu_to_le16(n);
  280. return sizeof(rate_tlv->header) + n;
  281. }
  282. /*
  283. * Add auth type TLV.
  284. *
  285. * This is only needed for newer firmware (V9 and up).
  286. */
  287. #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
  288. sizeof(struct mrvl_ie_auth_type)
  289. static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
  290. {
  291. struct mrvl_ie_auth_type *auth = (void *) tlv;
  292. /*
  293. * 1f 01 TLV_TYPE_AUTH_TYPE
  294. * 01 00 len
  295. * 01 auth type
  296. */
  297. auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  298. auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
  299. auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
  300. return sizeof(*auth);
  301. }
  302. /*
  303. * Add channel (phy ds) TLV
  304. */
  305. #define LBS_MAX_CHANNEL_TLV_SIZE \
  306. sizeof(struct mrvl_ie_header)
  307. static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
  308. {
  309. struct mrvl_ie_ds_param_set *ds = (void *) tlv;
  310. /*
  311. * 03 00 TLV_TYPE_PHY_DS
  312. * 01 00 len
  313. * 06 channel
  314. */
  315. ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
  316. ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
  317. ds->channel = channel;
  318. return sizeof(*ds);
  319. }
  320. /*
  321. * Add (empty) CF param TLV of the form:
  322. */
  323. #define LBS_MAX_CF_PARAM_TLV_SIZE \
  324. sizeof(struct mrvl_ie_header)
  325. static int lbs_add_cf_param_tlv(u8 *tlv)
  326. {
  327. struct mrvl_ie_cf_param_set *cf = (void *)tlv;
  328. /*
  329. * 04 00 TLV_TYPE_CF
  330. * 06 00 len
  331. * 00 cfpcnt
  332. * 00 cfpperiod
  333. * 00 00 cfpmaxduration
  334. * 00 00 cfpdurationremaining
  335. */
  336. cf->header.type = cpu_to_le16(TLV_TYPE_CF);
  337. cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
  338. return sizeof(*cf);
  339. }
  340. /*
  341. * Add WPA TLV
  342. */
  343. #define LBS_MAX_WPA_TLV_SIZE \
  344. (sizeof(struct mrvl_ie_header) \
  345. + 128 /* TODO: I guessed the size */)
  346. static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
  347. {
  348. size_t tlv_len;
  349. /*
  350. * We need just convert an IE to an TLV. IEs use u8 for the header,
  351. * u8 type
  352. * u8 len
  353. * u8[] data
  354. * but TLVs use __le16 instead:
  355. * __le16 type
  356. * __le16 len
  357. * u8[] data
  358. */
  359. *tlv++ = *ie++;
  360. *tlv++ = 0;
  361. tlv_len = *tlv++ = *ie++;
  362. *tlv++ = 0;
  363. while (tlv_len--)
  364. *tlv++ = *ie++;
  365. /* the TLV is two bytes larger than the IE */
  366. return ie_len + 2;
  367. }
  368. /*
  369. * Set Channel
  370. */
  371. static int lbs_cfg_set_channel(struct wiphy *wiphy,
  372. struct net_device *netdev,
  373. struct ieee80211_channel *channel,
  374. enum nl80211_channel_type channel_type)
  375. {
  376. struct lbs_private *priv = wiphy_priv(wiphy);
  377. int ret = -ENOTSUPP;
  378. lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
  379. channel->center_freq, channel_type);
  380. if (channel_type != NL80211_CHAN_NO_HT)
  381. goto out;
  382. ret = lbs_set_channel(priv, channel->hw_value);
  383. out:
  384. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  385. return ret;
  386. }
  387. /*
  388. * Scanning
  389. */
  390. /*
  391. * When scanning, the firmware doesn't send a nul packet with the power-safe
  392. * bit to the AP. So we cannot stay away from our current channel too long,
  393. * otherwise we loose data. So take a "nap" while scanning every other
  394. * while.
  395. */
  396. #define LBS_SCAN_BEFORE_NAP 4
  397. /*
  398. * When the firmware reports back a scan-result, it gives us an "u8 rssi",
  399. * which isn't really an RSSI, as it becomes larger when moving away from
  400. * the AP. Anyway, we need to convert that into mBm.
  401. */
  402. #define LBS_SCAN_RSSI_TO_MBM(rssi) \
  403. ((-(int)rssi + 3)*100)
  404. static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
  405. struct cmd_header *resp)
  406. {
  407. struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
  408. int bsssize;
  409. const u8 *pos;
  410. const u8 *tsfdesc;
  411. int tsfsize;
  412. int i;
  413. int ret = -EILSEQ;
  414. lbs_deb_enter(LBS_DEB_CFG80211);
  415. bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
  416. lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
  417. scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
  418. if (scanresp->nr_sets == 0) {
  419. ret = 0;
  420. goto done;
  421. }
  422. /*
  423. * The general layout of the scan response is described in chapter
  424. * 5.7.1. Basically we have a common part, then any number of BSS
  425. * descriptor sections. Finally we have section with the same number
  426. * of TSFs.
  427. *
  428. * cmd_ds_802_11_scan_rsp
  429. * cmd_header
  430. * pos_size
  431. * nr_sets
  432. * bssdesc 1
  433. * bssid
  434. * rssi
  435. * timestamp
  436. * intvl
  437. * capa
  438. * IEs
  439. * bssdesc 2
  440. * bssdesc n
  441. * MrvlIEtypes_TsfFimestamp_t
  442. * TSF for BSS 1
  443. * TSF for BSS 2
  444. * TSF for BSS n
  445. */
  446. pos = scanresp->bssdesc_and_tlvbuffer;
  447. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
  448. scanresp->bssdescriptsize);
  449. tsfdesc = pos + bsssize;
  450. tsfsize = 4 + 8 * scanresp->nr_sets;
  451. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
  452. /* Validity check: we expect a Marvell-Local TLV */
  453. i = get_unaligned_le16(tsfdesc);
  454. tsfdesc += 2;
  455. if (i != TLV_TYPE_TSFTIMESTAMP) {
  456. lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
  457. goto done;
  458. }
  459. /*
  460. * Validity check: the TLV holds TSF values with 8 bytes each, so
  461. * the size in the TLV must match the nr_sets value
  462. */
  463. i = get_unaligned_le16(tsfdesc);
  464. tsfdesc += 2;
  465. if (i / 8 != scanresp->nr_sets) {
  466. lbs_deb_scan("scan response: invalid number of TSF timestamp "
  467. "sets (expected %d got %d)\n", scanresp->nr_sets,
  468. i / 8);
  469. goto done;
  470. }
  471. for (i = 0; i < scanresp->nr_sets; i++) {
  472. const u8 *bssid;
  473. const u8 *ie;
  474. int left;
  475. int ielen;
  476. int rssi;
  477. u16 intvl;
  478. u16 capa;
  479. int chan_no = -1;
  480. const u8 *ssid = NULL;
  481. u8 ssid_len = 0;
  482. DECLARE_SSID_BUF(ssid_buf);
  483. int len = get_unaligned_le16(pos);
  484. pos += 2;
  485. /* BSSID */
  486. bssid = pos;
  487. pos += ETH_ALEN;
  488. /* RSSI */
  489. rssi = *pos++;
  490. /* Packet time stamp */
  491. pos += 8;
  492. /* Beacon interval */
  493. intvl = get_unaligned_le16(pos);
  494. pos += 2;
  495. /* Capabilities */
  496. capa = get_unaligned_le16(pos);
  497. pos += 2;
  498. /* To find out the channel, we must parse the IEs */
  499. ie = pos;
  500. /*
  501. * 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
  502. * interval, capabilities
  503. */
  504. ielen = left = len - (6 + 1 + 8 + 2 + 2);
  505. while (left >= 2) {
  506. u8 id, elen;
  507. id = *pos++;
  508. elen = *pos++;
  509. left -= 2;
  510. if (elen > left || elen == 0) {
  511. lbs_deb_scan("scan response: invalid IE fmt\n");
  512. goto done;
  513. }
  514. if (id == WLAN_EID_DS_PARAMS)
  515. chan_no = *pos;
  516. if (id == WLAN_EID_SSID) {
  517. ssid = pos;
  518. ssid_len = elen;
  519. }
  520. left -= elen;
  521. pos += elen;
  522. }
  523. /* No channel, no luck */
  524. if (chan_no != -1) {
  525. struct wiphy *wiphy = priv->wdev->wiphy;
  526. int freq = ieee80211_channel_to_frequency(chan_no,
  527. IEEE80211_BAND_2GHZ);
  528. struct ieee80211_channel *channel =
  529. ieee80211_get_channel(wiphy, freq);
  530. lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
  531. "%d dBm\n",
  532. bssid, capa, chan_no,
  533. print_ssid(ssid_buf, ssid, ssid_len),
  534. LBS_SCAN_RSSI_TO_MBM(rssi)/100);
  535. if (channel &&
  536. !(channel->flags & IEEE80211_CHAN_DISABLED))
  537. cfg80211_inform_bss(wiphy, channel,
  538. bssid, le64_to_cpu(*(__le64 *)tsfdesc),
  539. capa, intvl, ie, ielen,
  540. LBS_SCAN_RSSI_TO_MBM(rssi),
  541. GFP_KERNEL);
  542. } else
  543. lbs_deb_scan("scan response: missing BSS channel IE\n");
  544. tsfdesc += 8;
  545. }
  546. ret = 0;
  547. done:
  548. lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
  549. return ret;
  550. }
  551. /*
  552. * Our scan command contains a TLV, consting of a SSID TLV, a channel list
  553. * TLV and a rates TLV. Determine the maximum size of them:
  554. */
  555. #define LBS_SCAN_MAX_CMD_SIZE \
  556. (sizeof(struct cmd_ds_802_11_scan) \
  557. + LBS_MAX_SSID_TLV_SIZE \
  558. + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
  559. + LBS_MAX_RATES_TLV_SIZE)
  560. /*
  561. * Assumes priv->scan_req is initialized and valid
  562. * Assumes priv->scan_channel is initialized
  563. */
  564. static void lbs_scan_worker(struct work_struct *work)
  565. {
  566. struct lbs_private *priv =
  567. container_of(work, struct lbs_private, scan_work.work);
  568. struct cmd_ds_802_11_scan *scan_cmd;
  569. u8 *tlv; /* pointer into our current, growing TLV storage area */
  570. int last_channel;
  571. int running, carrier;
  572. lbs_deb_enter(LBS_DEB_SCAN);
  573. scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
  574. if (scan_cmd == NULL)
  575. goto out_no_scan_cmd;
  576. /* prepare fixed part of scan command */
  577. scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
  578. /* stop network while we're away from our main channel */
  579. running = !netif_queue_stopped(priv->dev);
  580. carrier = netif_carrier_ok(priv->dev);
  581. if (running)
  582. netif_stop_queue(priv->dev);
  583. if (carrier)
  584. netif_carrier_off(priv->dev);
  585. /* prepare fixed part of scan command */
  586. tlv = scan_cmd->tlvbuffer;
  587. /* add SSID TLV */
  588. if (priv->scan_req->n_ssids)
  589. tlv += lbs_add_ssid_tlv(tlv,
  590. priv->scan_req->ssids[0].ssid,
  591. priv->scan_req->ssids[0].ssid_len);
  592. /* add channel TLVs */
  593. last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
  594. if (last_channel > priv->scan_req->n_channels)
  595. last_channel = priv->scan_req->n_channels;
  596. tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
  597. priv->scan_req->n_ssids);
  598. /* add rates TLV */
  599. tlv += lbs_add_supported_rates_tlv(tlv);
  600. if (priv->scan_channel < priv->scan_req->n_channels) {
  601. cancel_delayed_work(&priv->scan_work);
  602. if (!priv->stopping)
  603. queue_delayed_work(priv->work_thread, &priv->scan_work,
  604. msecs_to_jiffies(300));
  605. }
  606. /* This is the final data we are about to send */
  607. scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
  608. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
  609. sizeof(*scan_cmd));
  610. lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
  611. tlv - scan_cmd->tlvbuffer);
  612. __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
  613. le16_to_cpu(scan_cmd->hdr.size),
  614. lbs_ret_scan, 0);
  615. if (priv->scan_channel >= priv->scan_req->n_channels) {
  616. /* Mark scan done */
  617. if (priv->internal_scan)
  618. kfree(priv->scan_req);
  619. else
  620. cfg80211_scan_done(priv->scan_req, false);
  621. priv->scan_req = NULL;
  622. priv->last_scan = jiffies;
  623. }
  624. /* Restart network */
  625. if (carrier)
  626. netif_carrier_on(priv->dev);
  627. if (running && !priv->tx_pending_len)
  628. netif_wake_queue(priv->dev);
  629. kfree(scan_cmd);
  630. /* Wake up anything waiting on scan completion */
  631. if (priv->scan_req == NULL) {
  632. lbs_deb_scan("scan: waking up waiters\n");
  633. wake_up_all(&priv->scan_q);
  634. }
  635. out_no_scan_cmd:
  636. lbs_deb_leave(LBS_DEB_SCAN);
  637. }
  638. static void _internal_start_scan(struct lbs_private *priv, bool internal,
  639. struct cfg80211_scan_request *request)
  640. {
  641. lbs_deb_enter(LBS_DEB_CFG80211);
  642. lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
  643. request->n_ssids, request->n_channels, request->ie_len);
  644. priv->scan_channel = 0;
  645. queue_delayed_work(priv->work_thread, &priv->scan_work,
  646. msecs_to_jiffies(50));
  647. priv->scan_req = request;
  648. priv->internal_scan = internal;
  649. lbs_deb_leave(LBS_DEB_CFG80211);
  650. }
  651. static int lbs_cfg_scan(struct wiphy *wiphy,
  652. struct net_device *dev,
  653. struct cfg80211_scan_request *request)
  654. {
  655. struct lbs_private *priv = wiphy_priv(wiphy);
  656. int ret = 0;
  657. lbs_deb_enter(LBS_DEB_CFG80211);
  658. if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
  659. /* old scan request not yet processed */
  660. ret = -EAGAIN;
  661. goto out;
  662. }
  663. _internal_start_scan(priv, false, request);
  664. if (priv->surpriseremoved)
  665. ret = -EIO;
  666. out:
  667. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  668. return ret;
  669. }
  670. /*
  671. * Events
  672. */
  673. void lbs_send_disconnect_notification(struct lbs_private *priv)
  674. {
  675. lbs_deb_enter(LBS_DEB_CFG80211);
  676. cfg80211_disconnected(priv->dev,
  677. 0,
  678. NULL, 0,
  679. GFP_KERNEL);
  680. lbs_deb_leave(LBS_DEB_CFG80211);
  681. }
  682. void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
  683. {
  684. lbs_deb_enter(LBS_DEB_CFG80211);
  685. cfg80211_michael_mic_failure(priv->dev,
  686. priv->assoc_bss,
  687. event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
  688. NL80211_KEYTYPE_GROUP :
  689. NL80211_KEYTYPE_PAIRWISE,
  690. -1,
  691. NULL,
  692. GFP_KERNEL);
  693. lbs_deb_leave(LBS_DEB_CFG80211);
  694. }
  695. /*
  696. * Connect/disconnect
  697. */
  698. /*
  699. * This removes all WEP keys
  700. */
  701. static int lbs_remove_wep_keys(struct lbs_private *priv)
  702. {
  703. struct cmd_ds_802_11_set_wep cmd;
  704. int ret;
  705. lbs_deb_enter(LBS_DEB_CFG80211);
  706. memset(&cmd, 0, sizeof(cmd));
  707. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  708. cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
  709. cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
  710. ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
  711. lbs_deb_leave(LBS_DEB_CFG80211);
  712. return ret;
  713. }
  714. /*
  715. * Set WEP keys
  716. */
  717. static int lbs_set_wep_keys(struct lbs_private *priv)
  718. {
  719. struct cmd_ds_802_11_set_wep cmd;
  720. int i;
  721. int ret;
  722. lbs_deb_enter(LBS_DEB_CFG80211);
  723. /*
  724. * command 13 00
  725. * size 50 00
  726. * sequence xx xx
  727. * result 00 00
  728. * action 02 00 ACT_ADD
  729. * transmit key 00 00
  730. * type for key 1 01 WEP40
  731. * type for key 2 00
  732. * type for key 3 00
  733. * type for key 4 00
  734. * key 1 39 39 39 39 39 00 00 00
  735. * 00 00 00 00 00 00 00 00
  736. * key 2 00 00 00 00 00 00 00 00
  737. * 00 00 00 00 00 00 00 00
  738. * key 3 00 00 00 00 00 00 00 00
  739. * 00 00 00 00 00 00 00 00
  740. * key 4 00 00 00 00 00 00 00 00
  741. */
  742. if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
  743. priv->wep_key_len[2] || priv->wep_key_len[3]) {
  744. /* Only set wep keys if we have at least one of them */
  745. memset(&cmd, 0, sizeof(cmd));
  746. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  747. cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
  748. cmd.action = cpu_to_le16(CMD_ACT_ADD);
  749. for (i = 0; i < 4; i++) {
  750. switch (priv->wep_key_len[i]) {
  751. case WLAN_KEY_LEN_WEP40:
  752. cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
  753. break;
  754. case WLAN_KEY_LEN_WEP104:
  755. cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
  756. break;
  757. default:
  758. cmd.keytype[i] = 0;
  759. break;
  760. }
  761. memcpy(cmd.keymaterial[i], priv->wep_key[i],
  762. priv->wep_key_len[i]);
  763. }
  764. ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
  765. } else {
  766. /* Otherwise remove all wep keys */
  767. ret = lbs_remove_wep_keys(priv);
  768. }
  769. lbs_deb_leave(LBS_DEB_CFG80211);
  770. return ret;
  771. }
  772. /*
  773. * Enable/Disable RSN status
  774. */
  775. static int lbs_enable_rsn(struct lbs_private *priv, int enable)
  776. {
  777. struct cmd_ds_802_11_enable_rsn cmd;
  778. int ret;
  779. lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
  780. /*
  781. * cmd 2f 00
  782. * size 0c 00
  783. * sequence xx xx
  784. * result 00 00
  785. * action 01 00 ACT_SET
  786. * enable 01 00
  787. */
  788. memset(&cmd, 0, sizeof(cmd));
  789. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  790. cmd.action = cpu_to_le16(CMD_ACT_SET);
  791. cmd.enable = cpu_to_le16(enable);
  792. ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
  793. lbs_deb_leave(LBS_DEB_CFG80211);
  794. return ret;
  795. }
  796. /*
  797. * Set WPA/WPA key material
  798. */
  799. /*
  800. * like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
  801. * get rid of WEXT, this should go into host.h
  802. */
  803. struct cmd_key_material {
  804. struct cmd_header hdr;
  805. __le16 action;
  806. struct MrvlIEtype_keyParamSet param;
  807. } __packed;
  808. static int lbs_set_key_material(struct lbs_private *priv,
  809. int key_type,
  810. int key_info,
  811. u8 *key, u16 key_len)
  812. {
  813. struct cmd_key_material cmd;
  814. int ret;
  815. lbs_deb_enter(LBS_DEB_CFG80211);
  816. /*
  817. * Example for WPA (TKIP):
  818. *
  819. * cmd 5e 00
  820. * size 34 00
  821. * sequence xx xx
  822. * result 00 00
  823. * action 01 00
  824. * TLV type 00 01 key param
  825. * length 00 26
  826. * key type 01 00 TKIP
  827. * key info 06 00 UNICAST | ENABLED
  828. * key len 20 00
  829. * key 32 bytes
  830. */
  831. memset(&cmd, 0, sizeof(cmd));
  832. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  833. cmd.action = cpu_to_le16(CMD_ACT_SET);
  834. cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  835. cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
  836. cmd.param.keytypeid = cpu_to_le16(key_type);
  837. cmd.param.keyinfo = cpu_to_le16(key_info);
  838. cmd.param.keylen = cpu_to_le16(key_len);
  839. if (key && key_len)
  840. memcpy(cmd.param.key, key, key_len);
  841. ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
  842. lbs_deb_leave(LBS_DEB_CFG80211);
  843. return ret;
  844. }
  845. /*
  846. * Sets the auth type (open, shared, etc) in the firmware. That
  847. * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
  848. * command doesn't send an authentication frame at all, it just
  849. * stores the auth_type.
  850. */
  851. static int lbs_set_authtype(struct lbs_private *priv,
  852. struct cfg80211_connect_params *sme)
  853. {
  854. struct cmd_ds_802_11_authenticate cmd;
  855. int ret;
  856. lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
  857. /*
  858. * cmd 11 00
  859. * size 19 00
  860. * sequence xx xx
  861. * result 00 00
  862. * BSS id 00 13 19 80 da 30
  863. * auth type 00
  864. * reserved 00 00 00 00 00 00 00 00 00 00
  865. */
  866. memset(&cmd, 0, sizeof(cmd));
  867. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  868. if (sme->bssid)
  869. memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
  870. /* convert auth_type */
  871. ret = lbs_auth_to_authtype(sme->auth_type);
  872. if (ret < 0)
  873. goto done;
  874. cmd.authtype = ret;
  875. ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
  876. done:
  877. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  878. return ret;
  879. }
  880. /*
  881. * Create association request
  882. */
  883. #define LBS_ASSOC_MAX_CMD_SIZE \
  884. (sizeof(struct cmd_ds_802_11_associate) \
  885. - 512 /* cmd_ds_802_11_associate.iebuf */ \
  886. + LBS_MAX_SSID_TLV_SIZE \
  887. + LBS_MAX_CHANNEL_TLV_SIZE \
  888. + LBS_MAX_CF_PARAM_TLV_SIZE \
  889. + LBS_MAX_AUTH_TYPE_TLV_SIZE \
  890. + LBS_MAX_WPA_TLV_SIZE)
  891. static int lbs_associate(struct lbs_private *priv,
  892. struct cfg80211_bss *bss,
  893. struct cfg80211_connect_params *sme)
  894. {
  895. struct cmd_ds_802_11_associate_response *resp;
  896. struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
  897. GFP_KERNEL);
  898. const u8 *ssid_eid;
  899. size_t len, resp_ie_len;
  900. int status;
  901. int ret;
  902. u8 *pos = &(cmd->iebuf[0]);
  903. u8 *tmp;
  904. lbs_deb_enter(LBS_DEB_CFG80211);
  905. if (!cmd) {
  906. ret = -ENOMEM;
  907. goto done;
  908. }
  909. /*
  910. * cmd 50 00
  911. * length 34 00
  912. * sequence xx xx
  913. * result 00 00
  914. * BSS id 00 13 19 80 da 30
  915. * capabilities 11 00
  916. * listen interval 0a 00
  917. * beacon interval 00 00
  918. * DTIM period 00
  919. * TLVs xx (up to 512 bytes)
  920. */
  921. cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
  922. /* Fill in static fields */
  923. memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
  924. cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
  925. cmd->capability = cpu_to_le16(bss->capability);
  926. /* add SSID TLV */
  927. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  928. if (ssid_eid)
  929. pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
  930. else
  931. lbs_deb_assoc("no SSID\n");
  932. /* add DS param TLV */
  933. if (bss->channel)
  934. pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
  935. else
  936. lbs_deb_assoc("no channel\n");
  937. /* add (empty) CF param TLV */
  938. pos += lbs_add_cf_param_tlv(pos);
  939. /* add rates TLV */
  940. tmp = pos + 4; /* skip Marvell IE header */
  941. pos += lbs_add_common_rates_tlv(pos, bss);
  942. lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
  943. /* add auth type TLV */
  944. if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
  945. pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
  946. /* add WPA/WPA2 TLV */
  947. if (sme->ie && sme->ie_len)
  948. pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
  949. len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
  950. (u16)(pos - (u8 *) &cmd->iebuf);
  951. cmd->hdr.size = cpu_to_le16(len);
  952. lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
  953. le16_to_cpu(cmd->hdr.size));
  954. /* store for later use */
  955. memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
  956. ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
  957. if (ret)
  958. goto done;
  959. /* generate connect message to cfg80211 */
  960. resp = (void *) cmd; /* recast for easier field access */
  961. status = le16_to_cpu(resp->statuscode);
  962. /* Older FW versions map the IEEE 802.11 Status Code in the association
  963. * response to the following values returned in resp->statuscode:
  964. *
  965. * IEEE Status Code Marvell Status Code
  966. * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
  967. * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
  968. * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
  969. * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
  970. * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
  971. * others -> 0x0003 ASSOC_RESULT_REFUSED
  972. *
  973. * Other response codes:
  974. * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
  975. * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
  976. * association response from the AP)
  977. */
  978. if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
  979. switch (status) {
  980. case 0:
  981. break;
  982. case 1:
  983. lbs_deb_assoc("invalid association parameters\n");
  984. status = WLAN_STATUS_CAPS_UNSUPPORTED;
  985. break;
  986. case 2:
  987. lbs_deb_assoc("timer expired while waiting for AP\n");
  988. status = WLAN_STATUS_AUTH_TIMEOUT;
  989. break;
  990. case 3:
  991. lbs_deb_assoc("association refused by AP\n");
  992. status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
  993. break;
  994. case 4:
  995. lbs_deb_assoc("authentication refused by AP\n");
  996. status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  997. break;
  998. default:
  999. lbs_deb_assoc("association failure %d\n", status);
  1000. /* v5 OLPC firmware does return the AP status code if
  1001. * it's not one of the values above. Let that through.
  1002. */
  1003. break;
  1004. }
  1005. }
  1006. lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
  1007. "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
  1008. le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
  1009. resp_ie_len = le16_to_cpu(resp->hdr.size)
  1010. - sizeof(resp->hdr)
  1011. - 6;
  1012. cfg80211_connect_result(priv->dev,
  1013. priv->assoc_bss,
  1014. sme->ie, sme->ie_len,
  1015. resp->iebuf, resp_ie_len,
  1016. status,
  1017. GFP_KERNEL);
  1018. if (status == 0) {
  1019. /* TODO: get rid of priv->connect_status */
  1020. priv->connect_status = LBS_CONNECTED;
  1021. netif_carrier_on(priv->dev);
  1022. if (!priv->tx_pending_len)
  1023. netif_tx_wake_all_queues(priv->dev);
  1024. }
  1025. done:
  1026. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1027. return ret;
  1028. }
  1029. static struct cfg80211_scan_request *
  1030. _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
  1031. {
  1032. struct cfg80211_scan_request *creq = NULL;
  1033. int i, n_channels = 0;
  1034. enum ieee80211_band band;
  1035. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1036. if (wiphy->bands[band])
  1037. n_channels += wiphy->bands[band]->n_channels;
  1038. }
  1039. creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
  1040. n_channels * sizeof(void *),
  1041. GFP_ATOMIC);
  1042. if (!creq)
  1043. return NULL;
  1044. /* SSIDs come after channels */
  1045. creq->ssids = (void *)&creq->channels[n_channels];
  1046. creq->n_channels = n_channels;
  1047. creq->n_ssids = 1;
  1048. /* Scan all available channels */
  1049. i = 0;
  1050. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1051. int j;
  1052. if (!wiphy->bands[band])
  1053. continue;
  1054. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  1055. /* ignore disabled channels */
  1056. if (wiphy->bands[band]->channels[j].flags &
  1057. IEEE80211_CHAN_DISABLED)
  1058. continue;
  1059. creq->channels[i] = &wiphy->bands[band]->channels[j];
  1060. i++;
  1061. }
  1062. }
  1063. if (i) {
  1064. /* Set real number of channels specified in creq->channels[] */
  1065. creq->n_channels = i;
  1066. /* Scan for the SSID we're going to connect to */
  1067. memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
  1068. creq->ssids[0].ssid_len = sme->ssid_len;
  1069. } else {
  1070. /* No channels found... */
  1071. kfree(creq);
  1072. creq = NULL;
  1073. }
  1074. return creq;
  1075. }
  1076. static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
  1077. struct cfg80211_connect_params *sme)
  1078. {
  1079. struct lbs_private *priv = wiphy_priv(wiphy);
  1080. struct cfg80211_bss *bss = NULL;
  1081. int ret = 0;
  1082. u8 preamble = RADIO_PREAMBLE_SHORT;
  1083. lbs_deb_enter(LBS_DEB_CFG80211);
  1084. if (!sme->bssid) {
  1085. /* Run a scan if one isn't in-progress already and if the last
  1086. * scan was done more than 2 seconds ago.
  1087. */
  1088. if (priv->scan_req == NULL &&
  1089. time_after(jiffies, priv->last_scan + (2 * HZ))) {
  1090. struct cfg80211_scan_request *creq;
  1091. creq = _new_connect_scan_req(wiphy, sme);
  1092. if (!creq) {
  1093. ret = -EINVAL;
  1094. goto done;
  1095. }
  1096. lbs_deb_assoc("assoc: scanning for compatible AP\n");
  1097. _internal_start_scan(priv, true, creq);
  1098. }
  1099. /* Wait for any in-progress scan to complete */
  1100. lbs_deb_assoc("assoc: waiting for scan to complete\n");
  1101. wait_event_interruptible_timeout(priv->scan_q,
  1102. (priv->scan_req == NULL),
  1103. (15 * HZ));
  1104. lbs_deb_assoc("assoc: scanning competed\n");
  1105. }
  1106. /* Find the BSS we want using available scan results */
  1107. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  1108. sme->ssid, sme->ssid_len,
  1109. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  1110. if (!bss) {
  1111. wiphy_err(wiphy, "assoc: bss %pM not in scan results\n",
  1112. sme->bssid);
  1113. ret = -ENOENT;
  1114. goto done;
  1115. }
  1116. lbs_deb_assoc("trying %pM\n", bss->bssid);
  1117. lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
  1118. sme->crypto.cipher_group,
  1119. sme->key_idx, sme->key_len);
  1120. /* As this is a new connection, clear locally stored WEP keys */
  1121. priv->wep_tx_key = 0;
  1122. memset(priv->wep_key, 0, sizeof(priv->wep_key));
  1123. memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
  1124. /* set/remove WEP keys */
  1125. switch (sme->crypto.cipher_group) {
  1126. case WLAN_CIPHER_SUITE_WEP40:
  1127. case WLAN_CIPHER_SUITE_WEP104:
  1128. /* Store provided WEP keys in priv-> */
  1129. priv->wep_tx_key = sme->key_idx;
  1130. priv->wep_key_len[sme->key_idx] = sme->key_len;
  1131. memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
  1132. /* Set WEP keys and WEP mode */
  1133. lbs_set_wep_keys(priv);
  1134. priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
  1135. lbs_set_mac_control(priv);
  1136. /* No RSN mode for WEP */
  1137. lbs_enable_rsn(priv, 0);
  1138. break;
  1139. case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
  1140. /*
  1141. * If we don't have no WEP, no WPA and no WPA2,
  1142. * we remove all keys like in the WPA/WPA2 setup,
  1143. * we just don't set RSN.
  1144. *
  1145. * Therefore: fall-through
  1146. */
  1147. case WLAN_CIPHER_SUITE_TKIP:
  1148. case WLAN_CIPHER_SUITE_CCMP:
  1149. /* Remove WEP keys and WEP mode */
  1150. lbs_remove_wep_keys(priv);
  1151. priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
  1152. lbs_set_mac_control(priv);
  1153. /* clear the WPA/WPA2 keys */
  1154. lbs_set_key_material(priv,
  1155. KEY_TYPE_ID_WEP, /* doesn't matter */
  1156. KEY_INFO_WPA_UNICAST,
  1157. NULL, 0);
  1158. lbs_set_key_material(priv,
  1159. KEY_TYPE_ID_WEP, /* doesn't matter */
  1160. KEY_INFO_WPA_MCAST,
  1161. NULL, 0);
  1162. /* RSN mode for WPA/WPA2 */
  1163. lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
  1164. break;
  1165. default:
  1166. wiphy_err(wiphy, "unsupported cipher group 0x%x\n",
  1167. sme->crypto.cipher_group);
  1168. ret = -ENOTSUPP;
  1169. goto done;
  1170. }
  1171. lbs_set_authtype(priv, sme);
  1172. lbs_set_radio(priv, preamble, 1);
  1173. /* Do the actual association */
  1174. ret = lbs_associate(priv, bss, sme);
  1175. done:
  1176. if (bss)
  1177. cfg80211_put_bss(bss);
  1178. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1179. return ret;
  1180. }
  1181. static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1182. u16 reason_code)
  1183. {
  1184. struct lbs_private *priv = wiphy_priv(wiphy);
  1185. struct cmd_ds_802_11_deauthenticate cmd;
  1186. lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
  1187. /* store for lbs_cfg_ret_disconnect() */
  1188. priv->disassoc_reason = reason_code;
  1189. memset(&cmd, 0, sizeof(cmd));
  1190. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1191. /* Mildly ugly to use a locally store my own BSSID ... */
  1192. memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
  1193. cmd.reasoncode = cpu_to_le16(reason_code);
  1194. if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
  1195. return -EFAULT;
  1196. cfg80211_disconnected(priv->dev,
  1197. priv->disassoc_reason,
  1198. NULL, 0,
  1199. GFP_KERNEL);
  1200. priv->connect_status = LBS_DISCONNECTED;
  1201. return 0;
  1202. }
  1203. static int lbs_cfg_set_default_key(struct wiphy *wiphy,
  1204. struct net_device *netdev,
  1205. u8 key_index, bool unicast,
  1206. bool multicast)
  1207. {
  1208. struct lbs_private *priv = wiphy_priv(wiphy);
  1209. lbs_deb_enter(LBS_DEB_CFG80211);
  1210. if (key_index != priv->wep_tx_key) {
  1211. lbs_deb_assoc("set_default_key: to %d\n", key_index);
  1212. priv->wep_tx_key = key_index;
  1213. lbs_set_wep_keys(priv);
  1214. }
  1215. return 0;
  1216. }
  1217. static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
  1218. u8 idx, bool pairwise, const u8 *mac_addr,
  1219. struct key_params *params)
  1220. {
  1221. struct lbs_private *priv = wiphy_priv(wiphy);
  1222. u16 key_info;
  1223. u16 key_type;
  1224. int ret = 0;
  1225. lbs_deb_enter(LBS_DEB_CFG80211);
  1226. lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
  1227. params->cipher, mac_addr);
  1228. lbs_deb_assoc("add_key: key index %d, key len %d\n",
  1229. idx, params->key_len);
  1230. if (params->key_len)
  1231. lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
  1232. params->key, params->key_len);
  1233. lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
  1234. if (params->seq_len)
  1235. lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
  1236. params->seq, params->seq_len);
  1237. switch (params->cipher) {
  1238. case WLAN_CIPHER_SUITE_WEP40:
  1239. case WLAN_CIPHER_SUITE_WEP104:
  1240. /* actually compare if something has changed ... */
  1241. if ((priv->wep_key_len[idx] != params->key_len) ||
  1242. memcmp(priv->wep_key[idx],
  1243. params->key, params->key_len) != 0) {
  1244. priv->wep_key_len[idx] = params->key_len;
  1245. memcpy(priv->wep_key[idx],
  1246. params->key, params->key_len);
  1247. lbs_set_wep_keys(priv);
  1248. }
  1249. break;
  1250. case WLAN_CIPHER_SUITE_TKIP:
  1251. case WLAN_CIPHER_SUITE_CCMP:
  1252. key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
  1253. ? KEY_INFO_WPA_UNICAST
  1254. : KEY_INFO_WPA_MCAST);
  1255. key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
  1256. ? KEY_TYPE_ID_TKIP
  1257. : KEY_TYPE_ID_AES;
  1258. lbs_set_key_material(priv,
  1259. key_type,
  1260. key_info,
  1261. params->key, params->key_len);
  1262. break;
  1263. default:
  1264. wiphy_err(wiphy, "unhandled cipher 0x%x\n", params->cipher);
  1265. ret = -ENOTSUPP;
  1266. break;
  1267. }
  1268. return ret;
  1269. }
  1270. static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
  1271. u8 key_index, bool pairwise, const u8 *mac_addr)
  1272. {
  1273. lbs_deb_enter(LBS_DEB_CFG80211);
  1274. lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
  1275. key_index, mac_addr);
  1276. #ifdef TODO
  1277. struct lbs_private *priv = wiphy_priv(wiphy);
  1278. /*
  1279. * I think can keep this a NO-OP, because:
  1280. * - we clear all keys whenever we do lbs_cfg_connect() anyway
  1281. * - neither "iw" nor "wpa_supplicant" won't call this during
  1282. * an ongoing connection
  1283. * - TODO: but I have to check if this is still true when
  1284. * I set the AP to periodic re-keying
  1285. * - we've not kzallec() something when we've added a key at
  1286. * lbs_cfg_connect() or lbs_cfg_add_key().
  1287. *
  1288. * This causes lbs_cfg_del_key() only called at disconnect time,
  1289. * where we'd just waste time deleting a key that is not going
  1290. * to be used anyway.
  1291. */
  1292. if (key_index < 3 && priv->wep_key_len[key_index]) {
  1293. priv->wep_key_len[key_index] = 0;
  1294. lbs_set_wep_keys(priv);
  1295. }
  1296. #endif
  1297. return 0;
  1298. }
  1299. /*
  1300. * Get station
  1301. */
  1302. static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
  1303. u8 *mac, struct station_info *sinfo)
  1304. {
  1305. struct lbs_private *priv = wiphy_priv(wiphy);
  1306. s8 signal, noise;
  1307. int ret;
  1308. size_t i;
  1309. lbs_deb_enter(LBS_DEB_CFG80211);
  1310. sinfo->filled |= STATION_INFO_TX_BYTES |
  1311. STATION_INFO_TX_PACKETS |
  1312. STATION_INFO_RX_BYTES |
  1313. STATION_INFO_RX_PACKETS;
  1314. sinfo->tx_bytes = priv->dev->stats.tx_bytes;
  1315. sinfo->tx_packets = priv->dev->stats.tx_packets;
  1316. sinfo->rx_bytes = priv->dev->stats.rx_bytes;
  1317. sinfo->rx_packets = priv->dev->stats.rx_packets;
  1318. /* Get current RSSI */
  1319. ret = lbs_get_rssi(priv, &signal, &noise);
  1320. if (ret == 0) {
  1321. sinfo->signal = signal;
  1322. sinfo->filled |= STATION_INFO_SIGNAL;
  1323. }
  1324. /* Convert priv->cur_rate from hw_value to NL80211 value */
  1325. for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
  1326. if (priv->cur_rate == lbs_rates[i].hw_value) {
  1327. sinfo->txrate.legacy = lbs_rates[i].bitrate;
  1328. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1329. break;
  1330. }
  1331. }
  1332. return 0;
  1333. }
  1334. /*
  1335. * "Site survey", here just current channel and noise level
  1336. */
  1337. static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
  1338. int idx, struct survey_info *survey)
  1339. {
  1340. struct lbs_private *priv = wiphy_priv(wiphy);
  1341. s8 signal, noise;
  1342. int ret;
  1343. if (idx != 0)
  1344. ret = -ENOENT;
  1345. lbs_deb_enter(LBS_DEB_CFG80211);
  1346. survey->channel = ieee80211_get_channel(wiphy,
  1347. ieee80211_channel_to_frequency(priv->channel,
  1348. IEEE80211_BAND_2GHZ));
  1349. ret = lbs_get_rssi(priv, &signal, &noise);
  1350. if (ret == 0) {
  1351. survey->filled = SURVEY_INFO_NOISE_DBM;
  1352. survey->noise = noise;
  1353. }
  1354. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1355. return ret;
  1356. }
  1357. /*
  1358. * Change interface
  1359. */
  1360. static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
  1361. enum nl80211_iftype type, u32 *flags,
  1362. struct vif_params *params)
  1363. {
  1364. struct lbs_private *priv = wiphy_priv(wiphy);
  1365. int ret = 0;
  1366. lbs_deb_enter(LBS_DEB_CFG80211);
  1367. switch (type) {
  1368. case NL80211_IFTYPE_MONITOR:
  1369. ret = lbs_set_monitor_mode(priv, 1);
  1370. break;
  1371. case NL80211_IFTYPE_STATION:
  1372. if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
  1373. ret = lbs_set_monitor_mode(priv, 0);
  1374. if (!ret)
  1375. ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
  1376. break;
  1377. case NL80211_IFTYPE_ADHOC:
  1378. if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
  1379. ret = lbs_set_monitor_mode(priv, 0);
  1380. if (!ret)
  1381. ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
  1382. break;
  1383. default:
  1384. ret = -ENOTSUPP;
  1385. }
  1386. if (!ret)
  1387. priv->wdev->iftype = type;
  1388. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1389. return ret;
  1390. }
  1391. /*
  1392. * IBSS (Ad-Hoc)
  1393. */
  1394. /*
  1395. * The firmware needs the following bits masked out of the beacon-derived
  1396. * capability field when associating/joining to a BSS:
  1397. * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
  1398. */
  1399. #define CAPINFO_MASK (~(0xda00))
  1400. static void lbs_join_post(struct lbs_private *priv,
  1401. struct cfg80211_ibss_params *params,
  1402. u8 *bssid, u16 capability)
  1403. {
  1404. u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
  1405. 2 + 4 + /* basic rates */
  1406. 2 + 1 + /* DS parameter */
  1407. 2 + 2 + /* atim */
  1408. 2 + 8]; /* extended rates */
  1409. u8 *fake = fake_ie;
  1410. lbs_deb_enter(LBS_DEB_CFG80211);
  1411. /*
  1412. * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
  1413. * the real IE from the firmware. So we fabricate a fake IE based on
  1414. * what the firmware actually sends (sniffed with wireshark).
  1415. */
  1416. /* Fake SSID IE */
  1417. *fake++ = WLAN_EID_SSID;
  1418. *fake++ = params->ssid_len;
  1419. memcpy(fake, params->ssid, params->ssid_len);
  1420. fake += params->ssid_len;
  1421. /* Fake supported basic rates IE */
  1422. *fake++ = WLAN_EID_SUPP_RATES;
  1423. *fake++ = 4;
  1424. *fake++ = 0x82;
  1425. *fake++ = 0x84;
  1426. *fake++ = 0x8b;
  1427. *fake++ = 0x96;
  1428. /* Fake DS channel IE */
  1429. *fake++ = WLAN_EID_DS_PARAMS;
  1430. *fake++ = 1;
  1431. *fake++ = params->channel->hw_value;
  1432. /* Fake IBSS params IE */
  1433. *fake++ = WLAN_EID_IBSS_PARAMS;
  1434. *fake++ = 2;
  1435. *fake++ = 0; /* ATIM=0 */
  1436. *fake++ = 0;
  1437. /* Fake extended rates IE, TODO: don't add this for 802.11b only,
  1438. * but I don't know how this could be checked */
  1439. *fake++ = WLAN_EID_EXT_SUPP_RATES;
  1440. *fake++ = 8;
  1441. *fake++ = 0x0c;
  1442. *fake++ = 0x12;
  1443. *fake++ = 0x18;
  1444. *fake++ = 0x24;
  1445. *fake++ = 0x30;
  1446. *fake++ = 0x48;
  1447. *fake++ = 0x60;
  1448. *fake++ = 0x6c;
  1449. lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
  1450. cfg80211_inform_bss(priv->wdev->wiphy,
  1451. params->channel,
  1452. bssid,
  1453. 0,
  1454. capability,
  1455. params->beacon_interval,
  1456. fake_ie, fake - fake_ie,
  1457. 0, GFP_KERNEL);
  1458. memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
  1459. priv->wdev->ssid_len = params->ssid_len;
  1460. cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
  1461. /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
  1462. priv->connect_status = LBS_CONNECTED;
  1463. netif_carrier_on(priv->dev);
  1464. if (!priv->tx_pending_len)
  1465. netif_wake_queue(priv->dev);
  1466. lbs_deb_leave(LBS_DEB_CFG80211);
  1467. }
  1468. static int lbs_ibss_join_existing(struct lbs_private *priv,
  1469. struct cfg80211_ibss_params *params,
  1470. struct cfg80211_bss *bss)
  1471. {
  1472. const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
  1473. struct cmd_ds_802_11_ad_hoc_join cmd;
  1474. u8 preamble = RADIO_PREAMBLE_SHORT;
  1475. int ret = 0;
  1476. lbs_deb_enter(LBS_DEB_CFG80211);
  1477. /* TODO: set preamble based on scan result */
  1478. ret = lbs_set_radio(priv, preamble, 1);
  1479. if (ret)
  1480. goto out;
  1481. /*
  1482. * Example CMD_802_11_AD_HOC_JOIN command:
  1483. *
  1484. * command 2c 00 CMD_802_11_AD_HOC_JOIN
  1485. * size 65 00
  1486. * sequence xx xx
  1487. * result 00 00
  1488. * bssid 02 27 27 97 2f 96
  1489. * ssid 49 42 53 53 00 00 00 00
  1490. * 00 00 00 00 00 00 00 00
  1491. * 00 00 00 00 00 00 00 00
  1492. * 00 00 00 00 00 00 00 00
  1493. * type 02 CMD_BSS_TYPE_IBSS
  1494. * beacon period 64 00
  1495. * dtim period 00
  1496. * timestamp 00 00 00 00 00 00 00 00
  1497. * localtime 00 00 00 00 00 00 00 00
  1498. * IE DS 03
  1499. * IE DS len 01
  1500. * IE DS channel 01
  1501. * reserveed 00 00 00 00
  1502. * IE IBSS 06
  1503. * IE IBSS len 02
  1504. * IE IBSS atim 00 00
  1505. * reserved 00 00 00 00
  1506. * capability 02 00
  1507. * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
  1508. * fail timeout ff 00
  1509. * probe delay 00 00
  1510. */
  1511. memset(&cmd, 0, sizeof(cmd));
  1512. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1513. memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
  1514. memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
  1515. cmd.bss.type = CMD_BSS_TYPE_IBSS;
  1516. cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
  1517. cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
  1518. cmd.bss.ds.header.len = 1;
  1519. cmd.bss.ds.channel = params->channel->hw_value;
  1520. cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
  1521. cmd.bss.ibss.header.len = 2;
  1522. cmd.bss.ibss.atimwindow = 0;
  1523. cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
  1524. /* set rates to the intersection of our rates and the rates in the
  1525. bss */
  1526. if (!rates_eid) {
  1527. lbs_add_rates(cmd.bss.rates);
  1528. } else {
  1529. int hw, i;
  1530. u8 rates_max = rates_eid[1];
  1531. u8 *rates = cmd.bss.rates;
  1532. for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
  1533. u8 hw_rate = lbs_rates[hw].bitrate / 5;
  1534. for (i = 0; i < rates_max; i++) {
  1535. if (hw_rate == (rates_eid[i+2] & 0x7f)) {
  1536. u8 rate = rates_eid[i+2];
  1537. if (rate == 0x02 || rate == 0x04 ||
  1538. rate == 0x0b || rate == 0x16)
  1539. rate |= 0x80;
  1540. *rates++ = rate;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. /* Only v8 and below support setting this */
  1546. if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
  1547. cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
  1548. cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
  1549. }
  1550. ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
  1551. if (ret)
  1552. goto out;
  1553. /*
  1554. * This is a sample response to CMD_802_11_AD_HOC_JOIN:
  1555. *
  1556. * response 2c 80
  1557. * size 09 00
  1558. * sequence xx xx
  1559. * result 00 00
  1560. * reserved 00
  1561. */
  1562. lbs_join_post(priv, params, bss->bssid, bss->capability);
  1563. out:
  1564. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1565. return ret;
  1566. }
  1567. static int lbs_ibss_start_new(struct lbs_private *priv,
  1568. struct cfg80211_ibss_params *params)
  1569. {
  1570. struct cmd_ds_802_11_ad_hoc_start cmd;
  1571. struct cmd_ds_802_11_ad_hoc_result *resp =
  1572. (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
  1573. u8 preamble = RADIO_PREAMBLE_SHORT;
  1574. int ret = 0;
  1575. u16 capability;
  1576. lbs_deb_enter(LBS_DEB_CFG80211);
  1577. ret = lbs_set_radio(priv, preamble, 1);
  1578. if (ret)
  1579. goto out;
  1580. /*
  1581. * Example CMD_802_11_AD_HOC_START command:
  1582. *
  1583. * command 2b 00 CMD_802_11_AD_HOC_START
  1584. * size b1 00
  1585. * sequence xx xx
  1586. * result 00 00
  1587. * ssid 54 45 53 54 00 00 00 00
  1588. * 00 00 00 00 00 00 00 00
  1589. * 00 00 00 00 00 00 00 00
  1590. * 00 00 00 00 00 00 00 00
  1591. * bss type 02
  1592. * beacon period 64 00
  1593. * dtim period 00
  1594. * IE IBSS 06
  1595. * IE IBSS len 02
  1596. * IE IBSS atim 00 00
  1597. * reserved 00 00 00 00
  1598. * IE DS 03
  1599. * IE DS len 01
  1600. * IE DS channel 01
  1601. * reserved 00 00 00 00
  1602. * probe delay 00 00
  1603. * capability 02 00
  1604. * rates 82 84 8b 96 (basic rates with have bit 7 set)
  1605. * 0c 12 18 24 30 48 60 6c
  1606. * padding 100 bytes
  1607. */
  1608. memset(&cmd, 0, sizeof(cmd));
  1609. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1610. memcpy(cmd.ssid, params->ssid, params->ssid_len);
  1611. cmd.bsstype = CMD_BSS_TYPE_IBSS;
  1612. cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
  1613. cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
  1614. cmd.ibss.header.len = 2;
  1615. cmd.ibss.atimwindow = 0;
  1616. cmd.ds.header.id = WLAN_EID_DS_PARAMS;
  1617. cmd.ds.header.len = 1;
  1618. cmd.ds.channel = params->channel->hw_value;
  1619. /* Only v8 and below support setting probe delay */
  1620. if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
  1621. cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
  1622. /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
  1623. capability = WLAN_CAPABILITY_IBSS;
  1624. cmd.capability = cpu_to_le16(capability);
  1625. lbs_add_rates(cmd.rates);
  1626. ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
  1627. if (ret)
  1628. goto out;
  1629. /*
  1630. * This is a sample response to CMD_802_11_AD_HOC_JOIN:
  1631. *
  1632. * response 2b 80
  1633. * size 14 00
  1634. * sequence xx xx
  1635. * result 00 00
  1636. * reserved 00
  1637. * bssid 02 2b 7b 0f 86 0e
  1638. */
  1639. lbs_join_post(priv, params, resp->bssid, capability);
  1640. out:
  1641. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1642. return ret;
  1643. }
  1644. static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1645. struct cfg80211_ibss_params *params)
  1646. {
  1647. struct lbs_private *priv = wiphy_priv(wiphy);
  1648. int ret = 0;
  1649. struct cfg80211_bss *bss;
  1650. DECLARE_SSID_BUF(ssid_buf);
  1651. lbs_deb_enter(LBS_DEB_CFG80211);
  1652. if (!params->channel) {
  1653. ret = -ENOTSUPP;
  1654. goto out;
  1655. }
  1656. ret = lbs_set_channel(priv, params->channel->hw_value);
  1657. if (ret)
  1658. goto out;
  1659. /* Search if someone is beaconing. This assumes that the
  1660. * bss list is populated already */
  1661. bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
  1662. params->ssid, params->ssid_len,
  1663. WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
  1664. if (bss) {
  1665. ret = lbs_ibss_join_existing(priv, params, bss);
  1666. cfg80211_put_bss(bss);
  1667. } else
  1668. ret = lbs_ibss_start_new(priv, params);
  1669. out:
  1670. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1671. return ret;
  1672. }
  1673. static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1674. {
  1675. struct lbs_private *priv = wiphy_priv(wiphy);
  1676. struct cmd_ds_802_11_ad_hoc_stop cmd;
  1677. int ret = 0;
  1678. lbs_deb_enter(LBS_DEB_CFG80211);
  1679. memset(&cmd, 0, sizeof(cmd));
  1680. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1681. ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
  1682. /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
  1683. lbs_mac_event_disconnected(priv);
  1684. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1685. return ret;
  1686. }
  1687. /*
  1688. * Initialization
  1689. */
  1690. static struct cfg80211_ops lbs_cfg80211_ops = {
  1691. .set_channel = lbs_cfg_set_channel,
  1692. .scan = lbs_cfg_scan,
  1693. .connect = lbs_cfg_connect,
  1694. .disconnect = lbs_cfg_disconnect,
  1695. .add_key = lbs_cfg_add_key,
  1696. .del_key = lbs_cfg_del_key,
  1697. .set_default_key = lbs_cfg_set_default_key,
  1698. .get_station = lbs_cfg_get_station,
  1699. .dump_survey = lbs_get_survey,
  1700. .change_virtual_intf = lbs_change_intf,
  1701. .join_ibss = lbs_join_ibss,
  1702. .leave_ibss = lbs_leave_ibss,
  1703. };
  1704. /*
  1705. * At this time lbs_private *priv doesn't even exist, so we just allocate
  1706. * memory and don't initialize the wiphy further. This is postponed until we
  1707. * can talk to the firmware and happens at registration time in
  1708. * lbs_cfg_wiphy_register().
  1709. */
  1710. struct wireless_dev *lbs_cfg_alloc(struct device *dev)
  1711. {
  1712. int ret = 0;
  1713. struct wireless_dev *wdev;
  1714. lbs_deb_enter(LBS_DEB_CFG80211);
  1715. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1716. if (!wdev) {
  1717. dev_err(dev, "cannot allocate wireless device\n");
  1718. return ERR_PTR(-ENOMEM);
  1719. }
  1720. wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
  1721. if (!wdev->wiphy) {
  1722. dev_err(dev, "cannot allocate wiphy\n");
  1723. ret = -ENOMEM;
  1724. goto err_wiphy_new;
  1725. }
  1726. lbs_deb_leave(LBS_DEB_CFG80211);
  1727. return wdev;
  1728. err_wiphy_new:
  1729. kfree(wdev);
  1730. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1731. return ERR_PTR(ret);
  1732. }
  1733. static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
  1734. {
  1735. struct region_code_mapping {
  1736. const char *cn;
  1737. int code;
  1738. };
  1739. /* Section 5.17.2 */
  1740. static const struct region_code_mapping regmap[] = {
  1741. {"US ", 0x10}, /* US FCC */
  1742. {"CA ", 0x20}, /* Canada */
  1743. {"EU ", 0x30}, /* ETSI */
  1744. {"ES ", 0x31}, /* Spain */
  1745. {"FR ", 0x32}, /* France */
  1746. {"JP ", 0x40}, /* Japan */
  1747. };
  1748. size_t i;
  1749. lbs_deb_enter(LBS_DEB_CFG80211);
  1750. for (i = 0; i < ARRAY_SIZE(regmap); i++)
  1751. if (regmap[i].code == priv->regioncode) {
  1752. regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
  1753. break;
  1754. }
  1755. lbs_deb_leave(LBS_DEB_CFG80211);
  1756. }
  1757. /*
  1758. * This function get's called after lbs_setup_firmware() determined the
  1759. * firmware capabities. So we can setup the wiphy according to our
  1760. * hardware/firmware.
  1761. */
  1762. int lbs_cfg_register(struct lbs_private *priv)
  1763. {
  1764. struct wireless_dev *wdev = priv->wdev;
  1765. int ret;
  1766. lbs_deb_enter(LBS_DEB_CFG80211);
  1767. wdev->wiphy->max_scan_ssids = 1;
  1768. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1769. wdev->wiphy->interface_modes =
  1770. BIT(NL80211_IFTYPE_STATION) |
  1771. BIT(NL80211_IFTYPE_ADHOC);
  1772. if (lbs_rtap_supported(priv))
  1773. wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  1774. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
  1775. /*
  1776. * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
  1777. * never seen a firmware without WPA
  1778. */
  1779. wdev->wiphy->cipher_suites = cipher_suites;
  1780. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  1781. wdev->wiphy->reg_notifier = lbs_reg_notifier;
  1782. ret = wiphy_register(wdev->wiphy);
  1783. if (ret < 0)
  1784. pr_err("cannot register wiphy device\n");
  1785. priv->wiphy_registered = true;
  1786. ret = register_netdev(priv->dev);
  1787. if (ret)
  1788. pr_err("cannot register network device\n");
  1789. INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
  1790. lbs_cfg_set_regulatory_hint(priv);
  1791. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  1792. return ret;
  1793. }
  1794. int lbs_reg_notifier(struct wiphy *wiphy,
  1795. struct regulatory_request *request)
  1796. {
  1797. struct lbs_private *priv = wiphy_priv(wiphy);
  1798. int ret;
  1799. lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
  1800. "callback for domain %c%c\n", request->alpha2[0],
  1801. request->alpha2[1]);
  1802. ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
  1803. lbs_deb_leave(LBS_DEB_CFG80211);
  1804. return ret;
  1805. }
  1806. void lbs_scan_deinit(struct lbs_private *priv)
  1807. {
  1808. lbs_deb_enter(LBS_DEB_CFG80211);
  1809. cancel_delayed_work_sync(&priv->scan_work);
  1810. }
  1811. void lbs_cfg_free(struct lbs_private *priv)
  1812. {
  1813. struct wireless_dev *wdev = priv->wdev;
  1814. lbs_deb_enter(LBS_DEB_CFG80211);
  1815. if (!wdev)
  1816. return;
  1817. if (priv->wiphy_registered)
  1818. wiphy_unregister(wdev->wiphy);
  1819. if (wdev->wiphy)
  1820. wiphy_free(wdev->wiphy);
  1821. kfree(wdev);
  1822. }