1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #include "wilc_wfi_cfgoperations.h"
10 #define ENCRYPT_ENABLED BIT(0)
12 #define WEP_EXTENDED BIT(2)
18 #define FRAME_TYPE_ID 0
19 #define ACTION_CAT_ID 24
20 #define ACTION_SUBTYPE_ID 25
21 #define P2P_PUB_ACTION_SUBTYPE 30
23 #define ACTION_FRAME 0xd0
24 #define GO_INTENT_ATTR_ID 0x04
25 #define CHANLIST_ATTR_ID 0x0b
26 #define OPERCHAN_ATTR_ID 0x11
27 #define PUB_ACTION_ATTR_ID 0x04
28 #define P2PELEM_ATTR_ID 0xdd
30 #define GO_NEG_REQ 0x00
31 #define GO_NEG_RSP 0x01
32 #define GO_NEG_CONF 0x02
33 #define P2P_INV_REQ 0x03
34 #define P2P_INV_RSP 0x04
35 #define PUBLIC_ACT_VENDORSPEC 0x09
36 #define GAS_INITIAL_REQ 0x0a
37 #define GAS_INITIAL_RSP 0x0b
39 #define INVALID_CHANNEL 0
41 #define nl80211_SCAN_RESULT_EXPIRE (3 * HZ)
42 #define SCAN_RESULT_EXPIRE (40 * HZ)
44 static const u32 cipher_suites[] = {
45 WLAN_CIPHER_SUITE_WEP40,
46 WLAN_CIPHER_SUITE_WEP104,
47 WLAN_CIPHER_SUITE_TKIP,
48 WLAN_CIPHER_SUITE_CCMP,
49 WLAN_CIPHER_SUITE_AES_CMAC,
52 static const struct ieee80211_txrx_stypes
53 wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = {
54 [NL80211_IFTYPE_STATION] = {
56 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
57 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
59 [NL80211_IFTYPE_AP] = {
61 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
62 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
63 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
64 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
65 BIT(IEEE80211_STYPE_AUTH >> 4) |
66 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
67 BIT(IEEE80211_STYPE_ACTION >> 4)
69 [NL80211_IFTYPE_P2P_CLIENT] = {
71 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
72 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
73 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
74 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
75 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
76 BIT(IEEE80211_STYPE_AUTH >> 4) |
77 BIT(IEEE80211_STYPE_DEAUTH >> 4)
81 static const struct wiphy_wowlan_support wowlan_support = {
82 .flags = WIPHY_WOWLAN_ANY
85 static struct network_info last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
86 static u32 last_scanned_cnt;
87 struct timer_list wilc_during_ip_timer;
88 static struct timer_list aging_timer;
91 #define CHAN2G(_channel, _freq, _flags) { \
92 .band = NL80211_BAND_2GHZ, \
93 .center_freq = (_freq), \
94 .hw_value = (_channel), \
96 .max_antenna_gain = 0, \
100 static struct ieee80211_channel ieee80211_2ghz_channels[] = {
117 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
118 .bitrate = (_rate), \
119 .hw_value = (_hw_value), \
123 static struct ieee80211_rate ieee80211_bitrates[] = {
124 RATETAB_ENT(10, 0, 0),
125 RATETAB_ENT(20, 1, 0),
126 RATETAB_ENT(55, 2, 0),
127 RATETAB_ENT(110, 3, 0),
128 RATETAB_ENT(60, 9, 0),
129 RATETAB_ENT(90, 6, 0),
130 RATETAB_ENT(120, 7, 0),
131 RATETAB_ENT(180, 8, 0),
132 RATETAB_ENT(240, 9, 0),
133 RATETAB_ENT(360, 10, 0),
134 RATETAB_ENT(480, 11, 0),
135 RATETAB_ENT(540, 12, 0),
138 struct p2p_mgmt_data {
143 static u8 wlan_channel = INVALID_CHANNEL;
144 static u8 curr_channel;
145 static u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09};
146 static u8 p2p_local_random = 0x01;
147 static u8 p2p_recv_random;
148 static u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
151 static struct ieee80211_supported_band wilc_band_2ghz = {
152 .channels = ieee80211_2ghz_channels,
153 .n_channels = ARRAY_SIZE(ieee80211_2ghz_channels),
154 .bitrates = ieee80211_bitrates,
155 .n_bitrates = ARRAY_SIZE(ieee80211_bitrates),
158 #define AGING_TIME (9 * 1000)
159 #define DURING_IP_TIME_OUT 15000
161 static void clear_shadow_scan(void)
168 del_timer_sync(&aging_timer);
170 for (i = 0; i < last_scanned_cnt; i++) {
171 if (last_scanned_shadow[last_scanned_cnt].ies) {
172 kfree(last_scanned_shadow[i].ies);
173 last_scanned_shadow[last_scanned_cnt].ies = NULL;
176 kfree(last_scanned_shadow[i].join_params);
177 last_scanned_shadow[i].join_params = NULL;
179 last_scanned_cnt = 0;
182 static u32 get_rssi_avg(struct network_info *network_info)
186 u8 num_rssi = (network_info->rssi_history.full) ?
187 NUM_RSSI : (network_info->rssi_history.index);
189 for (i = 0; i < num_rssi; i++)
190 rssi_v += network_info->rssi_history.samples[i];
196 static void refresh_scan(struct wilc_priv *priv, bool direct_scan)
198 struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy;
201 for (i = 0; i < last_scanned_cnt; i++) {
202 struct network_info *network_info;
204 struct ieee80211_channel *channel;
206 struct cfg80211_bss *bss;
208 network_info = &last_scanned_shadow[i];
210 if (!memcmp("DIRECT-", network_info->ssid, 7) && !direct_scan)
213 freq = ieee80211_channel_to_frequency((s32)network_info->ch,
215 channel = ieee80211_get_channel(wiphy, freq);
216 rssi = get_rssi_avg(network_info);
217 bss = cfg80211_inform_bss(wiphy,
219 CFG80211_BSS_FTYPE_UNKNOWN,
221 network_info->tsf_hi,
222 network_info->cap_info,
223 network_info->beacon_period,
224 (const u8 *)network_info->ies,
225 (size_t)network_info->ies_len,
228 cfg80211_put_bss(wiphy, bss);
232 static void reset_shadow_found(void)
236 for (i = 0; i < last_scanned_cnt; i++)
237 last_scanned_shadow[i].found = 0;
240 static void update_scan_time(void)
244 for (i = 0; i < last_scanned_cnt; i++)
245 last_scanned_shadow[i].time_scan = jiffies;
248 static void remove_network_from_shadow(struct timer_list *unused)
250 unsigned long now = jiffies;
253 for (i = 0; i < last_scanned_cnt; i++) {
254 if (!time_after(now, last_scanned_shadow[i].time_scan +
255 (unsigned long)(SCAN_RESULT_EXPIRE)))
257 kfree(last_scanned_shadow[i].ies);
258 last_scanned_shadow[i].ies = NULL;
260 kfree(last_scanned_shadow[i].join_params);
262 for (j = i; (j < last_scanned_cnt - 1); j++)
263 last_scanned_shadow[j] = last_scanned_shadow[j + 1];
268 if (last_scanned_cnt != 0)
269 mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME));
272 static void clear_during_ip(struct timer_list *unused)
274 wilc_optaining_ip = false;
277 static int is_network_in_shadow(struct network_info *nw_info, void *user_void)
282 if (last_scanned_cnt == 0) {
283 mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME));
286 for (i = 0; i < last_scanned_cnt; i++) {
287 if (memcmp(last_scanned_shadow[i].bssid,
288 nw_info->bssid, 6) == 0) {
297 static void add_network_to_shadow(struct network_info *nw_info,
298 void *user_void, void *join_params)
300 int ap_found = is_network_in_shadow(nw_info, user_void);
303 struct network_info *shadow_nw_info;
305 if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW)
308 if (ap_found == -1) {
309 ap_index = last_scanned_cnt;
314 shadow_nw_info = &last_scanned_shadow[ap_index];
315 rssi_index = shadow_nw_info->rssi_history.index;
316 shadow_nw_info->rssi_history.samples[rssi_index++] = nw_info->rssi;
317 if (rssi_index == NUM_RSSI) {
319 shadow_nw_info->rssi_history.full = true;
321 shadow_nw_info->rssi_history.index = rssi_index;
322 shadow_nw_info->rssi = nw_info->rssi;
323 shadow_nw_info->cap_info = nw_info->cap_info;
324 shadow_nw_info->ssid_len = nw_info->ssid_len;
325 memcpy(shadow_nw_info->ssid, nw_info->ssid, nw_info->ssid_len);
326 memcpy(shadow_nw_info->bssid, nw_info->bssid, ETH_ALEN);
327 shadow_nw_info->beacon_period = nw_info->beacon_period;
328 shadow_nw_info->dtim_period = nw_info->dtim_period;
329 shadow_nw_info->ch = nw_info->ch;
330 shadow_nw_info->tsf_hi = nw_info->tsf_hi;
332 kfree(shadow_nw_info->ies);
333 shadow_nw_info->ies = kmemdup(nw_info->ies, nw_info->ies_len,
335 if (shadow_nw_info->ies)
336 shadow_nw_info->ies_len = nw_info->ies_len;
338 shadow_nw_info->ies_len = 0;
339 shadow_nw_info->time_scan = jiffies;
340 shadow_nw_info->time_scan_cached = jiffies;
341 shadow_nw_info->found = 1;
343 kfree(shadow_nw_info->join_params);
344 shadow_nw_info->join_params = join_params;
347 static void cfg_scan_result(enum scan_event scan_event,
348 struct network_info *network_info,
349 void *user_void, void *join_params)
351 struct wilc_priv *priv;
354 struct ieee80211_channel *channel;
355 struct cfg80211_bss *bss = NULL;
358 if (!priv->cfg_scanning)
361 if (scan_event == SCAN_EVENT_NETWORK_FOUND) {
362 wiphy = priv->dev->ieee80211_ptr->wiphy;
364 if (!wiphy || !network_info)
367 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
368 (((s32)network_info->rssi * 100) < 0 ||
369 ((s32)network_info->rssi * 100) > 100))
372 freq = ieee80211_channel_to_frequency((s32)network_info->ch,
374 channel = ieee80211_get_channel(wiphy, freq);
379 if (network_info->new_network) {
380 if (priv->rcvd_ch_cnt >= MAX_NUM_SCANNED_NETWORKS)
385 add_network_to_shadow(network_info, priv, join_params);
387 if (memcmp("DIRECT-", network_info->ssid, 7))
390 bss = cfg80211_inform_bss(wiphy,
392 CFG80211_BSS_FTYPE_UNKNOWN,
394 network_info->tsf_hi,
395 network_info->cap_info,
396 network_info->beacon_period,
397 (const u8 *)network_info->ies,
398 (size_t)network_info->ies_len,
399 (s32)network_info->rssi * 100,
401 cfg80211_put_bss(wiphy, bss);
405 for (i = 0; i < priv->rcvd_ch_cnt; i++) {
406 if (memcmp(last_scanned_shadow[i].bssid,
407 network_info->bssid, 6) == 0)
411 if (i >= priv->rcvd_ch_cnt)
414 last_scanned_shadow[i].rssi = network_info->rssi;
415 last_scanned_shadow[i].time_scan = jiffies;
417 } else if (scan_event == SCAN_EVENT_DONE) {
418 refresh_scan(priv, false);
420 mutex_lock(&priv->scan_req_lock);
422 if (priv->scan_req) {
423 struct cfg80211_scan_info info = {
427 cfg80211_scan_done(priv->scan_req, &info);
428 priv->rcvd_ch_cnt = 0;
429 priv->cfg_scanning = false;
430 priv->scan_req = NULL;
432 mutex_unlock(&priv->scan_req_lock);
433 } else if (scan_event == SCAN_EVENT_ABORTED) {
434 mutex_lock(&priv->scan_req_lock);
436 if (priv->scan_req) {
437 struct cfg80211_scan_info info = {
442 refresh_scan(priv, false);
444 cfg80211_scan_done(priv->scan_req, &info);
445 priv->cfg_scanning = false;
446 priv->scan_req = NULL;
448 mutex_unlock(&priv->scan_req_lock);
452 static inline bool wilc_wfi_cfg_scan_time_expired(int i)
454 unsigned long now = jiffies;
456 if (time_after(now, last_scanned_shadow[i].time_scan_cached +
457 (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ))))
465 static void cfg_connect_result(enum conn_event conn_disconn_evt,
466 struct connect_info *conn_info,
468 struct disconnect_info *disconn_info,
471 struct wilc_priv *priv = priv_data;
472 struct net_device *dev = priv->dev;
473 struct wilc_vif *vif = netdev_priv(dev);
474 struct wilc *wl = vif->wilc;
475 struct host_if_drv *wfi_drv = priv->hif_drv;
476 u8 null_bssid[ETH_ALEN] = {0};
480 if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
483 connect_status = conn_info->status;
485 if (mac_status == MAC_STATUS_DISCONNECTED &&
486 conn_info->status == WLAN_STATUS_SUCCESS) {
487 connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
488 wilc_wlan_set_bssid(priv->dev, null_bssid,
490 eth_zero_addr(wilc_connected_ssid);
492 if (!wfi_drv->p2p_connect)
493 wlan_channel = INVALID_CHANNEL;
495 netdev_err(dev, "Unspecified failure\n");
498 if (connect_status == WLAN_STATUS_SUCCESS) {
499 bool scan_refresh = false;
502 memcpy(priv->associated_bss, conn_info->bssid,
505 for (i = 0; i < last_scanned_cnt; i++) {
506 if (memcmp(last_scanned_shadow[i].bssid,
509 if (wilc_wfi_cfg_scan_time_expired(i))
517 refresh_scan(priv, true);
520 cfg80211_connect_result(dev, conn_info->bssid,
522 conn_info->req_ies_len,
524 conn_info->resp_ies_len, connect_status,
526 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
527 wilc_optaining_ip = false;
528 p2p_local_random = 0x01;
529 p2p_recv_random = 0x00;
531 eth_zero_addr(priv->associated_bss);
532 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
533 eth_zero_addr(wilc_connected_ssid);
535 if (!wfi_drv->p2p_connect)
536 wlan_channel = INVALID_CHANNEL;
537 if (wfi_drv->ifc_up && dev == wl->vif[1]->ndev)
538 disconn_info->reason = 3;
539 else if (!wfi_drv->ifc_up && dev == wl->vif[1]->ndev)
540 disconn_info->reason = 1;
542 cfg80211_disconnected(dev, disconn_info->reason,
543 disconn_info->ie, disconn_info->ie_len,
548 static int set_channel(struct wiphy *wiphy,
549 struct cfg80211_chan_def *chandef)
552 struct wilc_priv *priv = wiphy_priv(wiphy);
553 struct wilc_vif *vif = netdev_priv(priv->dev);
556 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
558 curr_channel = channelnum;
559 result = wilc_set_mac_chnl_num(vif, channelnum);
562 netdev_err(priv->dev, "Error in setting channel\n");
568 wilc_wfi_cfg_alloc_fill_ssid(struct cfg80211_scan_request *request,
569 struct hidden_network *ntwk)
574 ntwk->net_info = kcalloc(request->n_ssids, sizeof(*ntwk->net_info),
579 ntwk->n_ssids = request->n_ssids;
581 for (i = 0; i < request->n_ssids; i++) {
582 if (request->ssids[i].ssid_len > 0) {
583 struct hidden_net_info *info = &ntwk->net_info[slot_id];
585 info->ssid = kmemdup(request->ssids[i].ssid,
586 request->ssids[i].ssid_len,
591 info->ssid_len = request->ssids[i].ssid_len;
601 for (i = 0; i < slot_id; i++)
602 kfree(ntwk->net_info[i].ssid);
604 kfree(ntwk->net_info);
610 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
612 struct wilc_priv *priv = wiphy_priv(wiphy);
613 struct wilc_vif *vif = netdev_priv(priv->dev);
616 u8 scan_ch_list[MAX_NUM_SCANNED_NETWORKS];
617 struct hidden_network hidden_ntwk;
619 priv->scan_req = request;
621 priv->rcvd_ch_cnt = 0;
623 reset_shadow_found();
625 priv->cfg_scanning = true;
626 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) {
627 for (i = 0; i < request->n_channels; i++) {
628 u16 freq = request->channels[i]->center_freq;
630 scan_ch_list[i] = ieee80211_frequency_to_channel(freq);
633 if (request->n_ssids >= 1) {
634 if (wilc_wfi_cfg_alloc_fill_ssid(request,
638 ret = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN,
641 (const u8 *)request->ie,
642 request->ie_len, cfg_scan_result,
643 (void *)priv, &hidden_ntwk);
645 ret = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN,
648 (const u8 *)request->ie,
649 request->ie_len, cfg_scan_result,
653 netdev_err(priv->dev, "Requested scanned channels over\n");
662 static int connect(struct wiphy *wiphy, struct net_device *dev,
663 struct cfg80211_connect_params *sme)
665 struct wilc_priv *priv = wiphy_priv(wiphy);
666 struct wilc_vif *vif = netdev_priv(priv->dev);
667 struct host_if_drv *wfi_drv = priv->hif_drv;
668 struct network_info *nw_info;
671 u32 sel_bssi_idx = UINT_MAX;
672 u8 security = NO_ENCRYPT;
673 enum authtype auth_type = ANY;
678 if (!(strncmp(sme->ssid, "DIRECT-", 7)))
679 wfi_drv->p2p_connect = 1;
681 wfi_drv->p2p_connect = 0;
683 for (i = 0; i < last_scanned_cnt; i++) {
684 if (sme->ssid_len == last_scanned_shadow[i].ssid_len &&
685 memcmp(last_scanned_shadow[i].ssid,
687 sme->ssid_len) == 0) {
689 if (sel_bssi_idx == UINT_MAX ||
690 last_scanned_shadow[i].rssi >
691 last_scanned_shadow[sel_bssi_idx].rssi)
694 if (memcmp(last_scanned_shadow[i].bssid,
704 if (sel_bssi_idx < last_scanned_cnt) {
705 nw_info = &last_scanned_shadow[sel_bssi_idx];
712 memset(priv->wep_key, 0, sizeof(priv->wep_key));
713 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
715 cipher_group = sme->crypto.cipher_group;
716 if (cipher_group != NO_ENCRYPT) {
717 if (cipher_group == WLAN_CIPHER_SUITE_WEP40) {
718 security = ENCRYPT_ENABLED | WEP;
720 priv->wep_key_len[sme->key_idx] = sme->key_len;
721 memcpy(priv->wep_key[sme->key_idx], sme->key,
724 wilc_set_wep_default_keyid(vif, sme->key_idx);
725 wilc_add_wep_key_bss_sta(vif, sme->key, sme->key_len,
727 } else if (cipher_group == WLAN_CIPHER_SUITE_WEP104) {
728 security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
730 priv->wep_key_len[sme->key_idx] = sme->key_len;
731 memcpy(priv->wep_key[sme->key_idx], sme->key,
734 wilc_set_wep_default_keyid(vif, sme->key_idx);
735 wilc_add_wep_key_bss_sta(vif, sme->key, sme->key_len,
737 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
738 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
739 security = ENCRYPT_ENABLED | WPA2 | TKIP;
741 security = ENCRYPT_ENABLED | WPA2 | AES;
742 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
743 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
744 security = ENCRYPT_ENABLED | WPA | TKIP;
746 security = ENCRYPT_ENABLED | WPA | AES;
749 netdev_err(dev, "%s: Unsupported cipher\n",
756 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) ||
757 (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
758 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
759 u32 ciphers_pairwise = sme->crypto.ciphers_pairwise[i];
761 if (ciphers_pairwise == WLAN_CIPHER_SUITE_TKIP)
762 security = security | TKIP;
764 security = security | AES;
768 switch (sme->auth_type) {
769 case NL80211_AUTHTYPE_OPEN_SYSTEM:
770 auth_type = OPEN_SYSTEM;
773 case NL80211_AUTHTYPE_SHARED_KEY:
774 auth_type = SHARED_KEY;
781 if (sme->crypto.n_akm_suites) {
782 if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X)
783 auth_type = IEEE8021;
786 curr_channel = nw_info->ch;
788 if (!wfi_drv->p2p_connect)
789 wlan_channel = nw_info->ch;
791 wilc_wlan_set_bssid(dev, nw_info->bssid, STATION_MODE);
793 ret = wilc_set_join_req(vif, nw_info->bssid, sme->ssid,
794 sme->ssid_len, sme->ie, sme->ie_len,
795 cfg_connect_result, (void *)priv,
798 nw_info->join_params);
800 netdev_err(dev, "wilc_set_join_req(): Error\n");
809 static int disconnect(struct wiphy *wiphy, struct net_device *dev,
812 struct wilc_priv *priv = wiphy_priv(wiphy);
813 struct wilc_vif *vif = netdev_priv(priv->dev);
814 struct wilc *wilc = vif->wilc;
815 struct host_if_drv *wfi_drv;
817 u8 null_bssid[ETH_ALEN] = {0};
825 /* already disconnected done */
826 cfg80211_disconnected(dev, 0, NULL, 0, true, GFP_KERNEL);
830 wfi_drv = (struct host_if_drv *)priv->hif_drv;
831 if (!wfi_drv->p2p_connect)
832 wlan_channel = INVALID_CHANNEL;
833 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
835 p2p_local_random = 0x01;
836 p2p_recv_random = 0x00;
838 wfi_drv->p2p_timeout = 0;
840 ret = wilc_disconnect(vif, reason_code);
842 netdev_err(priv->dev, "Error in disconnecting\n");
849 static inline void wilc_wfi_cfg_copy_wep_info(struct wilc_priv *priv,
851 struct key_params *params)
853 priv->wep_key_len[key_index] = params->key_len;
854 memcpy(priv->wep_key[key_index], params->key, params->key_len);
857 static int wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv *priv, u8 idx)
859 if (!priv->wilc_gtk[idx]) {
860 priv->wilc_gtk[idx] = kzalloc(sizeof(*priv->wilc_gtk[idx]),
862 if (!priv->wilc_gtk[idx])
866 if (!priv->wilc_ptk[idx]) {
867 priv->wilc_ptk[idx] = kzalloc(sizeof(*priv->wilc_ptk[idx]),
869 if (!priv->wilc_ptk[idx])
876 static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key *key_info,
877 struct key_params *params)
879 kfree(key_info->key);
881 key_info->key = kmemdup(params->key, params->key_len, GFP_KERNEL);
885 kfree(key_info->seq);
887 if (params->seq_len > 0) {
888 key_info->seq = kmemdup(params->seq, params->seq_len,
894 key_info->cipher = params->cipher;
895 key_info->key_len = params->key_len;
896 key_info->seq_len = params->seq_len;
901 static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
902 bool pairwise, const u8 *mac_addr, struct key_params *params)
905 int ret = 0, keylen = params->key_len;
906 struct wilc_priv *priv = wiphy_priv(wiphy);
907 const u8 *rx_mic = NULL;
908 const u8 *tx_mic = NULL;
909 u8 mode = NO_ENCRYPT;
911 struct wilc_vif *vif = netdev_priv(netdev);
913 switch (params->cipher) {
914 case WLAN_CIPHER_SUITE_WEP40:
915 case WLAN_CIPHER_SUITE_WEP104:
916 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
917 wilc_wfi_cfg_copy_wep_info(priv, key_index, params);
919 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
920 mode = ENCRYPT_ENABLED | WEP;
922 mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
924 ret = wilc_add_wep_key_bss_ap(vif, params->key,
930 if (memcmp(params->key, priv->wep_key[key_index],
932 wilc_wfi_cfg_copy_wep_info(priv, key_index, params);
934 ret = wilc_add_wep_key_bss_sta(vif, params->key,
941 case WLAN_CIPHER_SUITE_TKIP:
942 case WLAN_CIPHER_SUITE_CCMP:
943 if (priv->wdev->iftype == NL80211_IFTYPE_AP ||
944 priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
945 struct wilc_wfi_key *key;
947 ret = wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
951 if (params->key_len > 16 &&
952 params->cipher == WLAN_CIPHER_SUITE_TKIP) {
953 tx_mic = params->key + 24;
954 rx_mic = params->key + 16;
955 keylen = params->key_len - 16;
959 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
960 mode = ENCRYPT_ENABLED | WPA | TKIP;
962 mode = ENCRYPT_ENABLED | WPA2 | AES;
964 priv->wilc_groupkey = mode;
966 key = priv->wilc_gtk[key_index];
968 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
969 mode = ENCRYPT_ENABLED | WPA | TKIP;
971 mode = priv->wilc_groupkey | AES;
973 key = priv->wilc_ptk[key_index];
975 ret = wilc_wfi_cfg_copy_wpa_info(key, params);
981 if (params->key_len > 16 &&
982 params->cipher == WLAN_CIPHER_SUITE_TKIP) {
983 rx_mic = params->key + 24;
984 tx_mic = params->key + 16;
985 keylen = params->key_len - 16;
988 op_mode = STATION_MODE;
992 ret = wilc_add_rx_gtk(vif, params->key, keylen,
993 key_index, params->seq_len,
994 params->seq, rx_mic, tx_mic,
997 ret = wilc_add_ptk(vif, params->key, keylen, mac_addr,
998 rx_mic, tx_mic, op_mode, mode,
1004 netdev_err(netdev, "%s: Unsupported cipher\n", __func__);
1011 static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1016 struct wilc_priv *priv = wiphy_priv(wiphy);
1017 struct wilc_vif *vif = netdev_priv(netdev);
1018 struct wilc *wl = vif->wilc;
1020 if (netdev == wl->vif[0]->ndev) {
1021 if (priv->wilc_gtk[key_index]) {
1022 kfree(priv->wilc_gtk[key_index]->key);
1023 priv->wilc_gtk[key_index]->key = NULL;
1024 kfree(priv->wilc_gtk[key_index]->seq);
1025 priv->wilc_gtk[key_index]->seq = NULL;
1027 kfree(priv->wilc_gtk[key_index]);
1028 priv->wilc_gtk[key_index] = NULL;
1031 if (priv->wilc_ptk[key_index]) {
1032 kfree(priv->wilc_ptk[key_index]->key);
1033 priv->wilc_ptk[key_index]->key = NULL;
1034 kfree(priv->wilc_ptk[key_index]->seq);
1035 priv->wilc_ptk[key_index]->seq = NULL;
1036 kfree(priv->wilc_ptk[key_index]);
1037 priv->wilc_ptk[key_index] = NULL;
1041 if (key_index <= 3 && priv->wep_key_len[key_index]) {
1042 memset(priv->wep_key[key_index], 0,
1043 priv->wep_key_len[key_index]);
1044 priv->wep_key_len[key_index] = 0;
1045 wilc_remove_wep_key(vif, key_index);
1051 static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1052 bool pairwise, const u8 *mac_addr, void *cookie,
1053 void (*callback)(void *cookie, struct key_params *))
1055 struct wilc_priv *priv = wiphy_priv(wiphy);
1056 struct key_params key_params;
1059 key_params.key = priv->wilc_gtk[key_index]->key;
1060 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1061 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1062 key_params.seq = priv->wilc_gtk[key_index]->seq;
1063 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1065 key_params.key = priv->wilc_ptk[key_index]->key;
1066 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1067 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1068 key_params.seq = priv->wilc_ptk[key_index]->seq;
1069 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1072 callback(cookie, &key_params);
1077 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
1078 u8 key_index, bool unicast, bool multicast)
1080 struct wilc_priv *priv = wiphy_priv(wiphy);
1081 struct wilc_vif *vif = netdev_priv(priv->dev);
1083 wilc_set_wep_default_keyid(vif, key_index);
1088 static int get_station(struct wiphy *wiphy, struct net_device *dev,
1089 const u8 *mac, struct station_info *sinfo)
1091 struct wilc_priv *priv = wiphy_priv(wiphy);
1092 struct wilc_vif *vif = netdev_priv(dev);
1094 u32 associatedsta = ~0;
1095 u32 inactive_time = 0;
1097 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
1098 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1100 priv->assoc_stainfo.sta_associated_bss[i],
1107 if (associatedsta == ~0) {
1108 netdev_err(dev, "sta required is not associated\n");
1112 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
1114 wilc_get_inactive_time(vif, mac, &inactive_time);
1115 sinfo->inactive_time = 1000 * inactive_time;
1116 } else if (vif->iftype == STATION_MODE) {
1117 struct rf_info stats;
1119 wilc_get_statistics(vif, &stats, true);
1121 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL) |
1122 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
1123 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1124 BIT_ULL(NL80211_STA_INFO_TX_FAILED) |
1125 BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
1127 sinfo->signal = stats.rssi;
1128 sinfo->rx_packets = stats.rx_cnt;
1129 sinfo->tx_packets = stats.tx_cnt + stats.tx_fail_cnt;
1130 sinfo->tx_failed = stats.tx_fail_cnt;
1131 sinfo->txrate.legacy = stats.link_speed * 10;
1133 if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
1134 stats.link_speed != DEFAULT_LINK_SPEED)
1135 wilc_enable_tcp_ack_filter(true);
1136 else if (stats.link_speed != DEFAULT_LINK_SPEED)
1137 wilc_enable_tcp_ack_filter(false);
1142 static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1143 struct bss_parameters *params)
1148 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
1151 struct cfg_param_attr cfg_param_val;
1152 struct wilc_priv *priv = wiphy_priv(wiphy);
1153 struct wilc_vif *vif = netdev_priv(priv->dev);
1155 cfg_param_val.flag = 0;
1157 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1158 cfg_param_val.flag |= RETRY_SHORT;
1159 cfg_param_val.short_retry_limit = wiphy->retry_short;
1161 if (changed & WIPHY_PARAM_RETRY_LONG) {
1162 cfg_param_val.flag |= RETRY_LONG;
1163 cfg_param_val.long_retry_limit = wiphy->retry_long;
1165 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1166 cfg_param_val.flag |= FRAG_THRESHOLD;
1167 cfg_param_val.frag_threshold = wiphy->frag_threshold;
1170 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1171 cfg_param_val.flag |= RTS_THRESHOLD;
1172 cfg_param_val.rts_threshold = wiphy->rts_threshold;
1175 ret = wilc_hif_set_cfg(vif, &cfg_param_val);
1177 netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
1182 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1183 struct cfg80211_pmksa *pmksa)
1185 struct wilc_priv *priv = wiphy_priv(wiphy);
1186 struct wilc_vif *vif = netdev_priv(priv->dev);
1191 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1192 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1198 if (i < WILC_MAX_NUM_PMKIDS) {
1199 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
1201 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
1203 if (!(flag == PMKID_FOUND))
1204 priv->pmkid_list.numpmkid++;
1206 netdev_err(netdev, "Invalid PMKID index\n");
1211 ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
1216 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1217 struct cfg80211_pmksa *pmksa)
1221 struct wilc_priv *priv = wiphy_priv(wiphy);
1223 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1224 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1226 memset(&priv->pmkid_list.pmkidlist[i], 0,
1227 sizeof(struct host_if_pmkid));
1232 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1233 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
1234 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
1235 priv->pmkid_list.pmkidlist[i + 1].bssid,
1237 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
1238 priv->pmkid_list.pmkidlist[i + 1].pmkid,
1241 priv->pmkid_list.numpmkid--;
1249 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1251 struct wilc_priv *priv = wiphy_priv(wiphy);
1253 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
1258 static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u8 ch_list_attr_idx,
1264 if (ch_list_attr_idx) {
1265 u8 limit = ch_list_attr_idx + 3 + buf[ch_list_attr_idx + 1];
1267 for (i = ch_list_attr_idx + 3; i < limit; i++) {
1268 if (buf[i] == 0x51) {
1269 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++)
1270 buf[j] = wlan_channel;
1276 if (op_ch_attr_idx) {
1277 buf[op_ch_attr_idx + 6] = 0x51;
1278 buf[op_ch_attr_idx + 7] = wlan_channel;
1282 static void wilc_wfi_cfg_parse_rx_action(u8 *buf, u32 len)
1285 u8 op_channel_attr_index = 0;
1286 u8 channel_list_attr_index = 0;
1288 while (index < len) {
1289 if (buf[index] == GO_INTENT_ATTR_ID)
1290 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
1292 if (buf[index] == CHANLIST_ATTR_ID)
1293 channel_list_attr_index = index;
1294 else if (buf[index] == OPERCHAN_ATTR_ID)
1295 op_channel_attr_index = index;
1296 index += buf[index + 1] + 3;
1298 if (wlan_channel != INVALID_CHANNEL)
1299 wilc_wfi_cfg_parse_ch_attr(buf, channel_list_attr_index,
1300 op_channel_attr_index);
1303 static void wilc_wfi_cfg_parse_tx_action(u8 *buf, u32 len, bool oper_ch,
1307 u8 op_channel_attr_index = 0;
1308 u8 channel_list_attr_index = 0;
1310 while (index < len) {
1311 if (buf[index] == GO_INTENT_ATTR_ID) {
1312 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
1317 if (buf[index] == CHANLIST_ATTR_ID)
1318 channel_list_attr_index = index;
1319 else if (buf[index] == OPERCHAN_ATTR_ID)
1320 op_channel_attr_index = index;
1321 index += buf[index + 1] + 3;
1323 if (wlan_channel != INVALID_CHANNEL && oper_ch)
1324 wilc_wfi_cfg_parse_ch_attr(buf, channel_list_attr_index,
1325 op_channel_attr_index);
1328 static void wilc_wfi_cfg_parse_rx_vendor_spec(struct wilc_priv *priv, u8 *buff,
1333 struct wilc_vif *vif = netdev_priv(priv->dev);
1335 subtype = buff[P2P_PUB_ACTION_SUBTYPE];
1336 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && !wilc_ie) {
1337 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
1338 if (!memcmp(p2p_vendor_spec, &buff[i], 6)) {
1339 p2p_recv_random = buff[i + 6];
1346 if (p2p_local_random <= p2p_recv_random) {
1347 netdev_dbg(vif->ndev,
1348 "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n",
1349 p2p_local_random, p2p_recv_random);
1353 if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP ||
1354 subtype == P2P_INV_REQ || subtype == P2P_INV_RSP) {
1355 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
1356 if (buff[i] == P2PELEM_ATTR_ID &&
1357 !(memcmp(p2p_oui, &buff[i + 2], 4))) {
1358 wilc_wfi_cfg_parse_rx_action(&buff[i + 6],
1366 void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1368 struct wilc_priv *priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1369 struct host_if_drv *wfi_drv = priv->hif_drv;
1370 u32 header, pkt_offset;
1374 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
1375 le32_to_cpus(&header);
1376 pkt_offset = GET_PKT_OFFSET(header);
1378 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1381 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP ||
1382 pkt_offset & IS_MGMT_STATUS_SUCCES)
1385 cfg80211_mgmt_tx_status(priv->wdev, priv->tx_cookie, buff, size,
1390 freq = ieee80211_channel_to_frequency(curr_channel, NL80211_BAND_2GHZ);
1392 fc = ((struct ieee80211_hdr *)buff)->frame_control;
1393 if (!ieee80211_is_action(fc)) {
1394 cfg80211_rx_mgmt(priv->wdev, freq, 0, buff, size, 0);
1398 if (priv->cfg_scanning &&
1399 time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
1400 netdev_dbg(dev, "Receiving action wrong ch\n");
1403 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1404 u8 subtype = buff[P2P_PUB_ACTION_SUBTYPE];
1406 switch (buff[ACTION_SUBTYPE_ID]) {
1407 case GAS_INITIAL_REQ:
1408 case GAS_INITIAL_RSP:
1411 case PUBLIC_ACT_VENDORSPEC:
1412 if (!memcmp(p2p_oui, &buff[ACTION_SUBTYPE_ID + 1], 4))
1413 wilc_wfi_cfg_parse_rx_vendor_spec(priv, buff,
1416 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) &&
1424 "%s: Not handled action frame type:%x\n",
1425 __func__, buff[ACTION_SUBTYPE_ID]);
1430 cfg80211_rx_mgmt(priv->wdev, freq, 0, buff, size, 0);
1433 static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
1435 struct p2p_mgmt_data *pv_data = priv;
1437 kfree(pv_data->buff);
1441 static void wilc_wfi_remain_on_channel_ready(void *priv_data)
1443 struct wilc_priv *priv;
1447 priv->p2p_listen_state = true;
1449 cfg80211_ready_on_channel(priv->wdev,
1450 priv->remain_on_ch_params.listen_cookie,
1451 priv->remain_on_ch_params.listen_ch,
1452 priv->remain_on_ch_params.listen_duration,
1456 static void wilc_wfi_remain_on_channel_expired(void *data, u32 session_id)
1458 struct wilc_priv *priv = data;
1459 struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
1461 if (session_id != params->listen_session_id)
1464 priv->p2p_listen_state = false;
1466 cfg80211_remain_on_channel_expired(priv->wdev, params->listen_cookie,
1467 params->listen_ch, GFP_KERNEL);
1470 static int remain_on_channel(struct wiphy *wiphy,
1471 struct wireless_dev *wdev,
1472 struct ieee80211_channel *chan,
1473 unsigned int duration, u64 *cookie)
1476 struct wilc_priv *priv = wiphy_priv(wiphy);
1477 struct wilc_vif *vif = netdev_priv(priv->dev);
1479 if (wdev->iftype == NL80211_IFTYPE_AP) {
1480 netdev_dbg(vif->ndev, "Required while in AP mode\n");
1484 curr_channel = chan->hw_value;
1486 priv->remain_on_ch_params.listen_ch = chan;
1487 priv->remain_on_ch_params.listen_cookie = *cookie;
1488 priv->remain_on_ch_params.listen_duration = duration;
1489 priv->remain_on_ch_params.listen_session_id++;
1491 return wilc_remain_on_channel(vif,
1492 priv->remain_on_ch_params.listen_session_id,
1493 duration, chan->hw_value,
1494 wilc_wfi_remain_on_channel_expired,
1495 wilc_wfi_remain_on_channel_ready, (void *)priv);
1498 static int cancel_remain_on_channel(struct wiphy *wiphy,
1499 struct wireless_dev *wdev,
1502 struct wilc_priv *priv = wiphy_priv(wiphy);
1503 struct wilc_vif *vif = netdev_priv(priv->dev);
1505 return wilc_listen_state_expired(vif,
1506 priv->remain_on_ch_params.listen_session_id);
1509 static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
1510 struct cfg80211_mgmt_tx_params *params,
1511 u8 iftype, u32 buf_len)
1513 const u8 *buf = params->buf;
1514 size_t len = params->len;
1516 u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE];
1518 if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) {
1519 if (p2p_local_random == 1 &&
1520 p2p_recv_random < p2p_local_random) {
1521 get_random_bytes(&p2p_local_random, 1);
1526 if (p2p_local_random <= p2p_recv_random || !(subtype == GO_NEG_REQ ||
1527 subtype == GO_NEG_RSP ||
1528 subtype == P2P_INV_REQ ||
1529 subtype == P2P_INV_RSP))
1532 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
1533 if (buf[i] == P2PELEM_ATTR_ID &&
1534 !memcmp(p2p_oui, &buf[i + 2], 4)) {
1535 bool oper_ch = false;
1536 u8 *tx_buff = &mgmt_tx->buff[i + 6];
1538 if (subtype == P2P_INV_REQ || subtype == P2P_INV_RSP)
1541 wilc_wfi_cfg_parse_tx_action(tx_buff, len - (i + 6),
1548 if (subtype != P2P_INV_REQ && subtype != P2P_INV_RSP) {
1549 int vendor_spec_len = sizeof(p2p_vendor_spec);
1551 memcpy(&mgmt_tx->buff[len], p2p_vendor_spec,
1553 mgmt_tx->buff[len + vendor_spec_len] = p2p_local_random;
1554 mgmt_tx->size = buf_len;
1558 static int mgmt_tx(struct wiphy *wiphy,
1559 struct wireless_dev *wdev,
1560 struct cfg80211_mgmt_tx_params *params,
1563 struct ieee80211_channel *chan = params->chan;
1564 unsigned int wait = params->wait;
1565 const u8 *buf = params->buf;
1566 size_t len = params->len;
1567 const struct ieee80211_mgmt *mgmt;
1568 struct p2p_mgmt_data *mgmt_tx;
1569 struct wilc_priv *priv = wiphy_priv(wiphy);
1570 struct host_if_drv *wfi_drv = priv->hif_drv;
1571 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1572 u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random);
1575 *cookie = (unsigned long)buf;
1576 priv->tx_cookie = *cookie;
1577 mgmt = (const struct ieee80211_mgmt *)buf;
1579 if (!ieee80211_is_mgmt(mgmt->frame_control))
1582 mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_KERNEL);
1588 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
1589 if (!mgmt_tx->buff) {
1595 memcpy(mgmt_tx->buff, buf, len);
1596 mgmt_tx->size = len;
1598 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
1599 wilc_set_mac_chnl_num(vif, chan->hw_value);
1600 curr_channel = chan->hw_value;
1601 goto out_txq_add_pkt;
1604 if (!ieee80211_is_action(mgmt->frame_control))
1605 goto out_txq_add_pkt;
1607 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1608 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
1609 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
1610 wilc_set_mac_chnl_num(vif, chan->hw_value);
1611 curr_channel = chan->hw_value;
1613 switch (buf[ACTION_SUBTYPE_ID]) {
1614 case GAS_INITIAL_REQ:
1615 case GAS_INITIAL_RSP:
1618 case PUBLIC_ACT_VENDORSPEC:
1619 if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4))
1620 wilc_wfi_cfg_tx_vendor_spec(mgmt_tx, params,
1624 netdev_dbg(vif->ndev,
1625 "Not a P2P public action frame\n");
1630 netdev_dbg(vif->ndev,
1631 "%s: Not handled action frame type:%x\n",
1632 __func__, buf[ACTION_SUBTYPE_ID]);
1637 wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
1641 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
1642 mgmt_tx->buff, mgmt_tx->size,
1643 wilc_wfi_mgmt_tx_complete);
1650 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
1651 struct wireless_dev *wdev,
1654 struct wilc_priv *priv = wiphy_priv(wiphy);
1655 struct host_if_drv *wfi_drv = priv->hif_drv;
1657 wfi_drv->p2p_timeout = jiffies;
1659 if (!priv->p2p_listen_state) {
1660 struct wilc_wfi_p2p_listen_params *params;
1662 params = &priv->remain_on_ch_params;
1664 cfg80211_remain_on_channel_expired(priv->wdev,
1665 params->listen_cookie,
1673 void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
1674 u16 frame_type, bool reg)
1676 struct wilc_priv *priv = wiphy_priv(wiphy);
1677 struct wilc_vif *vif = netdev_priv(priv->wdev->netdev);
1678 struct wilc *wl = vif->wilc;
1683 switch (frame_type) {
1685 vif->frame_reg[0].type = frame_type;
1686 vif->frame_reg[0].reg = reg;
1690 vif->frame_reg[1].type = frame_type;
1691 vif->frame_reg[1].reg = reg;
1698 if (!wl->initialized)
1700 wilc_frame_register(vif, frame_type, reg);
1703 static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
1704 s32 rssi_thold, u32 rssi_hyst)
1709 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
1710 int idx, u8 *mac, struct station_info *sinfo)
1712 struct wilc_priv *priv = wiphy_priv(wiphy);
1713 struct wilc_vif *vif = netdev_priv(priv->dev);
1718 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
1720 wilc_get_rssi(vif, &sinfo->signal);
1722 memcpy(mac, priv->associated_bss, ETH_ALEN);
1726 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1727 bool enabled, int timeout)
1729 struct wilc_priv *priv = wiphy_priv(wiphy);
1730 struct wilc_vif *vif = netdev_priv(priv->dev);
1736 wilc_set_power_mgmt(vif, enabled, timeout);
1741 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1742 enum nl80211_iftype type,
1743 struct vif_params *params)
1745 struct wilc_priv *priv = wiphy_priv(wiphy);
1746 struct wilc_vif *vif = netdev_priv(dev);
1747 struct wilc *wl = vif->wilc;
1749 p2p_local_random = 0x01;
1750 p2p_recv_random = 0x00;
1752 wilc_optaining_ip = false;
1753 del_timer(&wilc_during_ip_timer);
1756 case NL80211_IFTYPE_STATION:
1757 wilc_connecting = 0;
1758 dev->ieee80211_ptr->iftype = type;
1759 priv->wdev->iftype = type;
1760 vif->monitor_flag = 0;
1761 vif->iftype = STATION_MODE;
1762 wilc_set_operation_mode(vif, STATION_MODE);
1764 memset(priv->assoc_stainfo.sta_associated_bss, 0,
1765 MAX_NUM_STA * ETH_ALEN);
1767 wilc_enable_ps = true;
1768 wilc_set_power_mgmt(vif, 1, 0);
1771 case NL80211_IFTYPE_P2P_CLIENT:
1772 wilc_connecting = 0;
1773 dev->ieee80211_ptr->iftype = type;
1774 priv->wdev->iftype = type;
1775 vif->monitor_flag = 0;
1776 vif->iftype = CLIENT_MODE;
1777 wilc_set_operation_mode(vif, STATION_MODE);
1779 wilc_enable_ps = false;
1780 wilc_set_power_mgmt(vif, 0, 0);
1783 case NL80211_IFTYPE_AP:
1784 wilc_enable_ps = false;
1785 dev->ieee80211_ptr->iftype = type;
1786 priv->wdev->iftype = type;
1787 vif->iftype = AP_MODE;
1789 if (wl->initialized) {
1790 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
1792 wilc_set_operation_mode(vif, AP_MODE);
1793 wilc_set_power_mgmt(vif, 0, 0);
1797 case NL80211_IFTYPE_P2P_GO:
1798 wilc_optaining_ip = true;
1799 mod_timer(&wilc_during_ip_timer,
1800 jiffies + msecs_to_jiffies(DURING_IP_TIME_OUT));
1801 wilc_set_operation_mode(vif, AP_MODE);
1802 dev->ieee80211_ptr->iftype = type;
1803 priv->wdev->iftype = type;
1804 vif->iftype = GO_MODE;
1806 wilc_enable_ps = false;
1807 wilc_set_power_mgmt(vif, 0, 0);
1811 netdev_err(dev, "Unknown interface type= %d\n", type);
1818 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1819 struct cfg80211_ap_settings *settings)
1821 struct wilc_vif *vif = netdev_priv(dev);
1822 struct wilc *wl = vif->wilc;
1823 struct cfg80211_beacon_data *beacon = &settings->beacon;
1826 ret = set_channel(wiphy, &settings->chandef);
1829 netdev_err(dev, "Error in setting channel\n");
1831 wilc_wlan_set_bssid(dev, wl->vif[vif->idx]->src_addr, AP_MODE);
1832 wilc_set_power_mgmt(vif, 0, 0);
1834 return wilc_add_beacon(vif, settings->beacon_interval,
1835 settings->dtim_period, beacon->head_len,
1836 (u8 *)beacon->head, beacon->tail_len,
1837 (u8 *)beacon->tail);
1840 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
1841 struct cfg80211_beacon_data *beacon)
1843 struct wilc_priv *priv = wiphy_priv(wiphy);
1844 struct wilc_vif *vif = netdev_priv(priv->dev);
1846 return wilc_add_beacon(vif, 0, 0, beacon->head_len,
1847 (u8 *)beacon->head, beacon->tail_len,
1848 (u8 *)beacon->tail);
1851 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
1854 struct wilc_priv *priv = wiphy_priv(wiphy);
1855 struct wilc_vif *vif = netdev_priv(priv->dev);
1856 u8 null_bssid[ETH_ALEN] = {0};
1858 wilc_wlan_set_bssid(dev, null_bssid, AP_MODE);
1860 ret = wilc_del_beacon(vif);
1863 netdev_err(dev, "Host delete beacon fail\n");
1868 static int add_station(struct wiphy *wiphy, struct net_device *dev,
1869 const u8 *mac, struct station_parameters *params)
1872 struct wilc_priv *priv = wiphy_priv(wiphy);
1873 struct add_sta_param sta_params = { {0} };
1874 struct wilc_vif *vif = netdev_priv(dev);
1876 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
1877 memcpy(sta_params.bssid, mac, ETH_ALEN);
1878 memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
1880 sta_params.aid = params->aid;
1881 sta_params.rates_len = params->supported_rates_len;
1882 sta_params.rates = params->supported_rates;
1884 if (!params->ht_capa) {
1885 sta_params.ht_supported = false;
1887 sta_params.ht_supported = true;
1888 sta_params.ht_capa = *params->ht_capa;
1891 sta_params.flags_mask = params->sta_flags_mask;
1892 sta_params.flags_set = params->sta_flags_set;
1894 ret = wilc_add_station(vif, &sta_params);
1896 netdev_err(dev, "Host add station fail\n");
1902 static int del_station(struct wiphy *wiphy, struct net_device *dev,
1903 struct station_del_parameters *params)
1905 const u8 *mac = params->mac;
1907 struct wilc_priv *priv = wiphy_priv(wiphy);
1908 struct wilc_vif *vif = netdev_priv(dev);
1909 struct sta_info *info;
1911 if (!(vif->iftype == AP_MODE || vif->iftype == GO_MODE))
1914 info = &priv->assoc_stainfo;
1917 ret = wilc_del_allstation(vif, info->sta_associated_bss);
1919 ret = wilc_del_station(vif, mac);
1921 netdev_err(dev, "Host delete station fail\n");
1925 static int change_station(struct wiphy *wiphy, struct net_device *dev,
1926 const u8 *mac, struct station_parameters *params)
1929 struct add_sta_param sta_params = { {0} };
1930 struct wilc_vif *vif = netdev_priv(dev);
1932 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
1933 memcpy(sta_params.bssid, mac, ETH_ALEN);
1934 sta_params.aid = params->aid;
1935 sta_params.rates_len = params->supported_rates_len;
1936 sta_params.rates = params->supported_rates;
1938 if (!params->ht_capa) {
1939 sta_params.ht_supported = false;
1941 sta_params.ht_supported = true;
1942 sta_params.ht_capa = *params->ht_capa;
1945 sta_params.flags_mask = params->sta_flags_mask;
1946 sta_params.flags_set = params->sta_flags_set;
1948 ret = wilc_edit_station(vif, &sta_params);
1950 netdev_err(dev, "Host edit station fail\n");
1955 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
1957 unsigned char name_assign_type,
1958 enum nl80211_iftype type,
1959 struct vif_params *params)
1961 struct wilc_priv *priv = wiphy_priv(wiphy);
1962 struct wilc_vif *vif = netdev_priv(priv->wdev->netdev);
1963 struct net_device *new_ifc;
1965 if (type == NL80211_IFTYPE_MONITOR) {
1966 new_ifc = wilc_wfi_init_mon_interface(name, vif->ndev);
1968 vif = netdev_priv(priv->wdev->netdev);
1969 vif->monitor_flag = 1;
1975 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1980 static int wilc_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow)
1982 struct wilc_priv *priv = wiphy_priv(wiphy);
1983 struct wilc_vif *vif = netdev_priv(priv->dev);
1985 if (!wow && wilc_wlan_get_num_conn_ifcs(vif->wilc))
1986 vif->wilc->suspend_event = true;
1988 vif->wilc->suspend_event = false;
1993 static int wilc_resume(struct wiphy *wiphy)
1995 struct wilc_priv *priv = wiphy_priv(wiphy);
1996 struct wilc_vif *vif = netdev_priv(priv->dev);
1998 netdev_info(vif->ndev, "cfg resume\n");
2002 static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
2004 struct wilc_priv *priv = wiphy_priv(wiphy);
2005 struct wilc_vif *vif = netdev_priv(priv->dev);
2007 netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
2010 static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2011 enum nl80211_tx_power_setting type, int mbm)
2014 s32 tx_power = MBM_TO_DBM(mbm);
2015 struct wilc_priv *priv = wiphy_priv(wiphy);
2016 struct wilc_vif *vif = netdev_priv(priv->dev);
2020 else if (tx_power > 18)
2022 ret = wilc_set_tx_power(vif, tx_power);
2024 netdev_err(vif->ndev, "Failed to set tx power\n");
2029 static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2033 struct wilc_priv *priv = wiphy_priv(wiphy);
2034 struct wilc_vif *vif = netdev_priv(priv->dev);
2035 struct wilc *wl = vif->wilc;
2037 /* If firmware is not started, return. */
2038 if (!wl->initialized)
2041 ret = wilc_get_tx_power(vif, (u8 *)dbm);
2043 netdev_err(vif->ndev, "Failed to get tx power\n");
2048 static const struct cfg80211_ops wilc_cfg80211_ops = {
2049 .set_monitor_channel = set_channel,
2052 .disconnect = disconnect,
2056 .set_default_key = set_default_key,
2057 .add_virtual_intf = add_virtual_intf,
2058 .del_virtual_intf = del_virtual_intf,
2059 .change_virtual_intf = change_virtual_intf,
2061 .start_ap = start_ap,
2062 .change_beacon = change_beacon,
2064 .add_station = add_station,
2065 .del_station = del_station,
2066 .change_station = change_station,
2067 .get_station = get_station,
2068 .dump_station = dump_station,
2069 .change_bss = change_bss,
2070 .set_wiphy_params = set_wiphy_params,
2072 .set_pmksa = set_pmksa,
2073 .del_pmksa = del_pmksa,
2074 .flush_pmksa = flush_pmksa,
2075 .remain_on_channel = remain_on_channel,
2076 .cancel_remain_on_channel = cancel_remain_on_channel,
2077 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
2079 .mgmt_frame_register = wilc_mgmt_frame_register,
2080 .set_power_mgmt = set_power_mgmt,
2081 .set_cqm_rssi_config = set_cqm_rssi_config,
2083 .suspend = wilc_suspend,
2084 .resume = wilc_resume,
2085 .set_wakeup = wilc_set_wakeup,
2086 .set_tx_power = set_tx_power,
2087 .get_tx_power = get_tx_power,
2091 static struct wireless_dev *wilc_wfi_cfg_alloc(void)
2093 struct wireless_dev *wdev;
2095 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
2099 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
2103 wilc_band_2ghz.ht_cap.ht_supported = 1;
2104 wilc_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
2105 wilc_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
2106 wilc_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
2107 wilc_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2109 wdev->wiphy->bands[NL80211_BAND_2GHZ] = &wilc_band_2ghz;
2119 struct wireless_dev *wilc_create_wiphy(struct net_device *net,
2122 struct wilc_priv *priv;
2123 struct wireless_dev *wdev;
2126 wdev = wilc_wfi_cfg_alloc();
2128 netdev_err(net, "wiphy new allocate failed\n");
2132 priv = wdev_priv(wdev);
2134 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
2136 wdev->wiphy->wowlan = &wowlan_support;
2138 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
2139 wdev->wiphy->max_scan_ie_len = 1000;
2140 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2141 wdev->wiphy->cipher_suites = cipher_suites;
2142 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2143 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
2145 wdev->wiphy->max_remain_on_channel_duration = 500;
2146 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2147 BIT(NL80211_IFTYPE_AP) |
2148 BIT(NL80211_IFTYPE_MONITOR) |
2149 BIT(NL80211_IFTYPE_P2P_GO) |
2150 BIT(NL80211_IFTYPE_P2P_CLIENT);
2151 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
2152 wdev->iftype = NL80211_IFTYPE_STATION;
2154 set_wiphy_dev(wdev->wiphy, dev);
2156 ret = wiphy_register(wdev->wiphy);
2158 netdev_err(net, "Cannot register wiphy device\n");
2164 int wilc_init_host_int(struct net_device *net)
2167 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
2170 timer_setup(&aging_timer, remove_network_from_shadow, 0);
2171 timer_setup(&wilc_during_ip_timer, clear_during_ip, 0);
2175 priv->p2p_listen_state = false;
2177 mutex_init(&priv->scan_req_lock);
2178 ret = wilc_init(net, &priv->hif_drv);
2180 netdev_err(net, "Error while initializing hostinterface\n");
2185 int wilc_deinit_host_int(struct net_device *net)
2188 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
2189 struct wilc_vif *vif = netdev_priv(priv->dev);
2191 priv->p2p_listen_state = false;
2195 mutex_destroy(&priv->scan_req_lock);
2196 ret = wilc_deinit(vif);
2198 clear_shadow_scan();
2200 del_timer_sync(&wilc_during_ip_timer);
2203 netdev_err(net, "Error while deinitializing host interface\n");
2208 void wilc_free_wiphy(struct net_device *net)
2213 if (!net->ieee80211_ptr)
2216 if (!net->ieee80211_ptr->wiphy)
2219 wiphy_unregister(net->ieee80211_ptr->wiphy);
2221 wiphy_free(net->ieee80211_ptr->wiphy);
2222 kfree(net->ieee80211_ptr);