cfg80211.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "cfg80211.h"
  18. #include "debug.h"
  19. #include "hif-ops.h"
  20. #include "testmode.h"
  21. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  22. .bitrate = (_rate), \
  23. .flags = (_flags), \
  24. .hw_value = (_rateid), \
  25. }
  26. #define CHAN2G(_channel, _freq, _flags) { \
  27. .band = IEEE80211_BAND_2GHZ, \
  28. .hw_value = (_channel), \
  29. .center_freq = (_freq), \
  30. .flags = (_flags), \
  31. .max_antenna_gain = 0, \
  32. .max_power = 30, \
  33. }
  34. #define CHAN5G(_channel, _flags) { \
  35. .band = IEEE80211_BAND_5GHZ, \
  36. .hw_value = (_channel), \
  37. .center_freq = 5000 + (5 * (_channel)), \
  38. .flags = (_flags), \
  39. .max_antenna_gain = 0, \
  40. .max_power = 30, \
  41. }
  42. static struct ieee80211_rate ath6kl_rates[] = {
  43. RATETAB_ENT(10, 0x1, 0),
  44. RATETAB_ENT(20, 0x2, 0),
  45. RATETAB_ENT(55, 0x4, 0),
  46. RATETAB_ENT(110, 0x8, 0),
  47. RATETAB_ENT(60, 0x10, 0),
  48. RATETAB_ENT(90, 0x20, 0),
  49. RATETAB_ENT(120, 0x40, 0),
  50. RATETAB_ENT(180, 0x80, 0),
  51. RATETAB_ENT(240, 0x100, 0),
  52. RATETAB_ENT(360, 0x200, 0),
  53. RATETAB_ENT(480, 0x400, 0),
  54. RATETAB_ENT(540, 0x800, 0),
  55. };
  56. #define ath6kl_a_rates (ath6kl_rates + 4)
  57. #define ath6kl_a_rates_size 8
  58. #define ath6kl_g_rates (ath6kl_rates + 0)
  59. #define ath6kl_g_rates_size 12
  60. static struct ieee80211_channel ath6kl_2ghz_channels[] = {
  61. CHAN2G(1, 2412, 0),
  62. CHAN2G(2, 2417, 0),
  63. CHAN2G(3, 2422, 0),
  64. CHAN2G(4, 2427, 0),
  65. CHAN2G(5, 2432, 0),
  66. CHAN2G(6, 2437, 0),
  67. CHAN2G(7, 2442, 0),
  68. CHAN2G(8, 2447, 0),
  69. CHAN2G(9, 2452, 0),
  70. CHAN2G(10, 2457, 0),
  71. CHAN2G(11, 2462, 0),
  72. CHAN2G(12, 2467, 0),
  73. CHAN2G(13, 2472, 0),
  74. CHAN2G(14, 2484, 0),
  75. };
  76. static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
  77. CHAN5G(34, 0), CHAN5G(36, 0),
  78. CHAN5G(38, 0), CHAN5G(40, 0),
  79. CHAN5G(42, 0), CHAN5G(44, 0),
  80. CHAN5G(46, 0), CHAN5G(48, 0),
  81. CHAN5G(52, 0), CHAN5G(56, 0),
  82. CHAN5G(60, 0), CHAN5G(64, 0),
  83. CHAN5G(100, 0), CHAN5G(104, 0),
  84. CHAN5G(108, 0), CHAN5G(112, 0),
  85. CHAN5G(116, 0), CHAN5G(120, 0),
  86. CHAN5G(124, 0), CHAN5G(128, 0),
  87. CHAN5G(132, 0), CHAN5G(136, 0),
  88. CHAN5G(140, 0), CHAN5G(149, 0),
  89. CHAN5G(153, 0), CHAN5G(157, 0),
  90. CHAN5G(161, 0), CHAN5G(165, 0),
  91. CHAN5G(184, 0), CHAN5G(188, 0),
  92. CHAN5G(192, 0), CHAN5G(196, 0),
  93. CHAN5G(200, 0), CHAN5G(204, 0),
  94. CHAN5G(208, 0), CHAN5G(212, 0),
  95. CHAN5G(216, 0),
  96. };
  97. static struct ieee80211_supported_band ath6kl_band_2ghz = {
  98. .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
  99. .channels = ath6kl_2ghz_channels,
  100. .n_bitrates = ath6kl_g_rates_size,
  101. .bitrates = ath6kl_g_rates,
  102. };
  103. static struct ieee80211_supported_band ath6kl_band_5ghz = {
  104. .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
  105. .channels = ath6kl_5ghz_a_channels,
  106. .n_bitrates = ath6kl_a_rates_size,
  107. .bitrates = ath6kl_a_rates,
  108. };
  109. static int ath6kl_set_wpa_version(struct ath6kl *ar,
  110. enum nl80211_wpa_versions wpa_version)
  111. {
  112. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
  113. if (!wpa_version) {
  114. ar->auth_mode = NONE_AUTH;
  115. } else if (wpa_version & NL80211_WPA_VERSION_2) {
  116. ar->auth_mode = WPA2_AUTH;
  117. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  118. ar->auth_mode = WPA_AUTH;
  119. } else {
  120. ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
  121. return -ENOTSUPP;
  122. }
  123. return 0;
  124. }
  125. static int ath6kl_set_auth_type(struct ath6kl *ar,
  126. enum nl80211_auth_type auth_type)
  127. {
  128. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
  129. switch (auth_type) {
  130. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  131. ar->dot11_auth_mode = OPEN_AUTH;
  132. break;
  133. case NL80211_AUTHTYPE_SHARED_KEY:
  134. ar->dot11_auth_mode = SHARED_AUTH;
  135. break;
  136. case NL80211_AUTHTYPE_NETWORK_EAP:
  137. ar->dot11_auth_mode = LEAP_AUTH;
  138. break;
  139. case NL80211_AUTHTYPE_AUTOMATIC:
  140. ar->dot11_auth_mode = OPEN_AUTH;
  141. ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS;
  142. break;
  143. default:
  144. ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
  145. return -ENOTSUPP;
  146. }
  147. return 0;
  148. }
  149. static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
  150. {
  151. u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
  152. u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len :
  153. &ar->grp_crypto_len;
  154. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
  155. __func__, cipher, ucast);
  156. switch (cipher) {
  157. case 0:
  158. /* our own hack to use value 0 as no crypto used */
  159. *ar_cipher = NONE_CRYPT;
  160. *ar_cipher_len = 0;
  161. break;
  162. case WLAN_CIPHER_SUITE_WEP40:
  163. *ar_cipher = WEP_CRYPT;
  164. *ar_cipher_len = 5;
  165. break;
  166. case WLAN_CIPHER_SUITE_WEP104:
  167. *ar_cipher = WEP_CRYPT;
  168. *ar_cipher_len = 13;
  169. break;
  170. case WLAN_CIPHER_SUITE_TKIP:
  171. *ar_cipher = TKIP_CRYPT;
  172. *ar_cipher_len = 0;
  173. break;
  174. case WLAN_CIPHER_SUITE_CCMP:
  175. *ar_cipher = AES_CRYPT;
  176. *ar_cipher_len = 0;
  177. break;
  178. default:
  179. ath6kl_err("cipher 0x%x not supported\n", cipher);
  180. return -ENOTSUPP;
  181. }
  182. return 0;
  183. }
  184. static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
  185. {
  186. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
  187. if (key_mgmt == WLAN_AKM_SUITE_PSK) {
  188. if (ar->auth_mode == WPA_AUTH)
  189. ar->auth_mode = WPA_PSK_AUTH;
  190. else if (ar->auth_mode == WPA2_AUTH)
  191. ar->auth_mode = WPA2_PSK_AUTH;
  192. } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
  193. ar->auth_mode = NONE_AUTH;
  194. }
  195. }
  196. static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
  197. {
  198. if (!test_bit(WMI_READY, &ar->flag)) {
  199. ath6kl_err("wmi is not ready\n");
  200. return false;
  201. }
  202. if (!test_bit(WLAN_ENABLED, &ar->flag)) {
  203. ath6kl_err("wlan disabled\n");
  204. return false;
  205. }
  206. return true;
  207. }
  208. static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  209. struct cfg80211_connect_params *sme)
  210. {
  211. struct ath6kl *ar = ath6kl_priv(dev);
  212. int status;
  213. ar->sme_state = SME_CONNECTING;
  214. if (!ath6kl_cfg80211_ready(ar))
  215. return -EIO;
  216. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  217. ath6kl_err("destroy in progress\n");
  218. return -EBUSY;
  219. }
  220. if (test_bit(SKIP_SCAN, &ar->flag) &&
  221. ((sme->channel && sme->channel->center_freq == 0) ||
  222. (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
  223. ath6kl_err("SkipScan: channel or bssid invalid\n");
  224. return -EINVAL;
  225. }
  226. if (down_interruptible(&ar->sem)) {
  227. ath6kl_err("busy, couldn't get access\n");
  228. return -ERESTARTSYS;
  229. }
  230. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  231. ath6kl_err("busy, destroy in progress\n");
  232. up(&ar->sem);
  233. return -EBUSY;
  234. }
  235. if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
  236. /*
  237. * sleep until the command queue drains
  238. */
  239. wait_event_interruptible_timeout(ar->event_wq,
  240. ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
  241. WMI_TIMEOUT);
  242. if (signal_pending(current)) {
  243. ath6kl_err("cmd queue drain timeout\n");
  244. up(&ar->sem);
  245. return -EINTR;
  246. }
  247. }
  248. if (test_bit(CONNECTED, &ar->flag) &&
  249. ar->ssid_len == sme->ssid_len &&
  250. !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
  251. ar->reconnect_flag = true;
  252. status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
  253. ar->ch_hint);
  254. up(&ar->sem);
  255. if (status) {
  256. ath6kl_err("wmi_reconnect_cmd failed\n");
  257. return -EIO;
  258. }
  259. return 0;
  260. } else if (ar->ssid_len == sme->ssid_len &&
  261. !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
  262. ath6kl_disconnect(ar);
  263. }
  264. memset(ar->ssid, 0, sizeof(ar->ssid));
  265. ar->ssid_len = sme->ssid_len;
  266. memcpy(ar->ssid, sme->ssid, sme->ssid_len);
  267. if (sme->channel)
  268. ar->ch_hint = sme->channel->center_freq;
  269. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  270. if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
  271. memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
  272. ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
  273. status = ath6kl_set_auth_type(ar, sme->auth_type);
  274. if (status) {
  275. up(&ar->sem);
  276. return status;
  277. }
  278. if (sme->crypto.n_ciphers_pairwise)
  279. ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
  280. else
  281. ath6kl_set_cipher(ar, 0, true);
  282. ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
  283. if (sme->crypto.n_akm_suites)
  284. ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
  285. if ((sme->key_len) &&
  286. (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
  287. struct ath6kl_key *key = NULL;
  288. if (sme->key_idx < WMI_MIN_KEY_INDEX ||
  289. sme->key_idx > WMI_MAX_KEY_INDEX) {
  290. ath6kl_err("key index %d out of bounds\n",
  291. sme->key_idx);
  292. up(&ar->sem);
  293. return -ENOENT;
  294. }
  295. key = &ar->keys[sme->key_idx];
  296. key->key_len = sme->key_len;
  297. memcpy(key->key, sme->key, key->key_len);
  298. key->cipher = ar->prwise_crypto;
  299. ar->def_txkey_index = sme->key_idx;
  300. ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
  301. ar->prwise_crypto,
  302. GROUP_USAGE | TX_USAGE,
  303. key->key_len,
  304. NULL,
  305. key->key, KEY_OP_INIT_VAL, NULL,
  306. NO_SYNC_WMIFLAG);
  307. }
  308. if (!ar->usr_bss_filter) {
  309. if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
  310. ath6kl_err("couldn't set bss filtering\n");
  311. up(&ar->sem);
  312. return -EIO;
  313. }
  314. }
  315. ar->nw_type = ar->next_mode;
  316. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  317. "%s: connect called with authmode %d dot11 auth %d"
  318. " PW crypto %d PW crypto len %d GRP crypto %d"
  319. " GRP crypto len %d channel hint %u\n",
  320. __func__,
  321. ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
  322. ar->prwise_crypto_len, ar->grp_crypto,
  323. ar->grp_crypto_len, ar->ch_hint);
  324. ar->reconnect_flag = 0;
  325. status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
  326. ar->dot11_auth_mode, ar->auth_mode,
  327. ar->prwise_crypto,
  328. ar->prwise_crypto_len,
  329. ar->grp_crypto, ar->grp_crypto_len,
  330. ar->ssid_len, ar->ssid,
  331. ar->req_bssid, ar->ch_hint,
  332. ar->connect_ctrl_flags);
  333. up(&ar->sem);
  334. if (status == -EINVAL) {
  335. memset(ar->ssid, 0, sizeof(ar->ssid));
  336. ar->ssid_len = 0;
  337. ath6kl_err("invalid request\n");
  338. return -ENOENT;
  339. } else if (status) {
  340. ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
  341. return -EIO;
  342. }
  343. if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
  344. ((ar->auth_mode == WPA_PSK_AUTH)
  345. || (ar->auth_mode == WPA2_PSK_AUTH))) {
  346. mod_timer(&ar->disconnect_timer,
  347. jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
  348. }
  349. ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
  350. set_bit(CONNECT_PEND, &ar->flag);
  351. return 0;
  352. }
  353. void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
  354. u8 *bssid, u16 listen_intvl,
  355. u16 beacon_intvl,
  356. enum network_type nw_type,
  357. u8 beacon_ie_len, u8 assoc_req_len,
  358. u8 assoc_resp_len, u8 *assoc_info)
  359. {
  360. u16 size = 0;
  361. u16 capability = 0;
  362. struct cfg80211_bss *bss = NULL;
  363. struct ieee80211_mgmt *mgmt = NULL;
  364. struct ieee80211_channel *ibss_ch = NULL;
  365. s32 signal = 50 * 100;
  366. u8 ie_buf_len = 0;
  367. unsigned char ie_buf[256];
  368. unsigned char *ptr_ie_buf = ie_buf;
  369. unsigned char *ieeemgmtbuf = NULL;
  370. u8 source_mac[ETH_ALEN];
  371. /* capinfo + listen interval */
  372. u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
  373. /* capinfo + status code + associd */
  374. u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
  375. u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
  376. u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
  377. assoc_resp_ie_offset;
  378. assoc_req_len -= assoc_req_ie_offset;
  379. assoc_resp_len -= assoc_resp_ie_offset;
  380. ar->auto_auth_stage = AUTH_IDLE;
  381. if (nw_type & ADHOC_NETWORK) {
  382. if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
  383. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  384. "%s: ath6k not in ibss mode\n", __func__);
  385. return;
  386. }
  387. }
  388. if (nw_type & INFRA_NETWORK) {
  389. if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
  390. ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
  391. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  392. "%s: ath6k not in station mode\n", __func__);
  393. return;
  394. }
  395. }
  396. /*
  397. * Earlier we were updating the cfg about bss by making a beacon frame
  398. * only if the entry for bss is not there. This can have some issue if
  399. * ROAM event is generated and a heavy traffic is ongoing. The ROAM
  400. * event is handled through a work queue and by the time it really gets
  401. * handled, BSS would have been aged out. So it is better to update the
  402. * cfg about BSS irrespective of its entry being present right now or
  403. * not.
  404. */
  405. if (nw_type & ADHOC_NETWORK) {
  406. /* construct 802.11 mgmt beacon */
  407. if (ptr_ie_buf) {
  408. *ptr_ie_buf++ = WLAN_EID_SSID;
  409. *ptr_ie_buf++ = ar->ssid_len;
  410. memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
  411. ptr_ie_buf += ar->ssid_len;
  412. *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
  413. *ptr_ie_buf++ = 2; /* length */
  414. *ptr_ie_buf++ = 0; /* ATIM window */
  415. *ptr_ie_buf++ = 0; /* ATIM window */
  416. /* TODO: update ibss params and include supported rates,
  417. * DS param set, extened support rates, wmm. */
  418. ie_buf_len = ptr_ie_buf - ie_buf;
  419. }
  420. capability |= WLAN_CAPABILITY_IBSS;
  421. if (ar->prwise_crypto == WEP_CRYPT)
  422. capability |= WLAN_CAPABILITY_PRIVACY;
  423. memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
  424. ptr_ie_buf = ie_buf;
  425. } else {
  426. capability = *(u16 *) (&assoc_info[beacon_ie_len]);
  427. memcpy(source_mac, bssid, ETH_ALEN);
  428. ptr_ie_buf = assoc_req_ie;
  429. ie_buf_len = assoc_req_len;
  430. }
  431. size = offsetof(struct ieee80211_mgmt, u)
  432. + sizeof(mgmt->u.beacon)
  433. + ie_buf_len;
  434. ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
  435. if (!ieeemgmtbuf) {
  436. ath6kl_err("ieee mgmt buf alloc error\n");
  437. return;
  438. }
  439. mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
  440. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  441. IEEE80211_STYPE_BEACON);
  442. memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
  443. memcpy(mgmt->sa, source_mac, ETH_ALEN);
  444. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  445. mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
  446. mgmt->u.beacon.capab_info = cpu_to_le16(capability);
  447. memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
  448. ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
  449. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  450. "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
  451. __func__, mgmt->bssid, ibss_ch->hw_value,
  452. beacon_intvl, capability);
  453. bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
  454. ibss_ch, mgmt,
  455. size, signal, GFP_KERNEL);
  456. kfree(ieeemgmtbuf);
  457. cfg80211_put_bss(bss);
  458. if (nw_type & ADHOC_NETWORK) {
  459. cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
  460. return;
  461. }
  462. if (ar->sme_state == SME_CONNECTING) {
  463. /* inform connect result to cfg80211 */
  464. ar->sme_state = SME_CONNECTED;
  465. cfg80211_connect_result(ar->net_dev, bssid,
  466. assoc_req_ie, assoc_req_len,
  467. assoc_resp_ie, assoc_resp_len,
  468. WLAN_STATUS_SUCCESS, GFP_KERNEL);
  469. } else if (ar->sme_state == SME_CONNECTED) {
  470. /* inform roam event to cfg80211 */
  471. cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
  472. assoc_req_ie, assoc_req_len,
  473. assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
  474. }
  475. }
  476. static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
  477. struct net_device *dev, u16 reason_code)
  478. {
  479. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  480. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
  481. reason_code);
  482. if (!ath6kl_cfg80211_ready(ar))
  483. return -EIO;
  484. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  485. ath6kl_err("busy, destroy in progress\n");
  486. return -EBUSY;
  487. }
  488. if (down_interruptible(&ar->sem)) {
  489. ath6kl_err("busy, couldn't get access\n");
  490. return -ERESTARTSYS;
  491. }
  492. ar->reconnect_flag = 0;
  493. ath6kl_disconnect(ar);
  494. memset(ar->ssid, 0, sizeof(ar->ssid));
  495. ar->ssid_len = 0;
  496. if (!test_bit(SKIP_SCAN, &ar->flag))
  497. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  498. up(&ar->sem);
  499. return 0;
  500. }
  501. void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
  502. u8 *bssid, u8 assoc_resp_len,
  503. u8 *assoc_info, u16 proto_reason)
  504. {
  505. struct ath6kl_key *key = NULL;
  506. u16 status;
  507. if (ar->scan_req) {
  508. cfg80211_scan_done(ar->scan_req, true);
  509. ar->scan_req = NULL;
  510. }
  511. if (ar->nw_type & ADHOC_NETWORK) {
  512. if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
  513. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  514. "%s: ath6k not in ibss mode\n", __func__);
  515. return;
  516. }
  517. memset(bssid, 0, ETH_ALEN);
  518. cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
  519. return;
  520. }
  521. if (ar->nw_type & INFRA_NETWORK) {
  522. if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
  523. ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
  524. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  525. "%s: ath6k not in station mode\n", __func__);
  526. return;
  527. }
  528. }
  529. if (!test_bit(CONNECT_PEND, &ar->flag)) {
  530. if (reason != DISCONNECT_CMD)
  531. ath6kl_wmi_disconnect_cmd(ar->wmi);
  532. return;
  533. }
  534. if (reason == NO_NETWORK_AVAIL) {
  535. /* connect cmd failed */
  536. ath6kl_wmi_disconnect_cmd(ar->wmi);
  537. return;
  538. }
  539. if (reason != DISCONNECT_CMD)
  540. return;
  541. if (!ar->auto_auth_stage) {
  542. clear_bit(CONNECT_PEND, &ar->flag);
  543. if (ar->sme_state == SME_CONNECTING) {
  544. cfg80211_connect_result(ar->net_dev,
  545. bssid, NULL, 0,
  546. NULL, 0,
  547. WLAN_STATUS_UNSPECIFIED_FAILURE,
  548. GFP_KERNEL);
  549. } else if (ar->sme_state == SME_CONNECTED) {
  550. cfg80211_disconnected(ar->net_dev, reason,
  551. NULL, 0, GFP_KERNEL);
  552. }
  553. ar->sme_state = SME_DISCONNECTED;
  554. return;
  555. }
  556. if (ar->dot11_auth_mode != OPEN_AUTH)
  557. return;
  558. /*
  559. * If the current auth algorithm is open, try shared and
  560. * make autoAuthStage idle. We do not make it leap for now
  561. * being.
  562. */
  563. key = &ar->keys[ar->def_txkey_index];
  564. if (down_interruptible(&ar->sem)) {
  565. ath6kl_err("busy, couldn't get access\n");
  566. return;
  567. }
  568. ar->dot11_auth_mode = SHARED_AUTH;
  569. ar->auto_auth_stage = AUTH_IDLE;
  570. ath6kl_wmi_addkey_cmd(ar->wmi,
  571. ar->def_txkey_index,
  572. ar->prwise_crypto,
  573. GROUP_USAGE | TX_USAGE,
  574. key->key_len, NULL,
  575. key->key,
  576. KEY_OP_INIT_VAL, NULL,
  577. NO_SYNC_WMIFLAG);
  578. status = ath6kl_wmi_connect_cmd(ar->wmi,
  579. ar->nw_type,
  580. ar->dot11_auth_mode,
  581. ar->auth_mode,
  582. ar->prwise_crypto,
  583. ar->prwise_crypto_len,
  584. ar->grp_crypto,
  585. ar->grp_crypto_len,
  586. ar->ssid_len,
  587. ar->ssid,
  588. ar->req_bssid,
  589. ar->ch_hint,
  590. ar->connect_ctrl_flags);
  591. up(&ar->sem);
  592. }
  593. static inline bool is_ch_11a(u16 ch)
  594. {
  595. return (!((ch >= 2412) && (ch <= 2484)));
  596. }
  597. /* struct ath6kl_node_table::nt_nodelock is locked when calling this */
  598. void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
  599. {
  600. struct ieee80211_mgmt *mgmt;
  601. struct ieee80211_channel *channel;
  602. struct ieee80211_supported_band *band;
  603. struct ath6kl_common_ie *cie;
  604. s32 signal;
  605. int freq;
  606. cie = &ni->ni_cie;
  607. if (is_ch_11a(cie->ie_chan))
  608. band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
  609. else if ((cie->ie_erp) || (cie->ie_xrates))
  610. band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
  611. else
  612. band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
  613. freq = cie->ie_chan;
  614. channel = ieee80211_get_channel(wiphy, freq);
  615. signal = ni->ni_snr * 100;
  616. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  617. "%s: bssid %pM ch %d freq %d size %d\n", __func__,
  618. ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
  619. /*
  620. * Both Beacon and Probe Response frames have same payload structure,
  621. * so it is fine to share the parser for both.
  622. */
  623. if (ni->ni_framelen < 8 + 2 + 2)
  624. return;
  625. mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
  626. offsetof(struct ieee80211_mgmt, u));
  627. cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
  628. le64_to_cpu(mgmt->u.beacon.timestamp),
  629. le16_to_cpu(mgmt->u.beacon.capab_info),
  630. le16_to_cpu(mgmt->u.beacon.beacon_int),
  631. mgmt->u.beacon.variable,
  632. ni->ni_buf + ni->ni_framelen -
  633. mgmt->u.beacon.variable,
  634. signal, GFP_ATOMIC);
  635. }
  636. static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  637. struct cfg80211_scan_request *request)
  638. {
  639. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  640. s8 n_channels = 0;
  641. u16 *channels = NULL;
  642. int ret = 0;
  643. if (!ath6kl_cfg80211_ready(ar))
  644. return -EIO;
  645. if (!ar->usr_bss_filter) {
  646. ret = ath6kl_wmi_bssfilter_cmd(
  647. ar->wmi,
  648. (test_bit(CONNECTED, &ar->flag) ?
  649. ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
  650. if (ret) {
  651. ath6kl_err("couldn't set bss filtering\n");
  652. return ret;
  653. }
  654. }
  655. if (request->n_ssids && request->ssids[0].ssid_len) {
  656. u8 i;
  657. if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
  658. request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
  659. for (i = 0; i < request->n_ssids; i++)
  660. ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
  661. SPECIFIC_SSID_FLAG,
  662. request->ssids[i].ssid_len,
  663. request->ssids[i].ssid);
  664. }
  665. if (request->ie) {
  666. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
  667. request->ie, request->ie_len);
  668. if (ret) {
  669. ath6kl_err("failed to set Probe Request appie for "
  670. "scan");
  671. return ret;
  672. }
  673. }
  674. if (request->n_channels > 0) {
  675. u8 i;
  676. n_channels = min(127U, request->n_channels);
  677. channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
  678. if (channels == NULL) {
  679. ath6kl_warn("failed to set scan channels, "
  680. "scan all channels");
  681. n_channels = 0;
  682. }
  683. for (i = 0; i < n_channels; i++)
  684. channels[i] = request->channels[i]->center_freq;
  685. }
  686. ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
  687. false, 0, 0, n_channels, channels);
  688. if (ret)
  689. ath6kl_err("wmi_startscan_cmd failed\n");
  690. ar->scan_req = request;
  691. kfree(channels);
  692. return ret;
  693. }
  694. void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
  695. {
  696. int i;
  697. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
  698. if (!ar->scan_req)
  699. return;
  700. if ((status == -ECANCELED) || (status == -EBUSY)) {
  701. cfg80211_scan_done(ar->scan_req, true);
  702. goto out;
  703. }
  704. /* Translate data to cfg80211 mgmt format */
  705. wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
  706. cfg80211_scan_done(ar->scan_req, false);
  707. if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
  708. for (i = 0; i < ar->scan_req->n_ssids; i++) {
  709. ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
  710. DISABLE_SSID_FLAG,
  711. 0, NULL);
  712. }
  713. }
  714. out:
  715. ar->scan_req = NULL;
  716. }
  717. static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  718. u8 key_index, bool pairwise,
  719. const u8 *mac_addr,
  720. struct key_params *params)
  721. {
  722. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  723. struct ath6kl_key *key = NULL;
  724. u8 key_usage;
  725. u8 key_type;
  726. int status = 0;
  727. if (!ath6kl_cfg80211_ready(ar))
  728. return -EIO;
  729. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  730. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  731. "%s: key index %d out of bounds\n", __func__,
  732. key_index);
  733. return -ENOENT;
  734. }
  735. key = &ar->keys[key_index];
  736. memset(key, 0, sizeof(struct ath6kl_key));
  737. if (pairwise)
  738. key_usage = PAIRWISE_USAGE;
  739. else
  740. key_usage = GROUP_USAGE;
  741. if (params) {
  742. if (params->key_len > WLAN_MAX_KEY_LEN ||
  743. params->seq_len > sizeof(key->seq))
  744. return -EINVAL;
  745. key->key_len = params->key_len;
  746. memcpy(key->key, params->key, key->key_len);
  747. key->seq_len = params->seq_len;
  748. memcpy(key->seq, params->seq, key->seq_len);
  749. key->cipher = params->cipher;
  750. }
  751. switch (key->cipher) {
  752. case WLAN_CIPHER_SUITE_WEP40:
  753. case WLAN_CIPHER_SUITE_WEP104:
  754. key_type = WEP_CRYPT;
  755. break;
  756. case WLAN_CIPHER_SUITE_TKIP:
  757. key_type = TKIP_CRYPT;
  758. break;
  759. case WLAN_CIPHER_SUITE_CCMP:
  760. key_type = AES_CRYPT;
  761. break;
  762. default:
  763. return -ENOTSUPP;
  764. }
  765. if (((ar->auth_mode == WPA_PSK_AUTH)
  766. || (ar->auth_mode == WPA2_PSK_AUTH))
  767. && (key_usage & GROUP_USAGE))
  768. del_timer(&ar->disconnect_timer);
  769. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  770. "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
  771. __func__, key_index, key->key_len, key_type,
  772. key_usage, key->seq_len);
  773. ar->def_txkey_index = key_index;
  774. if (ar->nw_type == AP_NETWORK && !pairwise &&
  775. (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
  776. ar->ap_mode_bkey.valid = true;
  777. ar->ap_mode_bkey.key_index = key_index;
  778. ar->ap_mode_bkey.key_type = key_type;
  779. ar->ap_mode_bkey.key_len = key->key_len;
  780. memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
  781. if (!test_bit(CONNECTED, &ar->flag)) {
  782. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
  783. "key configuration until AP mode has been "
  784. "started\n");
  785. /*
  786. * The key will be set in ath6kl_connect_ap_mode() once
  787. * the connected event is received from the target.
  788. */
  789. return 0;
  790. }
  791. }
  792. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  793. key_type, key_usage, key->key_len,
  794. key->seq, key->key, KEY_OP_INIT_VAL,
  795. (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
  796. if (status)
  797. return -EIO;
  798. return 0;
  799. }
  800. static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  801. u8 key_index, bool pairwise,
  802. const u8 *mac_addr)
  803. {
  804. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  805. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  806. if (!ath6kl_cfg80211_ready(ar))
  807. return -EIO;
  808. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  809. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  810. "%s: key index %d out of bounds\n", __func__,
  811. key_index);
  812. return -ENOENT;
  813. }
  814. if (!ar->keys[key_index].key_len) {
  815. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  816. "%s: index %d is empty\n", __func__, key_index);
  817. return 0;
  818. }
  819. ar->keys[key_index].key_len = 0;
  820. return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
  821. }
  822. static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  823. u8 key_index, bool pairwise,
  824. const u8 *mac_addr, void *cookie,
  825. void (*callback) (void *cookie,
  826. struct key_params *))
  827. {
  828. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  829. struct ath6kl_key *key = NULL;
  830. struct key_params params;
  831. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  832. if (!ath6kl_cfg80211_ready(ar))
  833. return -EIO;
  834. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  835. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  836. "%s: key index %d out of bounds\n", __func__,
  837. key_index);
  838. return -ENOENT;
  839. }
  840. key = &ar->keys[key_index];
  841. memset(&params, 0, sizeof(params));
  842. params.cipher = key->cipher;
  843. params.key_len = key->key_len;
  844. params.seq_len = key->seq_len;
  845. params.seq = key->seq;
  846. params.key = key->key;
  847. callback(cookie, &params);
  848. return key->key_len ? 0 : -ENOENT;
  849. }
  850. static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
  851. struct net_device *ndev,
  852. u8 key_index, bool unicast,
  853. bool multicast)
  854. {
  855. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  856. struct ath6kl_key *key = NULL;
  857. int status = 0;
  858. u8 key_usage;
  859. enum crypto_type key_type = NONE_CRYPT;
  860. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  861. if (!ath6kl_cfg80211_ready(ar))
  862. return -EIO;
  863. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  864. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  865. "%s: key index %d out of bounds\n",
  866. __func__, key_index);
  867. return -ENOENT;
  868. }
  869. if (!ar->keys[key_index].key_len) {
  870. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
  871. __func__, key_index);
  872. return -EINVAL;
  873. }
  874. ar->def_txkey_index = key_index;
  875. key = &ar->keys[ar->def_txkey_index];
  876. key_usage = GROUP_USAGE;
  877. if (ar->prwise_crypto == WEP_CRYPT)
  878. key_usage |= TX_USAGE;
  879. if (unicast)
  880. key_type = ar->prwise_crypto;
  881. if (multicast)
  882. key_type = ar->grp_crypto;
  883. if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
  884. return 0; /* Delay until AP mode has been started */
  885. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  886. key_type, key_usage,
  887. key->key_len, key->seq, key->key,
  888. KEY_OP_INIT_VAL, NULL,
  889. SYNC_BOTH_WMIFLAG);
  890. if (status)
  891. return -EIO;
  892. return 0;
  893. }
  894. void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
  895. bool ismcast)
  896. {
  897. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  898. "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
  899. cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
  900. (ismcast ? NL80211_KEYTYPE_GROUP :
  901. NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
  902. GFP_KERNEL);
  903. }
  904. static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  905. {
  906. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  907. int ret;
  908. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
  909. changed);
  910. if (!ath6kl_cfg80211_ready(ar))
  911. return -EIO;
  912. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  913. ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
  914. if (ret != 0) {
  915. ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
  916. return -EIO;
  917. }
  918. }
  919. return 0;
  920. }
  921. /*
  922. * The type nl80211_tx_power_setting replaces the following
  923. * data type from 2.6.36 onwards
  924. */
  925. static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
  926. enum nl80211_tx_power_setting type,
  927. int dbm)
  928. {
  929. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  930. u8 ath6kl_dbm;
  931. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
  932. type, dbm);
  933. if (!ath6kl_cfg80211_ready(ar))
  934. return -EIO;
  935. switch (type) {
  936. case NL80211_TX_POWER_AUTOMATIC:
  937. return 0;
  938. case NL80211_TX_POWER_LIMITED:
  939. ar->tx_pwr = ath6kl_dbm = dbm;
  940. break;
  941. default:
  942. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
  943. __func__, type);
  944. return -EOPNOTSUPP;
  945. }
  946. ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
  947. return 0;
  948. }
  949. static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  950. {
  951. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  952. if (!ath6kl_cfg80211_ready(ar))
  953. return -EIO;
  954. if (test_bit(CONNECTED, &ar->flag)) {
  955. ar->tx_pwr = 0;
  956. if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
  957. ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
  958. return -EIO;
  959. }
  960. wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
  961. 5 * HZ);
  962. if (signal_pending(current)) {
  963. ath6kl_err("target did not respond\n");
  964. return -EINTR;
  965. }
  966. }
  967. *dbm = ar->tx_pwr;
  968. return 0;
  969. }
  970. static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  971. struct net_device *dev,
  972. bool pmgmt, int timeout)
  973. {
  974. struct ath6kl *ar = ath6kl_priv(dev);
  975. struct wmi_power_mode_cmd mode;
  976. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
  977. __func__, pmgmt, timeout);
  978. if (!ath6kl_cfg80211_ready(ar))
  979. return -EIO;
  980. if (pmgmt) {
  981. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
  982. mode.pwr_mode = REC_POWER;
  983. } else {
  984. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
  985. mode.pwr_mode = MAX_PERF_POWER;
  986. }
  987. if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
  988. ath6kl_err("wmi_powermode_cmd failed\n");
  989. return -EIO;
  990. }
  991. return 0;
  992. }
  993. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  994. struct net_device *ndev,
  995. enum nl80211_iftype type, u32 *flags,
  996. struct vif_params *params)
  997. {
  998. struct ath6kl *ar = ath6kl_priv(ndev);
  999. struct wireless_dev *wdev = ar->wdev;
  1000. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  1001. if (!ath6kl_cfg80211_ready(ar))
  1002. return -EIO;
  1003. switch (type) {
  1004. case NL80211_IFTYPE_STATION:
  1005. ar->next_mode = INFRA_NETWORK;
  1006. break;
  1007. case NL80211_IFTYPE_ADHOC:
  1008. ar->next_mode = ADHOC_NETWORK;
  1009. break;
  1010. case NL80211_IFTYPE_P2P_CLIENT:
  1011. ar->next_mode = INFRA_NETWORK;
  1012. break;
  1013. case NL80211_IFTYPE_P2P_GO:
  1014. ar->next_mode = AP_NETWORK;
  1015. break;
  1016. default:
  1017. ath6kl_err("invalid interface type %u\n", type);
  1018. return -EOPNOTSUPP;
  1019. }
  1020. wdev->iftype = type;
  1021. return 0;
  1022. }
  1023. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  1024. struct net_device *dev,
  1025. struct cfg80211_ibss_params *ibss_param)
  1026. {
  1027. struct ath6kl *ar = ath6kl_priv(dev);
  1028. int status;
  1029. if (!ath6kl_cfg80211_ready(ar))
  1030. return -EIO;
  1031. ar->ssid_len = ibss_param->ssid_len;
  1032. memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
  1033. if (ibss_param->channel)
  1034. ar->ch_hint = ibss_param->channel->center_freq;
  1035. if (ibss_param->channel_fixed) {
  1036. /*
  1037. * TODO: channel_fixed: The channel should be fixed, do not
  1038. * search for IBSSs to join on other channels. Target
  1039. * firmware does not support this feature, needs to be
  1040. * updated.
  1041. */
  1042. return -EOPNOTSUPP;
  1043. }
  1044. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  1045. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1046. memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
  1047. ath6kl_set_wpa_version(ar, 0);
  1048. status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1049. if (status)
  1050. return status;
  1051. if (ibss_param->privacy) {
  1052. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
  1053. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
  1054. } else {
  1055. ath6kl_set_cipher(ar, 0, true);
  1056. ath6kl_set_cipher(ar, 0, false);
  1057. }
  1058. ar->nw_type = ar->next_mode;
  1059. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1060. "%s: connect called with authmode %d dot11 auth %d"
  1061. " PW crypto %d PW crypto len %d GRP crypto %d"
  1062. " GRP crypto len %d channel hint %u\n",
  1063. __func__,
  1064. ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
  1065. ar->prwise_crypto_len, ar->grp_crypto,
  1066. ar->grp_crypto_len, ar->ch_hint);
  1067. status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
  1068. ar->dot11_auth_mode, ar->auth_mode,
  1069. ar->prwise_crypto,
  1070. ar->prwise_crypto_len,
  1071. ar->grp_crypto, ar->grp_crypto_len,
  1072. ar->ssid_len, ar->ssid,
  1073. ar->req_bssid, ar->ch_hint,
  1074. ar->connect_ctrl_flags);
  1075. set_bit(CONNECT_PEND, &ar->flag);
  1076. return 0;
  1077. }
  1078. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1079. struct net_device *dev)
  1080. {
  1081. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  1082. if (!ath6kl_cfg80211_ready(ar))
  1083. return -EIO;
  1084. ath6kl_disconnect(ar);
  1085. memset(ar->ssid, 0, sizeof(ar->ssid));
  1086. ar->ssid_len = 0;
  1087. return 0;
  1088. }
  1089. static const u32 cipher_suites[] = {
  1090. WLAN_CIPHER_SUITE_WEP40,
  1091. WLAN_CIPHER_SUITE_WEP104,
  1092. WLAN_CIPHER_SUITE_TKIP,
  1093. WLAN_CIPHER_SUITE_CCMP,
  1094. };
  1095. static bool is_rate_legacy(s32 rate)
  1096. {
  1097. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1098. 6000, 9000, 12000, 18000, 24000,
  1099. 36000, 48000, 54000
  1100. };
  1101. u8 i;
  1102. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1103. if (rate == legacy[i])
  1104. return true;
  1105. return false;
  1106. }
  1107. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1108. {
  1109. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1110. 52000, 58500, 65000, 72200
  1111. };
  1112. u8 i;
  1113. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1114. if (rate == ht20[i]) {
  1115. if (i == ARRAY_SIZE(ht20) - 1)
  1116. /* last rate uses sgi */
  1117. *sgi = true;
  1118. else
  1119. *sgi = false;
  1120. *mcs = i;
  1121. return true;
  1122. }
  1123. }
  1124. return false;
  1125. }
  1126. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1127. {
  1128. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1129. 81000, 108000, 121500, 135000,
  1130. 150000
  1131. };
  1132. u8 i;
  1133. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1134. if (rate == ht40[i]) {
  1135. if (i == ARRAY_SIZE(ht40) - 1)
  1136. /* last rate uses sgi */
  1137. *sgi = true;
  1138. else
  1139. *sgi = false;
  1140. *mcs = i;
  1141. return true;
  1142. }
  1143. }
  1144. return false;
  1145. }
  1146. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1147. u8 *mac, struct station_info *sinfo)
  1148. {
  1149. struct ath6kl *ar = ath6kl_priv(dev);
  1150. long left;
  1151. bool sgi;
  1152. s32 rate;
  1153. int ret;
  1154. u8 mcs;
  1155. if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
  1156. return -ENOENT;
  1157. if (down_interruptible(&ar->sem))
  1158. return -EBUSY;
  1159. set_bit(STATS_UPDATE_PEND, &ar->flag);
  1160. ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
  1161. if (ret != 0) {
  1162. up(&ar->sem);
  1163. return -EIO;
  1164. }
  1165. left = wait_event_interruptible_timeout(ar->event_wq,
  1166. !test_bit(STATS_UPDATE_PEND,
  1167. &ar->flag),
  1168. WMI_TIMEOUT);
  1169. up(&ar->sem);
  1170. if (left == 0)
  1171. return -ETIMEDOUT;
  1172. else if (left < 0)
  1173. return left;
  1174. if (ar->target_stats.rx_byte) {
  1175. sinfo->rx_bytes = ar->target_stats.rx_byte;
  1176. sinfo->filled |= STATION_INFO_RX_BYTES;
  1177. sinfo->rx_packets = ar->target_stats.rx_pkt;
  1178. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1179. }
  1180. if (ar->target_stats.tx_byte) {
  1181. sinfo->tx_bytes = ar->target_stats.tx_byte;
  1182. sinfo->filled |= STATION_INFO_TX_BYTES;
  1183. sinfo->tx_packets = ar->target_stats.tx_pkt;
  1184. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1185. }
  1186. sinfo->signal = ar->target_stats.cs_rssi;
  1187. sinfo->filled |= STATION_INFO_SIGNAL;
  1188. rate = ar->target_stats.tx_ucast_rate;
  1189. if (is_rate_legacy(rate)) {
  1190. sinfo->txrate.legacy = rate / 100;
  1191. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1192. if (sgi) {
  1193. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1194. sinfo->txrate.mcs = mcs - 1;
  1195. } else {
  1196. sinfo->txrate.mcs = mcs;
  1197. }
  1198. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1199. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1200. if (sgi) {
  1201. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1202. sinfo->txrate.mcs = mcs - 1;
  1203. } else {
  1204. sinfo->txrate.mcs = mcs;
  1205. }
  1206. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1207. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1208. } else {
  1209. ath6kl_warn("invalid rate: %d\n", rate);
  1210. return 0;
  1211. }
  1212. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1213. return 0;
  1214. }
  1215. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1216. struct cfg80211_pmksa *pmksa)
  1217. {
  1218. struct ath6kl *ar = ath6kl_priv(netdev);
  1219. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1220. pmksa->pmkid, true);
  1221. }
  1222. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1223. struct cfg80211_pmksa *pmksa)
  1224. {
  1225. struct ath6kl *ar = ath6kl_priv(netdev);
  1226. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1227. pmksa->pmkid, false);
  1228. }
  1229. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1230. {
  1231. struct ath6kl *ar = ath6kl_priv(netdev);
  1232. if (test_bit(CONNECTED, &ar->flag))
  1233. return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
  1234. return 0;
  1235. }
  1236. #ifdef CONFIG_PM
  1237. static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
  1238. struct cfg80211_wowlan *wow)
  1239. {
  1240. struct ath6kl *ar = wiphy_priv(wiphy);
  1241. return ath6kl_hif_suspend(ar);
  1242. }
  1243. #endif
  1244. static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
  1245. struct ieee80211_channel *chan,
  1246. enum nl80211_channel_type channel_type)
  1247. {
  1248. struct ath6kl *ar = ath6kl_priv(dev);
  1249. if (!ath6kl_cfg80211_ready(ar))
  1250. return -EIO;
  1251. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
  1252. __func__, chan->center_freq, chan->hw_value);
  1253. ar->next_chan = chan->center_freq;
  1254. return 0;
  1255. }
  1256. static bool ath6kl_is_p2p_ie(const u8 *pos)
  1257. {
  1258. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1259. pos[2] == 0x50 && pos[3] == 0x6f &&
  1260. pos[4] == 0x9a && pos[5] == 0x09;
  1261. }
  1262. static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
  1263. size_t ies_len)
  1264. {
  1265. const u8 *pos;
  1266. u8 *buf = NULL;
  1267. size_t len = 0;
  1268. int ret;
  1269. /*
  1270. * Filter out P2P IE(s) since they will be included depending on
  1271. * the Probe Request frame in ath6kl_send_go_probe_resp().
  1272. */
  1273. if (ies && ies_len) {
  1274. buf = kmalloc(ies_len, GFP_KERNEL);
  1275. if (buf == NULL)
  1276. return -ENOMEM;
  1277. pos = ies;
  1278. while (pos + 1 < ies + ies_len) {
  1279. if (pos + 2 + pos[1] > ies + ies_len)
  1280. break;
  1281. if (!ath6kl_is_p2p_ie(pos)) {
  1282. memcpy(buf + len, pos, 2 + pos[1]);
  1283. len += 2 + pos[1];
  1284. }
  1285. pos += 2 + pos[1];
  1286. }
  1287. }
  1288. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
  1289. buf, len);
  1290. kfree(buf);
  1291. return ret;
  1292. }
  1293. static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
  1294. struct beacon_parameters *info, bool add)
  1295. {
  1296. struct ath6kl *ar = ath6kl_priv(dev);
  1297. struct ieee80211_mgmt *mgmt;
  1298. u8 *ies;
  1299. int ies_len;
  1300. struct wmi_connect_cmd p;
  1301. int res;
  1302. int i;
  1303. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
  1304. if (!ath6kl_cfg80211_ready(ar))
  1305. return -EIO;
  1306. if (ar->next_mode != AP_NETWORK)
  1307. return -EOPNOTSUPP;
  1308. if (info->beacon_ies) {
  1309. res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
  1310. info->beacon_ies,
  1311. info->beacon_ies_len);
  1312. if (res)
  1313. return res;
  1314. }
  1315. if (info->proberesp_ies) {
  1316. res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
  1317. info->proberesp_ies_len);
  1318. if (res)
  1319. return res;
  1320. }
  1321. if (info->assocresp_ies) {
  1322. res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
  1323. info->assocresp_ies,
  1324. info->assocresp_ies_len);
  1325. if (res)
  1326. return res;
  1327. }
  1328. if (!add)
  1329. return 0;
  1330. ar->ap_mode_bkey.valid = false;
  1331. /* TODO:
  1332. * info->interval
  1333. * info->dtim_period
  1334. */
  1335. if (info->head == NULL)
  1336. return -EINVAL;
  1337. mgmt = (struct ieee80211_mgmt *) info->head;
  1338. ies = mgmt->u.beacon.variable;
  1339. if (ies > info->head + info->head_len)
  1340. return -EINVAL;
  1341. ies_len = info->head + info->head_len - ies;
  1342. if (info->ssid == NULL)
  1343. return -EINVAL;
  1344. memcpy(ar->ssid, info->ssid, info->ssid_len);
  1345. ar->ssid_len = info->ssid_len;
  1346. if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
  1347. return -EOPNOTSUPP; /* TODO */
  1348. ar->dot11_auth_mode = OPEN_AUTH;
  1349. memset(&p, 0, sizeof(p));
  1350. for (i = 0; i < info->crypto.n_akm_suites; i++) {
  1351. switch (info->crypto.akm_suites[i]) {
  1352. case WLAN_AKM_SUITE_8021X:
  1353. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1354. p.auth_mode |= WPA_AUTH;
  1355. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1356. p.auth_mode |= WPA2_AUTH;
  1357. break;
  1358. case WLAN_AKM_SUITE_PSK:
  1359. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1360. p.auth_mode |= WPA_PSK_AUTH;
  1361. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1362. p.auth_mode |= WPA2_PSK_AUTH;
  1363. break;
  1364. }
  1365. }
  1366. if (p.auth_mode == 0)
  1367. p.auth_mode = NONE_AUTH;
  1368. ar->auth_mode = p.auth_mode;
  1369. for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
  1370. switch (info->crypto.ciphers_pairwise[i]) {
  1371. case WLAN_CIPHER_SUITE_WEP40:
  1372. case WLAN_CIPHER_SUITE_WEP104:
  1373. p.prwise_crypto_type |= WEP_CRYPT;
  1374. break;
  1375. case WLAN_CIPHER_SUITE_TKIP:
  1376. p.prwise_crypto_type |= TKIP_CRYPT;
  1377. break;
  1378. case WLAN_CIPHER_SUITE_CCMP:
  1379. p.prwise_crypto_type |= AES_CRYPT;
  1380. break;
  1381. }
  1382. }
  1383. if (p.prwise_crypto_type == 0) {
  1384. p.prwise_crypto_type = NONE_CRYPT;
  1385. ath6kl_set_cipher(ar, 0, true);
  1386. } else if (info->crypto.n_ciphers_pairwise == 1)
  1387. ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
  1388. switch (info->crypto.cipher_group) {
  1389. case WLAN_CIPHER_SUITE_WEP40:
  1390. case WLAN_CIPHER_SUITE_WEP104:
  1391. p.grp_crypto_type = WEP_CRYPT;
  1392. break;
  1393. case WLAN_CIPHER_SUITE_TKIP:
  1394. p.grp_crypto_type = TKIP_CRYPT;
  1395. break;
  1396. case WLAN_CIPHER_SUITE_CCMP:
  1397. p.grp_crypto_type = AES_CRYPT;
  1398. break;
  1399. default:
  1400. p.grp_crypto_type = NONE_CRYPT;
  1401. break;
  1402. }
  1403. ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
  1404. p.nw_type = AP_NETWORK;
  1405. ar->nw_type = ar->next_mode;
  1406. p.ssid_len = ar->ssid_len;
  1407. memcpy(p.ssid, ar->ssid, ar->ssid_len);
  1408. p.dot11_auth_mode = ar->dot11_auth_mode;
  1409. p.ch = cpu_to_le16(ar->next_chan);
  1410. res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
  1411. if (res < 0)
  1412. return res;
  1413. return 0;
  1414. }
  1415. static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  1416. struct beacon_parameters *info)
  1417. {
  1418. return ath6kl_ap_beacon(wiphy, dev, info, true);
  1419. }
  1420. static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  1421. struct beacon_parameters *info)
  1422. {
  1423. return ath6kl_ap_beacon(wiphy, dev, info, false);
  1424. }
  1425. static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  1426. {
  1427. struct ath6kl *ar = ath6kl_priv(dev);
  1428. if (ar->nw_type != AP_NETWORK)
  1429. return -EOPNOTSUPP;
  1430. if (!test_bit(CONNECTED, &ar->flag))
  1431. return -ENOTCONN;
  1432. ath6kl_wmi_disconnect_cmd(ar->wmi);
  1433. clear_bit(CONNECTED, &ar->flag);
  1434. return 0;
  1435. }
  1436. static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
  1437. u8 *mac, struct station_parameters *params)
  1438. {
  1439. struct ath6kl *ar = ath6kl_priv(dev);
  1440. if (ar->nw_type != AP_NETWORK)
  1441. return -EOPNOTSUPP;
  1442. /* Use this only for authorizing/unauthorizing a station */
  1443. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  1444. return -EOPNOTSUPP;
  1445. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1446. return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
  1447. mac, 0);
  1448. return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
  1449. 0);
  1450. }
  1451. static int ath6kl_remain_on_channel(struct wiphy *wiphy,
  1452. struct net_device *dev,
  1453. struct ieee80211_channel *chan,
  1454. enum nl80211_channel_type channel_type,
  1455. unsigned int duration,
  1456. u64 *cookie)
  1457. {
  1458. struct ath6kl *ar = ath6kl_priv(dev);
  1459. /* TODO: if already pending or ongoing remain-on-channel,
  1460. * return -EBUSY */
  1461. *cookie = 1; /* only a single pending request is supported */
  1462. return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
  1463. duration);
  1464. }
  1465. static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
  1466. struct net_device *dev,
  1467. u64 cookie)
  1468. {
  1469. struct ath6kl *ar = ath6kl_priv(dev);
  1470. if (cookie != 1)
  1471. return -ENOENT;
  1472. return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
  1473. }
  1474. static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
  1475. size_t len, unsigned int freq)
  1476. {
  1477. const u8 *pos;
  1478. u8 *p2p;
  1479. int p2p_len;
  1480. int ret;
  1481. const struct ieee80211_mgmt *mgmt;
  1482. mgmt = (const struct ieee80211_mgmt *) buf;
  1483. /* Include P2P IE(s) from the frame generated in user space. */
  1484. p2p = kmalloc(len, GFP_KERNEL);
  1485. if (p2p == NULL)
  1486. return -ENOMEM;
  1487. p2p_len = 0;
  1488. pos = mgmt->u.probe_resp.variable;
  1489. while (pos + 1 < buf + len) {
  1490. if (pos + 2 + pos[1] > buf + len)
  1491. break;
  1492. if (ath6kl_is_p2p_ie(pos)) {
  1493. memcpy(p2p + p2p_len, pos, 2 + pos[1]);
  1494. p2p_len += 2 + pos[1];
  1495. }
  1496. pos += 2 + pos[1];
  1497. }
  1498. ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
  1499. p2p, p2p_len);
  1500. kfree(p2p);
  1501. return ret;
  1502. }
  1503. static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1504. struct ieee80211_channel *chan, bool offchan,
  1505. enum nl80211_channel_type channel_type,
  1506. bool channel_type_valid, unsigned int wait,
  1507. const u8 *buf, size_t len, u64 *cookie)
  1508. {
  1509. struct ath6kl *ar = ath6kl_priv(dev);
  1510. u32 id;
  1511. const struct ieee80211_mgmt *mgmt;
  1512. mgmt = (const struct ieee80211_mgmt *) buf;
  1513. if (buf + len >= mgmt->u.probe_resp.variable &&
  1514. ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
  1515. ieee80211_is_probe_resp(mgmt->frame_control)) {
  1516. /*
  1517. * Send Probe Response frame in AP mode using a separate WMI
  1518. * command to allow the target to fill in the generic IEs.
  1519. */
  1520. *cookie = 0; /* TX status not supported */
  1521. return ath6kl_send_go_probe_resp(ar, buf, len,
  1522. chan->center_freq);
  1523. }
  1524. id = ar->send_action_id++;
  1525. if (id == 0) {
  1526. /*
  1527. * 0 is a reserved value in the WMI command and shall not be
  1528. * used for the command.
  1529. */
  1530. id = ar->send_action_id++;
  1531. }
  1532. *cookie = id;
  1533. return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
  1534. buf, len);
  1535. }
  1536. static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
  1537. struct net_device *dev,
  1538. u16 frame_type, bool reg)
  1539. {
  1540. struct ath6kl *ar = ath6kl_priv(dev);
  1541. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
  1542. __func__, frame_type, reg);
  1543. if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
  1544. /*
  1545. * Note: This notification callback is not allowed to sleep, so
  1546. * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
  1547. * hardcode target to report Probe Request frames all the time.
  1548. */
  1549. ar->probe_req_report = reg;
  1550. }
  1551. }
  1552. static const struct ieee80211_txrx_stypes
  1553. ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1554. [NL80211_IFTYPE_STATION] = {
  1555. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1556. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1557. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1558. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1559. },
  1560. [NL80211_IFTYPE_P2P_CLIENT] = {
  1561. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1562. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1563. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1564. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1565. },
  1566. [NL80211_IFTYPE_P2P_GO] = {
  1567. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1568. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1569. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1570. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1571. },
  1572. };
  1573. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  1574. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  1575. .scan = ath6kl_cfg80211_scan,
  1576. .connect = ath6kl_cfg80211_connect,
  1577. .disconnect = ath6kl_cfg80211_disconnect,
  1578. .add_key = ath6kl_cfg80211_add_key,
  1579. .get_key = ath6kl_cfg80211_get_key,
  1580. .del_key = ath6kl_cfg80211_del_key,
  1581. .set_default_key = ath6kl_cfg80211_set_default_key,
  1582. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  1583. .set_tx_power = ath6kl_cfg80211_set_txpower,
  1584. .get_tx_power = ath6kl_cfg80211_get_txpower,
  1585. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  1586. .join_ibss = ath6kl_cfg80211_join_ibss,
  1587. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  1588. .get_station = ath6kl_get_station,
  1589. .set_pmksa = ath6kl_set_pmksa,
  1590. .del_pmksa = ath6kl_del_pmksa,
  1591. .flush_pmksa = ath6kl_flush_pmksa,
  1592. CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
  1593. #ifdef CONFIG_PM
  1594. .suspend = ar6k_cfg80211_suspend,
  1595. #endif
  1596. .set_channel = ath6kl_set_channel,
  1597. .add_beacon = ath6kl_add_beacon,
  1598. .set_beacon = ath6kl_set_beacon,
  1599. .del_beacon = ath6kl_del_beacon,
  1600. .change_station = ath6kl_change_station,
  1601. .remain_on_channel = ath6kl_remain_on_channel,
  1602. .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
  1603. .mgmt_tx = ath6kl_mgmt_tx,
  1604. .mgmt_frame_register = ath6kl_mgmt_frame_register,
  1605. };
  1606. struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
  1607. {
  1608. int ret = 0;
  1609. struct wireless_dev *wdev;
  1610. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1611. if (!wdev) {
  1612. ath6kl_err("couldn't allocate wireless device\n");
  1613. return NULL;
  1614. }
  1615. /* create a new wiphy for use with cfg80211 */
  1616. wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  1617. if (!wdev->wiphy) {
  1618. ath6kl_err("couldn't allocate wiphy device\n");
  1619. kfree(wdev);
  1620. return NULL;
  1621. }
  1622. wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
  1623. wdev->wiphy->max_remain_on_channel_duration = 5000;
  1624. /* set device pointer for wiphy */
  1625. set_wiphy_dev(wdev->wiphy, dev);
  1626. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1627. BIT(NL80211_IFTYPE_ADHOC);
  1628. /* max num of ssids that can be probed during scanning */
  1629. wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
  1630. wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
  1631. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  1632. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  1633. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1634. wdev->wiphy->cipher_suites = cipher_suites;
  1635. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  1636. ret = wiphy_register(wdev->wiphy);
  1637. if (ret < 0) {
  1638. ath6kl_err("couldn't register wiphy device\n");
  1639. wiphy_free(wdev->wiphy);
  1640. kfree(wdev);
  1641. return NULL;
  1642. }
  1643. return wdev;
  1644. }
  1645. void ath6kl_cfg80211_deinit(struct ath6kl *ar)
  1646. {
  1647. struct wireless_dev *wdev = ar->wdev;
  1648. if (ar->scan_req) {
  1649. cfg80211_scan_done(ar->scan_req, true);
  1650. ar->scan_req = NULL;
  1651. }
  1652. if (!wdev)
  1653. return;
  1654. wiphy_unregister(wdev->wiphy);
  1655. wiphy_free(wdev->wiphy);
  1656. kfree(wdev);
  1657. }