1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #include "wilc_wfi_netdevice.h"
9 #define WILC_HIF_SCAN_TIMEOUT_MS 5000
10 #define WILC_HIF_CONNECT_TIMEOUT_MS 9500
12 #define WILC_FALSE_FRMWR_CHANNEL 100
13 #define WILC_MAX_RATES_SUPPORTED 12
15 struct wilc_rcvd_mac_info {
19 struct wilc_set_multicast {
25 struct wilc_del_all_sta {
27 u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
34 struct wilc_reg_frame {
40 struct wilc_drv_handler {
51 struct wilc_sta_wpa_ptk {
52 u8 mac_addr[ETH_ALEN];
57 struct wilc_ap_wpa_ptk {
58 u8 mac_addr[ETH_ALEN];
65 u8 mac_addr[ETH_ALEN];
72 union wilc_message_body {
73 struct wilc_rcvd_net_info net_info;
74 struct wilc_rcvd_mac_info mac_info;
75 struct wilc_set_multicast mc_info;
76 struct wilc_remain_ch remain_on_ch;
81 union wilc_message_body body;
83 struct work_struct work;
84 void (*fn)(struct work_struct *ws);
85 struct completion work_comp;
89 struct wilc_noa_opp_enable {
97 struct wilc_noa_opp_disable {
104 struct wilc_join_bss_param {
105 char ssid[IEEE80211_MAX_SSID_LEN];
112 __le16 beacon_period;
114 u8 supp_rates[WILC_MAX_RATES_SUPPORTED + 1];
129 struct wilc_noa_opp_disable opp_dis;
130 struct wilc_noa_opp_enable opp_en;
134 /* 'msg' should be free by the caller for syc */
135 static struct host_if_msg*
136 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
139 struct host_if_msg *msg;
142 return ERR_PTR(-EINVAL);
144 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
146 return ERR_PTR(-ENOMEM);
149 msg->is_sync = is_sync;
151 init_completion(&msg->work_comp);
156 static int wilc_enqueue_work(struct host_if_msg *msg)
158 INIT_WORK(&msg->work, msg->fn);
160 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
163 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
169 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
170 * special purpose in wilc device, so we add 1 to the index to starts from 1.
171 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
173 int wilc_get_vif_idx(struct wilc_vif *vif)
178 /* We need to minus 1 from idx which is from wilc device to get real index
179 * of wilc->vif[], because we add 1 when pass to wilc device in the function
181 * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
183 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
187 if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
190 return wilc->vif[index];
193 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
196 u8 abort_running_scan;
198 struct host_if_drv *hif_drv = vif->hif_drv;
199 struct wilc_user_scan_req *scan_req;
201 if (evt == SCAN_EVENT_ABORTED) {
202 abort_running_scan = 1;
203 wid.id = WID_ABORT_RUNNING_SCAN;
205 wid.val = (s8 *)&abort_running_scan;
206 wid.size = sizeof(char);
208 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
210 netdev_err(vif->ndev, "Failed to set abort running\n");
216 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
220 scan_req = &hif_drv->usr_scan_req;
221 if (scan_req->scan_result) {
222 scan_req->scan_result(evt, NULL, scan_req->arg);
223 scan_req->scan_result = NULL;
229 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
230 u8 *ch_freq_list, u8 ch_list_len,
231 void (*scan_result_fn)(enum scan_event,
232 struct wilc_rcvd_net_info *, void *),
233 void *user_arg, struct cfg80211_scan_request *request)
236 struct wid wid_list[5];
241 u8 *search_ssid_vals = NULL;
242 struct host_if_drv *hif_drv = vif->hif_drv;
244 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
245 hif_drv->hif_state < HOST_IF_CONNECTED) {
246 netdev_err(vif->ndev, "Already scan\n");
251 if (vif->connecting) {
252 netdev_err(vif->ndev, "Don't do obss scan\n");
257 hif_drv->usr_scan_req.ch_cnt = 0;
259 if (request->n_ssids) {
260 for (i = 0; i < request->n_ssids; i++)
261 valuesize += ((request->ssids[i].ssid_len) + 1);
262 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
263 if (search_ssid_vals) {
264 wid_list[index].id = WID_SSID_PROBE_REQ;
265 wid_list[index].type = WID_STR;
266 wid_list[index].val = search_ssid_vals;
267 buffer = wid_list[index].val;
269 *buffer++ = request->n_ssids;
271 for (i = 0; i < request->n_ssids; i++) {
272 *buffer++ = request->ssids[i].ssid_len;
273 memcpy(buffer, request->ssids[i].ssid,
274 request->ssids[i].ssid_len);
275 buffer += request->ssids[i].ssid_len;
277 wid_list[index].size = (s32)(valuesize + 1);
282 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
283 wid_list[index].type = WID_BIN_DATA;
284 wid_list[index].val = (s8 *)request->ie;
285 wid_list[index].size = request->ie_len;
288 wid_list[index].id = WID_SCAN_TYPE;
289 wid_list[index].type = WID_CHAR;
290 wid_list[index].size = sizeof(char);
291 wid_list[index].val = (s8 *)&scan_type;
294 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
295 wid_list[index].id = WID_PASSIVE_SCAN_TIME;
296 wid_list[index].type = WID_SHORT;
297 wid_list[index].size = sizeof(u16);
298 wid_list[index].val = (s8 *)&request->duration;
301 scan_timeout = (request->duration * ch_list_len) + 500;
303 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
306 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
307 wid_list[index].type = WID_BIN_DATA;
309 if (ch_freq_list && ch_list_len > 0) {
310 for (i = 0; i < ch_list_len; i++) {
311 if (ch_freq_list[i] > 0)
312 ch_freq_list[i] -= 1;
316 wid_list[index].val = ch_freq_list;
317 wid_list[index].size = ch_list_len;
320 wid_list[index].id = WID_START_SCAN_REQ;
321 wid_list[index].type = WID_CHAR;
322 wid_list[index].size = sizeof(char);
323 wid_list[index].val = (s8 *)&scan_source;
326 hif_drv->usr_scan_req.scan_result = scan_result_fn;
327 hif_drv->usr_scan_req.arg = user_arg;
329 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
331 netdev_err(vif->ndev, "Failed to send scan parameters\n");
335 hif_drv->scan_timer_vif = vif;
336 mod_timer(&hif_drv->scan_timer,
337 jiffies + msecs_to_jiffies(scan_timeout));
341 kfree(search_ssid_vals);
346 static int wilc_send_connect_wid(struct wilc_vif *vif)
349 struct wid wid_list[4];
351 struct host_if_drv *hif_drv = vif->hif_drv;
352 struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
353 struct wilc_join_bss_param *bss_param = conn_attr->param;
355 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
356 wid_list[wid_cnt].type = WID_BIN_DATA;
357 wid_list[wid_cnt].val = conn_attr->req_ies;
358 wid_list[wid_cnt].size = conn_attr->req_ies_len;
361 wid_list[wid_cnt].id = WID_11I_MODE;
362 wid_list[wid_cnt].type = WID_CHAR;
363 wid_list[wid_cnt].size = sizeof(char);
364 wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
367 wid_list[wid_cnt].id = WID_AUTH_TYPE;
368 wid_list[wid_cnt].type = WID_CHAR;
369 wid_list[wid_cnt].size = sizeof(char);
370 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
373 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
374 wid_list[wid_cnt].type = WID_STR;
375 wid_list[wid_cnt].size = sizeof(*bss_param);
376 wid_list[wid_cnt].val = (u8 *)bss_param;
379 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
381 netdev_err(vif->ndev, "failed to send config packet\n");
384 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
391 kfree(conn_attr->req_ies);
392 conn_attr->req_ies = NULL;
397 static void handle_connect_timeout(struct work_struct *work)
399 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
400 struct wilc_vif *vif = msg->vif;
403 u16 dummy_reason_code = 0;
404 struct host_if_drv *hif_drv = vif->hif_drv;
407 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
411 hif_drv->hif_state = HOST_IF_IDLE;
413 if (hif_drv->conn_info.conn_result) {
414 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
415 WILC_MAC_STATUS_DISCONNECTED,
416 hif_drv->conn_info.arg);
419 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
422 wid.id = WID_DISCONNECT;
424 wid.val = (s8 *)&dummy_reason_code;
425 wid.size = sizeof(char);
427 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
429 netdev_err(vif->ndev, "Failed to send disconnect\n");
431 hif_drv->conn_info.req_ies_len = 0;
432 kfree(hif_drv->conn_info.req_ies);
433 hif_drv->conn_info.req_ies = NULL;
439 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
440 struct cfg80211_crypto_settings *crypto)
442 struct wilc_join_bss_param *param;
443 struct ieee80211_p2p_noa_attr noa_attr;
445 const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
446 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
448 const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
450 param = kzalloc(sizeof(*param), GFP_KERNEL);
454 param->beacon_period = cpu_to_le16(bss->beacon_interval);
455 param->cap_info = cpu_to_le16(bss->capability);
456 param->bss_type = WILC_FW_BSS_TYPE_INFRA;
457 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
458 ether_addr_copy(param->bssid, bss->bssid);
460 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
462 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
463 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
466 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
467 if (tim_elm && tim_elm[1] >= 2)
468 param->dtim_period = tim_elm[3];
470 memset(param->p_suites, 0xFF, 3);
471 memset(param->akm_suites, 0xFF, 3);
473 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
475 rates_len = rates_ie[1];
476 param->supp_rates[0] = rates_len;
477 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
480 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies->data,
483 if (supp_rates_ie[1] > (WILC_MAX_RATES_SUPPORTED - rates_len))
484 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
486 param->supp_rates[0] += supp_rates_ie[1];
488 memcpy(¶m->supp_rates[rates_len + 1], supp_rates_ie + 2,
489 (param->supp_rates[0] - rates_len));
492 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
494 param->ht_capable = true;
496 ret = cfg80211_get_p2p_attr(ies->data, ies->len,
497 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
498 (u8 *)&noa_attr, sizeof(noa_attr));
500 param->tsf_lo = cpu_to_le32(ies->tsf);
501 param->noa_enabled = 1;
502 param->idx = noa_attr.index;
503 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
504 param->opp_enabled = 1;
505 param->opp_en.ct_window = noa_attr.oppps_ctwindow;
506 param->opp_en.cnt = noa_attr.desc[0].count;
507 param->opp_en.duration = noa_attr.desc[0].duration;
508 param->opp_en.interval = noa_attr.desc[0].interval;
509 param->opp_en.start_time = noa_attr.desc[0].start_time;
511 param->opp_enabled = 0;
512 param->opp_dis.cnt = noa_attr.desc[0].count;
513 param->opp_dis.duration = noa_attr.desc[0].duration;
514 param->opp_dis.interval = noa_attr.desc[0].interval;
515 param->opp_dis.start_time = noa_attr.desc[0].start_time;
518 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
519 WLAN_OUI_TYPE_MICROSOFT_WMM,
520 ies->data, ies->len);
522 struct ieee80211_wmm_param_ie *ie;
524 ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
525 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
527 param->wmm_cap = true;
528 if (ie->qos_info & BIT(7))
529 param->uapsd_cap = true;
533 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
534 WLAN_OUI_TYPE_MICROSOFT_WPA,
535 ies->data, ies->len);
537 param->mode_802_11i = 1;
538 param->rsn_found = true;
541 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
545 param->mode_802_11i = 2;
546 param->rsn_found = true;
547 //extract RSN capabilities
548 offset += (rsn_ie[offset] * 4) + 2;
549 offset += (rsn_ie[offset] * 4) + 2;
550 memcpy(param->rsn_cap, &rsn_ie[offset], 2);
553 if (param->rsn_found) {
556 param->rsn_grp_policy = crypto->cipher_group & 0xFF;
557 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
558 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
560 for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
561 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
564 return (void *)param;
567 static void handle_rcvd_ntwrk_info(struct work_struct *work)
569 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
570 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
571 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
577 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
578 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
579 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
580 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
584 ies = rcvd_info->mgmt->u.beacon.variable;
585 ies_len = rcvd_info->frame_len - offset;
589 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
590 if (ch_elm && ch_elm[1] > 0)
591 rcvd_info->ch = ch_elm[2];
593 if (scan_req->scan_result)
594 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
598 kfree(rcvd_info->mgmt);
602 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
604 u32 max_assoc_resp_info_len,
605 u32 *rcvd_assoc_resp_info_len)
610 wid.id = WID_ASSOC_RES_INFO;
612 wid.val = assoc_resp_info;
613 wid.size = max_assoc_resp_info_len;
615 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
617 *rcvd_assoc_resp_info_len = 0;
618 netdev_err(vif->ndev, "Failed to send association response\n");
622 *rcvd_assoc_resp_info_len = wid.size;
625 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
626 struct wilc_conn_info *ret_conn_info)
630 struct assoc_resp *res = (struct assoc_resp *)buffer;
632 ret_conn_info->status = le16_to_cpu(res->status_code);
633 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
634 ies = &buffer[sizeof(*res)];
635 ies_len = buffer_len - sizeof(*res);
637 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
638 if (!ret_conn_info->resp_ies)
641 ret_conn_info->resp_ies_len = ies_len;
647 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
650 struct host_if_drv *hif_drv = vif->hif_drv;
651 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
653 if (mac_status == WILC_MAC_STATUS_CONNECTED) {
654 u32 assoc_resp_info_len;
656 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
658 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
659 WILC_MAX_ASSOC_RESP_FRAME_SIZE,
660 &assoc_resp_info_len);
662 if (assoc_resp_info_len != 0) {
665 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
669 netdev_err(vif->ndev,
670 "wilc_parse_assoc_resp_info() returned error %d\n",
675 del_timer(&hif_drv->connect_timer);
676 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
677 hif_drv->conn_info.arg);
679 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
680 conn_info->status == WLAN_STATUS_SUCCESS) {
681 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
682 hif_drv->hif_state = HOST_IF_CONNECTED;
684 hif_drv->hif_state = HOST_IF_IDLE;
687 kfree(conn_info->resp_ies);
688 conn_info->resp_ies = NULL;
689 conn_info->resp_ies_len = 0;
691 kfree(conn_info->req_ies);
692 conn_info->req_ies = NULL;
693 conn_info->req_ies_len = 0;
696 static inline void host_int_handle_disconnect(struct wilc_vif *vif)
698 struct host_if_drv *hif_drv = vif->hif_drv;
700 if (hif_drv->usr_scan_req.scan_result) {
701 del_timer(&hif_drv->scan_timer);
702 handle_scan_done(vif, SCAN_EVENT_ABORTED);
705 if (hif_drv->conn_info.conn_result)
706 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
707 0, hif_drv->conn_info.arg);
709 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
711 eth_zero_addr(hif_drv->assoc_bssid);
713 hif_drv->conn_info.req_ies_len = 0;
714 kfree(hif_drv->conn_info.req_ies);
715 hif_drv->conn_info.req_ies = NULL;
716 hif_drv->hif_state = HOST_IF_IDLE;
719 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
721 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
722 struct wilc_vif *vif = msg->vif;
723 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
724 struct host_if_drv *hif_drv = vif->hif_drv;
727 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
731 if (!hif_drv->conn_info.conn_result) {
732 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
736 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
737 host_int_parse_assoc_resp_info(vif, mac_info->status);
738 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
739 if (hif_drv->hif_state == HOST_IF_CONNECTED) {
740 host_int_handle_disconnect(vif);
741 } else if (hif_drv->usr_scan_req.scan_result) {
742 del_timer(&hif_drv->scan_timer);
743 handle_scan_done(vif, SCAN_EVENT_ABORTED);
751 int wilc_disconnect(struct wilc_vif *vif)
754 struct host_if_drv *hif_drv = vif->hif_drv;
755 struct wilc_user_scan_req *scan_req;
756 struct wilc_conn_info *conn_info;
758 u16 dummy_reason_code = 0;
760 wid.id = WID_DISCONNECT;
762 wid.val = (s8 *)&dummy_reason_code;
763 wid.size = sizeof(char);
765 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
767 netdev_err(vif->ndev, "Failed to send disconnect\n");
771 scan_req = &hif_drv->usr_scan_req;
772 conn_info = &hif_drv->conn_info;
774 if (scan_req->scan_result) {
775 del_timer(&hif_drv->scan_timer);
776 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
777 scan_req->scan_result = NULL;
780 if (conn_info->conn_result) {
781 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
782 del_timer(&hif_drv->connect_timer);
784 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
787 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
790 hif_drv->hif_state = HOST_IF_IDLE;
792 eth_zero_addr(hif_drv->assoc_bssid);
794 conn_info->req_ies_len = 0;
795 kfree(conn_info->req_ies);
796 conn_info->req_ies = NULL;
801 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
803 struct wid wid_list[5];
804 u32 wid_cnt = 0, result;
806 wid_list[wid_cnt].id = WID_LINKSPEED;
807 wid_list[wid_cnt].type = WID_CHAR;
808 wid_list[wid_cnt].size = sizeof(char);
809 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
812 wid_list[wid_cnt].id = WID_RSSI;
813 wid_list[wid_cnt].type = WID_CHAR;
814 wid_list[wid_cnt].size = sizeof(char);
815 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
818 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
819 wid_list[wid_cnt].type = WID_INT;
820 wid_list[wid_cnt].size = sizeof(u32);
821 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
824 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
825 wid_list[wid_cnt].type = WID_INT;
826 wid_list[wid_cnt].size = sizeof(u32);
827 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
830 wid_list[wid_cnt].id = WID_FAILED_COUNT;
831 wid_list[wid_cnt].type = WID_INT;
832 wid_list[wid_cnt].size = sizeof(u32);
833 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
836 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
838 netdev_err(vif->ndev, "Failed to send scan parameters\n");
842 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
843 stats->link_speed != DEFAULT_LINK_SPEED)
844 wilc_enable_tcp_ack_filter(vif, true);
845 else if (stats->link_speed != DEFAULT_LINK_SPEED)
846 wilc_enable_tcp_ack_filter(vif, false);
851 static void handle_get_statistics(struct work_struct *work)
853 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
854 struct wilc_vif *vif = msg->vif;
855 struct rf_info *stats = (struct rf_info *)msg->body.data;
857 wilc_get_statistics(vif, stats);
862 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
863 struct station_parameters *params)
865 ether_addr_copy(cur_byte, mac);
866 cur_byte += ETH_ALEN;
868 put_unaligned_le16(params->aid, cur_byte);
871 *cur_byte++ = params->supported_rates_len;
872 if (params->supported_rates_len > 0)
873 memcpy(cur_byte, params->supported_rates,
874 params->supported_rates_len);
875 cur_byte += params->supported_rates_len;
877 if (params->ht_capa) {
879 memcpy(cur_byte, ¶ms->ht_capa,
880 sizeof(struct ieee80211_ht_cap));
884 cur_byte += sizeof(struct ieee80211_ht_cap);
886 put_unaligned_le16(params->sta_flags_mask, cur_byte);
888 put_unaligned_le16(params->sta_flags_set, cur_byte);
891 static int handle_remain_on_chan(struct wilc_vif *vif,
892 struct wilc_remain_ch *hif_remain_ch)
895 u8 remain_on_chan_flag;
897 struct host_if_drv *hif_drv = vif->hif_drv;
899 if (hif_drv->usr_scan_req.scan_result)
902 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
908 remain_on_chan_flag = true;
909 wid.id = WID_REMAIN_ON_CHAN;
912 wid.val = kmalloc(wid.size, GFP_KERNEL);
916 wid.val[0] = remain_on_chan_flag;
917 wid.val[1] = (s8)hif_remain_ch->ch;
919 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
924 hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
925 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
926 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
927 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
928 hif_drv->remain_on_ch_timer_vif = vif;
933 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
935 u8 remain_on_chan_flag;
938 struct host_if_drv *hif_drv = vif->hif_drv;
939 struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
941 if (priv->p2p_listen_state) {
942 remain_on_chan_flag = false;
943 wid.id = WID_REMAIN_ON_CHAN;
947 wid.val = kmalloc(wid.size, GFP_KERNEL);
951 wid.val[0] = remain_on_chan_flag;
952 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
954 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
957 netdev_err(vif->ndev, "Failed to set remain channel\n");
961 if (hif_drv->remain_on_ch.expired) {
962 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
966 netdev_dbg(vif->ndev, "Not in listen state\n");
972 static void wilc_handle_listen_state_expired(struct work_struct *work)
974 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
976 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
980 static void listen_timer_cb(struct timer_list *t)
982 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
984 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
986 struct host_if_msg *msg;
988 del_timer(&vif->hif_drv->remain_on_ch_timer);
990 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
994 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
996 result = wilc_enqueue_work(msg);
998 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1003 static void handle_set_mcast_filter(struct work_struct *work)
1005 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1006 struct wilc_vif *vif = msg->vif;
1007 struct wilc_set_multicast *set_mc = &msg->body.mc_info;
1012 wid.id = WID_SETUP_MULTICAST_FILTER;
1014 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
1015 wid.val = kmalloc(wid.size, GFP_KERNEL);
1020 put_unaligned_le32(set_mc->enabled, cur_byte);
1023 put_unaligned_le32(set_mc->cnt, cur_byte);
1026 if (set_mc->cnt > 0 && set_mc->mc_list)
1027 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
1029 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1031 netdev_err(vif->ndev, "Failed to send setup multicast\n");
1034 kfree(set_mc->mc_list);
1039 static void handle_scan_timer(struct work_struct *work)
1041 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1043 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
1047 static void handle_scan_complete(struct work_struct *work)
1049 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1051 del_timer(&msg->vif->hif_drv->scan_timer);
1053 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1058 static void timer_scan_cb(struct timer_list *t)
1060 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
1061 struct wilc_vif *vif = hif_drv->scan_timer_vif;
1062 struct host_if_msg *msg;
1065 msg = wilc_alloc_work(vif, handle_scan_timer, false);
1069 result = wilc_enqueue_work(msg);
1074 static void timer_connect_cb(struct timer_list *t)
1076 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1078 struct wilc_vif *vif = hif_drv->connect_timer_vif;
1079 struct host_if_msg *msg;
1082 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1086 result = wilc_enqueue_work(msg);
1091 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
1096 wid.id = WID_REMOVE_WEP_KEY;
1098 wid.size = sizeof(char);
1101 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1103 netdev_err(vif->ndev,
1104 "Failed to send remove wep key config packet\n");
1108 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
1113 wid.id = WID_KEY_ID;
1114 wid.type = WID_CHAR;
1115 wid.size = sizeof(char);
1117 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1119 netdev_err(vif->ndev,
1120 "Failed to send wep default key config packet\n");
1125 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
1130 struct wilc_wep_key *wep_key;
1132 wid.id = WID_ADD_WEP_KEY;
1134 wid.size = sizeof(*wep_key) + len;
1135 wep_key = kzalloc(wid.size, GFP_KERNEL);
1139 wid.val = (u8 *)wep_key;
1141 wep_key->index = index;
1142 wep_key->key_len = len;
1143 memcpy(wep_key->key, key, len);
1145 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1147 netdev_err(vif->ndev,
1148 "Failed to add wep key config packet\n");
1154 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
1155 u8 index, u8 mode, enum authtype auth_type)
1157 struct wid wid_list[3];
1159 struct wilc_wep_key *wep_key;
1161 wid_list[0].id = WID_11I_MODE;
1162 wid_list[0].type = WID_CHAR;
1163 wid_list[0].size = sizeof(char);
1164 wid_list[0].val = &mode;
1166 wid_list[1].id = WID_AUTH_TYPE;
1167 wid_list[1].type = WID_CHAR;
1168 wid_list[1].size = sizeof(char);
1169 wid_list[1].val = (s8 *)&auth_type;
1171 wid_list[2].id = WID_WEP_KEY_VALUE;
1172 wid_list[2].type = WID_STR;
1173 wid_list[2].size = sizeof(*wep_key) + len;
1174 wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
1178 wid_list[2].val = (u8 *)wep_key;
1180 wep_key->index = index;
1181 wep_key->key_len = len;
1182 memcpy(wep_key->key, key, len);
1183 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1184 ARRAY_SIZE(wid_list));
1186 netdev_err(vif->ndev,
1187 "Failed to add wep ap key config packet\n");
1193 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1194 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1195 u8 mode, u8 cipher_mode, u8 index)
1198 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1200 if (mode == WILC_AP_MODE) {
1201 struct wid wid_list[2];
1202 struct wilc_ap_wpa_ptk *key_buf;
1204 wid_list[0].id = WID_11I_MODE;
1205 wid_list[0].type = WID_CHAR;
1206 wid_list[0].size = sizeof(char);
1207 wid_list[0].val = (s8 *)&cipher_mode;
1209 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1213 ether_addr_copy(key_buf->mac_addr, mac_addr);
1214 key_buf->index = index;
1215 key_buf->key_len = t_key_len;
1216 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1219 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1220 WILC_RX_MIC_KEY_LEN);
1223 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1224 tx_mic, WILC_TX_MIC_KEY_LEN);
1226 wid_list[1].id = WID_ADD_PTK;
1227 wid_list[1].type = WID_STR;
1228 wid_list[1].size = sizeof(*key_buf) + t_key_len;
1229 wid_list[1].val = (u8 *)key_buf;
1230 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1231 ARRAY_SIZE(wid_list));
1233 } else if (mode == WILC_STATION_MODE) {
1235 struct wilc_sta_wpa_ptk *key_buf;
1237 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1241 ether_addr_copy(key_buf->mac_addr, mac_addr);
1242 key_buf->key_len = t_key_len;
1243 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1246 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1247 WILC_RX_MIC_KEY_LEN);
1250 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1251 tx_mic, WILC_TX_MIC_KEY_LEN);
1253 wid.id = WID_ADD_PTK;
1255 wid.size = sizeof(*key_buf) + t_key_len;
1256 wid.val = (s8 *)key_buf;
1257 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1264 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1265 u8 index, u32 key_rsc_len, const u8 *key_rsc,
1266 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1270 struct wilc_gtk_key *gtk_key;
1271 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1273 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1277 /* fill bssid value only in station mode */
1278 if (mode == WILC_STATION_MODE &&
1279 vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1280 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1283 memcpy(gtk_key->rsc, key_rsc, 8);
1284 gtk_key->index = index;
1285 gtk_key->key_len = t_key_len;
1286 memcpy(>k_key->key[0], rx_gtk, gtk_key_len);
1289 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1292 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1293 tx_mic, WILC_TX_MIC_KEY_LEN);
1295 if (mode == WILC_AP_MODE) {
1296 struct wid wid_list[2];
1298 wid_list[0].id = WID_11I_MODE;
1299 wid_list[0].type = WID_CHAR;
1300 wid_list[0].size = sizeof(char);
1301 wid_list[0].val = (s8 *)&cipher_mode;
1303 wid_list[1].id = WID_ADD_RX_GTK;
1304 wid_list[1].type = WID_STR;
1305 wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1306 wid_list[1].val = (u8 *)gtk_key;
1308 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1309 ARRAY_SIZE(wid_list));
1310 } else if (mode == WILC_STATION_MODE) {
1313 wid.id = WID_ADD_RX_GTK;
1315 wid.size = sizeof(*gtk_key) + t_key_len;
1316 wid.val = (u8 *)gtk_key;
1317 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1324 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1328 wid.id = WID_PMKID_INFO;
1330 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1331 wid.val = (u8 *)pmkid;
1333 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1336 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1341 wid.id = WID_MAC_ADDR;
1343 wid.size = ETH_ALEN;
1346 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1348 netdev_err(vif->ndev, "Failed to get mac address\n");
1353 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1357 struct host_if_drv *hif_drv = vif->hif_drv;
1358 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1361 ether_addr_copy(conn_info->bssid, bssid);
1364 conn_info->req_ies_len = ies_len;
1365 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1366 if (!conn_info->req_ies)
1370 result = wilc_send_connect_wid(vif);
1374 hif_drv->connect_timer_vif = vif;
1375 mod_timer(&hif_drv->connect_timer,
1376 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1381 kfree(conn_info->req_ies);
1386 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1391 wid.id = WID_CURRENT_CHANNEL;
1392 wid.type = WID_CHAR;
1393 wid.size = sizeof(char);
1396 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1398 netdev_err(vif->ndev, "Failed to set channel\n");
1403 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1408 struct wilc_drv_handler drv;
1410 wid.id = WID_SET_OPERATION_MODE;
1412 wid.size = sizeof(drv);
1413 wid.val = (u8 *)&drv;
1415 drv.handler = cpu_to_le32(index);
1416 drv.mode = (ifc_id | (mode << 1));
1418 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1420 netdev_err(vif->ndev, "Failed to set driver handler\n");
1425 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1430 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1432 wid.size = ETH_ALEN;
1433 wid.val = kzalloc(wid.size, GFP_KERNEL);
1437 ether_addr_copy(wid.val, mac);
1438 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1441 netdev_err(vif->ndev, "Failed to set inactive mac\n");
1445 wid.id = WID_GET_INACTIVE_TIME;
1447 wid.val = (s8 *)out_val;
1448 wid.size = sizeof(u32);
1449 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1451 netdev_err(vif->ndev, "Failed to get inactive time\n");
1456 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1462 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1467 wid.type = WID_CHAR;
1468 wid.size = sizeof(char);
1469 wid.val = rssi_level;
1470 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1472 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1477 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1480 struct host_if_msg *msg;
1482 msg = wilc_alloc_work(vif, handle_get_statistics, false);
1484 return PTR_ERR(msg);
1486 msg->body.data = (char *)stats;
1488 result = wilc_enqueue_work(msg);
1490 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1498 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1500 struct wid wid_list[4];
1503 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1504 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1505 wid_list[i].val = (s8 *)¶m->short_retry_limit;
1506 wid_list[i].type = WID_SHORT;
1507 wid_list[i].size = sizeof(u16);
1510 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1511 wid_list[i].id = WID_LONG_RETRY_LIMIT;
1512 wid_list[i].val = (s8 *)¶m->long_retry_limit;
1513 wid_list[i].type = WID_SHORT;
1514 wid_list[i].size = sizeof(u16);
1517 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1518 wid_list[i].id = WID_FRAG_THRESHOLD;
1519 wid_list[i].val = (s8 *)¶m->frag_threshold;
1520 wid_list[i].type = WID_SHORT;
1521 wid_list[i].size = sizeof(u16);
1524 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1525 wid_list[i].id = WID_RTS_THRESHOLD;
1526 wid_list[i].val = (s8 *)¶m->rts_threshold;
1527 wid_list[i].type = WID_SHORT;
1528 wid_list[i].size = sizeof(u16);
1532 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1535 static void get_periodic_rssi(struct timer_list *t)
1537 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1539 if (!vif->hif_drv) {
1540 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1544 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1545 wilc_get_stats_async(vif, &vif->periodic_stat);
1547 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1550 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1552 struct host_if_drv *hif_drv;
1553 struct wilc_vif *vif = netdev_priv(dev);
1554 struct wilc *wilc = vif->wilc;
1556 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1560 *hif_drv_handler = hif_drv;
1562 vif->hif_drv = hif_drv;
1564 if (wilc->clients_count == 0)
1565 mutex_init(&wilc->deinit_lock);
1567 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1568 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1570 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1571 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1572 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1574 hif_drv->hif_state = HOST_IF_IDLE;
1576 hif_drv->p2p_timeout = 0;
1578 wilc->clients_count++;
1583 int wilc_deinit(struct wilc_vif *vif)
1586 struct host_if_drv *hif_drv = vif->hif_drv;
1589 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1593 mutex_lock(&vif->wilc->deinit_lock);
1595 del_timer_sync(&hif_drv->scan_timer);
1596 del_timer_sync(&hif_drv->connect_timer);
1597 del_timer_sync(&vif->periodic_rssi);
1598 del_timer_sync(&hif_drv->remain_on_ch_timer);
1600 if (hif_drv->usr_scan_req.scan_result) {
1601 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1602 hif_drv->usr_scan_req.arg);
1603 hif_drv->usr_scan_req.scan_result = NULL;
1606 hif_drv->hif_state = HOST_IF_IDLE;
1609 vif->hif_drv = NULL;
1610 vif->wilc->clients_count--;
1611 mutex_unlock(&vif->wilc->deinit_lock);
1615 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1618 struct host_if_msg *msg;
1620 struct host_if_drv *hif_drv;
1621 struct wilc_vif *vif;
1623 id = get_unaligned_le32(&buffer[length - 4]);
1624 vif = wilc_get_vif_from_idx(wilc, id);
1627 hif_drv = vif->hif_drv;
1630 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1634 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1638 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1639 msg->body.net_info.rssi = buffer[8];
1640 msg->body.net_info.mgmt = kmemdup(&buffer[9],
1641 msg->body.net_info.frame_len,
1643 if (!msg->body.net_info.mgmt) {
1648 result = wilc_enqueue_work(msg);
1650 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1651 kfree(msg->body.net_info.mgmt);
1656 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1659 struct host_if_msg *msg;
1661 struct host_if_drv *hif_drv;
1662 struct wilc_vif *vif;
1664 mutex_lock(&wilc->deinit_lock);
1666 id = get_unaligned_le32(&buffer[length - 4]);
1667 vif = wilc_get_vif_from_idx(wilc, id);
1669 mutex_unlock(&wilc->deinit_lock);
1673 hif_drv = vif->hif_drv;
1676 mutex_unlock(&wilc->deinit_lock);
1680 if (!hif_drv->conn_info.conn_result) {
1681 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1682 mutex_unlock(&wilc->deinit_lock);
1686 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1688 mutex_unlock(&wilc->deinit_lock);
1692 msg->body.mac_info.status = buffer[7];
1693 result = wilc_enqueue_work(msg);
1695 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1699 mutex_unlock(&wilc->deinit_lock);
1702 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1706 struct host_if_drv *hif_drv;
1707 struct wilc_vif *vif;
1709 id = get_unaligned_le32(&buffer[length - 4]);
1710 vif = wilc_get_vif_from_idx(wilc, id);
1713 hif_drv = vif->hif_drv;
1718 if (hif_drv->usr_scan_req.scan_result) {
1719 struct host_if_msg *msg;
1721 msg = wilc_alloc_work(vif, handle_scan_complete, false);
1725 result = wilc_enqueue_work(msg);
1727 netdev_err(vif->ndev, "%s: enqueue work failed\n",
1734 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
1735 u32 duration, u16 chan,
1736 void (*expired)(void *, u64),
1739 struct wilc_remain_ch roc;
1743 roc.expired = expired;
1745 roc.duration = duration;
1746 roc.cookie = cookie;
1747 result = handle_remain_on_chan(vif, &roc);
1749 netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1755 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1757 if (!vif->hif_drv) {
1758 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1762 del_timer(&vif->hif_drv->remain_on_ch_timer);
1764 return wilc_handle_roc_expired(vif, cookie);
1767 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1771 struct wilc_reg_frame reg_frame;
1773 wid.id = WID_REGISTER_FRAME;
1775 wid.size = sizeof(reg_frame);
1776 wid.val = (u8 *)®_frame;
1778 memset(®_frame, 0x0, sizeof(reg_frame));
1779 reg_frame.reg = reg;
1781 switch (frame_type) {
1782 case IEEE80211_STYPE_ACTION:
1783 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1786 case IEEE80211_STYPE_PROBE_REQ:
1787 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1793 reg_frame.frame_type = cpu_to_le16(frame_type);
1794 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1796 netdev_err(vif->ndev, "Failed to frame register\n");
1799 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1800 struct cfg80211_beacon_data *params)
1806 wid.id = WID_ADD_BEACON;
1808 wid.size = params->head_len + params->tail_len + 16;
1809 wid.val = kzalloc(wid.size, GFP_KERNEL);
1814 put_unaligned_le32(interval, cur_byte);
1816 put_unaligned_le32(dtim_period, cur_byte);
1818 put_unaligned_le32(params->head_len, cur_byte);
1821 if (params->head_len > 0)
1822 memcpy(cur_byte, params->head, params->head_len);
1823 cur_byte += params->head_len;
1825 put_unaligned_le32(params->tail_len, cur_byte);
1828 if (params->tail_len > 0)
1829 memcpy(cur_byte, params->tail, params->tail_len);
1831 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1833 netdev_err(vif->ndev, "Failed to send add beacon\n");
1840 int wilc_del_beacon(struct wilc_vif *vif)
1846 wid.id = WID_DEL_BEACON;
1847 wid.type = WID_CHAR;
1848 wid.size = sizeof(char);
1849 wid.val = &del_beacon;
1851 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1853 netdev_err(vif->ndev, "Failed to send delete beacon\n");
1858 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1859 struct station_parameters *params)
1865 wid.id = WID_ADD_STA;
1867 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1868 wid.val = kmalloc(wid.size, GFP_KERNEL);
1873 wilc_hif_pack_sta_param(cur_byte, mac, params);
1875 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1877 netdev_err(vif->ndev, "Failed to send add station\n");
1884 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1889 wid.id = WID_REMOVE_STA;
1891 wid.size = ETH_ALEN;
1892 wid.val = kzalloc(wid.size, GFP_KERNEL);
1897 eth_broadcast_addr(wid.val);
1899 ether_addr_copy(wid.val, mac_addr);
1901 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1903 netdev_err(vif->ndev, "Failed to del station\n");
1910 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1916 struct wilc_del_all_sta del_sta;
1918 memset(&del_sta, 0x0, sizeof(del_sta));
1919 for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1920 if (!is_zero_ether_addr(mac_addr[i])) {
1922 ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1929 del_sta.assoc_sta = assoc_sta;
1931 wid.id = WID_DEL_ALL_STA;
1933 wid.size = (assoc_sta * ETH_ALEN) + 1;
1934 wid.val = (u8 *)&del_sta;
1936 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1938 netdev_err(vif->ndev, "Failed to send delete all station\n");
1943 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1944 struct station_parameters *params)
1950 wid.id = WID_EDIT_STA;
1952 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1953 wid.val = kmalloc(wid.size, GFP_KERNEL);
1958 wilc_hif_pack_sta_param(cur_byte, mac, params);
1960 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1962 netdev_err(vif->ndev, "Failed to send edit station\n");
1968 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1975 power_mode = WILC_FW_MIN_FAST_PS;
1977 power_mode = WILC_FW_NO_POWERSAVE;
1979 wid.id = WID_POWER_MANAGEMENT;
1980 wid.val = &power_mode;
1981 wid.size = sizeof(char);
1982 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1984 netdev_err(vif->ndev, "Failed to send power management\n");
1989 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1993 struct host_if_msg *msg;
1995 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1997 return PTR_ERR(msg);
1999 msg->body.mc_info.enabled = enabled;
2000 msg->body.mc_info.cnt = count;
2001 msg->body.mc_info.mc_list = mc_list;
2003 result = wilc_enqueue_work(msg);
2005 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
2011 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
2015 wid.id = WID_TX_POWER;
2016 wid.type = WID_CHAR;
2017 wid.val = &tx_power;
2018 wid.size = sizeof(char);
2020 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
2023 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
2027 wid.id = WID_TX_POWER;
2028 wid.type = WID_CHAR;
2030 wid.size = sizeof(char);
2032 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);