cfg80211.c 54 KB

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