cfg80211.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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. /*
  675. * Scan only the requested channels if the request specifies a set of
  676. * channels. If the list is longer than the target supports, do not
  677. * configure the list and instead, scan all available channels.
  678. */
  679. if (request->n_channels > 0 &&
  680. request->n_channels <= WMI_MAX_CHANNELS) {
  681. u8 i;
  682. n_channels = request->n_channels;
  683. channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
  684. if (channels == NULL) {
  685. ath6kl_warn("failed to set scan channels, "
  686. "scan all channels");
  687. n_channels = 0;
  688. }
  689. for (i = 0; i < n_channels; i++)
  690. channels[i] = request->channels[i]->center_freq;
  691. }
  692. ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
  693. false, 0, 0, n_channels, channels);
  694. if (ret)
  695. ath6kl_err("wmi_startscan_cmd failed\n");
  696. else
  697. ar->scan_req = request;
  698. kfree(channels);
  699. return ret;
  700. }
  701. void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
  702. {
  703. int i;
  704. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
  705. if (!ar->scan_req)
  706. return;
  707. if ((status == -ECANCELED) || (status == -EBUSY)) {
  708. cfg80211_scan_done(ar->scan_req, true);
  709. goto out;
  710. }
  711. /* Translate data to cfg80211 mgmt format */
  712. wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
  713. cfg80211_scan_done(ar->scan_req, false);
  714. if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
  715. for (i = 0; i < ar->scan_req->n_ssids; i++) {
  716. ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
  717. DISABLE_SSID_FLAG,
  718. 0, NULL);
  719. }
  720. }
  721. out:
  722. ar->scan_req = NULL;
  723. }
  724. static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  725. u8 key_index, bool pairwise,
  726. const u8 *mac_addr,
  727. struct key_params *params)
  728. {
  729. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  730. struct ath6kl_key *key = NULL;
  731. u8 key_usage;
  732. u8 key_type;
  733. int status = 0;
  734. if (!ath6kl_cfg80211_ready(ar))
  735. return -EIO;
  736. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  737. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  738. "%s: key index %d out of bounds\n", __func__,
  739. key_index);
  740. return -ENOENT;
  741. }
  742. key = &ar->keys[key_index];
  743. memset(key, 0, sizeof(struct ath6kl_key));
  744. if (pairwise)
  745. key_usage = PAIRWISE_USAGE;
  746. else
  747. key_usage = GROUP_USAGE;
  748. if (params) {
  749. if (params->key_len > WLAN_MAX_KEY_LEN ||
  750. params->seq_len > sizeof(key->seq))
  751. return -EINVAL;
  752. key->key_len = params->key_len;
  753. memcpy(key->key, params->key, key->key_len);
  754. key->seq_len = params->seq_len;
  755. memcpy(key->seq, params->seq, key->seq_len);
  756. key->cipher = params->cipher;
  757. }
  758. switch (key->cipher) {
  759. case WLAN_CIPHER_SUITE_WEP40:
  760. case WLAN_CIPHER_SUITE_WEP104:
  761. key_type = WEP_CRYPT;
  762. break;
  763. case WLAN_CIPHER_SUITE_TKIP:
  764. key_type = TKIP_CRYPT;
  765. break;
  766. case WLAN_CIPHER_SUITE_CCMP:
  767. key_type = AES_CRYPT;
  768. break;
  769. default:
  770. return -ENOTSUPP;
  771. }
  772. if (((ar->auth_mode == WPA_PSK_AUTH)
  773. || (ar->auth_mode == WPA2_PSK_AUTH))
  774. && (key_usage & GROUP_USAGE))
  775. del_timer(&ar->disconnect_timer);
  776. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  777. "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
  778. __func__, key_index, key->key_len, key_type,
  779. key_usage, key->seq_len);
  780. ar->def_txkey_index = key_index;
  781. if (ar->nw_type == AP_NETWORK && !pairwise &&
  782. (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
  783. ar->ap_mode_bkey.valid = true;
  784. ar->ap_mode_bkey.key_index = key_index;
  785. ar->ap_mode_bkey.key_type = key_type;
  786. ar->ap_mode_bkey.key_len = key->key_len;
  787. memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
  788. if (!test_bit(CONNECTED, &ar->flag)) {
  789. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
  790. "key configuration until AP mode has been "
  791. "started\n");
  792. /*
  793. * The key will be set in ath6kl_connect_ap_mode() once
  794. * the connected event is received from the target.
  795. */
  796. return 0;
  797. }
  798. }
  799. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  800. key_type, key_usage, key->key_len,
  801. key->seq, key->key, KEY_OP_INIT_VAL,
  802. (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
  803. if (status)
  804. return -EIO;
  805. return 0;
  806. }
  807. static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  808. u8 key_index, bool pairwise,
  809. const u8 *mac_addr)
  810. {
  811. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  812. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  813. if (!ath6kl_cfg80211_ready(ar))
  814. return -EIO;
  815. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  816. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  817. "%s: key index %d out of bounds\n", __func__,
  818. key_index);
  819. return -ENOENT;
  820. }
  821. if (!ar->keys[key_index].key_len) {
  822. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  823. "%s: index %d is empty\n", __func__, key_index);
  824. return 0;
  825. }
  826. ar->keys[key_index].key_len = 0;
  827. return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
  828. }
  829. static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  830. u8 key_index, bool pairwise,
  831. const u8 *mac_addr, void *cookie,
  832. void (*callback) (void *cookie,
  833. struct key_params *))
  834. {
  835. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  836. struct ath6kl_key *key = NULL;
  837. struct key_params params;
  838. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  839. if (!ath6kl_cfg80211_ready(ar))
  840. return -EIO;
  841. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  842. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  843. "%s: key index %d out of bounds\n", __func__,
  844. key_index);
  845. return -ENOENT;
  846. }
  847. key = &ar->keys[key_index];
  848. memset(&params, 0, sizeof(params));
  849. params.cipher = key->cipher;
  850. params.key_len = key->key_len;
  851. params.seq_len = key->seq_len;
  852. params.seq = key->seq;
  853. params.key = key->key;
  854. callback(cookie, &params);
  855. return key->key_len ? 0 : -ENOENT;
  856. }
  857. static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
  858. struct net_device *ndev,
  859. u8 key_index, bool unicast,
  860. bool multicast)
  861. {
  862. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  863. struct ath6kl_key *key = NULL;
  864. int status = 0;
  865. u8 key_usage;
  866. enum crypto_type key_type = NONE_CRYPT;
  867. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  868. if (!ath6kl_cfg80211_ready(ar))
  869. return -EIO;
  870. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  871. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  872. "%s: key index %d out of bounds\n",
  873. __func__, key_index);
  874. return -ENOENT;
  875. }
  876. if (!ar->keys[key_index].key_len) {
  877. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
  878. __func__, key_index);
  879. return -EINVAL;
  880. }
  881. ar->def_txkey_index = key_index;
  882. key = &ar->keys[ar->def_txkey_index];
  883. key_usage = GROUP_USAGE;
  884. if (ar->prwise_crypto == WEP_CRYPT)
  885. key_usage |= TX_USAGE;
  886. if (unicast)
  887. key_type = ar->prwise_crypto;
  888. if (multicast)
  889. key_type = ar->grp_crypto;
  890. if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
  891. return 0; /* Delay until AP mode has been started */
  892. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  893. key_type, key_usage,
  894. key->key_len, key->seq, key->key,
  895. KEY_OP_INIT_VAL, NULL,
  896. SYNC_BOTH_WMIFLAG);
  897. if (status)
  898. return -EIO;
  899. return 0;
  900. }
  901. void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
  902. bool ismcast)
  903. {
  904. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  905. "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
  906. cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
  907. (ismcast ? NL80211_KEYTYPE_GROUP :
  908. NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
  909. GFP_KERNEL);
  910. }
  911. static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  912. {
  913. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  914. int ret;
  915. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
  916. changed);
  917. if (!ath6kl_cfg80211_ready(ar))
  918. return -EIO;
  919. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  920. ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
  921. if (ret != 0) {
  922. ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
  923. return -EIO;
  924. }
  925. }
  926. return 0;
  927. }
  928. /*
  929. * The type nl80211_tx_power_setting replaces the following
  930. * data type from 2.6.36 onwards
  931. */
  932. static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
  933. enum nl80211_tx_power_setting type,
  934. int dbm)
  935. {
  936. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  937. u8 ath6kl_dbm;
  938. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
  939. type, dbm);
  940. if (!ath6kl_cfg80211_ready(ar))
  941. return -EIO;
  942. switch (type) {
  943. case NL80211_TX_POWER_AUTOMATIC:
  944. return 0;
  945. case NL80211_TX_POWER_LIMITED:
  946. ar->tx_pwr = ath6kl_dbm = dbm;
  947. break;
  948. default:
  949. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
  950. __func__, type);
  951. return -EOPNOTSUPP;
  952. }
  953. ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
  954. return 0;
  955. }
  956. static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  957. {
  958. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  959. if (!ath6kl_cfg80211_ready(ar))
  960. return -EIO;
  961. if (test_bit(CONNECTED, &ar->flag)) {
  962. ar->tx_pwr = 0;
  963. if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
  964. ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
  965. return -EIO;
  966. }
  967. wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
  968. 5 * HZ);
  969. if (signal_pending(current)) {
  970. ath6kl_err("target did not respond\n");
  971. return -EINTR;
  972. }
  973. }
  974. *dbm = ar->tx_pwr;
  975. return 0;
  976. }
  977. static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  978. struct net_device *dev,
  979. bool pmgmt, int timeout)
  980. {
  981. struct ath6kl *ar = ath6kl_priv(dev);
  982. struct wmi_power_mode_cmd mode;
  983. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
  984. __func__, pmgmt, timeout);
  985. if (!ath6kl_cfg80211_ready(ar))
  986. return -EIO;
  987. if (pmgmt) {
  988. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
  989. mode.pwr_mode = REC_POWER;
  990. } else {
  991. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
  992. mode.pwr_mode = MAX_PERF_POWER;
  993. }
  994. if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
  995. ath6kl_err("wmi_powermode_cmd failed\n");
  996. return -EIO;
  997. }
  998. return 0;
  999. }
  1000. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  1001. struct net_device *ndev,
  1002. enum nl80211_iftype type, u32 *flags,
  1003. struct vif_params *params)
  1004. {
  1005. struct ath6kl *ar = ath6kl_priv(ndev);
  1006. struct wireless_dev *wdev = ar->wdev;
  1007. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  1008. if (!ath6kl_cfg80211_ready(ar))
  1009. return -EIO;
  1010. switch (type) {
  1011. case NL80211_IFTYPE_STATION:
  1012. ar->next_mode = INFRA_NETWORK;
  1013. break;
  1014. case NL80211_IFTYPE_ADHOC:
  1015. ar->next_mode = ADHOC_NETWORK;
  1016. break;
  1017. case NL80211_IFTYPE_AP:
  1018. ar->next_mode = AP_NETWORK;
  1019. break;
  1020. case NL80211_IFTYPE_P2P_CLIENT:
  1021. ar->next_mode = INFRA_NETWORK;
  1022. break;
  1023. case NL80211_IFTYPE_P2P_GO:
  1024. ar->next_mode = AP_NETWORK;
  1025. break;
  1026. default:
  1027. ath6kl_err("invalid interface type %u\n", type);
  1028. return -EOPNOTSUPP;
  1029. }
  1030. wdev->iftype = type;
  1031. return 0;
  1032. }
  1033. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  1034. struct net_device *dev,
  1035. struct cfg80211_ibss_params *ibss_param)
  1036. {
  1037. struct ath6kl *ar = ath6kl_priv(dev);
  1038. int status;
  1039. if (!ath6kl_cfg80211_ready(ar))
  1040. return -EIO;
  1041. ar->ssid_len = ibss_param->ssid_len;
  1042. memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
  1043. if (ibss_param->channel)
  1044. ar->ch_hint = ibss_param->channel->center_freq;
  1045. if (ibss_param->channel_fixed) {
  1046. /*
  1047. * TODO: channel_fixed: The channel should be fixed, do not
  1048. * search for IBSSs to join on other channels. Target
  1049. * firmware does not support this feature, needs to be
  1050. * updated.
  1051. */
  1052. return -EOPNOTSUPP;
  1053. }
  1054. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  1055. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1056. memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
  1057. ath6kl_set_wpa_version(ar, 0);
  1058. status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1059. if (status)
  1060. return status;
  1061. if (ibss_param->privacy) {
  1062. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
  1063. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
  1064. } else {
  1065. ath6kl_set_cipher(ar, 0, true);
  1066. ath6kl_set_cipher(ar, 0, false);
  1067. }
  1068. ar->nw_type = ar->next_mode;
  1069. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1070. "%s: connect called with authmode %d dot11 auth %d"
  1071. " PW crypto %d PW crypto len %d GRP crypto %d"
  1072. " GRP crypto len %d channel hint %u\n",
  1073. __func__,
  1074. ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
  1075. ar->prwise_crypto_len, ar->grp_crypto,
  1076. ar->grp_crypto_len, ar->ch_hint);
  1077. status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
  1078. ar->dot11_auth_mode, ar->auth_mode,
  1079. ar->prwise_crypto,
  1080. ar->prwise_crypto_len,
  1081. ar->grp_crypto, ar->grp_crypto_len,
  1082. ar->ssid_len, ar->ssid,
  1083. ar->req_bssid, ar->ch_hint,
  1084. ar->connect_ctrl_flags);
  1085. set_bit(CONNECT_PEND, &ar->flag);
  1086. return 0;
  1087. }
  1088. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1089. struct net_device *dev)
  1090. {
  1091. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  1092. if (!ath6kl_cfg80211_ready(ar))
  1093. return -EIO;
  1094. ath6kl_disconnect(ar);
  1095. memset(ar->ssid, 0, sizeof(ar->ssid));
  1096. ar->ssid_len = 0;
  1097. return 0;
  1098. }
  1099. static const u32 cipher_suites[] = {
  1100. WLAN_CIPHER_SUITE_WEP40,
  1101. WLAN_CIPHER_SUITE_WEP104,
  1102. WLAN_CIPHER_SUITE_TKIP,
  1103. WLAN_CIPHER_SUITE_CCMP,
  1104. };
  1105. static bool is_rate_legacy(s32 rate)
  1106. {
  1107. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1108. 6000, 9000, 12000, 18000, 24000,
  1109. 36000, 48000, 54000
  1110. };
  1111. u8 i;
  1112. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1113. if (rate == legacy[i])
  1114. return true;
  1115. return false;
  1116. }
  1117. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1118. {
  1119. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1120. 52000, 58500, 65000, 72200
  1121. };
  1122. u8 i;
  1123. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1124. if (rate == ht20[i]) {
  1125. if (i == ARRAY_SIZE(ht20) - 1)
  1126. /* last rate uses sgi */
  1127. *sgi = true;
  1128. else
  1129. *sgi = false;
  1130. *mcs = i;
  1131. return true;
  1132. }
  1133. }
  1134. return false;
  1135. }
  1136. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1137. {
  1138. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1139. 81000, 108000, 121500, 135000,
  1140. 150000
  1141. };
  1142. u8 i;
  1143. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1144. if (rate == ht40[i]) {
  1145. if (i == ARRAY_SIZE(ht40) - 1)
  1146. /* last rate uses sgi */
  1147. *sgi = true;
  1148. else
  1149. *sgi = false;
  1150. *mcs = i;
  1151. return true;
  1152. }
  1153. }
  1154. return false;
  1155. }
  1156. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1157. u8 *mac, struct station_info *sinfo)
  1158. {
  1159. struct ath6kl *ar = ath6kl_priv(dev);
  1160. long left;
  1161. bool sgi;
  1162. s32 rate;
  1163. int ret;
  1164. u8 mcs;
  1165. if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
  1166. return -ENOENT;
  1167. if (down_interruptible(&ar->sem))
  1168. return -EBUSY;
  1169. set_bit(STATS_UPDATE_PEND, &ar->flag);
  1170. ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
  1171. if (ret != 0) {
  1172. up(&ar->sem);
  1173. return -EIO;
  1174. }
  1175. left = wait_event_interruptible_timeout(ar->event_wq,
  1176. !test_bit(STATS_UPDATE_PEND,
  1177. &ar->flag),
  1178. WMI_TIMEOUT);
  1179. up(&ar->sem);
  1180. if (left == 0)
  1181. return -ETIMEDOUT;
  1182. else if (left < 0)
  1183. return left;
  1184. if (ar->target_stats.rx_byte) {
  1185. sinfo->rx_bytes = ar->target_stats.rx_byte;
  1186. sinfo->filled |= STATION_INFO_RX_BYTES;
  1187. sinfo->rx_packets = ar->target_stats.rx_pkt;
  1188. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1189. }
  1190. if (ar->target_stats.tx_byte) {
  1191. sinfo->tx_bytes = ar->target_stats.tx_byte;
  1192. sinfo->filled |= STATION_INFO_TX_BYTES;
  1193. sinfo->tx_packets = ar->target_stats.tx_pkt;
  1194. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1195. }
  1196. sinfo->signal = ar->target_stats.cs_rssi;
  1197. sinfo->filled |= STATION_INFO_SIGNAL;
  1198. rate = ar->target_stats.tx_ucast_rate;
  1199. if (is_rate_legacy(rate)) {
  1200. sinfo->txrate.legacy = rate / 100;
  1201. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1202. if (sgi) {
  1203. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1204. sinfo->txrate.mcs = mcs - 1;
  1205. } else {
  1206. sinfo->txrate.mcs = mcs;
  1207. }
  1208. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1209. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1210. if (sgi) {
  1211. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1212. sinfo->txrate.mcs = mcs - 1;
  1213. } else {
  1214. sinfo->txrate.mcs = mcs;
  1215. }
  1216. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1217. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1218. } else {
  1219. ath6kl_warn("invalid rate: %d\n", rate);
  1220. return 0;
  1221. }
  1222. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1223. return 0;
  1224. }
  1225. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1226. struct cfg80211_pmksa *pmksa)
  1227. {
  1228. struct ath6kl *ar = ath6kl_priv(netdev);
  1229. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1230. pmksa->pmkid, true);
  1231. }
  1232. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1233. struct cfg80211_pmksa *pmksa)
  1234. {
  1235. struct ath6kl *ar = ath6kl_priv(netdev);
  1236. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1237. pmksa->pmkid, false);
  1238. }
  1239. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1240. {
  1241. struct ath6kl *ar = ath6kl_priv(netdev);
  1242. if (test_bit(CONNECTED, &ar->flag))
  1243. return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
  1244. return 0;
  1245. }
  1246. #ifdef CONFIG_PM
  1247. static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
  1248. struct cfg80211_wowlan *wow)
  1249. {
  1250. struct ath6kl *ar = wiphy_priv(wiphy);
  1251. return ath6kl_hif_suspend(ar);
  1252. }
  1253. #endif
  1254. static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
  1255. struct ieee80211_channel *chan,
  1256. enum nl80211_channel_type channel_type)
  1257. {
  1258. struct ath6kl *ar = ath6kl_priv(dev);
  1259. if (!ath6kl_cfg80211_ready(ar))
  1260. return -EIO;
  1261. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
  1262. __func__, chan->center_freq, chan->hw_value);
  1263. ar->next_chan = chan->center_freq;
  1264. return 0;
  1265. }
  1266. static bool ath6kl_is_p2p_ie(const u8 *pos)
  1267. {
  1268. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1269. pos[2] == 0x50 && pos[3] == 0x6f &&
  1270. pos[4] == 0x9a && pos[5] == 0x09;
  1271. }
  1272. static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
  1273. size_t ies_len)
  1274. {
  1275. const u8 *pos;
  1276. u8 *buf = NULL;
  1277. size_t len = 0;
  1278. int ret;
  1279. /*
  1280. * Filter out P2P IE(s) since they will be included depending on
  1281. * the Probe Request frame in ath6kl_send_go_probe_resp().
  1282. */
  1283. if (ies && ies_len) {
  1284. buf = kmalloc(ies_len, GFP_KERNEL);
  1285. if (buf == NULL)
  1286. return -ENOMEM;
  1287. pos = ies;
  1288. while (pos + 1 < ies + ies_len) {
  1289. if (pos + 2 + pos[1] > ies + ies_len)
  1290. break;
  1291. if (!ath6kl_is_p2p_ie(pos)) {
  1292. memcpy(buf + len, pos, 2 + pos[1]);
  1293. len += 2 + pos[1];
  1294. }
  1295. pos += 2 + pos[1];
  1296. }
  1297. }
  1298. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
  1299. buf, len);
  1300. kfree(buf);
  1301. return ret;
  1302. }
  1303. static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
  1304. struct beacon_parameters *info, bool add)
  1305. {
  1306. struct ath6kl *ar = ath6kl_priv(dev);
  1307. struct ieee80211_mgmt *mgmt;
  1308. u8 *ies;
  1309. int ies_len;
  1310. struct wmi_connect_cmd p;
  1311. int res;
  1312. int i;
  1313. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
  1314. if (!ath6kl_cfg80211_ready(ar))
  1315. return -EIO;
  1316. if (ar->next_mode != AP_NETWORK)
  1317. return -EOPNOTSUPP;
  1318. if (info->beacon_ies) {
  1319. res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
  1320. info->beacon_ies,
  1321. info->beacon_ies_len);
  1322. if (res)
  1323. return res;
  1324. }
  1325. if (info->proberesp_ies) {
  1326. res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
  1327. info->proberesp_ies_len);
  1328. if (res)
  1329. return res;
  1330. }
  1331. if (info->assocresp_ies) {
  1332. res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
  1333. info->assocresp_ies,
  1334. info->assocresp_ies_len);
  1335. if (res)
  1336. return res;
  1337. }
  1338. if (!add)
  1339. return 0;
  1340. ar->ap_mode_bkey.valid = false;
  1341. /* TODO:
  1342. * info->interval
  1343. * info->dtim_period
  1344. */
  1345. if (info->head == NULL)
  1346. return -EINVAL;
  1347. mgmt = (struct ieee80211_mgmt *) info->head;
  1348. ies = mgmt->u.beacon.variable;
  1349. if (ies > info->head + info->head_len)
  1350. return -EINVAL;
  1351. ies_len = info->head + info->head_len - ies;
  1352. if (info->ssid == NULL)
  1353. return -EINVAL;
  1354. memcpy(ar->ssid, info->ssid, info->ssid_len);
  1355. ar->ssid_len = info->ssid_len;
  1356. if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
  1357. return -EOPNOTSUPP; /* TODO */
  1358. ar->dot11_auth_mode = OPEN_AUTH;
  1359. memset(&p, 0, sizeof(p));
  1360. for (i = 0; i < info->crypto.n_akm_suites; i++) {
  1361. switch (info->crypto.akm_suites[i]) {
  1362. case WLAN_AKM_SUITE_8021X:
  1363. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1364. p.auth_mode |= WPA_AUTH;
  1365. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1366. p.auth_mode |= WPA2_AUTH;
  1367. break;
  1368. case WLAN_AKM_SUITE_PSK:
  1369. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1370. p.auth_mode |= WPA_PSK_AUTH;
  1371. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1372. p.auth_mode |= WPA2_PSK_AUTH;
  1373. break;
  1374. }
  1375. }
  1376. if (p.auth_mode == 0)
  1377. p.auth_mode = NONE_AUTH;
  1378. ar->auth_mode = p.auth_mode;
  1379. for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
  1380. switch (info->crypto.ciphers_pairwise[i]) {
  1381. case WLAN_CIPHER_SUITE_WEP40:
  1382. case WLAN_CIPHER_SUITE_WEP104:
  1383. p.prwise_crypto_type |= WEP_CRYPT;
  1384. break;
  1385. case WLAN_CIPHER_SUITE_TKIP:
  1386. p.prwise_crypto_type |= TKIP_CRYPT;
  1387. break;
  1388. case WLAN_CIPHER_SUITE_CCMP:
  1389. p.prwise_crypto_type |= AES_CRYPT;
  1390. break;
  1391. }
  1392. }
  1393. if (p.prwise_crypto_type == 0) {
  1394. p.prwise_crypto_type = NONE_CRYPT;
  1395. ath6kl_set_cipher(ar, 0, true);
  1396. } else if (info->crypto.n_ciphers_pairwise == 1)
  1397. ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
  1398. switch (info->crypto.cipher_group) {
  1399. case WLAN_CIPHER_SUITE_WEP40:
  1400. case WLAN_CIPHER_SUITE_WEP104:
  1401. p.grp_crypto_type = WEP_CRYPT;
  1402. break;
  1403. case WLAN_CIPHER_SUITE_TKIP:
  1404. p.grp_crypto_type = TKIP_CRYPT;
  1405. break;
  1406. case WLAN_CIPHER_SUITE_CCMP:
  1407. p.grp_crypto_type = AES_CRYPT;
  1408. break;
  1409. default:
  1410. p.grp_crypto_type = NONE_CRYPT;
  1411. break;
  1412. }
  1413. ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
  1414. p.nw_type = AP_NETWORK;
  1415. ar->nw_type = ar->next_mode;
  1416. p.ssid_len = ar->ssid_len;
  1417. memcpy(p.ssid, ar->ssid, ar->ssid_len);
  1418. p.dot11_auth_mode = ar->dot11_auth_mode;
  1419. p.ch = cpu_to_le16(ar->next_chan);
  1420. res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
  1421. if (res < 0)
  1422. return res;
  1423. return 0;
  1424. }
  1425. static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  1426. struct beacon_parameters *info)
  1427. {
  1428. return ath6kl_ap_beacon(wiphy, dev, info, true);
  1429. }
  1430. static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  1431. struct beacon_parameters *info)
  1432. {
  1433. return ath6kl_ap_beacon(wiphy, dev, info, false);
  1434. }
  1435. static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  1436. {
  1437. struct ath6kl *ar = ath6kl_priv(dev);
  1438. if (ar->nw_type != AP_NETWORK)
  1439. return -EOPNOTSUPP;
  1440. if (!test_bit(CONNECTED, &ar->flag))
  1441. return -ENOTCONN;
  1442. ath6kl_wmi_disconnect_cmd(ar->wmi);
  1443. clear_bit(CONNECTED, &ar->flag);
  1444. return 0;
  1445. }
  1446. static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
  1447. u8 *mac, struct station_parameters *params)
  1448. {
  1449. struct ath6kl *ar = ath6kl_priv(dev);
  1450. if (ar->nw_type != AP_NETWORK)
  1451. return -EOPNOTSUPP;
  1452. /* Use this only for authorizing/unauthorizing a station */
  1453. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  1454. return -EOPNOTSUPP;
  1455. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1456. return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
  1457. mac, 0);
  1458. return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
  1459. 0);
  1460. }
  1461. static int ath6kl_remain_on_channel(struct wiphy *wiphy,
  1462. struct net_device *dev,
  1463. struct ieee80211_channel *chan,
  1464. enum nl80211_channel_type channel_type,
  1465. unsigned int duration,
  1466. u64 *cookie)
  1467. {
  1468. struct ath6kl *ar = ath6kl_priv(dev);
  1469. /* TODO: if already pending or ongoing remain-on-channel,
  1470. * return -EBUSY */
  1471. *cookie = 1; /* only a single pending request is supported */
  1472. return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
  1473. duration);
  1474. }
  1475. static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
  1476. struct net_device *dev,
  1477. u64 cookie)
  1478. {
  1479. struct ath6kl *ar = ath6kl_priv(dev);
  1480. if (cookie != 1)
  1481. return -ENOENT;
  1482. return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
  1483. }
  1484. static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
  1485. size_t len, unsigned int freq)
  1486. {
  1487. const u8 *pos;
  1488. u8 *p2p;
  1489. int p2p_len;
  1490. int ret;
  1491. const struct ieee80211_mgmt *mgmt;
  1492. mgmt = (const struct ieee80211_mgmt *) buf;
  1493. /* Include P2P IE(s) from the frame generated in user space. */
  1494. p2p = kmalloc(len, GFP_KERNEL);
  1495. if (p2p == NULL)
  1496. return -ENOMEM;
  1497. p2p_len = 0;
  1498. pos = mgmt->u.probe_resp.variable;
  1499. while (pos + 1 < buf + len) {
  1500. if (pos + 2 + pos[1] > buf + len)
  1501. break;
  1502. if (ath6kl_is_p2p_ie(pos)) {
  1503. memcpy(p2p + p2p_len, pos, 2 + pos[1]);
  1504. p2p_len += 2 + pos[1];
  1505. }
  1506. pos += 2 + pos[1];
  1507. }
  1508. ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
  1509. p2p, p2p_len);
  1510. kfree(p2p);
  1511. return ret;
  1512. }
  1513. static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1514. struct ieee80211_channel *chan, bool offchan,
  1515. enum nl80211_channel_type channel_type,
  1516. bool channel_type_valid, unsigned int wait,
  1517. const u8 *buf, size_t len, u64 *cookie)
  1518. {
  1519. struct ath6kl *ar = ath6kl_priv(dev);
  1520. u32 id;
  1521. const struct ieee80211_mgmt *mgmt;
  1522. mgmt = (const struct ieee80211_mgmt *) buf;
  1523. if (buf + len >= mgmt->u.probe_resp.variable &&
  1524. ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
  1525. ieee80211_is_probe_resp(mgmt->frame_control)) {
  1526. /*
  1527. * Send Probe Response frame in AP mode using a separate WMI
  1528. * command to allow the target to fill in the generic IEs.
  1529. */
  1530. *cookie = 0; /* TX status not supported */
  1531. return ath6kl_send_go_probe_resp(ar, buf, len,
  1532. chan->center_freq);
  1533. }
  1534. id = ar->send_action_id++;
  1535. if (id == 0) {
  1536. /*
  1537. * 0 is a reserved value in the WMI command and shall not be
  1538. * used for the command.
  1539. */
  1540. id = ar->send_action_id++;
  1541. }
  1542. *cookie = id;
  1543. return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
  1544. buf, len);
  1545. }
  1546. static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
  1547. struct net_device *dev,
  1548. u16 frame_type, bool reg)
  1549. {
  1550. struct ath6kl *ar = ath6kl_priv(dev);
  1551. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
  1552. __func__, frame_type, reg);
  1553. if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
  1554. /*
  1555. * Note: This notification callback is not allowed to sleep, so
  1556. * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
  1557. * hardcode target to report Probe Request frames all the time.
  1558. */
  1559. ar->probe_req_report = reg;
  1560. }
  1561. }
  1562. static const struct ieee80211_txrx_stypes
  1563. ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1564. [NL80211_IFTYPE_STATION] = {
  1565. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1566. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1567. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1568. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1569. },
  1570. [NL80211_IFTYPE_P2P_CLIENT] = {
  1571. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1572. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1573. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1574. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1575. },
  1576. [NL80211_IFTYPE_P2P_GO] = {
  1577. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1578. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1579. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1580. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1581. },
  1582. };
  1583. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  1584. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  1585. .scan = ath6kl_cfg80211_scan,
  1586. .connect = ath6kl_cfg80211_connect,
  1587. .disconnect = ath6kl_cfg80211_disconnect,
  1588. .add_key = ath6kl_cfg80211_add_key,
  1589. .get_key = ath6kl_cfg80211_get_key,
  1590. .del_key = ath6kl_cfg80211_del_key,
  1591. .set_default_key = ath6kl_cfg80211_set_default_key,
  1592. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  1593. .set_tx_power = ath6kl_cfg80211_set_txpower,
  1594. .get_tx_power = ath6kl_cfg80211_get_txpower,
  1595. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  1596. .join_ibss = ath6kl_cfg80211_join_ibss,
  1597. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  1598. .get_station = ath6kl_get_station,
  1599. .set_pmksa = ath6kl_set_pmksa,
  1600. .del_pmksa = ath6kl_del_pmksa,
  1601. .flush_pmksa = ath6kl_flush_pmksa,
  1602. CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
  1603. #ifdef CONFIG_PM
  1604. .suspend = ar6k_cfg80211_suspend,
  1605. #endif
  1606. .set_channel = ath6kl_set_channel,
  1607. .add_beacon = ath6kl_add_beacon,
  1608. .set_beacon = ath6kl_set_beacon,
  1609. .del_beacon = ath6kl_del_beacon,
  1610. .change_station = ath6kl_change_station,
  1611. .remain_on_channel = ath6kl_remain_on_channel,
  1612. .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
  1613. .mgmt_tx = ath6kl_mgmt_tx,
  1614. .mgmt_frame_register = ath6kl_mgmt_frame_register,
  1615. };
  1616. struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
  1617. {
  1618. int ret = 0;
  1619. struct wireless_dev *wdev;
  1620. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1621. if (!wdev) {
  1622. ath6kl_err("couldn't allocate wireless device\n");
  1623. return NULL;
  1624. }
  1625. /* create a new wiphy for use with cfg80211 */
  1626. wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  1627. if (!wdev->wiphy) {
  1628. ath6kl_err("couldn't allocate wiphy device\n");
  1629. kfree(wdev);
  1630. return NULL;
  1631. }
  1632. wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
  1633. wdev->wiphy->max_remain_on_channel_duration = 5000;
  1634. /* set device pointer for wiphy */
  1635. set_wiphy_dev(wdev->wiphy, dev);
  1636. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1637. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
  1638. /* max num of ssids that can be probed during scanning */
  1639. wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
  1640. wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
  1641. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  1642. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  1643. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1644. wdev->wiphy->cipher_suites = cipher_suites;
  1645. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  1646. ret = wiphy_register(wdev->wiphy);
  1647. if (ret < 0) {
  1648. ath6kl_err("couldn't register wiphy device\n");
  1649. wiphy_free(wdev->wiphy);
  1650. kfree(wdev);
  1651. return NULL;
  1652. }
  1653. return wdev;
  1654. }
  1655. void ath6kl_cfg80211_deinit(struct ath6kl *ar)
  1656. {
  1657. struct wireless_dev *wdev = ar->wdev;
  1658. if (ar->scan_req) {
  1659. cfg80211_scan_done(ar->scan_req, true);
  1660. ar->scan_req = NULL;
  1661. }
  1662. if (!wdev)
  1663. return;
  1664. wiphy_unregister(wdev->wiphy);
  1665. wiphy_free(wdev->wiphy);
  1666. kfree(wdev);
  1667. }