cfg80211.c 54 KB

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