cfg.c 50 KB

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