cfg80211.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
  5. * Samuel Ortiz <samuel.ortiz@intel.com>
  6. * Zhu Yi <yi.zhu@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/wireless.h>
  27. #include <linux/ieee80211.h>
  28. #include <net/cfg80211.h>
  29. #include "iwm.h"
  30. #include "commands.h"
  31. #include "cfg80211.h"
  32. #include "debug.h"
  33. #define RATETAB_ENT(_rate, _rateid, _flags) \
  34. { \
  35. .bitrate = (_rate), \
  36. .hw_value = (_rateid), \
  37. .flags = (_flags), \
  38. }
  39. #define CHAN2G(_channel, _freq, _flags) { \
  40. .band = IEEE80211_BAND_2GHZ, \
  41. .center_freq = (_freq), \
  42. .hw_value = (_channel), \
  43. .flags = (_flags), \
  44. .max_antenna_gain = 0, \
  45. .max_power = 30, \
  46. }
  47. #define CHAN5G(_channel, _flags) { \
  48. .band = IEEE80211_BAND_5GHZ, \
  49. .center_freq = 5000 + (5 * (_channel)), \
  50. .hw_value = (_channel), \
  51. .flags = (_flags), \
  52. .max_antenna_gain = 0, \
  53. .max_power = 30, \
  54. }
  55. static struct ieee80211_rate iwm_rates[] = {
  56. RATETAB_ENT(10, 0x1, 0),
  57. RATETAB_ENT(20, 0x2, 0),
  58. RATETAB_ENT(55, 0x4, 0),
  59. RATETAB_ENT(110, 0x8, 0),
  60. RATETAB_ENT(60, 0x10, 0),
  61. RATETAB_ENT(90, 0x20, 0),
  62. RATETAB_ENT(120, 0x40, 0),
  63. RATETAB_ENT(180, 0x80, 0),
  64. RATETAB_ENT(240, 0x100, 0),
  65. RATETAB_ENT(360, 0x200, 0),
  66. RATETAB_ENT(480, 0x400, 0),
  67. RATETAB_ENT(540, 0x800, 0),
  68. };
  69. #define iwm_a_rates (iwm_rates + 4)
  70. #define iwm_a_rates_size 8
  71. #define iwm_g_rates (iwm_rates + 0)
  72. #define iwm_g_rates_size 12
  73. static struct ieee80211_channel iwm_2ghz_channels[] = {
  74. CHAN2G(1, 2412, 0),
  75. CHAN2G(2, 2417, 0),
  76. CHAN2G(3, 2422, 0),
  77. CHAN2G(4, 2427, 0),
  78. CHAN2G(5, 2432, 0),
  79. CHAN2G(6, 2437, 0),
  80. CHAN2G(7, 2442, 0),
  81. CHAN2G(8, 2447, 0),
  82. CHAN2G(9, 2452, 0),
  83. CHAN2G(10, 2457, 0),
  84. CHAN2G(11, 2462, 0),
  85. CHAN2G(12, 2467, 0),
  86. CHAN2G(13, 2472, 0),
  87. CHAN2G(14, 2484, 0),
  88. };
  89. static struct ieee80211_channel iwm_5ghz_a_channels[] = {
  90. CHAN5G(34, 0), CHAN5G(36, 0),
  91. CHAN5G(38, 0), CHAN5G(40, 0),
  92. CHAN5G(42, 0), CHAN5G(44, 0),
  93. CHAN5G(46, 0), CHAN5G(48, 0),
  94. CHAN5G(52, 0), CHAN5G(56, 0),
  95. CHAN5G(60, 0), CHAN5G(64, 0),
  96. CHAN5G(100, 0), CHAN5G(104, 0),
  97. CHAN5G(108, 0), CHAN5G(112, 0),
  98. CHAN5G(116, 0), CHAN5G(120, 0),
  99. CHAN5G(124, 0), CHAN5G(128, 0),
  100. CHAN5G(132, 0), CHAN5G(136, 0),
  101. CHAN5G(140, 0), CHAN5G(149, 0),
  102. CHAN5G(153, 0), CHAN5G(157, 0),
  103. CHAN5G(161, 0), CHAN5G(165, 0),
  104. CHAN5G(184, 0), CHAN5G(188, 0),
  105. CHAN5G(192, 0), CHAN5G(196, 0),
  106. CHAN5G(200, 0), CHAN5G(204, 0),
  107. CHAN5G(208, 0), CHAN5G(212, 0),
  108. CHAN5G(216, 0),
  109. };
  110. static struct ieee80211_supported_band iwm_band_2ghz = {
  111. .channels = iwm_2ghz_channels,
  112. .n_channels = ARRAY_SIZE(iwm_2ghz_channels),
  113. .bitrates = iwm_g_rates,
  114. .n_bitrates = iwm_g_rates_size,
  115. };
  116. static struct ieee80211_supported_band iwm_band_5ghz = {
  117. .channels = iwm_5ghz_a_channels,
  118. .n_channels = ARRAY_SIZE(iwm_5ghz_a_channels),
  119. .bitrates = iwm_a_rates,
  120. .n_bitrates = iwm_a_rates_size,
  121. };
  122. static int iwm_key_init(struct iwm_key *key, u8 key_index,
  123. const u8 *mac_addr, struct key_params *params)
  124. {
  125. key->hdr.key_idx = key_index;
  126. if (!mac_addr || is_broadcast_ether_addr(mac_addr)) {
  127. key->hdr.multicast = 1;
  128. memset(key->hdr.mac, 0xff, ETH_ALEN);
  129. } else {
  130. key->hdr.multicast = 0;
  131. memcpy(key->hdr.mac, mac_addr, ETH_ALEN);
  132. }
  133. if (params) {
  134. if (params->key_len > WLAN_MAX_KEY_LEN ||
  135. params->seq_len > IW_ENCODE_SEQ_MAX_SIZE)
  136. return -EINVAL;
  137. key->cipher = params->cipher;
  138. key->key_len = params->key_len;
  139. key->seq_len = params->seq_len;
  140. memcpy(key->key, params->key, key->key_len);
  141. memcpy(key->seq, params->seq, key->seq_len);
  142. }
  143. return 0;
  144. }
  145. static int iwm_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  146. u8 key_index, const u8 *mac_addr,
  147. struct key_params *params)
  148. {
  149. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  150. struct iwm_key *key = &iwm->keys[key_index];
  151. int ret;
  152. IWM_DBG_WEXT(iwm, DBG, "Adding key for %pM\n", mac_addr);
  153. memset(key, 0, sizeof(struct iwm_key));
  154. ret = iwm_key_init(key, key_index, mac_addr, params);
  155. if (ret < 0) {
  156. IWM_ERR(iwm, "Invalid key_params\n");
  157. return ret;
  158. }
  159. return iwm_set_key(iwm, 0, key);
  160. }
  161. static int iwm_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  162. u8 key_index, const u8 *mac_addr, void *cookie,
  163. void (*callback)(void *cookie,
  164. struct key_params*))
  165. {
  166. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  167. struct iwm_key *key = &iwm->keys[key_index];
  168. struct key_params params;
  169. IWM_DBG_WEXT(iwm, DBG, "Getting key %d\n", key_index);
  170. memset(&params, 0, sizeof(params));
  171. params.cipher = key->cipher;
  172. params.key_len = key->key_len;
  173. params.seq_len = key->seq_len;
  174. params.seq = key->seq;
  175. params.key = key->key;
  176. callback(cookie, &params);
  177. return key->key_len ? 0 : -ENOENT;
  178. }
  179. static int iwm_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  180. u8 key_index, const u8 *mac_addr)
  181. {
  182. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  183. struct iwm_key *key = &iwm->keys[key_index];
  184. if (!iwm->keys[key_index].key_len) {
  185. IWM_DBG_WEXT(iwm, DBG, "Key %d not used\n", key_index);
  186. return 0;
  187. }
  188. if (key_index == iwm->default_key)
  189. iwm->default_key = -1;
  190. return iwm_set_key(iwm, 1, key);
  191. }
  192. static int iwm_cfg80211_set_default_key(struct wiphy *wiphy,
  193. struct net_device *ndev,
  194. u8 key_index)
  195. {
  196. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  197. IWM_DBG_WEXT(iwm, DBG, "Default key index is: %d\n", key_index);
  198. if (!iwm->keys[key_index].key_len) {
  199. IWM_ERR(iwm, "Key %d not used\n", key_index);
  200. return -EINVAL;
  201. }
  202. iwm->default_key = key_index;
  203. return iwm_set_tx_key(iwm, key_index);
  204. }
  205. static int iwm_cfg80211_get_station(struct wiphy *wiphy,
  206. struct net_device *ndev,
  207. u8 *mac, struct station_info *sinfo)
  208. {
  209. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  210. if (memcmp(mac, iwm->bssid, ETH_ALEN))
  211. return -ENOENT;
  212. sinfo->filled |= STATION_INFO_TX_BITRATE;
  213. sinfo->txrate.legacy = iwm->rate * 10;
  214. if (test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)) {
  215. sinfo->filled |= STATION_INFO_SIGNAL;
  216. sinfo->signal = iwm->wstats.qual.level;
  217. }
  218. return 0;
  219. }
  220. int iwm_cfg80211_inform_bss(struct iwm_priv *iwm)
  221. {
  222. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  223. struct iwm_bss_info *bss, *next;
  224. struct iwm_umac_notif_bss_info *umac_bss;
  225. struct ieee80211_mgmt *mgmt;
  226. struct ieee80211_channel *channel;
  227. struct ieee80211_supported_band *band;
  228. s32 signal;
  229. int freq;
  230. list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
  231. umac_bss = bss->bss;
  232. mgmt = (struct ieee80211_mgmt *)(umac_bss->frame_buf);
  233. if (umac_bss->band == UMAC_BAND_2GHZ)
  234. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  235. else if (umac_bss->band == UMAC_BAND_5GHZ)
  236. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  237. else {
  238. IWM_ERR(iwm, "Invalid band: %d\n", umac_bss->band);
  239. return -EINVAL;
  240. }
  241. freq = ieee80211_channel_to_frequency(umac_bss->channel);
  242. channel = ieee80211_get_channel(wiphy, freq);
  243. signal = umac_bss->rssi * 100;
  244. if (!cfg80211_inform_bss_frame(wiphy, channel, mgmt,
  245. le16_to_cpu(umac_bss->frame_len),
  246. signal, GFP_KERNEL))
  247. return -EINVAL;
  248. }
  249. return 0;
  250. }
  251. static int iwm_cfg80211_change_iface(struct wiphy *wiphy,
  252. struct net_device *ndev,
  253. enum nl80211_iftype type, u32 *flags,
  254. struct vif_params *params)
  255. {
  256. struct wireless_dev *wdev;
  257. struct iwm_priv *iwm;
  258. u32 old_mode;
  259. wdev = ndev->ieee80211_ptr;
  260. iwm = ndev_to_iwm(ndev);
  261. old_mode = iwm->conf.mode;
  262. switch (type) {
  263. case NL80211_IFTYPE_STATION:
  264. iwm->conf.mode = UMAC_MODE_BSS;
  265. break;
  266. case NL80211_IFTYPE_ADHOC:
  267. iwm->conf.mode = UMAC_MODE_IBSS;
  268. break;
  269. default:
  270. return -EOPNOTSUPP;
  271. }
  272. wdev->iftype = type;
  273. if ((old_mode == iwm->conf.mode) || !iwm->umac_profile)
  274. return 0;
  275. iwm->umac_profile->mode = cpu_to_le32(iwm->conf.mode);
  276. if (iwm->umac_profile_active)
  277. iwm_invalidate_mlme_profile(iwm);
  278. return 0;
  279. }
  280. static int iwm_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  281. struct cfg80211_scan_request *request)
  282. {
  283. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  284. int ret;
  285. if (!test_bit(IWM_STATUS_READY, &iwm->status)) {
  286. IWM_ERR(iwm, "Scan while device is not ready\n");
  287. return -EIO;
  288. }
  289. if (test_bit(IWM_STATUS_SCANNING, &iwm->status)) {
  290. IWM_ERR(iwm, "Scanning already\n");
  291. return -EAGAIN;
  292. }
  293. if (test_bit(IWM_STATUS_SCAN_ABORTING, &iwm->status)) {
  294. IWM_ERR(iwm, "Scanning being aborted\n");
  295. return -EAGAIN;
  296. }
  297. set_bit(IWM_STATUS_SCANNING, &iwm->status);
  298. ret = iwm_scan_ssids(iwm, request->ssids, request->n_ssids);
  299. if (ret) {
  300. clear_bit(IWM_STATUS_SCANNING, &iwm->status);
  301. return ret;
  302. }
  303. iwm->scan_request = request;
  304. return 0;
  305. }
  306. static int iwm_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  307. {
  308. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  309. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  310. (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
  311. int ret;
  312. iwm->conf.rts_threshold = wiphy->rts_threshold;
  313. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  314. CFG_RTS_THRESHOLD,
  315. iwm->conf.rts_threshold);
  316. if (ret < 0)
  317. return ret;
  318. }
  319. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  320. (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
  321. int ret;
  322. iwm->conf.frag_threshold = wiphy->frag_threshold;
  323. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
  324. CFG_FRAG_THRESHOLD,
  325. iwm->conf.frag_threshold);
  326. if (ret < 0)
  327. return ret;
  328. }
  329. return 0;
  330. }
  331. static int iwm_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  332. struct cfg80211_ibss_params *params)
  333. {
  334. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  335. struct ieee80211_channel *chan = params->channel;
  336. struct cfg80211_bss *bss;
  337. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  338. return -EIO;
  339. /* UMAC doesn't support creating IBSS network with specified bssid.
  340. * This should be removed after we have join only mode supported. */
  341. if (params->bssid)
  342. return -EOPNOTSUPP;
  343. bss = cfg80211_get_ibss(iwm_to_wiphy(iwm), NULL,
  344. params->ssid, params->ssid_len);
  345. if (!bss) {
  346. iwm_scan_one_ssid(iwm, params->ssid, params->ssid_len);
  347. schedule_timeout_interruptible(2 * HZ);
  348. bss = cfg80211_get_ibss(iwm_to_wiphy(iwm), NULL,
  349. params->ssid, params->ssid_len);
  350. }
  351. /* IBSS join only mode is not supported by UMAC ATM */
  352. if (bss) {
  353. cfg80211_put_bss(bss);
  354. return -EOPNOTSUPP;
  355. }
  356. iwm->channel = ieee80211_frequency_to_channel(chan->center_freq);
  357. iwm->umac_profile->ibss.band = chan->band;
  358. iwm->umac_profile->ibss.channel = iwm->channel;
  359. iwm->umac_profile->ssid.ssid_len = params->ssid_len;
  360. memcpy(iwm->umac_profile->ssid.ssid, params->ssid, params->ssid_len);
  361. if (params->bssid)
  362. memcpy(&iwm->umac_profile->bssid[0], params->bssid, ETH_ALEN);
  363. return iwm_send_mlme_profile(iwm);
  364. }
  365. static int iwm_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  366. {
  367. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  368. if (iwm->umac_profile_active)
  369. return iwm_invalidate_mlme_profile(iwm);
  370. return 0;
  371. }
  372. static int iwm_set_auth_type(struct iwm_priv *iwm,
  373. enum nl80211_auth_type sme_auth_type)
  374. {
  375. u8 *auth_type = &iwm->umac_profile->sec.auth_type;
  376. switch (sme_auth_type) {
  377. case NL80211_AUTHTYPE_AUTOMATIC:
  378. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  379. IWM_DBG_WEXT(iwm, DBG, "OPEN auth\n");
  380. *auth_type = UMAC_AUTH_TYPE_OPEN;
  381. break;
  382. case NL80211_AUTHTYPE_SHARED_KEY:
  383. if (iwm->umac_profile->sec.flags &
  384. (UMAC_SEC_FLG_WPA_ON_MSK | UMAC_SEC_FLG_RSNA_ON_MSK)) {
  385. IWM_DBG_WEXT(iwm, DBG, "WPA auth alg\n");
  386. *auth_type = UMAC_AUTH_TYPE_RSNA_PSK;
  387. } else {
  388. IWM_DBG_WEXT(iwm, DBG, "WEP shared key auth alg\n");
  389. *auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
  390. }
  391. break;
  392. default:
  393. IWM_ERR(iwm, "Unsupported auth alg: 0x%x\n", sme_auth_type);
  394. return -ENOTSUPP;
  395. }
  396. return 0;
  397. }
  398. static int iwm_set_wpa_version(struct iwm_priv *iwm, u32 wpa_version)
  399. {
  400. IWM_DBG_WEXT(iwm, DBG, "wpa_version: %d\n", wpa_version);
  401. if (!wpa_version) {
  402. iwm->umac_profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
  403. return 0;
  404. }
  405. if (wpa_version & NL80211_WPA_VERSION_2)
  406. iwm->umac_profile->sec.flags = UMAC_SEC_FLG_RSNA_ON_MSK;
  407. if (wpa_version & NL80211_WPA_VERSION_1)
  408. iwm->umac_profile->sec.flags |= UMAC_SEC_FLG_WPA_ON_MSK;
  409. return 0;
  410. }
  411. static int iwm_set_cipher(struct iwm_priv *iwm, u32 cipher, bool ucast)
  412. {
  413. u8 *profile_cipher = ucast ? &iwm->umac_profile->sec.ucast_cipher :
  414. &iwm->umac_profile->sec.mcast_cipher;
  415. if (!cipher) {
  416. *profile_cipher = UMAC_CIPHER_TYPE_NONE;
  417. return 0;
  418. }
  419. IWM_DBG_WEXT(iwm, DBG, "%ccast cipher is 0x%x\n", ucast ? 'u' : 'm',
  420. cipher);
  421. switch (cipher) {
  422. case IW_AUTH_CIPHER_NONE:
  423. *profile_cipher = UMAC_CIPHER_TYPE_NONE;
  424. break;
  425. case WLAN_CIPHER_SUITE_WEP40:
  426. *profile_cipher = UMAC_CIPHER_TYPE_WEP_40;
  427. break;
  428. case WLAN_CIPHER_SUITE_WEP104:
  429. *profile_cipher = UMAC_CIPHER_TYPE_WEP_104;
  430. break;
  431. case WLAN_CIPHER_SUITE_TKIP:
  432. *profile_cipher = UMAC_CIPHER_TYPE_TKIP;
  433. break;
  434. case WLAN_CIPHER_SUITE_CCMP:
  435. *profile_cipher = UMAC_CIPHER_TYPE_CCMP;
  436. break;
  437. default:
  438. IWM_ERR(iwm, "Unsupported cipher: 0x%x\n", cipher);
  439. return -ENOTSUPP;
  440. }
  441. return 0;
  442. }
  443. static int iwm_set_key_mgt(struct iwm_priv *iwm, u32 key_mgt)
  444. {
  445. u8 *auth_type = &iwm->umac_profile->sec.auth_type;
  446. IWM_DBG_WEXT(iwm, DBG, "key_mgt: 0x%x\n", key_mgt);
  447. if (key_mgt == WLAN_AKM_SUITE_8021X)
  448. *auth_type = UMAC_AUTH_TYPE_8021X;
  449. else if (key_mgt == WLAN_AKM_SUITE_PSK) {
  450. if (iwm->umac_profile->sec.flags &
  451. (UMAC_SEC_FLG_WPA_ON_MSK | UMAC_SEC_FLG_RSNA_ON_MSK))
  452. *auth_type = UMAC_AUTH_TYPE_RSNA_PSK;
  453. else
  454. *auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
  455. } else {
  456. IWM_ERR(iwm, "Invalid key mgt: 0x%x\n", key_mgt);
  457. return -EINVAL;
  458. }
  459. return 0;
  460. }
  461. static int iwm_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  462. struct cfg80211_connect_params *sme)
  463. {
  464. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  465. struct ieee80211_channel *chan = sme->channel;
  466. struct key_params key_param;
  467. int ret;
  468. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  469. return -EIO;
  470. if (!sme->ssid)
  471. return -EINVAL;
  472. if (iwm->umac_profile_active) {
  473. ret = iwm_invalidate_mlme_profile(iwm);
  474. if (ret) {
  475. IWM_ERR(iwm, "Couldn't invalidate profile\n");
  476. return ret;
  477. }
  478. }
  479. if (chan)
  480. iwm->channel =
  481. ieee80211_frequency_to_channel(chan->center_freq);
  482. iwm->umac_profile->ssid.ssid_len = sme->ssid_len;
  483. memcpy(iwm->umac_profile->ssid.ssid, sme->ssid, sme->ssid_len);
  484. if (sme->bssid) {
  485. IWM_DBG_WEXT(iwm, DBG, "BSSID: %pM\n", sme->bssid);
  486. memcpy(&iwm->umac_profile->bssid[0], sme->bssid, ETH_ALEN);
  487. iwm->umac_profile->bss_num = 1;
  488. } else {
  489. memset(&iwm->umac_profile->bssid[0], 0, ETH_ALEN);
  490. iwm->umac_profile->bss_num = 0;
  491. }
  492. ret = iwm_set_wpa_version(iwm, sme->crypto.wpa_versions);
  493. if (ret < 0)
  494. return ret;
  495. ret = iwm_set_auth_type(iwm, sme->auth_type);
  496. if (ret < 0)
  497. return ret;
  498. if (sme->crypto.n_ciphers_pairwise) {
  499. ret = iwm_set_cipher(iwm, sme->crypto.ciphers_pairwise[0],
  500. true);
  501. if (ret < 0)
  502. return ret;
  503. }
  504. ret = iwm_set_cipher(iwm, sme->crypto.cipher_group, false);
  505. if (ret < 0)
  506. return ret;
  507. if (sme->crypto.n_akm_suites) {
  508. ret = iwm_set_key_mgt(iwm, sme->crypto.akm_suites[0]);
  509. if (ret < 0)
  510. return ret;
  511. }
  512. /*
  513. * We save the WEP key in case we want to do shared authentication.
  514. * We have to do it so because UMAC will assert whenever it gets a
  515. * key before a profile.
  516. */
  517. if (sme->key) {
  518. key_param.key = kmemdup(sme->key, sme->key_len, GFP_KERNEL);
  519. if (key_param.key == NULL)
  520. return -ENOMEM;
  521. key_param.key_len = sme->key_len;
  522. key_param.seq_len = 0;
  523. key_param.cipher = sme->crypto.ciphers_pairwise[0];
  524. ret = iwm_key_init(&iwm->keys[sme->key_idx], sme->key_idx,
  525. NULL, &key_param);
  526. kfree(key_param.key);
  527. if (ret < 0) {
  528. IWM_ERR(iwm, "Invalid key_params\n");
  529. return ret;
  530. }
  531. iwm->default_key = sme->key_idx;
  532. }
  533. ret = iwm_send_mlme_profile(iwm);
  534. if (iwm->umac_profile->sec.auth_type != UMAC_AUTH_TYPE_LEGACY_PSK ||
  535. sme->key == NULL)
  536. return ret;
  537. /*
  538. * We want to do shared auth.
  539. * We need to actually set the key we previously cached,
  540. * and then tell the UMAC it's the default one.
  541. * That will trigger the auth+assoc UMAC machinery, and again,
  542. * this must be done after setting the profile.
  543. */
  544. ret = iwm_set_key(iwm, 0, &iwm->keys[sme->key_idx]);
  545. if (ret < 0)
  546. return ret;
  547. return iwm_set_tx_key(iwm, iwm->default_key);
  548. }
  549. static int iwm_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  550. u16 reason_code)
  551. {
  552. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  553. IWM_DBG_WEXT(iwm, DBG, "Active: %d\n", iwm->umac_profile_active);
  554. if (iwm->umac_profile_active)
  555. iwm_invalidate_mlme_profile(iwm);
  556. return 0;
  557. }
  558. static int iwm_cfg80211_set_txpower(struct wiphy *wiphy,
  559. enum tx_power_setting type, int dbm)
  560. {
  561. switch (type) {
  562. case TX_POWER_AUTOMATIC:
  563. return 0;
  564. default:
  565. return -EOPNOTSUPP;
  566. }
  567. return 0;
  568. }
  569. static int iwm_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  570. {
  571. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  572. *dbm = iwm->txpower;
  573. return 0;
  574. }
  575. static int iwm_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  576. struct net_device *dev,
  577. bool enabled, int timeout)
  578. {
  579. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  580. u32 power_index;
  581. if (enabled)
  582. power_index = IWM_POWER_INDEX_DEFAULT;
  583. else
  584. power_index = IWM_POWER_INDEX_MIN;
  585. if (power_index == iwm->conf.power_index)
  586. return 0;
  587. iwm->conf.power_index = power_index;
  588. return iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  589. CFG_POWER_INDEX, iwm->conf.power_index);
  590. }
  591. static struct cfg80211_ops iwm_cfg80211_ops = {
  592. .change_virtual_intf = iwm_cfg80211_change_iface,
  593. .add_key = iwm_cfg80211_add_key,
  594. .get_key = iwm_cfg80211_get_key,
  595. .del_key = iwm_cfg80211_del_key,
  596. .set_default_key = iwm_cfg80211_set_default_key,
  597. .get_station = iwm_cfg80211_get_station,
  598. .scan = iwm_cfg80211_scan,
  599. .set_wiphy_params = iwm_cfg80211_set_wiphy_params,
  600. .connect = iwm_cfg80211_connect,
  601. .disconnect = iwm_cfg80211_disconnect,
  602. .join_ibss = iwm_cfg80211_join_ibss,
  603. .leave_ibss = iwm_cfg80211_leave_ibss,
  604. .set_tx_power = iwm_cfg80211_set_txpower,
  605. .get_tx_power = iwm_cfg80211_get_txpower,
  606. .set_power_mgmt = iwm_cfg80211_set_power_mgmt,
  607. };
  608. static const u32 cipher_suites[] = {
  609. WLAN_CIPHER_SUITE_WEP40,
  610. WLAN_CIPHER_SUITE_WEP104,
  611. WLAN_CIPHER_SUITE_TKIP,
  612. WLAN_CIPHER_SUITE_CCMP,
  613. };
  614. struct wireless_dev *iwm_wdev_alloc(int sizeof_bus, struct device *dev)
  615. {
  616. int ret = 0;
  617. struct wireless_dev *wdev;
  618. /*
  619. * We're trying to have the following memory
  620. * layout:
  621. *
  622. * +-------------------------+
  623. * | struct wiphy |
  624. * +-------------------------+
  625. * | struct iwm_priv |
  626. * +-------------------------+
  627. * | bus private data |
  628. * | (e.g. iwm_priv_sdio) |
  629. * +-------------------------+
  630. *
  631. */
  632. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  633. if (!wdev) {
  634. dev_err(dev, "Couldn't allocate wireless device\n");
  635. return ERR_PTR(-ENOMEM);
  636. }
  637. wdev->wiphy = wiphy_new(&iwm_cfg80211_ops,
  638. sizeof(struct iwm_priv) + sizeof_bus);
  639. if (!wdev->wiphy) {
  640. dev_err(dev, "Couldn't allocate wiphy device\n");
  641. ret = -ENOMEM;
  642. goto out_err_new;
  643. }
  644. set_wiphy_dev(wdev->wiphy, dev);
  645. wdev->wiphy->max_scan_ssids = UMAC_WIFI_IF_PROBE_OPTION_MAX;
  646. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  647. BIT(NL80211_IFTYPE_ADHOC);
  648. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &iwm_band_2ghz;
  649. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &iwm_band_5ghz;
  650. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  651. wdev->wiphy->cipher_suites = cipher_suites;
  652. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  653. ret = wiphy_register(wdev->wiphy);
  654. if (ret < 0) {
  655. dev_err(dev, "Couldn't register wiphy device\n");
  656. goto out_err_register;
  657. }
  658. return wdev;
  659. out_err_register:
  660. wiphy_free(wdev->wiphy);
  661. out_err_new:
  662. kfree(wdev);
  663. return ERR_PTR(ret);
  664. }
  665. void iwm_wdev_free(struct iwm_priv *iwm)
  666. {
  667. struct wireless_dev *wdev = iwm_to_wdev(iwm);
  668. if (!wdev)
  669. return;
  670. wiphy_unregister(wdev->wiphy);
  671. wiphy_free(wdev->wiphy);
  672. kfree(wdev);
  673. }