cfg80211.c 50 KB

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