cfg80211.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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_reset_profile(struct iwm_priv *iwm)
  146. {
  147. int ret;
  148. if (!iwm->umac_profile_active)
  149. return 0;
  150. /*
  151. * If there is a current active profile, but no
  152. * default key, it's not worth trying to associate again.
  153. */
  154. if (iwm->default_key < 0)
  155. return 0;
  156. /*
  157. * Here we have an active profile, but a key setting changed.
  158. * We thus have to invalidate the current profile, and push the
  159. * new one. Keys will be pushed when association takes place.
  160. */
  161. ret = iwm_invalidate_mlme_profile(iwm);
  162. if (ret < 0) {
  163. IWM_ERR(iwm, "Couldn't invalidate profile\n");
  164. return ret;
  165. }
  166. return iwm_send_mlme_profile(iwm);
  167. }
  168. static int iwm_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  169. u8 key_index, const u8 *mac_addr,
  170. struct key_params *params)
  171. {
  172. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  173. struct iwm_key *key = &iwm->keys[key_index];
  174. int ret;
  175. IWM_DBG_WEXT(iwm, DBG, "Adding key for %pM\n", mac_addr);
  176. memset(key, 0, sizeof(struct iwm_key));
  177. ret = iwm_key_init(key, key_index, mac_addr, params);
  178. if (ret < 0) {
  179. IWM_ERR(iwm, "Invalid key_params\n");
  180. return ret;
  181. }
  182. /*
  183. * The WEP keys can be set before or after setting the essid.
  184. * We need to handle both cases by simply pushing the keys after
  185. * we send the profile.
  186. * If the profile is not set yet (i.e. we're pushing keys before
  187. * the essid), we set the cipher appropriately.
  188. * If the profile is set, we havent associated yet because our
  189. * cipher was incorrectly set. So we invalidate and send the
  190. * profile again.
  191. */
  192. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  193. key->cipher == WLAN_CIPHER_SUITE_WEP104) {
  194. u8 *ucast_cipher = &iwm->umac_profile->sec.ucast_cipher;
  195. u8 *mcast_cipher = &iwm->umac_profile->sec.mcast_cipher;
  196. IWM_DBG_WEXT(iwm, DBG, "WEP key\n");
  197. if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
  198. *ucast_cipher = *mcast_cipher = UMAC_CIPHER_TYPE_WEP_40;
  199. if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
  200. *ucast_cipher = *mcast_cipher =
  201. UMAC_CIPHER_TYPE_WEP_104;
  202. return iwm_reset_profile(iwm);
  203. }
  204. return iwm_set_key(iwm, 0, key);
  205. }
  206. static int iwm_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  207. u8 key_index, const u8 *mac_addr, void *cookie,
  208. void (*callback)(void *cookie,
  209. struct key_params*))
  210. {
  211. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  212. struct iwm_key *key = &iwm->keys[key_index];
  213. struct key_params params;
  214. IWM_DBG_WEXT(iwm, DBG, "Getting key %d\n", key_index);
  215. memset(&params, 0, sizeof(params));
  216. params.cipher = key->cipher;
  217. params.key_len = key->key_len;
  218. params.seq_len = key->seq_len;
  219. params.seq = key->seq;
  220. params.key = key->key;
  221. callback(cookie, &params);
  222. return key->key_len ? 0 : -ENOENT;
  223. }
  224. static int iwm_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  225. u8 key_index, const u8 *mac_addr)
  226. {
  227. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  228. struct iwm_key *key = &iwm->keys[key_index];
  229. if (!iwm->keys[key_index].key_len) {
  230. IWM_DBG_WEXT(iwm, DBG, "Key %d not used\n", key_index);
  231. return 0;
  232. }
  233. if (key_index == iwm->default_key)
  234. iwm->default_key = -1;
  235. /* If the interface is down, we just cache this */
  236. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  237. return 0;
  238. return iwm_set_key(iwm, 1, key);
  239. }
  240. static int iwm_cfg80211_set_default_key(struct wiphy *wiphy,
  241. struct net_device *ndev,
  242. u8 key_index)
  243. {
  244. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  245. int ret;
  246. IWM_DBG_WEXT(iwm, DBG, "Default key index is: %d\n", key_index);
  247. if (!iwm->keys[key_index].key_len) {
  248. IWM_ERR(iwm, "Key %d not used\n", key_index);
  249. return -EINVAL;
  250. }
  251. iwm->default_key = key_index;
  252. /* If the interface is down, we just cache this */
  253. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  254. return 0;
  255. ret = iwm_set_tx_key(iwm, key_index);
  256. if (ret < 0)
  257. return ret;
  258. return iwm_reset_profile(iwm);
  259. }
  260. int iwm_cfg80211_inform_bss(struct iwm_priv *iwm)
  261. {
  262. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  263. struct iwm_bss_info *bss, *next;
  264. struct iwm_umac_notif_bss_info *umac_bss;
  265. struct ieee80211_mgmt *mgmt;
  266. struct ieee80211_channel *channel;
  267. struct ieee80211_supported_band *band;
  268. s32 signal;
  269. int freq;
  270. list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
  271. umac_bss = bss->bss;
  272. mgmt = (struct ieee80211_mgmt *)(umac_bss->frame_buf);
  273. if (umac_bss->band == UMAC_BAND_2GHZ)
  274. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  275. else if (umac_bss->band == UMAC_BAND_5GHZ)
  276. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  277. else {
  278. IWM_ERR(iwm, "Invalid band: %d\n", umac_bss->band);
  279. return -EINVAL;
  280. }
  281. freq = ieee80211_channel_to_frequency(umac_bss->channel);
  282. channel = ieee80211_get_channel(wiphy, freq);
  283. signal = umac_bss->rssi * 100;
  284. if (!cfg80211_inform_bss_frame(wiphy, channel, mgmt,
  285. le16_to_cpu(umac_bss->frame_len),
  286. signal, GFP_KERNEL))
  287. return -EINVAL;
  288. }
  289. return 0;
  290. }
  291. static int iwm_cfg80211_change_iface(struct wiphy *wiphy,
  292. struct net_device *ndev,
  293. enum nl80211_iftype type, u32 *flags,
  294. struct vif_params *params)
  295. {
  296. struct wireless_dev *wdev;
  297. struct iwm_priv *iwm;
  298. u32 old_mode;
  299. wdev = ndev->ieee80211_ptr;
  300. iwm = ndev_to_iwm(ndev);
  301. old_mode = iwm->conf.mode;
  302. switch (type) {
  303. case NL80211_IFTYPE_STATION:
  304. iwm->conf.mode = UMAC_MODE_BSS;
  305. break;
  306. case NL80211_IFTYPE_ADHOC:
  307. iwm->conf.mode = UMAC_MODE_IBSS;
  308. break;
  309. default:
  310. return -EOPNOTSUPP;
  311. }
  312. wdev->iftype = type;
  313. if ((old_mode == iwm->conf.mode) || !iwm->umac_profile)
  314. return 0;
  315. iwm->umac_profile->mode = cpu_to_le32(iwm->conf.mode);
  316. if (iwm->umac_profile_active) {
  317. int ret = iwm_invalidate_mlme_profile(iwm);
  318. if (ret < 0)
  319. IWM_ERR(iwm, "Couldn't invalidate profile\n");
  320. }
  321. return 0;
  322. }
  323. static int iwm_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  324. struct cfg80211_scan_request *request)
  325. {
  326. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  327. int ret;
  328. if (!test_bit(IWM_STATUS_READY, &iwm->status)) {
  329. IWM_ERR(iwm, "Scan while device is not ready\n");
  330. return -EIO;
  331. }
  332. if (test_bit(IWM_STATUS_SCANNING, &iwm->status)) {
  333. IWM_ERR(iwm, "Scanning already\n");
  334. return -EAGAIN;
  335. }
  336. if (test_bit(IWM_STATUS_SCAN_ABORTING, &iwm->status)) {
  337. IWM_ERR(iwm, "Scanning being aborted\n");
  338. return -EAGAIN;
  339. }
  340. set_bit(IWM_STATUS_SCANNING, &iwm->status);
  341. ret = iwm_scan_ssids(iwm, request->ssids, request->n_ssids);
  342. if (ret) {
  343. clear_bit(IWM_STATUS_SCANNING, &iwm->status);
  344. return ret;
  345. }
  346. iwm->scan_request = request;
  347. return 0;
  348. }
  349. static int iwm_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  350. {
  351. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  352. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  353. (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
  354. int ret;
  355. iwm->conf.rts_threshold = wiphy->rts_threshold;
  356. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  357. CFG_RTS_THRESHOLD,
  358. iwm->conf.rts_threshold);
  359. if (ret < 0)
  360. return ret;
  361. }
  362. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  363. (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
  364. int ret;
  365. iwm->conf.frag_threshold = wiphy->frag_threshold;
  366. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
  367. CFG_FRAG_THRESHOLD,
  368. iwm->conf.frag_threshold);
  369. if (ret < 0)
  370. return ret;
  371. }
  372. return 0;
  373. }
  374. static int iwm_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  375. struct cfg80211_ibss_params *params)
  376. {
  377. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  378. struct ieee80211_channel *chan = params->channel;
  379. struct cfg80211_bss *bss;
  380. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  381. return -EIO;
  382. /* UMAC doesn't support creating IBSS network with specified bssid.
  383. * This should be removed after we have join only mode supported. */
  384. if (params->bssid)
  385. return -EOPNOTSUPP;
  386. bss = cfg80211_get_ibss(iwm_to_wiphy(iwm), NULL,
  387. params->ssid, params->ssid_len);
  388. if (!bss) {
  389. iwm_scan_one_ssid(iwm, params->ssid, params->ssid_len);
  390. schedule_timeout_interruptible(2 * HZ);
  391. bss = cfg80211_get_ibss(iwm_to_wiphy(iwm), NULL,
  392. params->ssid, params->ssid_len);
  393. }
  394. /* IBSS join only mode is not supported by UMAC ATM */
  395. if (bss) {
  396. cfg80211_put_bss(bss);
  397. return -EOPNOTSUPP;
  398. }
  399. iwm->channel = ieee80211_frequency_to_channel(chan->center_freq);
  400. iwm->umac_profile->ibss.band = chan->band;
  401. iwm->umac_profile->ibss.channel = iwm->channel;
  402. iwm->umac_profile->ssid.ssid_len = params->ssid_len;
  403. memcpy(iwm->umac_profile->ssid.ssid, params->ssid, params->ssid_len);
  404. if (params->bssid)
  405. memcpy(&iwm->umac_profile->bssid[0], params->bssid, ETH_ALEN);
  406. return iwm_send_mlme_profile(iwm);
  407. }
  408. static int iwm_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  409. {
  410. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  411. if (iwm->umac_profile_active)
  412. return iwm_invalidate_mlme_profile(iwm);
  413. return 0;
  414. }
  415. static int iwm_cfg80211_set_txpower(struct wiphy *wiphy,
  416. enum tx_power_setting type, int dbm)
  417. {
  418. switch (type) {
  419. case TX_POWER_AUTOMATIC:
  420. return 0;
  421. default:
  422. return -EOPNOTSUPP;
  423. }
  424. return 0;
  425. }
  426. static int iwm_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  427. {
  428. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  429. *dbm = iwm->txpower;
  430. return 0;
  431. }
  432. static int iwm_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  433. struct net_device *dev,
  434. bool enabled, int timeout)
  435. {
  436. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  437. u32 power_index;
  438. if (enabled)
  439. power_index = IWM_POWER_INDEX_DEFAULT;
  440. else
  441. power_index = IWM_POWER_INDEX_MIN;
  442. if (power_index == iwm->conf.power_index)
  443. return 0;
  444. iwm->conf.power_index = power_index;
  445. return iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  446. CFG_POWER_INDEX, iwm->conf.power_index);
  447. }
  448. static struct cfg80211_ops iwm_cfg80211_ops = {
  449. .change_virtual_intf = iwm_cfg80211_change_iface,
  450. .add_key = iwm_cfg80211_add_key,
  451. .get_key = iwm_cfg80211_get_key,
  452. .del_key = iwm_cfg80211_del_key,
  453. .set_default_key = iwm_cfg80211_set_default_key,
  454. .scan = iwm_cfg80211_scan,
  455. .set_wiphy_params = iwm_cfg80211_set_wiphy_params,
  456. .join_ibss = iwm_cfg80211_join_ibss,
  457. .leave_ibss = iwm_cfg80211_leave_ibss,
  458. .set_tx_power = iwm_cfg80211_set_txpower,
  459. .get_tx_power = iwm_cfg80211_get_txpower,
  460. .set_power_mgmt = iwm_cfg80211_set_power_mgmt,
  461. };
  462. struct wireless_dev *iwm_wdev_alloc(int sizeof_bus, struct device *dev)
  463. {
  464. int ret = 0;
  465. struct wireless_dev *wdev;
  466. /*
  467. * We're trying to have the following memory
  468. * layout:
  469. *
  470. * +-------------------------+
  471. * | struct wiphy |
  472. * +-------------------------+
  473. * | struct iwm_priv |
  474. * +-------------------------+
  475. * | bus private data |
  476. * | (e.g. iwm_priv_sdio) |
  477. * +-------------------------+
  478. *
  479. */
  480. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  481. if (!wdev) {
  482. dev_err(dev, "Couldn't allocate wireless device\n");
  483. return ERR_PTR(-ENOMEM);
  484. }
  485. wdev->wiphy = wiphy_new(&iwm_cfg80211_ops,
  486. sizeof(struct iwm_priv) + sizeof_bus);
  487. if (!wdev->wiphy) {
  488. dev_err(dev, "Couldn't allocate wiphy device\n");
  489. ret = -ENOMEM;
  490. goto out_err_new;
  491. }
  492. set_wiphy_dev(wdev->wiphy, dev);
  493. wdev->wiphy->max_scan_ssids = UMAC_WIFI_IF_PROBE_OPTION_MAX;
  494. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  495. BIT(NL80211_IFTYPE_ADHOC);
  496. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &iwm_band_2ghz;
  497. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &iwm_band_5ghz;
  498. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  499. ret = wiphy_register(wdev->wiphy);
  500. if (ret < 0) {
  501. dev_err(dev, "Couldn't register wiphy device\n");
  502. goto out_err_register;
  503. }
  504. return wdev;
  505. out_err_register:
  506. wiphy_free(wdev->wiphy);
  507. out_err_new:
  508. kfree(wdev);
  509. return ERR_PTR(ret);
  510. }
  511. void iwm_wdev_free(struct iwm_priv *iwm)
  512. {
  513. struct wireless_dev *wdev = iwm_to_wdev(iwm);
  514. if (!wdev)
  515. return;
  516. wiphy_unregister(wdev->wiphy);
  517. wiphy_free(wdev->wiphy);
  518. kfree(wdev);
  519. }