1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
9 #define GO_NEG_REQ 0x00
10 #define GO_NEG_RSP 0x01
11 #define GO_NEG_CONF 0x02
12 #define P2P_INV_REQ 0x03
13 #define P2P_INV_RSP 0x04
15 #define WILC_INVALID_CHANNEL 0
17 /* Operation at 2.4 GHz with channels 1-13 */
18 #define WILC_WLAN_OPERATING_CLASS_2_4GHZ 0x51
20 static const struct ieee80211_txrx_stypes
21 wilc_wfi_cfg80211_mgmt_types
[NUM_NL80211_IFTYPES
] = {
22 [NL80211_IFTYPE_STATION
] = {
23 .tx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
24 BIT(IEEE80211_STYPE_AUTH
>> 4),
25 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
26 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
27 BIT(IEEE80211_STYPE_AUTH
>> 4)
29 [NL80211_IFTYPE_AP
] = {
31 .rx
= BIT(IEEE80211_STYPE_ASSOC_REQ
>> 4) |
32 BIT(IEEE80211_STYPE_REASSOC_REQ
>> 4) |
33 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
34 BIT(IEEE80211_STYPE_DISASSOC
>> 4) |
35 BIT(IEEE80211_STYPE_AUTH
>> 4) |
36 BIT(IEEE80211_STYPE_DEAUTH
>> 4) |
37 BIT(IEEE80211_STYPE_ACTION
>> 4)
39 [NL80211_IFTYPE_P2P_CLIENT
] = {
41 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
42 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
43 BIT(IEEE80211_STYPE_ASSOC_REQ
>> 4) |
44 BIT(IEEE80211_STYPE_REASSOC_REQ
>> 4) |
45 BIT(IEEE80211_STYPE_DISASSOC
>> 4) |
46 BIT(IEEE80211_STYPE_AUTH
>> 4) |
47 BIT(IEEE80211_STYPE_DEAUTH
>> 4)
52 static const struct wiphy_wowlan_support wowlan_support
= {
53 .flags
= WIPHY_WOWLAN_ANY
57 struct wilc_p2p_mgmt_data
{
62 struct wilc_p2p_pub_act_frame
{
72 struct wilc_vendor_specific_ie
{
80 struct wilc_attr_entry
{
86 struct wilc_attr_oper_ch
{
89 u8 country_code
[IEEE80211_COUNTRY_STRING_LEN
];
94 struct wilc_attr_ch_list
{
97 u8 country_code
[IEEE80211_COUNTRY_STRING_LEN
];
101 struct wilc_ch_list_elem
{
107 static void cfg_scan_result(enum scan_event scan_event
,
108 struct wilc_rcvd_net_info
*info
,
109 struct wilc_priv
*priv
)
111 if (!priv
->cfg_scanning
)
114 if (scan_event
== SCAN_EVENT_NETWORK_FOUND
) {
116 struct ieee80211_channel
*channel
;
117 struct cfg80211_bss
*bss
;
118 struct wiphy
*wiphy
= priv
->dev
->ieee80211_ptr
->wiphy
;
123 freq
= ieee80211_channel_to_frequency((s32
)info
->ch
,
125 channel
= ieee80211_get_channel(wiphy
, freq
);
129 bss
= cfg80211_inform_bss_frame(wiphy
, channel
, info
->mgmt
,
131 (s32
)info
->rssi
* 100,
133 cfg80211_put_bss(wiphy
, bss
);
134 } else if (scan_event
== SCAN_EVENT_DONE
) {
135 mutex_lock(&priv
->scan_req_lock
);
137 if (priv
->scan_req
) {
138 struct cfg80211_scan_info info
= {
142 cfg80211_scan_done(priv
->scan_req
, &info
);
143 priv
->cfg_scanning
= false;
144 priv
->scan_req
= NULL
;
146 mutex_unlock(&priv
->scan_req_lock
);
147 } else if (scan_event
== SCAN_EVENT_ABORTED
) {
148 mutex_lock(&priv
->scan_req_lock
);
150 if (priv
->scan_req
) {
151 struct cfg80211_scan_info info
= {
155 cfg80211_scan_done(priv
->scan_req
, &info
);
156 priv
->cfg_scanning
= false;
157 priv
->scan_req
= NULL
;
159 mutex_unlock(&priv
->scan_req_lock
);
163 static void cfg_connect_result(enum conn_event conn_disconn_evt
, u8 mac_status
,
164 struct wilc_priv
*priv
)
166 struct net_device
*dev
= priv
->dev
;
167 struct wilc_vif
*vif
= netdev_priv(dev
);
168 struct wilc
*wl
= vif
->wilc
;
169 struct host_if_drv
*wfi_drv
= priv
->hif_drv
;
170 struct wilc_conn_info
*conn_info
= &wfi_drv
->conn_info
;
171 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
173 vif
->connecting
= false;
175 if (conn_disconn_evt
== CONN_DISCONN_EVENT_CONN_RESP
) {
176 u16 connect_status
= conn_info
->status
;
178 if (mac_status
== WILC_MAC_STATUS_DISCONNECTED
&&
179 connect_status
== WLAN_STATUS_SUCCESS
) {
180 connect_status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
181 wilc_wlan_set_bssid(priv
->dev
, NULL
, WILC_STATION_MODE
);
183 if (vif
->iftype
!= WILC_CLIENT_MODE
)
184 wl
->sta_ch
= WILC_INVALID_CHANNEL
;
186 netdev_err(dev
, "Unspecified failure\n");
189 if (connect_status
== WLAN_STATUS_SUCCESS
)
190 memcpy(priv
->associated_bss
, conn_info
->bssid
,
193 cfg80211_ref_bss(wiphy
, vif
->bss
);
194 cfg80211_connect_bss(dev
, conn_info
->bssid
, vif
->bss
,
196 conn_info
->req_ies_len
,
198 conn_info
->resp_ies_len
,
199 connect_status
, GFP_KERNEL
,
200 NL80211_TIMEOUT_UNSPECIFIED
);
203 } else if (conn_disconn_evt
== CONN_DISCONN_EVENT_DISCONN_NOTIF
) {
206 eth_zero_addr(priv
->associated_bss
);
207 wilc_wlan_set_bssid(priv
->dev
, NULL
, WILC_STATION_MODE
);
209 if (vif
->iftype
!= WILC_CLIENT_MODE
) {
210 wl
->sta_ch
= WILC_INVALID_CHANNEL
;
218 cfg80211_disconnected(dev
, reason
, NULL
, 0, false, GFP_KERNEL
);
222 struct wilc_vif
*wilc_get_wl_to_vif(struct wilc
*wl
)
224 struct wilc_vif
*vif
;
226 vif
= list_first_or_null_rcu(&wl
->vif_list
, typeof(*vif
), list
);
228 return ERR_PTR(-EINVAL
);
233 static int set_channel(struct wiphy
*wiphy
,
234 struct net_device
*dev
,
235 struct cfg80211_chan_def
*chandef
)
237 struct wilc
*wl
= wiphy_priv(wiphy
);
238 struct wilc_vif
*vif
;
243 srcu_idx
= srcu_read_lock(&wl
->srcu
);
244 vif
= wilc_get_wl_to_vif(wl
);
246 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
250 channelnum
= ieee80211_frequency_to_channel(chandef
->chan
->center_freq
);
252 wl
->op_ch
= channelnum
;
253 result
= wilc_set_mac_chnl_num(vif
, channelnum
);
255 netdev_err(vif
->ndev
, "Error in setting channel\n");
257 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
261 static int scan(struct wiphy
*wiphy
, struct cfg80211_scan_request
*request
)
263 struct wilc_vif
*vif
= netdev_priv(request
->wdev
->netdev
);
264 struct wilc_priv
*priv
= &vif
->priv
;
267 u8 scan_ch_list
[WILC_MAX_NUM_SCANNED_CH
];
270 if (request
->n_channels
> WILC_MAX_NUM_SCANNED_CH
) {
271 netdev_err(vif
->ndev
, "Requested scanned channels over\n");
275 priv
->scan_req
= request
;
276 priv
->cfg_scanning
= true;
277 for (i
= 0; i
< request
->n_channels
; i
++) {
278 u16 freq
= request
->channels
[i
]->center_freq
;
280 scan_ch_list
[i
] = ieee80211_frequency_to_channel(freq
);
283 if (request
->n_ssids
)
284 scan_type
= WILC_FW_ACTIVE_SCAN
;
286 scan_type
= WILC_FW_PASSIVE_SCAN
;
288 ret
= wilc_scan(vif
, WILC_FW_USER_SCAN
, scan_type
,
289 scan_ch_list
, cfg_scan_result
, request
);
292 priv
->scan_req
= NULL
;
293 priv
->cfg_scanning
= false;
299 static int connect(struct wiphy
*wiphy
, struct net_device
*dev
,
300 struct cfg80211_connect_params
*sme
)
302 struct wilc_vif
*vif
= netdev_priv(dev
);
303 struct wilc_priv
*priv
= &vif
->priv
;
304 struct host_if_drv
*wfi_drv
= priv
->hif_drv
;
307 u8 security
= WILC_FW_SEC_NO
;
308 enum mfptype mfp_type
= WILC_FW_MFP_NONE
;
309 enum authtype auth_type
= WILC_FW_AUTH_ANY
;
311 struct cfg80211_bss
*bss
;
315 vif
->connecting
= true;
317 cipher_group
= sme
->crypto
.cipher_group
;
318 if (cipher_group
!= 0) {
319 if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_2
) {
320 if (cipher_group
== WLAN_CIPHER_SUITE_TKIP
)
321 security
= WILC_FW_SEC_WPA2_TKIP
;
323 security
= WILC_FW_SEC_WPA2_AES
;
324 } else if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_1
) {
325 if (cipher_group
== WLAN_CIPHER_SUITE_TKIP
)
326 security
= WILC_FW_SEC_WPA_TKIP
;
328 security
= WILC_FW_SEC_WPA_AES
;
331 netdev_err(dev
, "%s: Unsupported cipher\n",
337 if ((sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_1
) ||
338 (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_2
)) {
339 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++) {
340 u32 ciphers_pairwise
= sme
->crypto
.ciphers_pairwise
[i
];
342 if (ciphers_pairwise
== WLAN_CIPHER_SUITE_TKIP
)
343 security
|= WILC_FW_TKIP
;
345 security
|= WILC_FW_AES
;
349 switch (sme
->auth_type
) {
350 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
351 auth_type
= WILC_FW_AUTH_OPEN_SYSTEM
;
354 case NL80211_AUTHTYPE_SAE
:
355 auth_type
= WILC_FW_AUTH_SAE
;
357 memcpy(vif
->auth
.ssid
.ssid
, sme
->ssid
, sme
->ssid_len
);
358 vif
->auth
.ssid
.ssid_len
= sme
->ssid_len
;
360 vif
->auth
.key_mgmt_suite
= sme
->crypto
.akm_suites
[0];
361 ether_addr_copy(vif
->auth
.bssid
, sme
->bssid
);
368 if (sme
->crypto
.n_akm_suites
) {
369 if (sme
->crypto
.akm_suites
[0] == WLAN_AKM_SUITE_8021X
)
370 auth_type
= WILC_FW_AUTH_IEEE8021
;
371 else if (sme
->crypto
.akm_suites
[0] == WLAN_AKM_SUITE_PSK_SHA256
)
372 auth_type
= WILC_FW_AUTH_OPEN_SYSTEM_SHA256
;
373 else if (sme
->crypto
.akm_suites
[0] == WLAN_AKM_SUITE_8021X_SHA256
)
374 auth_type
= WILC_FW_AUTH_IEE8021X_SHA256
;
377 if (wfi_drv
->usr_scan_req
.scan_result
) {
378 netdev_err(vif
->ndev
, "%s: Scan in progress\n", __func__
);
383 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
, sme
->ssid
,
384 sme
->ssid_len
, IEEE80211_BSS_TYPE_ANY
,
385 IEEE80211_PRIVACY(sme
->privacy
));
391 if (ether_addr_equal_unaligned(vif
->bssid
, bss
->bssid
)) {
396 join_params
= wilc_parse_join_bss_param(bss
, &sme
->crypto
);
398 netdev_err(dev
, "%s: failed to construct join param\n",
404 ch
= ieee80211_frequency_to_channel(bss
->channel
->center_freq
);
405 vif
->wilc
->op_ch
= ch
;
406 if (vif
->iftype
!= WILC_CLIENT_MODE
)
407 vif
->wilc
->sta_ch
= ch
;
409 wilc_wlan_set_bssid(dev
, bss
->bssid
, WILC_STATION_MODE
);
411 wfi_drv
->conn_info
.security
= security
;
412 wfi_drv
->conn_info
.auth_type
= auth_type
;
413 wfi_drv
->conn_info
.conn_result
= cfg_connect_result
;
414 wfi_drv
->conn_info
.priv
= priv
;
415 wfi_drv
->conn_info
.param
= join_params
;
417 if (sme
->mfp
== NL80211_MFP_OPTIONAL
)
418 mfp_type
= WILC_FW_MFP_OPTIONAL
;
419 else if (sme
->mfp
== NL80211_MFP_REQUIRED
)
420 mfp_type
= WILC_FW_MFP_REQUIRED
;
422 wfi_drv
->conn_info
.mfp_type
= mfp_type
;
424 ret
= wilc_set_join_req(vif
, bss
->bssid
, sme
->ie
, sme
->ie_len
);
426 netdev_err(dev
, "wilc_set_join_req(): Error\n");
428 if (vif
->iftype
!= WILC_CLIENT_MODE
)
429 vif
->wilc
->sta_ch
= WILC_INVALID_CHANNEL
;
430 wilc_wlan_set_bssid(dev
, NULL
, WILC_STATION_MODE
);
431 wfi_drv
->conn_info
.conn_result
= NULL
;
437 cfg80211_put_bss(wiphy
, bss
);
441 cfg80211_put_bss(wiphy
, bss
);
444 vif
->connecting
= false;
448 static int disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
451 struct wilc_vif
*vif
= netdev_priv(dev
);
452 struct wilc_priv
*priv
= &vif
->priv
;
453 struct wilc
*wilc
= vif
->wilc
;
456 vif
->connecting
= false;
462 /* already disconnected done */
463 cfg80211_disconnected(dev
, 0, NULL
, 0, true, GFP_KERNEL
);
467 if (vif
->iftype
!= WILC_CLIENT_MODE
)
468 wilc
->sta_ch
= WILC_INVALID_CHANNEL
;
469 wilc_wlan_set_bssid(priv
->dev
, NULL
, WILC_STATION_MODE
);
471 priv
->hif_drv
->p2p_timeout
= 0;
473 ret
= wilc_disconnect(vif
);
475 netdev_err(priv
->dev
, "Error in disconnecting\n");
484 static int wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv
*priv
, u8 idx
)
486 if (!priv
->wilc_gtk
[idx
]) {
487 priv
->wilc_gtk
[idx
] = kzalloc(sizeof(*priv
->wilc_gtk
[idx
]),
489 if (!priv
->wilc_gtk
[idx
])
493 if (!priv
->wilc_ptk
[idx
]) {
494 priv
->wilc_ptk
[idx
] = kzalloc(sizeof(*priv
->wilc_ptk
[idx
]),
496 if (!priv
->wilc_ptk
[idx
])
503 static int wilc_wfi_cfg_allocate_wpa_igtk_entry(struct wilc_priv
*priv
, u8 idx
)
506 if (!priv
->wilc_igtk
[idx
]) {
507 priv
->wilc_igtk
[idx
] = kzalloc(sizeof(*priv
->wilc_igtk
[idx
]),
509 if (!priv
->wilc_igtk
[idx
])
515 static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key
*key_info
,
516 struct key_params
*params
)
518 kfree(key_info
->key
);
520 key_info
->key
= kmemdup(params
->key
, params
->key_len
, GFP_KERNEL
);
524 kfree(key_info
->seq
);
526 if (params
->seq_len
> 0) {
527 key_info
->seq
= kmemdup(params
->seq
, params
->seq_len
,
533 key_info
->cipher
= params
->cipher
;
534 key_info
->key_len
= params
->key_len
;
535 key_info
->seq_len
= params
->seq_len
;
540 static int add_key(struct wiphy
*wiphy
, struct net_device
*netdev
, int link_id
,
541 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
542 struct key_params
*params
)
545 int ret
= 0, keylen
= params
->key_len
;
546 const u8
*rx_mic
= NULL
;
547 const u8
*tx_mic
= NULL
;
548 u8 mode
= WILC_FW_SEC_NO
;
550 struct wilc_vif
*vif
= netdev_priv(netdev
);
551 struct wilc_priv
*priv
= &vif
->priv
;
552 struct wilc_wfi_key
*key
;
554 switch (params
->cipher
) {
555 case WLAN_CIPHER_SUITE_TKIP
:
556 case WLAN_CIPHER_SUITE_CCMP
:
557 if (priv
->wdev
.iftype
== NL80211_IFTYPE_AP
||
558 priv
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
) {
559 struct wilc_wfi_key
*key
;
561 ret
= wilc_wfi_cfg_allocate_wpa_entry(priv
, key_index
);
565 if (params
->key_len
> 16 &&
566 params
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
567 tx_mic
= params
->key
+ 24;
568 rx_mic
= params
->key
+ 16;
569 keylen
= params
->key_len
- 16;
573 if (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
574 mode
= WILC_FW_SEC_WPA_TKIP
;
576 mode
= WILC_FW_SEC_WPA2_AES
;
578 priv
->wilc_groupkey
= mode
;
580 key
= priv
->wilc_gtk
[key_index
];
582 if (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
583 mode
= WILC_FW_SEC_WPA_TKIP
;
585 mode
= priv
->wilc_groupkey
| WILC_FW_AES
;
587 key
= priv
->wilc_ptk
[key_index
];
589 ret
= wilc_wfi_cfg_copy_wpa_info(key
, params
);
593 op_mode
= WILC_AP_MODE
;
595 if (params
->key_len
> 16 &&
596 params
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
597 rx_mic
= params
->key
+ 24;
598 tx_mic
= params
->key
+ 16;
599 keylen
= params
->key_len
- 16;
602 op_mode
= WILC_STATION_MODE
;
606 ret
= wilc_add_rx_gtk(vif
, params
->key
, keylen
,
607 key_index
, params
->seq_len
,
608 params
->seq
, rx_mic
, tx_mic
,
611 ret
= wilc_add_ptk(vif
, params
->key
, keylen
, mac_addr
,
612 rx_mic
, tx_mic
, op_mode
, mode
,
616 case WLAN_CIPHER_SUITE_AES_CMAC
:
617 ret
= wilc_wfi_cfg_allocate_wpa_igtk_entry(priv
, key_index
);
621 key
= priv
->wilc_igtk
[key_index
- 4];
622 ret
= wilc_wfi_cfg_copy_wpa_info(key
, params
);
626 if (priv
->wdev
.iftype
== NL80211_IFTYPE_AP
||
627 priv
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
)
628 op_mode
= WILC_AP_MODE
;
630 op_mode
= WILC_STATION_MODE
;
632 ret
= wilc_add_igtk(vif
, params
->key
, keylen
, params
->seq
,
633 params
->seq_len
, mac_addr
, op_mode
,
638 netdev_err(netdev
, "%s: Unsupported cipher\n", __func__
);
645 static int del_key(struct wiphy
*wiphy
, struct net_device
*netdev
, int link_id
,
650 struct wilc_vif
*vif
= netdev_priv(netdev
);
651 struct wilc_priv
*priv
= &vif
->priv
;
653 if (!pairwise
&& (key_index
== 4 || key_index
== 5)) {
655 if (priv
->wilc_igtk
[key_index
]) {
656 kfree(priv
->wilc_igtk
[key_index
]->key
);
657 priv
->wilc_igtk
[key_index
]->key
= NULL
;
658 kfree(priv
->wilc_igtk
[key_index
]->seq
);
659 priv
->wilc_igtk
[key_index
]->seq
= NULL
;
660 kfree(priv
->wilc_igtk
[key_index
]);
661 priv
->wilc_igtk
[key_index
] = NULL
;
664 if (priv
->wilc_gtk
[key_index
]) {
665 kfree(priv
->wilc_gtk
[key_index
]->key
);
666 priv
->wilc_gtk
[key_index
]->key
= NULL
;
667 kfree(priv
->wilc_gtk
[key_index
]->seq
);
668 priv
->wilc_gtk
[key_index
]->seq
= NULL
;
670 kfree(priv
->wilc_gtk
[key_index
]);
671 priv
->wilc_gtk
[key_index
] = NULL
;
673 if (priv
->wilc_ptk
[key_index
]) {
674 kfree(priv
->wilc_ptk
[key_index
]->key
);
675 priv
->wilc_ptk
[key_index
]->key
= NULL
;
676 kfree(priv
->wilc_ptk
[key_index
]->seq
);
677 priv
->wilc_ptk
[key_index
]->seq
= NULL
;
678 kfree(priv
->wilc_ptk
[key_index
]);
679 priv
->wilc_ptk
[key_index
] = NULL
;
686 static int get_key(struct wiphy
*wiphy
, struct net_device
*netdev
, int link_id
,
687 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
689 void (*callback
)(void *cookie
, struct key_params
*))
691 struct wilc_vif
*vif
= netdev_priv(netdev
);
692 struct wilc_priv
*priv
= &vif
->priv
;
693 struct key_params key_params
;
696 if (key_index
== 4 || key_index
== 5) {
698 key_params
.key
= priv
->wilc_igtk
[key_index
]->key
;
699 key_params
.cipher
= priv
->wilc_igtk
[key_index
]->cipher
;
700 key_params
.key_len
= priv
->wilc_igtk
[key_index
]->key_len
;
701 key_params
.seq
= priv
->wilc_igtk
[key_index
]->seq
;
702 key_params
.seq_len
= priv
->wilc_igtk
[key_index
]->seq_len
;
704 key_params
.key
= priv
->wilc_gtk
[key_index
]->key
;
705 key_params
.cipher
= priv
->wilc_gtk
[key_index
]->cipher
;
706 key_params
.key_len
= priv
->wilc_gtk
[key_index
]->key_len
;
707 key_params
.seq
= priv
->wilc_gtk
[key_index
]->seq
;
708 key_params
.seq_len
= priv
->wilc_gtk
[key_index
]->seq_len
;
711 key_params
.key
= priv
->wilc_ptk
[key_index
]->key
;
712 key_params
.cipher
= priv
->wilc_ptk
[key_index
]->cipher
;
713 key_params
.key_len
= priv
->wilc_ptk
[key_index
]->key_len
;
714 key_params
.seq
= priv
->wilc_ptk
[key_index
]->seq
;
715 key_params
.seq_len
= priv
->wilc_ptk
[key_index
]->seq_len
;
718 callback(cookie
, &key_params
);
723 /* wiphy_new_nm() will WARNON if not present */
724 static int set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
725 int link_id
, u8 key_index
, bool unicast
,
731 static int set_default_mgmt_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
732 int link_id
, u8 key_index
)
734 struct wilc_vif
*vif
= netdev_priv(netdev
);
736 return wilc_set_default_mgmt_key_index(vif
, key_index
);
739 static int get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
740 const u8
*mac
, struct station_info
*sinfo
)
742 struct wilc_vif
*vif
= netdev_priv(dev
);
743 struct wilc_priv
*priv
= &vif
->priv
;
744 struct wilc
*wilc
= vif
->wilc
;
746 u32 associatedsta
= ~0;
747 u32 inactive_time
= 0;
749 if (vif
->iftype
== WILC_AP_MODE
|| vif
->iftype
== WILC_GO_MODE
) {
750 for (i
= 0; i
< NUM_STA_ASSOCIATED
; i
++) {
752 priv
->assoc_stainfo
.sta_associated_bss
[i
],
759 if (associatedsta
== ~0) {
760 netdev_err(dev
, "sta required is not associated\n");
764 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME
);
766 wilc_get_inactive_time(vif
, mac
, &inactive_time
);
767 sinfo
->inactive_time
= 1000 * inactive_time
;
768 } else if (vif
->iftype
== WILC_STATION_MODE
) {
769 struct rf_info stats
;
771 if (!wilc
->initialized
)
774 wilc_get_statistics(vif
, &stats
);
776 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_SIGNAL
) |
777 BIT_ULL(NL80211_STA_INFO_RX_PACKETS
) |
778 BIT_ULL(NL80211_STA_INFO_TX_PACKETS
) |
779 BIT_ULL(NL80211_STA_INFO_TX_FAILED
) |
780 BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
782 sinfo
->signal
= stats
.rssi
;
783 sinfo
->rx_packets
= stats
.rx_cnt
;
784 sinfo
->tx_packets
= stats
.tx_cnt
+ stats
.tx_fail_cnt
;
785 sinfo
->tx_failed
= stats
.tx_fail_cnt
;
786 sinfo
->txrate
.legacy
= stats
.link_speed
* 10;
788 if (stats
.link_speed
> TCP_ACK_FILTER_LINK_SPEED_THRESH
&&
789 stats
.link_speed
!= DEFAULT_LINK_SPEED
)
790 wilc_enable_tcp_ack_filter(vif
, true);
791 else if (stats
.link_speed
!= DEFAULT_LINK_SPEED
)
792 wilc_enable_tcp_ack_filter(vif
, false);
797 static int change_bss(struct wiphy
*wiphy
, struct net_device
*dev
,
798 struct bss_parameters
*params
)
803 static int set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
806 struct cfg_param_attr cfg_param_val
;
807 struct wilc
*wl
= wiphy_priv(wiphy
);
808 struct wilc_vif
*vif
;
809 struct wilc_priv
*priv
;
812 srcu_idx
= srcu_read_lock(&wl
->srcu
);
813 vif
= wilc_get_wl_to_vif(wl
);
818 cfg_param_val
.flag
= 0;
820 if (changed
& WIPHY_PARAM_RETRY_SHORT
) {
821 netdev_dbg(vif
->ndev
,
822 "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
824 cfg_param_val
.flag
|= WILC_CFG_PARAM_RETRY_SHORT
;
825 cfg_param_val
.short_retry_limit
= wiphy
->retry_short
;
827 if (changed
& WIPHY_PARAM_RETRY_LONG
) {
828 netdev_dbg(vif
->ndev
,
829 "Setting WIPHY_PARAM_RETRY_LONG %d\n",
831 cfg_param_val
.flag
|= WILC_CFG_PARAM_RETRY_LONG
;
832 cfg_param_val
.long_retry_limit
= wiphy
->retry_long
;
834 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
835 if (wiphy
->frag_threshold
> 255 &&
836 wiphy
->frag_threshold
< 7937) {
837 netdev_dbg(vif
->ndev
,
838 "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n",
839 wiphy
->frag_threshold
);
840 cfg_param_val
.flag
|= WILC_CFG_PARAM_FRAG_THRESHOLD
;
841 cfg_param_val
.frag_threshold
= wiphy
->frag_threshold
;
843 netdev_err(vif
->ndev
,
844 "Fragmentation threshold out of range\n");
849 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
850 if (wiphy
->rts_threshold
> 255) {
851 netdev_dbg(vif
->ndev
,
852 "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n",
853 wiphy
->rts_threshold
);
854 cfg_param_val
.flag
|= WILC_CFG_PARAM_RTS_THRESHOLD
;
855 cfg_param_val
.rts_threshold
= wiphy
->rts_threshold
;
857 netdev_err(vif
->ndev
, "RTS threshold out of range\n");
862 ret
= wilc_hif_set_cfg(vif
, &cfg_param_val
);
864 netdev_err(priv
->dev
, "Error in setting WIPHY PARAMS\n");
867 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
871 static int set_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
872 struct cfg80211_pmksa
*pmksa
)
874 struct wilc_vif
*vif
= netdev_priv(netdev
);
875 struct wilc_priv
*priv
= &vif
->priv
;
880 for (i
= 0; i
< priv
->pmkid_list
.numpmkid
; i
++) {
881 if (!memcmp(pmksa
->bssid
, priv
->pmkid_list
.pmkidlist
[i
].bssid
,
887 if (i
< WILC_MAX_NUM_PMKIDS
) {
888 memcpy(priv
->pmkid_list
.pmkidlist
[i
].bssid
, pmksa
->bssid
,
890 memcpy(priv
->pmkid_list
.pmkidlist
[i
].pmkid
, pmksa
->pmkid
,
892 if (!(flag
== PMKID_FOUND
))
893 priv
->pmkid_list
.numpmkid
++;
895 netdev_err(netdev
, "Invalid PMKID index\n");
900 ret
= wilc_set_pmkid_info(vif
, &priv
->pmkid_list
);
905 static int del_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
906 struct cfg80211_pmksa
*pmksa
)
909 struct wilc_vif
*vif
= netdev_priv(netdev
);
910 struct wilc_priv
*priv
= &vif
->priv
;
912 for (i
= 0; i
< priv
->pmkid_list
.numpmkid
; i
++) {
913 if (!memcmp(pmksa
->bssid
, priv
->pmkid_list
.pmkidlist
[i
].bssid
,
915 memset(&priv
->pmkid_list
.pmkidlist
[i
], 0,
916 sizeof(struct wilc_pmkid
));
921 if (i
== priv
->pmkid_list
.numpmkid
)
924 for (; i
< (priv
->pmkid_list
.numpmkid
- 1); i
++) {
925 memcpy(priv
->pmkid_list
.pmkidlist
[i
].bssid
,
926 priv
->pmkid_list
.pmkidlist
[i
+ 1].bssid
,
928 memcpy(priv
->pmkid_list
.pmkidlist
[i
].pmkid
,
929 priv
->pmkid_list
.pmkidlist
[i
+ 1].pmkid
,
932 priv
->pmkid_list
.numpmkid
--;
937 static int flush_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
)
939 struct wilc_vif
*vif
= netdev_priv(netdev
);
941 memset(&vif
->priv
.pmkid_list
, 0, sizeof(struct wilc_pmkid_attr
));
946 static inline void wilc_wfi_cfg_parse_ch_attr(u8
*buf
, u32 len
, u8 sta_ch
)
948 struct wilc_attr_entry
*e
;
949 struct wilc_attr_ch_list
*ch_list
;
950 struct wilc_attr_oper_ch
*op_ch
;
955 if (sta_ch
== WILC_INVALID_CHANNEL
)
958 while (index
+ sizeof(*e
) <= len
) {
961 e
= (struct wilc_attr_entry
*)&buf
[index
];
962 attr_size
= le16_to_cpu(e
->attr_len
);
964 if (index
+ sizeof(*e
) + attr_size
> len
)
967 if (e
->attr_type
== IEEE80211_P2P_ATTR_CHANNEL_LIST
&&
968 attr_size
>= (sizeof(struct wilc_attr_ch_list
) - sizeof(*e
)))
970 else if (e
->attr_type
== IEEE80211_P2P_ATTR_OPER_CHANNEL
&&
971 attr_size
== (sizeof(struct wilc_attr_oper_ch
) - sizeof(*e
)))
974 if (ch_list_idx
&& op_ch_idx
)
977 index
+= sizeof(*e
) + attr_size
;
983 ch_list
= (struct wilc_attr_ch_list
*)&buf
[ch_list_idx
];
984 /* the number of bytes following the final 'elem' member */
985 elem_size
= le16_to_cpu(ch_list
->attr_len
) -
986 (sizeof(*ch_list
) - sizeof(struct wilc_attr_entry
));
987 for (unsigned int i
= 0; i
< elem_size
;) {
988 struct wilc_ch_list_elem
*e
;
990 e
= (struct wilc_ch_list_elem
*)(ch_list
->elem
+ i
);
996 i
+= e
->no_of_channels
;
1000 if (e
->op_class
== WILC_WLAN_OPERATING_CLASS_2_4GHZ
) {
1001 memset(e
->ch_list
, sta_ch
, e
->no_of_channels
);
1008 op_ch
= (struct wilc_attr_oper_ch
*)&buf
[op_ch_idx
];
1009 op_ch
->op_class
= WILC_WLAN_OPERATING_CLASS_2_4GHZ
;
1010 op_ch
->op_channel
= sta_ch
;
1014 bool wilc_wfi_mgmt_frame_rx(struct wilc_vif
*vif
, u8
*buff
, u32 size
)
1016 struct wilc
*wl
= vif
->wilc
;
1017 struct wilc_priv
*priv
= &vif
->priv
;
1020 freq
= ieee80211_channel_to_frequency(wl
->op_ch
, NL80211_BAND_2GHZ
);
1022 return cfg80211_rx_mgmt(&priv
->wdev
, freq
, 0, buff
, size
, 0);
1025 void wilc_wfi_p2p_rx(struct wilc_vif
*vif
, u8
*buff
, u32 size
)
1027 struct wilc
*wl
= vif
->wilc
;
1028 struct wilc_priv
*priv
= &vif
->priv
;
1029 struct host_if_drv
*wfi_drv
= priv
->hif_drv
;
1030 struct ieee80211_mgmt
*mgmt
;
1031 struct wilc_vendor_specific_ie
*p
;
1032 struct wilc_p2p_pub_act_frame
*d
;
1033 int ie_offset
= offsetof(struct ieee80211_mgmt
, u
) + sizeof(*d
);
1034 const u8
*vendor_ie
;
1035 u32 header
, pkt_offset
;
1038 header
= get_unaligned_le32(buff
- HOST_HDR_OFFSET
);
1039 pkt_offset
= FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD
, header
);
1041 if (pkt_offset
& IS_MANAGMEMENT_CALLBACK
) {
1043 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)buff
;
1045 if (ieee80211_is_probe_resp(hdr
->frame_control
) ||
1046 pkt_offset
& IS_MGMT_STATUS_SUCCES
)
1049 cfg80211_mgmt_tx_status(&priv
->wdev
, priv
->tx_cookie
, buff
,
1050 size
, ack
, GFP_KERNEL
);
1054 freq
= ieee80211_channel_to_frequency(wl
->op_ch
, NL80211_BAND_2GHZ
);
1056 mgmt
= (struct ieee80211_mgmt
*)buff
;
1057 if (!ieee80211_is_action(mgmt
->frame_control
))
1060 if (priv
->cfg_scanning
&&
1061 time_after_eq(jiffies
, (unsigned long)wfi_drv
->p2p_timeout
)) {
1062 netdev_dbg(vif
->ndev
, "Receiving action wrong ch\n");
1066 if (!ieee80211_is_public_action((struct ieee80211_hdr
*)buff
, size
))
1069 d
= (struct wilc_p2p_pub_act_frame
*)(&mgmt
->u
.action
);
1070 if (d
->oui_subtype
!= GO_NEG_REQ
&& d
->oui_subtype
!= GO_NEG_RSP
&&
1071 d
->oui_subtype
!= P2P_INV_REQ
&& d
->oui_subtype
!= P2P_INV_RSP
)
1074 vendor_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1075 buff
+ ie_offset
, size
- ie_offset
);
1079 p
= (struct wilc_vendor_specific_ie
*)vendor_ie
;
1080 wilc_wfi_cfg_parse_ch_attr(p
->attr
, p
->tag_len
- 4, vif
->wilc
->sta_ch
);
1083 cfg80211_rx_mgmt(&priv
->wdev
, freq
, 0, buff
, size
, 0);
1086 static void wilc_wfi_mgmt_tx_complete(void *priv
, int status
)
1088 struct wilc_p2p_mgmt_data
*pv_data
= priv
;
1090 kfree(pv_data
->buff
);
1094 static void wilc_wfi_remain_on_channel_expired(struct wilc_vif
*vif
, u64 cookie
)
1096 struct wilc_priv
*priv
= &vif
->priv
;
1097 struct wilc_wfi_p2p_listen_params
*params
= &priv
->remain_on_ch_params
;
1099 if (cookie
!= params
->listen_cookie
)
1102 priv
->p2p_listen_state
= false;
1104 cfg80211_remain_on_channel_expired(&priv
->wdev
, params
->listen_cookie
,
1105 params
->listen_ch
, GFP_KERNEL
);
1108 static int remain_on_channel(struct wiphy
*wiphy
,
1109 struct wireless_dev
*wdev
,
1110 struct ieee80211_channel
*chan
,
1111 unsigned int duration
, u64
*cookie
)
1114 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1115 struct wilc_priv
*priv
= &vif
->priv
;
1118 if (wdev
->iftype
== NL80211_IFTYPE_AP
) {
1119 netdev_dbg(vif
->ndev
, "Required while in AP mode\n");
1123 id
= ++priv
->inc_roc_cookie
;
1125 id
= ++priv
->inc_roc_cookie
;
1127 ret
= wilc_remain_on_channel(vif
, id
, chan
->hw_value
,
1128 wilc_wfi_remain_on_channel_expired
);
1132 vif
->wilc
->op_ch
= chan
->hw_value
;
1134 priv
->remain_on_ch_params
.listen_ch
= chan
;
1135 priv
->remain_on_ch_params
.listen_cookie
= id
;
1137 priv
->p2p_listen_state
= true;
1138 priv
->remain_on_ch_params
.listen_duration
= duration
;
1140 cfg80211_ready_on_channel(wdev
, *cookie
, chan
, duration
, GFP_KERNEL
);
1141 mod_timer(&vif
->hif_drv
->remain_on_ch_timer
,
1142 jiffies
+ msecs_to_jiffies(duration
+ 1000));
1147 static int cancel_remain_on_channel(struct wiphy
*wiphy
,
1148 struct wireless_dev
*wdev
,
1151 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1152 struct wilc_priv
*priv
= &vif
->priv
;
1154 if (cookie
!= priv
->remain_on_ch_params
.listen_cookie
)
1157 return wilc_listen_state_expired(vif
, cookie
);
1160 static int mgmt_tx(struct wiphy
*wiphy
,
1161 struct wireless_dev
*wdev
,
1162 struct cfg80211_mgmt_tx_params
*params
,
1165 struct ieee80211_channel
*chan
= params
->chan
;
1166 unsigned int wait
= params
->wait
;
1167 const u8
*buf
= params
->buf
;
1168 size_t len
= params
->len
;
1169 const struct ieee80211_mgmt
*mgmt
;
1170 struct wilc_p2p_mgmt_data
*mgmt_tx
;
1171 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1172 struct wilc_priv
*priv
= &vif
->priv
;
1173 struct host_if_drv
*wfi_drv
= priv
->hif_drv
;
1174 struct wilc_vendor_specific_ie
*p
;
1175 struct wilc_p2p_pub_act_frame
*d
;
1176 int ie_offset
= offsetof(struct ieee80211_mgmt
, u
) + sizeof(*d
);
1177 const u8
*vendor_ie
;
1180 *cookie
= get_random_u32();
1181 priv
->tx_cookie
= *cookie
;
1182 mgmt
= (const struct ieee80211_mgmt
*)buf
;
1184 if (!ieee80211_is_mgmt(mgmt
->frame_control
))
1187 mgmt_tx
= kmalloc(sizeof(*mgmt_tx
), GFP_KERNEL
);
1193 mgmt_tx
->buff
= kmemdup(buf
, len
, GFP_KERNEL
);
1194 if (!mgmt_tx
->buff
) {
1200 mgmt_tx
->size
= len
;
1202 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
1203 wilc_set_mac_chnl_num(vif
, chan
->hw_value
);
1204 vif
->wilc
->op_ch
= chan
->hw_value
;
1205 goto out_txq_add_pkt
;
1208 if (!ieee80211_is_public_action((struct ieee80211_hdr
*)buf
, len
)) {
1210 wilc_set_mac_chnl_num(vif
, chan
->hw_value
);
1212 wilc_set_mac_chnl_num(vif
, vif
->wilc
->op_ch
);
1214 goto out_set_timeout
;
1217 d
= (struct wilc_p2p_pub_act_frame
*)(&mgmt
->u
.action
);
1218 if (d
->oui_type
!= WLAN_OUI_TYPE_WFA_P2P
||
1219 d
->oui_subtype
!= GO_NEG_CONF
) {
1220 wilc_set_mac_chnl_num(vif
, chan
->hw_value
);
1221 vif
->wilc
->op_ch
= chan
->hw_value
;
1224 if (d
->oui_subtype
!= P2P_INV_REQ
&& d
->oui_subtype
!= P2P_INV_RSP
)
1225 goto out_set_timeout
;
1227 vendor_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1228 mgmt_tx
->buff
+ ie_offset
,
1231 goto out_set_timeout
;
1233 p
= (struct wilc_vendor_specific_ie
*)vendor_ie
;
1234 wilc_wfi_cfg_parse_ch_attr(p
->attr
, p
->tag_len
- 4, vif
->wilc
->sta_ch
);
1237 wfi_drv
->p2p_timeout
= (jiffies
+ msecs_to_jiffies(wait
));
1241 wilc_wlan_txq_add_mgmt_pkt(wdev
->netdev
, mgmt_tx
,
1242 mgmt_tx
->buff
, mgmt_tx
->size
,
1243 wilc_wfi_mgmt_tx_complete
);
1250 static int mgmt_tx_cancel_wait(struct wiphy
*wiphy
,
1251 struct wireless_dev
*wdev
,
1254 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1255 struct wilc_priv
*priv
= &vif
->priv
;
1256 struct host_if_drv
*wfi_drv
= priv
->hif_drv
;
1258 wfi_drv
->p2p_timeout
= jiffies
;
1260 if (!priv
->p2p_listen_state
) {
1261 struct wilc_wfi_p2p_listen_params
*params
;
1263 params
= &priv
->remain_on_ch_params
;
1265 cfg80211_remain_on_channel_expired(wdev
,
1266 params
->listen_cookie
,
1274 void wilc_update_mgmt_frame_registrations(struct wiphy
*wiphy
,
1275 struct wireless_dev
*wdev
,
1276 struct mgmt_frame_regs
*upd
)
1278 struct wilc
*wl
= wiphy_priv(wiphy
);
1279 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1280 u32 presp_bit
= BIT(IEEE80211_STYPE_PROBE_REQ
>> 4);
1281 u32 action_bit
= BIT(IEEE80211_STYPE_ACTION
>> 4);
1282 u32 pauth_bit
= BIT(IEEE80211_STYPE_AUTH
>> 4);
1284 if (wl
->initialized
) {
1285 bool prev
= vif
->mgmt_reg_stypes
& presp_bit
;
1286 bool now
= upd
->interface_stypes
& presp_bit
;
1289 wilc_frame_register(vif
, IEEE80211_STYPE_PROBE_REQ
, now
);
1291 prev
= vif
->mgmt_reg_stypes
& action_bit
;
1292 now
= upd
->interface_stypes
& action_bit
;
1295 wilc_frame_register(vif
, IEEE80211_STYPE_ACTION
, now
);
1297 prev
= vif
->mgmt_reg_stypes
& pauth_bit
;
1298 now
= upd
->interface_stypes
& pauth_bit
;
1300 wilc_frame_register(vif
, IEEE80211_STYPE_AUTH
, now
);
1303 vif
->mgmt_reg_stypes
=
1304 upd
->interface_stypes
& (presp_bit
| action_bit
| pauth_bit
);
1307 static int external_auth(struct wiphy
*wiphy
, struct net_device
*dev
,
1308 struct cfg80211_external_auth_params
*auth
)
1310 struct wilc_vif
*vif
= netdev_priv(dev
);
1312 if (auth
->status
== WLAN_STATUS_SUCCESS
)
1313 wilc_set_external_auth_param(vif
, auth
);
1318 static int set_cqm_rssi_config(struct wiphy
*wiphy
, struct net_device
*dev
,
1319 s32 rssi_thold
, u32 rssi_hyst
)
1324 static int dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1325 int idx
, u8
*mac
, struct station_info
*sinfo
)
1327 struct wilc_vif
*vif
= netdev_priv(dev
);
1333 ret
= wilc_get_rssi(vif
, &sinfo
->signal
);
1337 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_SIGNAL
);
1338 memcpy(mac
, vif
->priv
.associated_bss
, ETH_ALEN
);
1342 static int set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
1343 bool enabled
, int timeout
)
1345 struct wilc_vif
*vif
= netdev_priv(dev
);
1346 struct wilc_priv
*priv
= &vif
->priv
;
1351 wilc_set_power_mgmt(vif
, enabled
, timeout
);
1356 static int change_virtual_intf(struct wiphy
*wiphy
, struct net_device
*dev
,
1357 enum nl80211_iftype type
,
1358 struct vif_params
*params
)
1360 struct wilc
*wl
= wiphy_priv(wiphy
);
1361 struct wilc_vif
*vif
= netdev_priv(dev
);
1362 struct wilc_priv
*priv
= &vif
->priv
;
1365 case NL80211_IFTYPE_STATION
:
1366 vif
->connecting
= false;
1367 dev
->ieee80211_ptr
->iftype
= type
;
1368 priv
->wdev
.iftype
= type
;
1369 vif
->monitor_flag
= 0;
1370 if (vif
->iftype
== WILC_AP_MODE
|| vif
->iftype
== WILC_GO_MODE
)
1371 wilc_wfi_deinit_mon_interface(wl
, true);
1372 vif
->iftype
= WILC_STATION_MODE
;
1374 if (wl
->initialized
)
1375 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
),
1376 WILC_STATION_MODE
, vif
->idx
);
1378 memset(priv
->assoc_stainfo
.sta_associated_bss
, 0,
1379 WILC_MAX_NUM_STA
* ETH_ALEN
);
1382 case NL80211_IFTYPE_P2P_CLIENT
:
1383 vif
->connecting
= false;
1384 dev
->ieee80211_ptr
->iftype
= type
;
1385 priv
->wdev
.iftype
= type
;
1386 vif
->monitor_flag
= 0;
1387 vif
->iftype
= WILC_CLIENT_MODE
;
1389 if (wl
->initialized
)
1390 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
),
1391 WILC_STATION_MODE
, vif
->idx
);
1394 case NL80211_IFTYPE_AP
:
1395 dev
->ieee80211_ptr
->iftype
= type
;
1396 priv
->wdev
.iftype
= type
;
1397 vif
->iftype
= WILC_AP_MODE
;
1399 if (wl
->initialized
)
1400 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
),
1401 WILC_AP_MODE
, vif
->idx
);
1404 case NL80211_IFTYPE_P2P_GO
:
1405 dev
->ieee80211_ptr
->iftype
= type
;
1406 priv
->wdev
.iftype
= type
;
1407 vif
->iftype
= WILC_GO_MODE
;
1409 if (wl
->initialized
)
1410 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
),
1411 WILC_AP_MODE
, vif
->idx
);
1415 netdev_err(dev
, "Unknown interface type= %d\n", type
);
1422 static int start_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
1423 struct cfg80211_ap_settings
*settings
)
1425 struct wilc_vif
*vif
= netdev_priv(dev
);
1428 ret
= set_channel(wiphy
, dev
, &settings
->chandef
);
1430 netdev_err(dev
, "Error in setting channel\n");
1432 wilc_wlan_set_bssid(dev
, dev
->dev_addr
, WILC_AP_MODE
);
1434 return wilc_add_beacon(vif
, settings
->beacon_interval
,
1435 settings
->dtim_period
, &settings
->beacon
);
1438 static int change_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
1439 struct cfg80211_ap_update
*params
)
1441 struct wilc_vif
*vif
= netdev_priv(dev
);
1443 return wilc_add_beacon(vif
, 0, 0, ¶ms
->beacon
);
1446 static int stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
1447 unsigned int link_id
)
1450 struct wilc_vif
*vif
= netdev_priv(dev
);
1452 wilc_wlan_set_bssid(dev
, NULL
, WILC_AP_MODE
);
1454 ret
= wilc_del_beacon(vif
);
1457 netdev_err(dev
, "Host delete beacon fail\n");
1462 static int add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1463 const u8
*mac
, struct station_parameters
*params
)
1466 struct wilc_vif
*vif
= netdev_priv(dev
);
1467 struct wilc_priv
*priv
= &vif
->priv
;
1469 if (vif
->iftype
== WILC_AP_MODE
|| vif
->iftype
== WILC_GO_MODE
) {
1470 memcpy(priv
->assoc_stainfo
.sta_associated_bss
[params
->aid
], mac
,
1473 ret
= wilc_add_station(vif
, mac
, params
);
1475 netdev_err(dev
, "Host add station fail\n");
1481 static int del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1482 struct station_del_parameters
*params
)
1484 const u8
*mac
= params
->mac
;
1486 struct wilc_vif
*vif
= netdev_priv(dev
);
1487 struct wilc_priv
*priv
= &vif
->priv
;
1488 struct sta_info
*info
;
1490 if (!(vif
->iftype
== WILC_AP_MODE
|| vif
->iftype
== WILC_GO_MODE
))
1493 info
= &priv
->assoc_stainfo
;
1496 ret
= wilc_del_allstation(vif
, info
->sta_associated_bss
);
1498 ret
= wilc_del_station(vif
, mac
);
1500 netdev_err(dev
, "Host delete station fail\n");
1504 static int change_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1505 const u8
*mac
, struct station_parameters
*params
)
1508 struct wilc_vif
*vif
= netdev_priv(dev
);
1510 if (vif
->iftype
== WILC_AP_MODE
|| vif
->iftype
== WILC_GO_MODE
) {
1511 ret
= wilc_edit_station(vif
, mac
, params
);
1513 netdev_err(dev
, "Host edit station fail\n");
1518 static struct wilc_vif
*wilc_get_vif_from_type(struct wilc
*wl
, int type
)
1520 struct wilc_vif
*vif
;
1522 wilc_for_each_vif(wl
, vif
) {
1523 if (vif
->iftype
== type
)
1530 static struct wireless_dev
*add_virtual_intf(struct wiphy
*wiphy
,
1532 unsigned char name_assign_type
,
1533 enum nl80211_iftype type
,
1534 struct vif_params
*params
)
1536 struct wilc
*wl
= wiphy_priv(wiphy
);
1537 struct wilc_vif
*vif
;
1538 struct wireless_dev
*wdev
;
1541 if (type
== NL80211_IFTYPE_MONITOR
) {
1542 struct net_device
*ndev
;
1545 srcu_idx
= srcu_read_lock(&wl
->srcu
);
1546 vif
= wilc_get_vif_from_type(wl
, WILC_AP_MODE
);
1548 vif
= wilc_get_vif_from_type(wl
, WILC_GO_MODE
);
1550 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1551 goto validate_interface
;
1555 if (vif
->monitor_flag
) {
1556 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1557 goto validate_interface
;
1560 ndev
= wilc_wfi_init_mon_interface(wl
, name
, vif
->ndev
);
1562 vif
->monitor_flag
= 1;
1564 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1565 return ERR_PTR(-EINVAL
);
1568 wdev
= &vif
->priv
.wdev
;
1569 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1574 mutex_lock(&wl
->vif_mutex
);
1575 if (wl
->vif_num
== WILC_NUM_CONCURRENT_IFC
) {
1576 pr_err("Reached maximum number of interface\n");
1577 mutex_unlock(&wl
->vif_mutex
);
1578 return ERR_PTR(-EINVAL
);
1580 mutex_unlock(&wl
->vif_mutex
);
1583 case NL80211_IFTYPE_STATION
:
1584 iftype
= WILC_STATION_MODE
;
1586 case NL80211_IFTYPE_AP
:
1587 iftype
= WILC_AP_MODE
;
1590 return ERR_PTR(-EOPNOTSUPP
);
1593 vif
= wilc_netdev_ifc_init(wl
, name
, iftype
, type
, true);
1595 return ERR_CAST(vif
);
1597 return &vif
->priv
.wdev
;
1600 static int del_virtual_intf(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
1602 struct wilc
*wl
= wiphy_priv(wiphy
);
1603 struct wilc_vif
*vif
;
1605 if (wdev
->iftype
== NL80211_IFTYPE_AP
||
1606 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
)
1607 wilc_wfi_deinit_mon_interface(wl
, true);
1608 vif
= netdev_priv(wdev
->netdev
);
1609 cfg80211_stop_iface(wiphy
, wdev
, GFP_KERNEL
);
1610 cfg80211_unregister_netdevice(vif
->ndev
);
1611 vif
->monitor_flag
= 0;
1613 mutex_lock(&wl
->vif_mutex
);
1614 list_del_rcu(&vif
->list
);
1616 mutex_unlock(&wl
->vif_mutex
);
1617 synchronize_srcu(&wl
->srcu
);
1621 static void wilc_set_wakeup(struct wiphy
*wiphy
, bool enabled
)
1623 struct wilc
*wl
= wiphy_priv(wiphy
);
1624 struct wilc_vif
*vif
;
1627 srcu_idx
= srcu_read_lock(&wl
->srcu
);
1628 vif
= wilc_get_wl_to_vif(wl
);
1630 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1634 netdev_info(vif
->ndev
, "cfg set wake up = %d\n", enabled
);
1635 wilc_set_wowlan_trigger(vif
, enabled
);
1636 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1639 static int set_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
1640 enum nl80211_tx_power_setting type
, int mbm
)
1644 s32 tx_power
= MBM_TO_DBM(mbm
);
1645 struct wilc
*wl
= wiphy_priv(wiphy
);
1646 struct wilc_vif
*vif
;
1648 if (!wl
->initialized
)
1651 srcu_idx
= srcu_read_lock(&wl
->srcu
);
1652 vif
= wilc_get_wl_to_vif(wl
);
1654 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1658 netdev_info(vif
->ndev
, "Setting tx power %d\n", tx_power
);
1661 else if (tx_power
> 18)
1663 ret
= wilc_set_tx_power(vif
, tx_power
);
1665 netdev_err(vif
->ndev
, "Failed to set tx power\n");
1666 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
1671 static int get_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
1675 struct wilc_vif
*vif
= netdev_priv(wdev
->netdev
);
1676 struct wilc
*wl
= vif
->wilc
;
1678 /* If firmware is not started, return. */
1679 if (!wl
->initialized
)
1682 ret
= wilc_get_tx_power(vif
, (u8
*)dbm
);
1684 netdev_err(vif
->ndev
, "Failed to get tx power\n");
1689 static const struct cfg80211_ops wilc_cfg80211_ops
= {
1690 .set_monitor_channel
= set_channel
,
1693 .disconnect
= disconnect
,
1697 .set_default_key
= set_default_key
,
1698 .set_default_mgmt_key
= set_default_mgmt_key
,
1699 .add_virtual_intf
= add_virtual_intf
,
1700 .del_virtual_intf
= del_virtual_intf
,
1701 .change_virtual_intf
= change_virtual_intf
,
1703 .start_ap
= start_ap
,
1704 .change_beacon
= change_beacon
,
1706 .add_station
= add_station
,
1707 .del_station
= del_station
,
1708 .change_station
= change_station
,
1709 .get_station
= get_station
,
1710 .dump_station
= dump_station
,
1711 .change_bss
= change_bss
,
1712 .set_wiphy_params
= set_wiphy_params
,
1714 .external_auth
= external_auth
,
1715 .set_pmksa
= set_pmksa
,
1716 .del_pmksa
= del_pmksa
,
1717 .flush_pmksa
= flush_pmksa
,
1718 .remain_on_channel
= remain_on_channel
,
1719 .cancel_remain_on_channel
= cancel_remain_on_channel
,
1720 .mgmt_tx_cancel_wait
= mgmt_tx_cancel_wait
,
1722 .update_mgmt_frame_registrations
= wilc_update_mgmt_frame_registrations
,
1723 .set_power_mgmt
= set_power_mgmt
,
1724 .set_cqm_rssi_config
= set_cqm_rssi_config
,
1726 .set_wakeup
= wilc_set_wakeup
,
1727 .set_tx_power
= set_tx_power
,
1728 .get_tx_power
= get_tx_power
,
1732 static void wlan_init_locks(struct wilc
*wl
)
1734 mutex_init(&wl
->hif_cs
);
1735 mutex_init(&wl
->rxq_cs
);
1736 mutex_init(&wl
->cfg_cmd_lock
);
1737 mutex_init(&wl
->vif_mutex
);
1738 mutex_init(&wl
->deinit_lock
);
1740 spin_lock_init(&wl
->txq_spinlock
);
1741 mutex_init(&wl
->txq_add_to_head_cs
);
1743 init_completion(&wl
->txq_event
);
1744 init_completion(&wl
->cfg_event
);
1745 init_completion(&wl
->sync_event
);
1746 init_completion(&wl
->txq_thread_started
);
1747 init_srcu_struct(&wl
->srcu
);
1750 void wlan_deinit_locks(struct wilc
*wilc
)
1752 mutex_destroy(&wilc
->hif_cs
);
1753 mutex_destroy(&wilc
->rxq_cs
);
1754 mutex_destroy(&wilc
->cfg_cmd_lock
);
1755 mutex_destroy(&wilc
->txq_add_to_head_cs
);
1756 mutex_destroy(&wilc
->vif_mutex
);
1757 mutex_destroy(&wilc
->deinit_lock
);
1758 cleanup_srcu_struct(&wilc
->srcu
);
1761 static struct wilc
*wilc_create_wiphy(struct device
*dev
)
1763 struct wiphy
*wiphy
;
1766 wiphy
= wiphy_new(&wilc_cfg80211_ops
, sizeof(*wl
));
1770 wl
= wiphy_priv(wiphy
);
1772 memcpy(wl
->bitrates
, wilc_bitrates
, sizeof(wilc_bitrates
));
1773 memcpy(wl
->channels
, wilc_2ghz_channels
, sizeof(wilc_2ghz_channels
));
1774 wl
->band
.bitrates
= wl
->bitrates
;
1775 wl
->band
.n_bitrates
= ARRAY_SIZE(wl
->bitrates
);
1776 wl
->band
.channels
= wl
->channels
;
1777 wl
->band
.n_channels
= ARRAY_SIZE(wilc_2ghz_channels
);
1779 wl
->band
.ht_cap
.ht_supported
= 1;
1780 wl
->band
.ht_cap
.cap
|= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT
);
1781 wl
->band
.ht_cap
.mcs
.rx_mask
[0] = 0xff;
1782 wl
->band
.ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_8K
;
1783 wl
->band
.ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
1785 wiphy
->bands
[NL80211_BAND_2GHZ
] = &wl
->band
;
1787 wiphy
->max_scan_ssids
= WILC_MAX_NUM_PROBED_SSID
;
1789 wiphy
->wowlan
= &wowlan_support
;
1791 wiphy
->max_num_pmkids
= WILC_MAX_NUM_PMKIDS
;
1792 wiphy
->max_scan_ie_len
= 1000;
1793 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
1794 memcpy(wl
->cipher_suites
, wilc_cipher_suites
,
1795 sizeof(wilc_cipher_suites
));
1796 wiphy
->cipher_suites
= wl
->cipher_suites
;
1797 wiphy
->n_cipher_suites
= ARRAY_SIZE(wilc_cipher_suites
);
1798 wiphy
->mgmt_stypes
= wilc_wfi_cfg80211_mgmt_types
;
1800 wiphy
->max_remain_on_channel_duration
= 500;
1801 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1802 BIT(NL80211_IFTYPE_AP
) |
1803 BIT(NL80211_IFTYPE_MONITOR
) |
1804 BIT(NL80211_IFTYPE_P2P_GO
) |
1805 BIT(NL80211_IFTYPE_P2P_CLIENT
);
1806 wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
1807 set_wiphy_dev(wiphy
, dev
);
1812 int wilc_cfg80211_init(struct wilc
**wilc
, struct device
*dev
, int io_type
,
1813 const struct wilc_hif_func
*ops
)
1818 wl
= wilc_create_wiphy(dev
);
1822 wlan_init_locks(wl
);
1824 ret
= wilc_wlan_cfg_init(wl
);
1829 wl
->io_type
= io_type
;
1832 for (i
= 0; i
< NQUEUES
; i
++)
1833 INIT_LIST_HEAD(&wl
->txq
[i
].txq_head
.list
);
1835 INIT_LIST_HEAD(&wl
->rxq_head
.list
);
1836 INIT_LIST_HEAD(&wl
->vif_list
);
1838 wl
->hif_workqueue
= alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM
,
1839 wiphy_name(wl
->wiphy
));
1840 if (!wl
->hif_workqueue
) {
1848 wilc_wlan_cfg_deinit(wl
);
1851 wlan_deinit_locks(wl
);
1852 wiphy_free(wl
->wiphy
);
1855 EXPORT_SYMBOL_GPL(wilc_cfg80211_init
);
1857 int wilc_cfg80211_register(struct wilc
*wilc
)
1859 /* WPA3/SAE supported only on WILC1000 */
1860 if (is_wilc1000(wilc
->chipid
))
1861 wilc
->wiphy
->features
|= NL80211_FEATURE_SAE
;
1863 return wiphy_register(wilc
->wiphy
);
1865 EXPORT_SYMBOL_GPL(wilc_cfg80211_register
);
1867 int wilc_init_host_int(struct net_device
*net
)
1870 struct wilc_vif
*vif
= netdev_priv(net
);
1871 struct wilc_priv
*priv
= &vif
->priv
;
1873 priv
->p2p_listen_state
= false;
1875 mutex_init(&priv
->scan_req_lock
);
1876 ret
= wilc_init(net
, &priv
->hif_drv
);
1878 netdev_err(net
, "Error while initializing hostinterface\n");
1883 void wilc_deinit_host_int(struct net_device
*net
)
1886 struct wilc_vif
*vif
= netdev_priv(net
);
1887 struct wilc_priv
*priv
= &vif
->priv
;
1889 priv
->p2p_listen_state
= false;
1891 flush_workqueue(vif
->wilc
->hif_workqueue
);
1892 mutex_destroy(&priv
->scan_req_lock
);
1893 ret
= wilc_deinit(vif
);
1896 netdev_err(net
, "Error while deinitializing host interface\n");