cfg80211.c 50 KB

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