cfg80211.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  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. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  20. .bitrate = (_rate), \
  21. .flags = (_flags), \
  22. .hw_value = (_rateid), \
  23. }
  24. #define CHAN2G(_channel, _freq, _flags) { \
  25. .band = IEEE80211_BAND_2GHZ, \
  26. .hw_value = (_channel), \
  27. .center_freq = (_freq), \
  28. .flags = (_flags), \
  29. .max_antenna_gain = 0, \
  30. .max_power = 30, \
  31. }
  32. #define CHAN5G(_channel, _flags) { \
  33. .band = IEEE80211_BAND_5GHZ, \
  34. .hw_value = (_channel), \
  35. .center_freq = 5000 + (5 * (_channel)), \
  36. .flags = (_flags), \
  37. .max_antenna_gain = 0, \
  38. .max_power = 30, \
  39. }
  40. static struct ieee80211_rate ath6kl_rates[] = {
  41. RATETAB_ENT(10, 0x1, 0),
  42. RATETAB_ENT(20, 0x2, 0),
  43. RATETAB_ENT(55, 0x4, 0),
  44. RATETAB_ENT(110, 0x8, 0),
  45. RATETAB_ENT(60, 0x10, 0),
  46. RATETAB_ENT(90, 0x20, 0),
  47. RATETAB_ENT(120, 0x40, 0),
  48. RATETAB_ENT(180, 0x80, 0),
  49. RATETAB_ENT(240, 0x100, 0),
  50. RATETAB_ENT(360, 0x200, 0),
  51. RATETAB_ENT(480, 0x400, 0),
  52. RATETAB_ENT(540, 0x800, 0),
  53. };
  54. #define ath6kl_a_rates (ath6kl_rates + 4)
  55. #define ath6kl_a_rates_size 8
  56. #define ath6kl_g_rates (ath6kl_rates + 0)
  57. #define ath6kl_g_rates_size 12
  58. static struct ieee80211_channel ath6kl_2ghz_channels[] = {
  59. CHAN2G(1, 2412, 0),
  60. CHAN2G(2, 2417, 0),
  61. CHAN2G(3, 2422, 0),
  62. CHAN2G(4, 2427, 0),
  63. CHAN2G(5, 2432, 0),
  64. CHAN2G(6, 2437, 0),
  65. CHAN2G(7, 2442, 0),
  66. CHAN2G(8, 2447, 0),
  67. CHAN2G(9, 2452, 0),
  68. CHAN2G(10, 2457, 0),
  69. CHAN2G(11, 2462, 0),
  70. CHAN2G(12, 2467, 0),
  71. CHAN2G(13, 2472, 0),
  72. CHAN2G(14, 2484, 0),
  73. };
  74. static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
  75. CHAN5G(34, 0), CHAN5G(36, 0),
  76. CHAN5G(38, 0), CHAN5G(40, 0),
  77. CHAN5G(42, 0), CHAN5G(44, 0),
  78. CHAN5G(46, 0), CHAN5G(48, 0),
  79. CHAN5G(52, 0), CHAN5G(56, 0),
  80. CHAN5G(60, 0), CHAN5G(64, 0),
  81. CHAN5G(100, 0), CHAN5G(104, 0),
  82. CHAN5G(108, 0), CHAN5G(112, 0),
  83. CHAN5G(116, 0), CHAN5G(120, 0),
  84. CHAN5G(124, 0), CHAN5G(128, 0),
  85. CHAN5G(132, 0), CHAN5G(136, 0),
  86. CHAN5G(140, 0), CHAN5G(149, 0),
  87. CHAN5G(153, 0), CHAN5G(157, 0),
  88. CHAN5G(161, 0), CHAN5G(165, 0),
  89. CHAN5G(184, 0), CHAN5G(188, 0),
  90. CHAN5G(192, 0), CHAN5G(196, 0),
  91. CHAN5G(200, 0), CHAN5G(204, 0),
  92. CHAN5G(208, 0), CHAN5G(212, 0),
  93. CHAN5G(216, 0),
  94. };
  95. static struct ieee80211_supported_band ath6kl_band_2ghz = {
  96. .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
  97. .channels = ath6kl_2ghz_channels,
  98. .n_bitrates = ath6kl_g_rates_size,
  99. .bitrates = ath6kl_g_rates,
  100. };
  101. static struct ieee80211_supported_band ath6kl_band_5ghz = {
  102. .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
  103. .channels = ath6kl_5ghz_a_channels,
  104. .n_bitrates = ath6kl_a_rates_size,
  105. .bitrates = ath6kl_a_rates,
  106. };
  107. static int ath6kl_set_wpa_version(struct ath6kl *ar,
  108. enum nl80211_wpa_versions wpa_version)
  109. {
  110. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
  111. if (!wpa_version) {
  112. ar->auth_mode = NONE_AUTH;
  113. } else if (wpa_version & NL80211_WPA_VERSION_2) {
  114. ar->auth_mode = WPA2_AUTH;
  115. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  116. ar->auth_mode = WPA_AUTH;
  117. } else {
  118. ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
  119. return -ENOTSUPP;
  120. }
  121. return 0;
  122. }
  123. static int ath6kl_set_auth_type(struct ath6kl *ar,
  124. enum nl80211_auth_type auth_type)
  125. {
  126. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
  127. switch (auth_type) {
  128. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  129. ar->dot11_auth_mode = OPEN_AUTH;
  130. break;
  131. case NL80211_AUTHTYPE_SHARED_KEY:
  132. ar->dot11_auth_mode = SHARED_AUTH;
  133. break;
  134. case NL80211_AUTHTYPE_NETWORK_EAP:
  135. ar->dot11_auth_mode = LEAP_AUTH;
  136. break;
  137. case NL80211_AUTHTYPE_AUTOMATIC:
  138. ar->dot11_auth_mode = OPEN_AUTH;
  139. ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS;
  140. break;
  141. default:
  142. ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
  143. return -ENOTSUPP;
  144. }
  145. return 0;
  146. }
  147. static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
  148. {
  149. u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
  150. u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len : &ar->grp_crpto_len;
  151. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
  152. __func__, cipher, ucast);
  153. switch (cipher) {
  154. case 0:
  155. /* our own hack to use value 0 as no crypto used */
  156. *ar_cipher = NONE_CRYPT;
  157. *ar_cipher_len = 0;
  158. break;
  159. case WLAN_CIPHER_SUITE_WEP40:
  160. *ar_cipher = WEP_CRYPT;
  161. *ar_cipher_len = 5;
  162. break;
  163. case WLAN_CIPHER_SUITE_WEP104:
  164. *ar_cipher = WEP_CRYPT;
  165. *ar_cipher_len = 13;
  166. break;
  167. case WLAN_CIPHER_SUITE_TKIP:
  168. *ar_cipher = TKIP_CRYPT;
  169. *ar_cipher_len = 0;
  170. break;
  171. case WLAN_CIPHER_SUITE_CCMP:
  172. *ar_cipher = AES_CRYPT;
  173. *ar_cipher_len = 0;
  174. break;
  175. default:
  176. ath6kl_err("cipher 0x%x not supported\n", cipher);
  177. return -ENOTSUPP;
  178. }
  179. return 0;
  180. }
  181. static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
  182. {
  183. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
  184. if (key_mgmt == WLAN_AKM_SUITE_PSK) {
  185. if (ar->auth_mode == WPA_AUTH)
  186. ar->auth_mode = WPA_PSK_AUTH;
  187. else if (ar->auth_mode == WPA2_AUTH)
  188. ar->auth_mode = WPA2_PSK_AUTH;
  189. } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
  190. ar->auth_mode = NONE_AUTH;
  191. }
  192. }
  193. static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
  194. {
  195. if (!test_bit(WMI_READY, &ar->flag)) {
  196. ath6kl_err("wmi is not ready\n");
  197. return false;
  198. }
  199. if (!test_bit(WLAN_ENABLED, &ar->flag)) {
  200. ath6kl_err("wlan disabled\n");
  201. return false;
  202. }
  203. return true;
  204. }
  205. static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  206. struct cfg80211_connect_params *sme)
  207. {
  208. struct ath6kl *ar = ath6kl_priv(dev);
  209. int status;
  210. ar->sme_state = SME_CONNECTING;
  211. if (!ath6kl_cfg80211_ready(ar))
  212. return -EIO;
  213. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  214. ath6kl_err("destroy in progress\n");
  215. return -EBUSY;
  216. }
  217. if (test_bit(SKIP_SCAN, &ar->flag) &&
  218. ((sme->channel && sme->channel->center_freq == 0) ||
  219. (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
  220. ath6kl_err("SkipScan: channel or bssid invalid\n");
  221. return -EINVAL;
  222. }
  223. if (down_interruptible(&ar->sem)) {
  224. ath6kl_err("busy, couldn't get access\n");
  225. return -ERESTARTSYS;
  226. }
  227. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  228. ath6kl_err("busy, destroy in progress\n");
  229. up(&ar->sem);
  230. return -EBUSY;
  231. }
  232. if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
  233. /*
  234. * sleep until the command queue drains
  235. */
  236. wait_event_interruptible_timeout(ar->event_wq,
  237. ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
  238. WMI_TIMEOUT);
  239. if (signal_pending(current)) {
  240. ath6kl_err("cmd queue drain timeout\n");
  241. up(&ar->sem);
  242. return -EINTR;
  243. }
  244. }
  245. if (test_bit(CONNECTED, &ar->flag) &&
  246. ar->ssid_len == sme->ssid_len &&
  247. !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
  248. ar->reconnect_flag = true;
  249. status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
  250. ar->ch_hint);
  251. up(&ar->sem);
  252. if (status) {
  253. ath6kl_err("wmi_reconnect_cmd failed\n");
  254. return -EIO;
  255. }
  256. return 0;
  257. } else if (ar->ssid_len == sme->ssid_len &&
  258. !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
  259. ath6kl_disconnect(ar);
  260. }
  261. memset(ar->ssid, 0, sizeof(ar->ssid));
  262. ar->ssid_len = sme->ssid_len;
  263. memcpy(ar->ssid, sme->ssid, sme->ssid_len);
  264. if (sme->channel)
  265. ar->ch_hint = sme->channel->center_freq;
  266. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  267. if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
  268. memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
  269. ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
  270. status = ath6kl_set_auth_type(ar, sme->auth_type);
  271. if (status) {
  272. up(&ar->sem);
  273. return status;
  274. }
  275. if (sme->crypto.n_ciphers_pairwise)
  276. ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
  277. else
  278. ath6kl_set_cipher(ar, 0, true);
  279. ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
  280. if (sme->crypto.n_akm_suites)
  281. ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
  282. if ((sme->key_len) &&
  283. (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
  284. struct ath6kl_key *key = NULL;
  285. if (sme->key_idx < WMI_MIN_KEY_INDEX ||
  286. sme->key_idx > WMI_MAX_KEY_INDEX) {
  287. ath6kl_err("key index %d out of bounds\n",
  288. sme->key_idx);
  289. up(&ar->sem);
  290. return -ENOENT;
  291. }
  292. key = &ar->keys[sme->key_idx];
  293. key->key_len = sme->key_len;
  294. memcpy(key->key, sme->key, key->key_len);
  295. key->cipher = ar->prwise_crypto;
  296. ar->def_txkey_index = sme->key_idx;
  297. ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
  298. ar->prwise_crypto,
  299. GROUP_USAGE | TX_USAGE,
  300. key->key_len,
  301. NULL,
  302. key->key, KEY_OP_INIT_VAL, NULL,
  303. NO_SYNC_WMIFLAG);
  304. }
  305. if (!ar->usr_bss_filter) {
  306. if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
  307. ath6kl_err("couldn't set bss filtering\n");
  308. up(&ar->sem);
  309. return -EIO;
  310. }
  311. }
  312. ar->nw_type = ar->next_mode;
  313. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  314. "%s: connect called with authmode %d dot11 auth %d"
  315. " PW crypto %d PW crypto len %d GRP crypto %d"
  316. " GRP crypto len %d channel hint %u\n",
  317. __func__,
  318. ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
  319. ar->prwise_crypto_len, ar->grp_crypto,
  320. ar->grp_crpto_len, ar->ch_hint);
  321. ar->reconnect_flag = 0;
  322. status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
  323. ar->dot11_auth_mode, ar->auth_mode,
  324. ar->prwise_crypto,
  325. ar->prwise_crypto_len,
  326. ar->grp_crypto, ar->grp_crpto_len,
  327. ar->ssid_len, ar->ssid,
  328. ar->req_bssid, ar->ch_hint,
  329. ar->connect_ctrl_flags);
  330. up(&ar->sem);
  331. if (status == -EINVAL) {
  332. memset(ar->ssid, 0, sizeof(ar->ssid));
  333. ar->ssid_len = 0;
  334. ath6kl_err("invalid request\n");
  335. return -ENOENT;
  336. } else if (status) {
  337. ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
  338. return -EIO;
  339. }
  340. if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
  341. ((ar->auth_mode == WPA_PSK_AUTH)
  342. || (ar->auth_mode == WPA2_PSK_AUTH))) {
  343. mod_timer(&ar->disconnect_timer,
  344. jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
  345. }
  346. ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
  347. set_bit(CONNECT_PEND, &ar->flag);
  348. return 0;
  349. }
  350. void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
  351. u8 *bssid, u16 listen_intvl,
  352. u16 beacon_intvl,
  353. enum network_type nw_type,
  354. u8 beacon_ie_len, u8 assoc_req_len,
  355. u8 assoc_resp_len, u8 *assoc_info)
  356. {
  357. u16 size = 0;
  358. u16 capability = 0;
  359. struct cfg80211_bss *bss = NULL;
  360. struct ieee80211_mgmt *mgmt = NULL;
  361. struct ieee80211_channel *ibss_ch = NULL;
  362. s32 signal = 50 * 100;
  363. u8 ie_buf_len = 0;
  364. unsigned char ie_buf[256];
  365. unsigned char *ptr_ie_buf = ie_buf;
  366. unsigned char *ieeemgmtbuf = NULL;
  367. u8 source_mac[ETH_ALEN];
  368. u16 capa_mask;
  369. u16 capa_val;
  370. /* capinfo + listen interval */
  371. u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
  372. /* capinfo + status code + associd */
  373. u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
  374. u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
  375. u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
  376. assoc_resp_ie_offset;
  377. assoc_req_len -= assoc_req_ie_offset;
  378. assoc_resp_len -= assoc_resp_ie_offset;
  379. ar->auto_auth_stage = AUTH_IDLE;
  380. if (nw_type & ADHOC_NETWORK) {
  381. if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
  382. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  383. "%s: ath6k not in ibss mode\n", __func__);
  384. return;
  385. }
  386. }
  387. if (nw_type & INFRA_NETWORK) {
  388. if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
  389. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  390. "%s: ath6k not in station mode\n", __func__);
  391. return;
  392. }
  393. }
  394. if (nw_type & ADHOC_NETWORK) {
  395. capa_mask = WLAN_CAPABILITY_IBSS;
  396. capa_val = WLAN_CAPABILITY_IBSS;
  397. } else {
  398. capa_mask = WLAN_CAPABILITY_ESS;
  399. capa_val = WLAN_CAPABILITY_ESS;
  400. }
  401. /* Before informing the join/connect event, make sure that
  402. * bss entry is present in scan list, if it not present
  403. * construct and insert into scan list, otherwise that
  404. * event will be dropped on the way by cfg80211, due to
  405. * this keys will not be plumbed in case of WEP and
  406. * application will not be aware of join/connect status. */
  407. bss = cfg80211_get_bss(ar->wdev->wiphy, NULL, bssid,
  408. ar->wdev->ssid, ar->wdev->ssid_len,
  409. capa_mask, capa_val);
  410. /*
  411. * Earlier we were updating the cfg about bss by making a beacon frame
  412. * only if the entry for bss is not there. This can have some issue if
  413. * ROAM event is generated and a heavy traffic is ongoing. The ROAM
  414. * event is handled through a work queue and by the time it really gets
  415. * handled, BSS would have been aged out. So it is better to update the
  416. * cfg about BSS irrespective of its entry being present right now or
  417. * not.
  418. */
  419. if (nw_type & ADHOC_NETWORK) {
  420. /* construct 802.11 mgmt beacon */
  421. if (ptr_ie_buf) {
  422. *ptr_ie_buf++ = WLAN_EID_SSID;
  423. *ptr_ie_buf++ = ar->ssid_len;
  424. memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
  425. ptr_ie_buf += ar->ssid_len;
  426. *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
  427. *ptr_ie_buf++ = 2; /* length */
  428. *ptr_ie_buf++ = 0; /* ATIM window */
  429. *ptr_ie_buf++ = 0; /* ATIM window */
  430. /* TODO: update ibss params and include supported rates,
  431. * DS param set, extened support rates, wmm. */
  432. ie_buf_len = ptr_ie_buf - ie_buf;
  433. }
  434. capability |= WLAN_CAPABILITY_IBSS;
  435. if (ar->prwise_crypto == WEP_CRYPT)
  436. capability |= WLAN_CAPABILITY_PRIVACY;
  437. memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
  438. ptr_ie_buf = ie_buf;
  439. } else {
  440. capability = *(u16 *) (&assoc_info[beacon_ie_len]);
  441. memcpy(source_mac, bssid, ETH_ALEN);
  442. ptr_ie_buf = assoc_req_ie;
  443. ie_buf_len = assoc_req_len;
  444. }
  445. size = offsetof(struct ieee80211_mgmt, u)
  446. + sizeof(mgmt->u.beacon)
  447. + ie_buf_len;
  448. ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
  449. if (!ieeemgmtbuf) {
  450. ath6kl_err("ieee mgmt buf alloc error\n");
  451. cfg80211_put_bss(bss);
  452. return;
  453. }
  454. mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
  455. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  456. IEEE80211_STYPE_BEACON);
  457. memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
  458. memcpy(mgmt->sa, source_mac, ETH_ALEN);
  459. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  460. mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
  461. mgmt->u.beacon.capab_info = cpu_to_le16(capability);
  462. memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
  463. ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
  464. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  465. "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
  466. __func__, mgmt->bssid, ibss_ch->hw_value,
  467. beacon_intvl, capability);
  468. bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
  469. ibss_ch, mgmt,
  470. size, signal, GFP_KERNEL);
  471. kfree(ieeemgmtbuf);
  472. cfg80211_put_bss(bss);
  473. if (nw_type & ADHOC_NETWORK) {
  474. cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
  475. return;
  476. }
  477. if (ar->sme_state == SME_CONNECTING) {
  478. /* inform connect result to cfg80211 */
  479. ar->sme_state = SME_CONNECTED;
  480. cfg80211_connect_result(ar->net_dev, bssid,
  481. assoc_req_ie, assoc_req_len,
  482. assoc_resp_ie, assoc_resp_len,
  483. WLAN_STATUS_SUCCESS, GFP_KERNEL);
  484. } else if (ar->sme_state == SME_CONNECTED) {
  485. /* inform roam event to cfg80211 */
  486. cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
  487. assoc_req_ie, assoc_req_len,
  488. assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
  489. }
  490. }
  491. static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
  492. struct net_device *dev, u16 reason_code)
  493. {
  494. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  495. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
  496. reason_code);
  497. if (!ath6kl_cfg80211_ready(ar))
  498. return -EIO;
  499. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  500. ath6kl_err("busy, destroy in progress\n");
  501. return -EBUSY;
  502. }
  503. if (down_interruptible(&ar->sem)) {
  504. ath6kl_err("busy, couldn't get access\n");
  505. return -ERESTARTSYS;
  506. }
  507. ar->reconnect_flag = 0;
  508. ath6kl_disconnect(ar);
  509. memset(ar->ssid, 0, sizeof(ar->ssid));
  510. ar->ssid_len = 0;
  511. if (!test_bit(SKIP_SCAN, &ar->flag))
  512. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  513. up(&ar->sem);
  514. return 0;
  515. }
  516. void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
  517. u8 *bssid, u8 assoc_resp_len,
  518. u8 *assoc_info, u16 proto_reason)
  519. {
  520. struct ath6kl_key *key = NULL;
  521. u16 status;
  522. if (ar->scan_req) {
  523. cfg80211_scan_done(ar->scan_req, true);
  524. ar->scan_req = NULL;
  525. }
  526. if (ar->nw_type & ADHOC_NETWORK) {
  527. if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
  528. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  529. "%s: ath6k not in ibss mode\n", __func__);
  530. return;
  531. }
  532. memset(bssid, 0, ETH_ALEN);
  533. cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
  534. return;
  535. }
  536. if (ar->nw_type & INFRA_NETWORK) {
  537. if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
  538. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  539. "%s: ath6k not in station mode\n", __func__);
  540. return;
  541. }
  542. }
  543. if (!test_bit(CONNECT_PEND, &ar->flag)) {
  544. if (reason != DISCONNECT_CMD)
  545. ath6kl_wmi_disconnect_cmd(ar->wmi);
  546. return;
  547. }
  548. if (reason == NO_NETWORK_AVAIL) {
  549. /* connect cmd failed */
  550. ath6kl_wmi_disconnect_cmd(ar->wmi);
  551. return;
  552. }
  553. if (reason != DISCONNECT_CMD)
  554. return;
  555. if (!ar->auto_auth_stage) {
  556. clear_bit(CONNECT_PEND, &ar->flag);
  557. if (ar->sme_state == SME_CONNECTING) {
  558. cfg80211_connect_result(ar->net_dev,
  559. bssid, NULL, 0,
  560. NULL, 0,
  561. WLAN_STATUS_UNSPECIFIED_FAILURE,
  562. GFP_KERNEL);
  563. } else {
  564. cfg80211_disconnected(ar->net_dev, reason,
  565. NULL, 0, GFP_KERNEL);
  566. }
  567. ar->sme_state = SME_DISCONNECTED;
  568. return;
  569. }
  570. if (ar->dot11_auth_mode != OPEN_AUTH)
  571. return;
  572. /*
  573. * If the current auth algorithm is open, try shared and
  574. * make autoAuthStage idle. We do not make it leap for now
  575. * being.
  576. */
  577. key = &ar->keys[ar->def_txkey_index];
  578. if (down_interruptible(&ar->sem)) {
  579. ath6kl_err("busy, couldn't get access\n");
  580. return;
  581. }
  582. ar->dot11_auth_mode = SHARED_AUTH;
  583. ar->auto_auth_stage = AUTH_IDLE;
  584. ath6kl_wmi_addkey_cmd(ar->wmi,
  585. ar->def_txkey_index,
  586. ar->prwise_crypto,
  587. GROUP_USAGE | TX_USAGE,
  588. key->key_len, NULL,
  589. key->key,
  590. KEY_OP_INIT_VAL, NULL,
  591. NO_SYNC_WMIFLAG);
  592. status = ath6kl_wmi_connect_cmd(ar->wmi,
  593. ar->nw_type,
  594. ar->dot11_auth_mode,
  595. ar->auth_mode,
  596. ar->prwise_crypto,
  597. ar->prwise_crypto_len,
  598. ar->grp_crypto,
  599. ar->grp_crpto_len,
  600. ar->ssid_len,
  601. ar->ssid,
  602. ar->req_bssid,
  603. ar->ch_hint,
  604. ar->connect_ctrl_flags);
  605. up(&ar->sem);
  606. }
  607. static inline bool is_ch_11a(u16 ch)
  608. {
  609. return (!((ch >= 2412) && (ch <= 2484)));
  610. }
  611. /* struct ath6kl_node_table::nt_nodelock is locked when calling this */
  612. void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
  613. {
  614. struct ieee80211_mgmt *mgmt;
  615. struct ieee80211_channel *channel;
  616. struct ieee80211_supported_band *band;
  617. struct ath6kl_common_ie *cie;
  618. s32 signal;
  619. int freq;
  620. cie = &ni->ni_cie;
  621. if (is_ch_11a(cie->ie_chan))
  622. band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
  623. else if ((cie->ie_erp) || (cie->ie_xrates))
  624. band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
  625. else
  626. band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
  627. freq = cie->ie_chan;
  628. channel = ieee80211_get_channel(wiphy, freq);
  629. signal = ni->ni_snr * 100;
  630. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  631. "%s: bssid %pM ch %d freq %d size %d\n", __func__,
  632. ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
  633. /*
  634. * Both Beacon and Probe Response frames have same payload structure,
  635. * so it is fine to share the parser for both.
  636. */
  637. if (ni->ni_framelen < 8 + 2 + 2)
  638. return;
  639. mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
  640. offsetof(struct ieee80211_mgmt, u));
  641. cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
  642. le64_to_cpu(mgmt->u.beacon.timestamp),
  643. le16_to_cpu(mgmt->u.beacon.capab_info),
  644. le16_to_cpu(mgmt->u.beacon.beacon_int),
  645. mgmt->u.beacon.variable,
  646. ni->ni_buf + ni->ni_framelen -
  647. mgmt->u.beacon.variable,
  648. signal, GFP_ATOMIC);
  649. }
  650. static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  651. struct cfg80211_scan_request *request)
  652. {
  653. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  654. int ret = 0;
  655. if (!ath6kl_cfg80211_ready(ar))
  656. return -EIO;
  657. if (!ar->usr_bss_filter) {
  658. if (ath6kl_wmi_bssfilter_cmd(ar->wmi,
  659. (test_bit(CONNECTED, &ar->flag) ?
  660. ALL_BUT_BSS_FILTER :
  661. ALL_BSS_FILTER), 0) != 0) {
  662. ath6kl_err("couldn't set bss filtering\n");
  663. return -EIO;
  664. }
  665. }
  666. if (request->n_ssids && request->ssids[0].ssid_len) {
  667. u8 i;
  668. if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
  669. request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
  670. for (i = 0; i < request->n_ssids; i++)
  671. ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
  672. SPECIFIC_SSID_FLAG,
  673. request->ssids[i].ssid_len,
  674. request->ssids[i].ssid);
  675. }
  676. if (ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
  677. false, 0, 0, 0, NULL) != 0) {
  678. ath6kl_err("wmi_startscan_cmd failed\n");
  679. ret = -EIO;
  680. }
  681. ar->scan_req = request;
  682. return ret;
  683. }
  684. void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
  685. {
  686. int i;
  687. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
  688. if (!ar->scan_req)
  689. return;
  690. if ((status == -ECANCELED) || (status == -EBUSY)) {
  691. cfg80211_scan_done(ar->scan_req, true);
  692. goto out;
  693. }
  694. /* Translate data to cfg80211 mgmt format */
  695. wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
  696. cfg80211_scan_done(ar->scan_req, false);
  697. if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
  698. for (i = 0; i < ar->scan_req->n_ssids; i++) {
  699. ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
  700. DISABLE_SSID_FLAG,
  701. 0, NULL);
  702. }
  703. }
  704. out:
  705. ar->scan_req = NULL;
  706. }
  707. static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  708. u8 key_index, bool pairwise,
  709. const u8 *mac_addr,
  710. struct key_params *params)
  711. {
  712. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  713. struct ath6kl_key *key = NULL;
  714. u8 key_usage;
  715. u8 key_type;
  716. int status = 0;
  717. if (!ath6kl_cfg80211_ready(ar))
  718. return -EIO;
  719. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  720. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  721. "%s: key index %d out of bounds\n", __func__,
  722. key_index);
  723. return -ENOENT;
  724. }
  725. key = &ar->keys[key_index];
  726. memset(key, 0, sizeof(struct ath6kl_key));
  727. if (pairwise)
  728. key_usage = PAIRWISE_USAGE;
  729. else
  730. key_usage = GROUP_USAGE;
  731. if (params) {
  732. if (params->key_len > WLAN_MAX_KEY_LEN ||
  733. params->seq_len > sizeof(key->seq))
  734. return -EINVAL;
  735. key->key_len = params->key_len;
  736. memcpy(key->key, params->key, key->key_len);
  737. key->seq_len = params->seq_len;
  738. memcpy(key->seq, params->seq, key->seq_len);
  739. key->cipher = params->cipher;
  740. }
  741. switch (key->cipher) {
  742. case WLAN_CIPHER_SUITE_WEP40:
  743. case WLAN_CIPHER_SUITE_WEP104:
  744. key_type = WEP_CRYPT;
  745. break;
  746. case WLAN_CIPHER_SUITE_TKIP:
  747. key_type = TKIP_CRYPT;
  748. break;
  749. case WLAN_CIPHER_SUITE_CCMP:
  750. key_type = AES_CRYPT;
  751. break;
  752. default:
  753. return -ENOTSUPP;
  754. }
  755. if (((ar->auth_mode == WPA_PSK_AUTH)
  756. || (ar->auth_mode == WPA2_PSK_AUTH))
  757. && (key_usage & GROUP_USAGE))
  758. del_timer(&ar->disconnect_timer);
  759. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  760. "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
  761. __func__, key_index, key->key_len, key_type,
  762. key_usage, key->seq_len);
  763. ar->def_txkey_index = key_index;
  764. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  765. key_type, key_usage, key->key_len,
  766. key->seq, key->key, KEY_OP_INIT_VAL,
  767. (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
  768. if (status)
  769. return -EIO;
  770. return 0;
  771. }
  772. static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  773. u8 key_index, bool pairwise,
  774. const u8 *mac_addr)
  775. {
  776. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  777. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  778. if (!ath6kl_cfg80211_ready(ar))
  779. return -EIO;
  780. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  781. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  782. "%s: key index %d out of bounds\n", __func__,
  783. key_index);
  784. return -ENOENT;
  785. }
  786. if (!ar->keys[key_index].key_len) {
  787. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  788. "%s: index %d is empty\n", __func__, key_index);
  789. return 0;
  790. }
  791. ar->keys[key_index].key_len = 0;
  792. return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
  793. }
  794. static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  795. u8 key_index, bool pairwise,
  796. const u8 *mac_addr, void *cookie,
  797. void (*callback) (void *cookie,
  798. struct key_params *))
  799. {
  800. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  801. struct ath6kl_key *key = NULL;
  802. struct key_params params;
  803. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  804. if (!ath6kl_cfg80211_ready(ar))
  805. return -EIO;
  806. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  807. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  808. "%s: key index %d out of bounds\n", __func__,
  809. key_index);
  810. return -ENOENT;
  811. }
  812. key = &ar->keys[key_index];
  813. memset(&params, 0, sizeof(params));
  814. params.cipher = key->cipher;
  815. params.key_len = key->key_len;
  816. params.seq_len = key->seq_len;
  817. params.seq = key->seq;
  818. params.key = key->key;
  819. callback(cookie, &params);
  820. return key->key_len ? 0 : -ENOENT;
  821. }
  822. static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
  823. struct net_device *ndev,
  824. u8 key_index, bool unicast,
  825. bool multicast)
  826. {
  827. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  828. struct ath6kl_key *key = NULL;
  829. int status = 0;
  830. u8 key_usage;
  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",
  837. __func__, key_index);
  838. return -ENOENT;
  839. }
  840. if (!ar->keys[key_index].key_len) {
  841. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
  842. __func__, key_index);
  843. return -EINVAL;
  844. }
  845. ar->def_txkey_index = key_index;
  846. key = &ar->keys[ar->def_txkey_index];
  847. key_usage = GROUP_USAGE;
  848. if (ar->prwise_crypto == WEP_CRYPT)
  849. key_usage |= TX_USAGE;
  850. status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
  851. ar->prwise_crypto, key_usage,
  852. key->key_len, key->seq, key->key,
  853. KEY_OP_INIT_VAL, NULL,
  854. SYNC_BOTH_WMIFLAG);
  855. if (status)
  856. return -EIO;
  857. return 0;
  858. }
  859. void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
  860. bool ismcast)
  861. {
  862. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  863. "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
  864. cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
  865. (ismcast ? NL80211_KEYTYPE_GROUP :
  866. NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
  867. GFP_KERNEL);
  868. }
  869. static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  870. {
  871. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  872. int ret;
  873. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
  874. changed);
  875. if (!ath6kl_cfg80211_ready(ar))
  876. return -EIO;
  877. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  878. ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
  879. if (ret != 0) {
  880. ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
  881. return -EIO;
  882. }
  883. }
  884. return 0;
  885. }
  886. /*
  887. * The type nl80211_tx_power_setting replaces the following
  888. * data type from 2.6.36 onwards
  889. */
  890. static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
  891. enum nl80211_tx_power_setting type,
  892. int dbm)
  893. {
  894. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  895. u8 ath6kl_dbm;
  896. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
  897. type, dbm);
  898. if (!ath6kl_cfg80211_ready(ar))
  899. return -EIO;
  900. switch (type) {
  901. case NL80211_TX_POWER_AUTOMATIC:
  902. return 0;
  903. case NL80211_TX_POWER_LIMITED:
  904. ar->tx_pwr = ath6kl_dbm = dbm;
  905. break;
  906. default:
  907. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
  908. __func__, type);
  909. return -EOPNOTSUPP;
  910. }
  911. ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
  912. return 0;
  913. }
  914. static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  915. {
  916. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  917. if (!ath6kl_cfg80211_ready(ar))
  918. return -EIO;
  919. if (test_bit(CONNECTED, &ar->flag)) {
  920. ar->tx_pwr = 0;
  921. if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
  922. ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
  923. return -EIO;
  924. }
  925. wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
  926. 5 * HZ);
  927. if (signal_pending(current)) {
  928. ath6kl_err("target did not respond\n");
  929. return -EINTR;
  930. }
  931. }
  932. *dbm = ar->tx_pwr;
  933. return 0;
  934. }
  935. static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  936. struct net_device *dev,
  937. bool pmgmt, int timeout)
  938. {
  939. struct ath6kl *ar = ath6kl_priv(dev);
  940. struct wmi_power_mode_cmd mode;
  941. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
  942. __func__, pmgmt, timeout);
  943. if (!ath6kl_cfg80211_ready(ar))
  944. return -EIO;
  945. if (pmgmt) {
  946. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
  947. mode.pwr_mode = REC_POWER;
  948. } else {
  949. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
  950. mode.pwr_mode = MAX_PERF_POWER;
  951. }
  952. if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
  953. ath6kl_err("wmi_powermode_cmd failed\n");
  954. return -EIO;
  955. }
  956. return 0;
  957. }
  958. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  959. struct net_device *ndev,
  960. enum nl80211_iftype type, u32 *flags,
  961. struct vif_params *params)
  962. {
  963. struct ath6kl *ar = ath6kl_priv(ndev);
  964. struct wireless_dev *wdev = ar->wdev;
  965. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  966. if (!ath6kl_cfg80211_ready(ar))
  967. return -EIO;
  968. switch (type) {
  969. case NL80211_IFTYPE_STATION:
  970. ar->next_mode = INFRA_NETWORK;
  971. break;
  972. case NL80211_IFTYPE_ADHOC:
  973. ar->next_mode = ADHOC_NETWORK;
  974. break;
  975. default:
  976. ath6kl_err("invalid interface type %u\n", type);
  977. return -EOPNOTSUPP;
  978. }
  979. wdev->iftype = type;
  980. return 0;
  981. }
  982. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  983. struct net_device *dev,
  984. struct cfg80211_ibss_params *ibss_param)
  985. {
  986. struct ath6kl *ar = ath6kl_priv(dev);
  987. int status;
  988. if (!ath6kl_cfg80211_ready(ar))
  989. return -EIO;
  990. ar->ssid_len = ibss_param->ssid_len;
  991. memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
  992. if (ibss_param->channel)
  993. ar->ch_hint = ibss_param->channel->center_freq;
  994. if (ibss_param->channel_fixed) {
  995. /*
  996. * TODO: channel_fixed: The channel should be fixed, do not
  997. * search for IBSSs to join on other channels. Target
  998. * firmware does not support this feature, needs to be
  999. * updated.
  1000. */
  1001. return -EOPNOTSUPP;
  1002. }
  1003. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  1004. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1005. memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
  1006. ath6kl_set_wpa_version(ar, 0);
  1007. status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1008. if (status)
  1009. return status;
  1010. if (ibss_param->privacy) {
  1011. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
  1012. ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
  1013. } else {
  1014. ath6kl_set_cipher(ar, 0, true);
  1015. ath6kl_set_cipher(ar, 0, false);
  1016. }
  1017. ar->nw_type = ar->next_mode;
  1018. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1019. "%s: connect called with authmode %d dot11 auth %d"
  1020. " PW crypto %d PW crypto len %d GRP crypto %d"
  1021. " GRP crypto len %d channel hint %u\n",
  1022. __func__,
  1023. ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
  1024. ar->prwise_crypto_len, ar->grp_crypto,
  1025. ar->grp_crpto_len, ar->ch_hint);
  1026. status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
  1027. ar->dot11_auth_mode, ar->auth_mode,
  1028. ar->prwise_crypto,
  1029. ar->prwise_crypto_len,
  1030. ar->grp_crypto, ar->grp_crpto_len,
  1031. ar->ssid_len, ar->ssid,
  1032. ar->req_bssid, ar->ch_hint,
  1033. ar->connect_ctrl_flags);
  1034. set_bit(CONNECT_PEND, &ar->flag);
  1035. return 0;
  1036. }
  1037. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1038. struct net_device *dev)
  1039. {
  1040. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  1041. if (!ath6kl_cfg80211_ready(ar))
  1042. return -EIO;
  1043. ath6kl_disconnect(ar);
  1044. memset(ar->ssid, 0, sizeof(ar->ssid));
  1045. ar->ssid_len = 0;
  1046. return 0;
  1047. }
  1048. static const u32 cipher_suites[] = {
  1049. WLAN_CIPHER_SUITE_WEP40,
  1050. WLAN_CIPHER_SUITE_WEP104,
  1051. WLAN_CIPHER_SUITE_TKIP,
  1052. WLAN_CIPHER_SUITE_CCMP,
  1053. };
  1054. static bool is_rate_legacy(s32 rate)
  1055. {
  1056. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1057. 6000, 9000, 12000, 18000, 24000,
  1058. 36000, 48000, 54000
  1059. };
  1060. u8 i;
  1061. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1062. if (rate == legacy[i])
  1063. return true;
  1064. return false;
  1065. }
  1066. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1067. {
  1068. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1069. 52000, 58500, 65000, 72200
  1070. };
  1071. u8 i;
  1072. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1073. if (rate == ht20[i]) {
  1074. if (i == ARRAY_SIZE(ht20) - 1)
  1075. /* last rate uses sgi */
  1076. *sgi = true;
  1077. else
  1078. *sgi = false;
  1079. *mcs = i;
  1080. return true;
  1081. }
  1082. }
  1083. return false;
  1084. }
  1085. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1086. {
  1087. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1088. 81000, 108000, 121500, 135000,
  1089. 150000
  1090. };
  1091. u8 i;
  1092. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1093. if (rate == ht40[i]) {
  1094. if (i == ARRAY_SIZE(ht40) - 1)
  1095. /* last rate uses sgi */
  1096. *sgi = true;
  1097. else
  1098. *sgi = false;
  1099. *mcs = i;
  1100. return true;
  1101. }
  1102. }
  1103. return false;
  1104. }
  1105. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1106. u8 *mac, struct station_info *sinfo)
  1107. {
  1108. struct ath6kl *ar = ath6kl_priv(dev);
  1109. long left;
  1110. bool sgi;
  1111. s32 rate;
  1112. int ret;
  1113. u8 mcs;
  1114. if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
  1115. return -ENOENT;
  1116. if (down_interruptible(&ar->sem))
  1117. return -EBUSY;
  1118. set_bit(STATS_UPDATE_PEND, &ar->flag);
  1119. ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
  1120. if (ret != 0) {
  1121. up(&ar->sem);
  1122. return -EIO;
  1123. }
  1124. left = wait_event_interruptible_timeout(ar->event_wq,
  1125. !test_bit(STATS_UPDATE_PEND,
  1126. &ar->flag),
  1127. WMI_TIMEOUT);
  1128. up(&ar->sem);
  1129. if (left == 0)
  1130. return -ETIMEDOUT;
  1131. else if (left < 0)
  1132. return left;
  1133. if (ar->target_stats.rx_byte) {
  1134. sinfo->rx_bytes = ar->target_stats.rx_byte;
  1135. sinfo->filled |= STATION_INFO_RX_BYTES;
  1136. sinfo->rx_packets = ar->target_stats.rx_pkt;
  1137. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1138. }
  1139. if (ar->target_stats.tx_byte) {
  1140. sinfo->tx_bytes = ar->target_stats.tx_byte;
  1141. sinfo->filled |= STATION_INFO_TX_BYTES;
  1142. sinfo->tx_packets = ar->target_stats.tx_pkt;
  1143. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1144. }
  1145. sinfo->signal = ar->target_stats.cs_rssi;
  1146. sinfo->filled |= STATION_INFO_SIGNAL;
  1147. rate = ar->target_stats.tx_ucast_rate;
  1148. if (is_rate_legacy(rate)) {
  1149. sinfo->txrate.legacy = rate / 100;
  1150. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1151. if (sgi) {
  1152. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1153. sinfo->txrate.mcs = mcs - 1;
  1154. } else {
  1155. sinfo->txrate.mcs = mcs;
  1156. }
  1157. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1158. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1159. if (sgi) {
  1160. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1161. sinfo->txrate.mcs = mcs - 1;
  1162. } else {
  1163. sinfo->txrate.mcs = mcs;
  1164. }
  1165. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1166. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1167. } else {
  1168. ath6kl_warn("invalid rate: %d\n", rate);
  1169. return 0;
  1170. }
  1171. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1172. return 0;
  1173. }
  1174. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1175. struct cfg80211_pmksa *pmksa)
  1176. {
  1177. struct ath6kl *ar = ath6kl_priv(netdev);
  1178. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1179. pmksa->pmkid, true);
  1180. }
  1181. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1182. struct cfg80211_pmksa *pmksa)
  1183. {
  1184. struct ath6kl *ar = ath6kl_priv(netdev);
  1185. return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
  1186. pmksa->pmkid, false);
  1187. }
  1188. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1189. {
  1190. struct ath6kl *ar = ath6kl_priv(netdev);
  1191. if (test_bit(CONNECTED, &ar->flag))
  1192. return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
  1193. return 0;
  1194. }
  1195. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  1196. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  1197. .scan = ath6kl_cfg80211_scan,
  1198. .connect = ath6kl_cfg80211_connect,
  1199. .disconnect = ath6kl_cfg80211_disconnect,
  1200. .add_key = ath6kl_cfg80211_add_key,
  1201. .get_key = ath6kl_cfg80211_get_key,
  1202. .del_key = ath6kl_cfg80211_del_key,
  1203. .set_default_key = ath6kl_cfg80211_set_default_key,
  1204. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  1205. .set_tx_power = ath6kl_cfg80211_set_txpower,
  1206. .get_tx_power = ath6kl_cfg80211_get_txpower,
  1207. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  1208. .join_ibss = ath6kl_cfg80211_join_ibss,
  1209. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  1210. .get_station = ath6kl_get_station,
  1211. .set_pmksa = ath6kl_set_pmksa,
  1212. .del_pmksa = ath6kl_del_pmksa,
  1213. .flush_pmksa = ath6kl_flush_pmksa,
  1214. };
  1215. struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
  1216. {
  1217. int ret = 0;
  1218. struct wireless_dev *wdev;
  1219. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1220. if (!wdev) {
  1221. ath6kl_err("couldn't allocate wireless device\n");
  1222. return NULL;
  1223. }
  1224. /* create a new wiphy for use with cfg80211 */
  1225. wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  1226. if (!wdev->wiphy) {
  1227. ath6kl_err("couldn't allocate wiphy device\n");
  1228. kfree(wdev);
  1229. return NULL;
  1230. }
  1231. /* set device pointer for wiphy */
  1232. set_wiphy_dev(wdev->wiphy, dev);
  1233. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1234. BIT(NL80211_IFTYPE_ADHOC);
  1235. /* max num of ssids that can be probed during scanning */
  1236. wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
  1237. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  1238. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  1239. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1240. wdev->wiphy->cipher_suites = cipher_suites;
  1241. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  1242. ret = wiphy_register(wdev->wiphy);
  1243. if (ret < 0) {
  1244. ath6kl_err("couldn't register wiphy device\n");
  1245. wiphy_free(wdev->wiphy);
  1246. kfree(wdev);
  1247. return NULL;
  1248. }
  1249. return wdev;
  1250. }
  1251. void ath6kl_cfg80211_deinit(struct ath6kl *ar)
  1252. {
  1253. struct wireless_dev *wdev = ar->wdev;
  1254. if (ar->scan_req) {
  1255. cfg80211_scan_done(ar->scan_req, true);
  1256. ar->scan_req = NULL;
  1257. }
  1258. if (!wdev)
  1259. return;
  1260. wiphy_unregister(wdev->wiphy);
  1261. wiphy_free(wdev->wiphy);
  1262. kfree(wdev);
  1263. }