2 * Intel Wireless Multicomm 3200 WiFi driver
4 * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
5 * Samuel Ortiz <samuel.ortiz@intel.com>
6 * Zhu Yi <yi.zhu@intel.com>
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.
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.
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
24 #include <linux/kernel.h>
25 #include <linux/netdevice.h>
26 #include <linux/sched.h>
27 #include <linux/etherdevice.h>
28 #include <linux/wireless.h>
29 #include <linux/ieee80211.h>
30 #include <linux/slab.h>
31 #include <net/cfg80211.h>
38 #define RATETAB_ENT(_rate, _rateid, _flags) \
41 .hw_value = (_rateid), \
45 #define CHAN2G(_channel, _freq, _flags) { \
46 .band = IEEE80211_BAND_2GHZ, \
47 .center_freq = (_freq), \
48 .hw_value = (_channel), \
50 .max_antenna_gain = 0, \
54 #define CHAN5G(_channel, _flags) { \
55 .band = IEEE80211_BAND_5GHZ, \
56 .center_freq = 5000 + (5 * (_channel)), \
57 .hw_value = (_channel), \
59 .max_antenna_gain = 0, \
63 static struct ieee80211_rate iwm_rates
[] = {
64 RATETAB_ENT(10, 0x1, 0),
65 RATETAB_ENT(20, 0x2, 0),
66 RATETAB_ENT(55, 0x4, 0),
67 RATETAB_ENT(110, 0x8, 0),
68 RATETAB_ENT(60, 0x10, 0),
69 RATETAB_ENT(90, 0x20, 0),
70 RATETAB_ENT(120, 0x40, 0),
71 RATETAB_ENT(180, 0x80, 0),
72 RATETAB_ENT(240, 0x100, 0),
73 RATETAB_ENT(360, 0x200, 0),
74 RATETAB_ENT(480, 0x400, 0),
75 RATETAB_ENT(540, 0x800, 0),
78 #define iwm_a_rates (iwm_rates + 4)
79 #define iwm_a_rates_size 8
80 #define iwm_g_rates (iwm_rates + 0)
81 #define iwm_g_rates_size 12
83 static struct ieee80211_channel iwm_2ghz_channels
[] = {
100 static struct ieee80211_channel iwm_5ghz_a_channels
[] = {
101 CHAN5G(34, 0), CHAN5G(36, 0),
102 CHAN5G(38, 0), CHAN5G(40, 0),
103 CHAN5G(42, 0), CHAN5G(44, 0),
104 CHAN5G(46, 0), CHAN5G(48, 0),
105 CHAN5G(52, 0), CHAN5G(56, 0),
106 CHAN5G(60, 0), CHAN5G(64, 0),
107 CHAN5G(100, 0), CHAN5G(104, 0),
108 CHAN5G(108, 0), CHAN5G(112, 0),
109 CHAN5G(116, 0), CHAN5G(120, 0),
110 CHAN5G(124, 0), CHAN5G(128, 0),
111 CHAN5G(132, 0), CHAN5G(136, 0),
112 CHAN5G(140, 0), CHAN5G(149, 0),
113 CHAN5G(153, 0), CHAN5G(157, 0),
114 CHAN5G(161, 0), CHAN5G(165, 0),
115 CHAN5G(184, 0), CHAN5G(188, 0),
116 CHAN5G(192, 0), CHAN5G(196, 0),
117 CHAN5G(200, 0), CHAN5G(204, 0),
118 CHAN5G(208, 0), CHAN5G(212, 0),
122 static struct ieee80211_supported_band iwm_band_2ghz
= {
123 .channels
= iwm_2ghz_channels
,
124 .n_channels
= ARRAY_SIZE(iwm_2ghz_channels
),
125 .bitrates
= iwm_g_rates
,
126 .n_bitrates
= iwm_g_rates_size
,
129 static struct ieee80211_supported_band iwm_band_5ghz
= {
130 .channels
= iwm_5ghz_a_channels
,
131 .n_channels
= ARRAY_SIZE(iwm_5ghz_a_channels
),
132 .bitrates
= iwm_a_rates
,
133 .n_bitrates
= iwm_a_rates_size
,
136 static int iwm_key_init(struct iwm_key
*key
, u8 key_index
,
137 const u8
*mac_addr
, struct key_params
*params
)
139 key
->hdr
.key_idx
= key_index
;
140 if (!mac_addr
|| is_broadcast_ether_addr(mac_addr
)) {
141 key
->hdr
.multicast
= 1;
142 memset(key
->hdr
.mac
, 0xff, ETH_ALEN
);
144 key
->hdr
.multicast
= 0;
145 memcpy(key
->hdr
.mac
, mac_addr
, ETH_ALEN
);
149 if (params
->key_len
> WLAN_MAX_KEY_LEN
||
150 params
->seq_len
> IW_ENCODE_SEQ_MAX_SIZE
)
153 key
->cipher
= params
->cipher
;
154 key
->key_len
= params
->key_len
;
155 key
->seq_len
= params
->seq_len
;
156 memcpy(key
->key
, params
->key
, key
->key_len
);
157 memcpy(key
->seq
, params
->seq
, key
->seq_len
);
163 static int iwm_cfg80211_add_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
164 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
165 struct key_params
*params
)
167 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
171 IWM_DBG_WEXT(iwm
, DBG
, "Adding key for %pM\n", mac_addr
);
173 if (key_index
>= IWM_NUM_KEYS
)
176 key
= &iwm
->keys
[key_index
];
177 memset(key
, 0, sizeof(struct iwm_key
));
178 ret
= iwm_key_init(key
, key_index
, mac_addr
, params
);
180 IWM_ERR(iwm
, "Invalid key_params\n");
184 return iwm_set_key(iwm
, 0, key
);
187 static int iwm_cfg80211_get_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
188 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
190 void (*callback
)(void *cookie
,
193 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
195 struct key_params params
;
197 IWM_DBG_WEXT(iwm
, DBG
, "Getting key %d\n", key_index
);
199 if (key_index
>= IWM_NUM_KEYS
)
202 memset(¶ms
, 0, sizeof(params
));
204 key
= &iwm
->keys
[key_index
];
205 params
.cipher
= key
->cipher
;
206 params
.key_len
= key
->key_len
;
207 params
.seq_len
= key
->seq_len
;
208 params
.seq
= key
->seq
;
209 params
.key
= key
->key
;
211 callback(cookie
, ¶ms
);
213 return key
->key_len
? 0 : -ENOENT
;
217 static int iwm_cfg80211_del_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
218 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
220 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
223 if (key_index
>= IWM_NUM_KEYS
)
226 key
= &iwm
->keys
[key_index
];
227 if (!iwm
->keys
[key_index
].key_len
) {
228 IWM_DBG_WEXT(iwm
, DBG
, "Key %d not used\n", key_index
);
232 if (key_index
== iwm
->default_key
)
233 iwm
->default_key
= -1;
235 return iwm_set_key(iwm
, 1, key
);
238 static int iwm_cfg80211_set_default_key(struct wiphy
*wiphy
,
239 struct net_device
*ndev
,
240 u8 key_index
, bool unicast
,
243 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
245 IWM_DBG_WEXT(iwm
, DBG
, "Default key index is: %d\n", key_index
);
247 if (key_index
>= IWM_NUM_KEYS
)
250 if (!iwm
->keys
[key_index
].key_len
) {
251 IWM_ERR(iwm
, "Key %d not used\n", key_index
);
255 iwm
->default_key
= key_index
;
257 return iwm_set_tx_key(iwm
, key_index
);
260 static int iwm_cfg80211_get_station(struct wiphy
*wiphy
,
261 struct net_device
*ndev
,
262 u8
*mac
, struct station_info
*sinfo
)
264 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
266 if (memcmp(mac
, iwm
->bssid
, ETH_ALEN
))
269 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
270 sinfo
->txrate
.legacy
= iwm
->rate
* 10;
272 if (test_bit(IWM_STATUS_ASSOCIATED
, &iwm
->status
)) {
273 sinfo
->filled
|= STATION_INFO_SIGNAL
;
274 sinfo
->signal
= iwm
->wstats
.qual
.level
;
281 int iwm_cfg80211_inform_bss(struct iwm_priv
*iwm
)
283 struct wiphy
*wiphy
= iwm_to_wiphy(iwm
);
284 struct iwm_bss_info
*bss
;
285 struct iwm_umac_notif_bss_info
*umac_bss
;
286 struct ieee80211_mgmt
*mgmt
;
287 struct ieee80211_channel
*channel
;
288 struct ieee80211_supported_band
*band
;
292 list_for_each_entry(bss
, &iwm
->bss_list
, node
) {
294 mgmt
= (struct ieee80211_mgmt
*)(umac_bss
->frame_buf
);
296 if (umac_bss
->band
== UMAC_BAND_2GHZ
)
297 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
298 else if (umac_bss
->band
== UMAC_BAND_5GHZ
)
299 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
301 IWM_ERR(iwm
, "Invalid band: %d\n", umac_bss
->band
);
305 freq
= ieee80211_channel_to_frequency(umac_bss
->channel
,
307 channel
= ieee80211_get_channel(wiphy
, freq
);
308 signal
= umac_bss
->rssi
* 100;
310 if (!cfg80211_inform_bss_frame(wiphy
, channel
, mgmt
,
311 le16_to_cpu(umac_bss
->frame_len
),
319 static int iwm_cfg80211_change_iface(struct wiphy
*wiphy
,
320 struct net_device
*ndev
,
321 enum nl80211_iftype type
, u32
*flags
,
322 struct vif_params
*params
)
324 struct wireless_dev
*wdev
;
325 struct iwm_priv
*iwm
;
328 wdev
= ndev
->ieee80211_ptr
;
329 iwm
= ndev_to_iwm(ndev
);
330 old_mode
= iwm
->conf
.mode
;
333 case NL80211_IFTYPE_STATION
:
334 iwm
->conf
.mode
= UMAC_MODE_BSS
;
336 case NL80211_IFTYPE_ADHOC
:
337 iwm
->conf
.mode
= UMAC_MODE_IBSS
;
345 if ((old_mode
== iwm
->conf
.mode
) || !iwm
->umac_profile
)
348 iwm
->umac_profile
->mode
= cpu_to_le32(iwm
->conf
.mode
);
350 if (iwm
->umac_profile_active
)
351 iwm_invalidate_mlme_profile(iwm
);
356 static int iwm_cfg80211_scan(struct wiphy
*wiphy
, struct net_device
*ndev
,
357 struct cfg80211_scan_request
*request
)
359 struct iwm_priv
*iwm
= ndev_to_iwm(ndev
);
362 if (!test_bit(IWM_STATUS_READY
, &iwm
->status
)) {
363 IWM_ERR(iwm
, "Scan while device is not ready\n");
367 if (test_bit(IWM_STATUS_SCANNING
, &iwm
->status
)) {
368 IWM_ERR(iwm
, "Scanning already\n");
372 if (test_bit(IWM_STATUS_SCAN_ABORTING
, &iwm
->status
)) {
373 IWM_ERR(iwm
, "Scanning being aborted\n");
377 set_bit(IWM_STATUS_SCANNING
, &iwm
->status
);
379 ret
= iwm_scan_ssids(iwm
, request
->ssids
, request
->n_ssids
);
381 clear_bit(IWM_STATUS_SCANNING
, &iwm
->status
);
385 iwm
->scan_request
= request
;
389 static int iwm_cfg80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
391 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
393 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
&&
394 (iwm
->conf
.rts_threshold
!= wiphy
->rts_threshold
)) {
397 iwm
->conf
.rts_threshold
= wiphy
->rts_threshold
;
399 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
401 iwm
->conf
.rts_threshold
);
406 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
&&
407 (iwm
->conf
.frag_threshold
!= wiphy
->frag_threshold
)) {
410 iwm
->conf
.frag_threshold
= wiphy
->frag_threshold
;
412 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_FA_CFG_FIX
,
414 iwm
->conf
.frag_threshold
);
422 static int iwm_cfg80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
423 struct cfg80211_ibss_params
*params
)
425 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
426 struct ieee80211_channel
*chan
= params
->channel
;
428 if (!test_bit(IWM_STATUS_READY
, &iwm
->status
))
431 /* UMAC doesn't support creating or joining an IBSS network
432 * with specified bssid. */
436 iwm
->channel
= ieee80211_frequency_to_channel(chan
->center_freq
);
437 iwm
->umac_profile
->ibss
.band
= chan
->band
;
438 iwm
->umac_profile
->ibss
.channel
= iwm
->channel
;
439 iwm
->umac_profile
->ssid
.ssid_len
= params
->ssid_len
;
440 memcpy(iwm
->umac_profile
->ssid
.ssid
, params
->ssid
, params
->ssid_len
);
442 return iwm_send_mlme_profile(iwm
);
445 static int iwm_cfg80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
447 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
449 if (iwm
->umac_profile_active
)
450 return iwm_invalidate_mlme_profile(iwm
);
455 static int iwm_set_auth_type(struct iwm_priv
*iwm
,
456 enum nl80211_auth_type sme_auth_type
)
458 u8
*auth_type
= &iwm
->umac_profile
->sec
.auth_type
;
460 switch (sme_auth_type
) {
461 case NL80211_AUTHTYPE_AUTOMATIC
:
462 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
463 IWM_DBG_WEXT(iwm
, DBG
, "OPEN auth\n");
464 *auth_type
= UMAC_AUTH_TYPE_OPEN
;
466 case NL80211_AUTHTYPE_SHARED_KEY
:
467 if (iwm
->umac_profile
->sec
.flags
&
468 (UMAC_SEC_FLG_WPA_ON_MSK
| UMAC_SEC_FLG_RSNA_ON_MSK
)) {
469 IWM_DBG_WEXT(iwm
, DBG
, "WPA auth alg\n");
470 *auth_type
= UMAC_AUTH_TYPE_RSNA_PSK
;
472 IWM_DBG_WEXT(iwm
, DBG
, "WEP shared key auth alg\n");
473 *auth_type
= UMAC_AUTH_TYPE_LEGACY_PSK
;
478 IWM_ERR(iwm
, "Unsupported auth alg: 0x%x\n", sme_auth_type
);
485 static int iwm_set_wpa_version(struct iwm_priv
*iwm
, u32 wpa_version
)
487 IWM_DBG_WEXT(iwm
, DBG
, "wpa_version: %d\n", wpa_version
);
490 iwm
->umac_profile
->sec
.flags
= UMAC_SEC_FLG_LEGACY_PROFILE
;
494 if (wpa_version
& NL80211_WPA_VERSION_1
)
495 iwm
->umac_profile
->sec
.flags
= UMAC_SEC_FLG_WPA_ON_MSK
;
497 if (wpa_version
& NL80211_WPA_VERSION_2
)
498 iwm
->umac_profile
->sec
.flags
= UMAC_SEC_FLG_RSNA_ON_MSK
;
503 static int iwm_set_cipher(struct iwm_priv
*iwm
, u32 cipher
, bool ucast
)
505 u8
*profile_cipher
= ucast
? &iwm
->umac_profile
->sec
.ucast_cipher
:
506 &iwm
->umac_profile
->sec
.mcast_cipher
;
509 *profile_cipher
= UMAC_CIPHER_TYPE_NONE
;
513 IWM_DBG_WEXT(iwm
, DBG
, "%ccast cipher is 0x%x\n", ucast
? 'u' : 'm',
517 case IW_AUTH_CIPHER_NONE
:
518 *profile_cipher
= UMAC_CIPHER_TYPE_NONE
;
520 case WLAN_CIPHER_SUITE_WEP40
:
521 *profile_cipher
= UMAC_CIPHER_TYPE_WEP_40
;
523 case WLAN_CIPHER_SUITE_WEP104
:
524 *profile_cipher
= UMAC_CIPHER_TYPE_WEP_104
;
526 case WLAN_CIPHER_SUITE_TKIP
:
527 *profile_cipher
= UMAC_CIPHER_TYPE_TKIP
;
529 case WLAN_CIPHER_SUITE_CCMP
:
530 *profile_cipher
= UMAC_CIPHER_TYPE_CCMP
;
533 IWM_ERR(iwm
, "Unsupported cipher: 0x%x\n", cipher
);
540 static int iwm_set_key_mgt(struct iwm_priv
*iwm
, u32 key_mgt
)
542 u8
*auth_type
= &iwm
->umac_profile
->sec
.auth_type
;
544 IWM_DBG_WEXT(iwm
, DBG
, "key_mgt: 0x%x\n", key_mgt
);
546 if (key_mgt
== WLAN_AKM_SUITE_8021X
)
547 *auth_type
= UMAC_AUTH_TYPE_8021X
;
548 else if (key_mgt
== WLAN_AKM_SUITE_PSK
) {
549 if (iwm
->umac_profile
->sec
.flags
&
550 (UMAC_SEC_FLG_WPA_ON_MSK
| UMAC_SEC_FLG_RSNA_ON_MSK
))
551 *auth_type
= UMAC_AUTH_TYPE_RSNA_PSK
;
553 *auth_type
= UMAC_AUTH_TYPE_LEGACY_PSK
;
555 IWM_ERR(iwm
, "Invalid key mgt: 0x%x\n", key_mgt
);
563 static int iwm_cfg80211_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
564 struct cfg80211_connect_params
*sme
)
566 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
567 struct ieee80211_channel
*chan
= sme
->channel
;
568 struct key_params key_param
;
571 if (!test_bit(IWM_STATUS_READY
, &iwm
->status
))
577 if (iwm
->umac_profile_active
) {
578 ret
= iwm_invalidate_mlme_profile(iwm
);
580 IWM_ERR(iwm
, "Couldn't invalidate profile\n");
587 ieee80211_frequency_to_channel(chan
->center_freq
);
589 iwm
->umac_profile
->ssid
.ssid_len
= sme
->ssid_len
;
590 memcpy(iwm
->umac_profile
->ssid
.ssid
, sme
->ssid
, sme
->ssid_len
);
593 IWM_DBG_WEXT(iwm
, DBG
, "BSSID: %pM\n", sme
->bssid
);
594 memcpy(&iwm
->umac_profile
->bssid
[0], sme
->bssid
, ETH_ALEN
);
595 iwm
->umac_profile
->bss_num
= 1;
597 memset(&iwm
->umac_profile
->bssid
[0], 0, ETH_ALEN
);
598 iwm
->umac_profile
->bss_num
= 0;
601 ret
= iwm_set_wpa_version(iwm
, sme
->crypto
.wpa_versions
);
605 ret
= iwm_set_auth_type(iwm
, sme
->auth_type
);
609 if (sme
->crypto
.n_ciphers_pairwise
) {
610 ret
= iwm_set_cipher(iwm
, sme
->crypto
.ciphers_pairwise
[0],
616 ret
= iwm_set_cipher(iwm
, sme
->crypto
.cipher_group
, false);
620 if (sme
->crypto
.n_akm_suites
) {
621 ret
= iwm_set_key_mgt(iwm
, sme
->crypto
.akm_suites
[0]);
627 * We save the WEP key in case we want to do shared authentication.
628 * We have to do it so because UMAC will assert whenever it gets a
629 * key before a profile.
632 key_param
.key
= kmemdup(sme
->key
, sme
->key_len
, GFP_KERNEL
);
633 if (key_param
.key
== NULL
)
635 key_param
.key_len
= sme
->key_len
;
636 key_param
.seq_len
= 0;
637 key_param
.cipher
= sme
->crypto
.ciphers_pairwise
[0];
639 ret
= iwm_key_init(&iwm
->keys
[sme
->key_idx
], sme
->key_idx
,
641 kfree(key_param
.key
);
643 IWM_ERR(iwm
, "Invalid key_params\n");
647 iwm
->default_key
= sme
->key_idx
;
650 /* WPA and open AUTH type from wpa_s means WPS (a.k.a. WSC) */
651 if ((iwm
->umac_profile
->sec
.flags
&
652 (UMAC_SEC_FLG_WPA_ON_MSK
| UMAC_SEC_FLG_RSNA_ON_MSK
)) &&
653 iwm
->umac_profile
->sec
.auth_type
== UMAC_AUTH_TYPE_OPEN
) {
654 iwm
->umac_profile
->sec
.flags
= UMAC_SEC_FLG_WSC_ON_MSK
;
657 ret
= iwm_send_mlme_profile(iwm
);
659 if (iwm
->umac_profile
->sec
.auth_type
!= UMAC_AUTH_TYPE_LEGACY_PSK
||
664 * We want to do shared auth.
665 * We need to actually set the key we previously cached,
666 * and then tell the UMAC it's the default one.
667 * That will trigger the auth+assoc UMAC machinery, and again,
668 * this must be done after setting the profile.
670 ret
= iwm_set_key(iwm
, 0, &iwm
->keys
[sme
->key_idx
]);
674 return iwm_set_tx_key(iwm
, iwm
->default_key
);
677 static int iwm_cfg80211_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
680 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
682 IWM_DBG_WEXT(iwm
, DBG
, "Active: %d\n", iwm
->umac_profile_active
);
684 if (iwm
->umac_profile_active
)
685 iwm_invalidate_mlme_profile(iwm
);
690 static int iwm_cfg80211_set_txpower(struct wiphy
*wiphy
,
691 enum nl80211_tx_power_setting type
, int mbm
)
693 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
697 case NL80211_TX_POWER_AUTOMATIC
:
699 case NL80211_TX_POWER_FIXED
:
700 if (mbm
< 0 || (mbm
% 100))
703 if (!test_bit(IWM_STATUS_READY
, &iwm
->status
))
706 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
707 CFG_TX_PWR_LIMIT_USR
,
708 MBM_TO_DBM(mbm
) * 2);
712 return iwm_tx_power_trigger(iwm
);
714 IWM_ERR(iwm
, "Unsupported power type: %d\n", type
);
721 static int iwm_cfg80211_get_txpower(struct wiphy
*wiphy
, int *dbm
)
723 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
725 *dbm
= iwm
->txpower
>> 1;
730 static int iwm_cfg80211_set_power_mgmt(struct wiphy
*wiphy
,
731 struct net_device
*dev
,
732 bool enabled
, int timeout
)
734 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
738 power_index
= IWM_POWER_INDEX_DEFAULT
;
740 power_index
= IWM_POWER_INDEX_MIN
;
742 if (power_index
== iwm
->conf
.power_index
)
745 iwm
->conf
.power_index
= power_index
;
747 return iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
748 CFG_POWER_INDEX
, iwm
->conf
.power_index
);
751 static int iwm_cfg80211_set_pmksa(struct wiphy
*wiphy
,
752 struct net_device
*netdev
,
753 struct cfg80211_pmksa
*pmksa
)
755 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
757 return iwm_send_pmkid_update(iwm
, pmksa
, IWM_CMD_PMKID_ADD
);
760 static int iwm_cfg80211_del_pmksa(struct wiphy
*wiphy
,
761 struct net_device
*netdev
,
762 struct cfg80211_pmksa
*pmksa
)
764 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
766 return iwm_send_pmkid_update(iwm
, pmksa
, IWM_CMD_PMKID_DEL
);
769 static int iwm_cfg80211_flush_pmksa(struct wiphy
*wiphy
,
770 struct net_device
*netdev
)
772 struct iwm_priv
*iwm
= wiphy_to_iwm(wiphy
);
773 struct cfg80211_pmksa pmksa
;
775 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
777 return iwm_send_pmkid_update(iwm
, &pmksa
, IWM_CMD_PMKID_FLUSH
);
781 static struct cfg80211_ops iwm_cfg80211_ops
= {
782 .change_virtual_intf
= iwm_cfg80211_change_iface
,
783 .add_key
= iwm_cfg80211_add_key
,
784 .get_key
= iwm_cfg80211_get_key
,
785 .del_key
= iwm_cfg80211_del_key
,
786 .set_default_key
= iwm_cfg80211_set_default_key
,
787 .get_station
= iwm_cfg80211_get_station
,
788 .scan
= iwm_cfg80211_scan
,
789 .set_wiphy_params
= iwm_cfg80211_set_wiphy_params
,
790 .connect
= iwm_cfg80211_connect
,
791 .disconnect
= iwm_cfg80211_disconnect
,
792 .join_ibss
= iwm_cfg80211_join_ibss
,
793 .leave_ibss
= iwm_cfg80211_leave_ibss
,
794 .set_tx_power
= iwm_cfg80211_set_txpower
,
795 .get_tx_power
= iwm_cfg80211_get_txpower
,
796 .set_power_mgmt
= iwm_cfg80211_set_power_mgmt
,
797 .set_pmksa
= iwm_cfg80211_set_pmksa
,
798 .del_pmksa
= iwm_cfg80211_del_pmksa
,
799 .flush_pmksa
= iwm_cfg80211_flush_pmksa
,
802 static const u32 cipher_suites
[] = {
803 WLAN_CIPHER_SUITE_WEP40
,
804 WLAN_CIPHER_SUITE_WEP104
,
805 WLAN_CIPHER_SUITE_TKIP
,
806 WLAN_CIPHER_SUITE_CCMP
,
809 struct wireless_dev
*iwm_wdev_alloc(int sizeof_bus
, struct device
*dev
)
812 struct wireless_dev
*wdev
;
815 * We're trying to have the following memory
818 * +-------------------------+
820 * +-------------------------+
821 * | struct iwm_priv |
822 * +-------------------------+
823 * | bus private data |
824 * | (e.g. iwm_priv_sdio) |
825 * +-------------------------+
829 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
831 dev_err(dev
, "Couldn't allocate wireless device\n");
832 return ERR_PTR(-ENOMEM
);
835 wdev
->wiphy
= wiphy_new(&iwm_cfg80211_ops
,
836 sizeof(struct iwm_priv
) + sizeof_bus
);
838 dev_err(dev
, "Couldn't allocate wiphy device\n");
843 set_wiphy_dev(wdev
->wiphy
, dev
);
844 wdev
->wiphy
->max_scan_ssids
= UMAC_WIFI_IF_PROBE_OPTION_MAX
;
845 wdev
->wiphy
->max_num_pmkids
= UMAC_MAX_NUM_PMKIDS
;
846 wdev
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
847 BIT(NL80211_IFTYPE_ADHOC
);
848 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &iwm_band_2ghz
;
849 wdev
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &iwm_band_5ghz
;
850 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
852 wdev
->wiphy
->cipher_suites
= cipher_suites
;
853 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
855 ret
= wiphy_register(wdev
->wiphy
);
857 dev_err(dev
, "Couldn't register wiphy device\n");
858 goto out_err_register
;
864 wiphy_free(wdev
->wiphy
);
872 void iwm_wdev_free(struct iwm_priv
*iwm
)
874 struct wireless_dev
*wdev
= iwm_to_wdev(iwm
);
879 wiphy_unregister(wdev
->wiphy
);
880 wiphy_free(wdev
->wiphy
);