1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
9 #define WILC_HIF_SCAN_TIMEOUT_MS 5000
10 #define WILC_HIF_CONNECT_TIMEOUT_MS 9500
12 #define WILC_FALSE_FRMWR_CHANNEL 100
14 #define WILC_SCAN_WID_LIST_SIZE 6
16 struct wilc_rcvd_mac_info {
20 struct wilc_set_multicast {
26 struct host_if_wowlan_trigger {
30 struct wilc_del_all_sta {
32 u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
35 union wilc_message_body {
36 struct wilc_rcvd_net_info net_info;
37 struct wilc_rcvd_mac_info mac_info;
38 struct wilc_set_multicast mc_info;
39 struct wilc_remain_ch remain_on_ch;
41 struct host_if_wowlan_trigger wow_trigger;
45 union wilc_message_body body;
47 struct work_struct work;
48 void (*fn)(struct work_struct *ws);
49 struct completion work_comp;
53 /* 'msg' should be free by the caller for syc */
54 static struct host_if_msg*
55 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
58 struct host_if_msg *msg;
61 return ERR_PTR(-EINVAL);
63 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
65 return ERR_PTR(-ENOMEM);
68 msg->is_sync = is_sync;
70 init_completion(&msg->work_comp);
75 static int wilc_enqueue_work(struct host_if_msg *msg)
77 INIT_WORK(&msg->work, msg->fn);
79 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
82 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
88 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
89 * special purpose in wilc device, so we add 1 to the index to starts from 1.
90 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
92 int wilc_get_vif_idx(struct wilc_vif *vif)
97 /* We need to minus 1 from idx which is from wilc device to get real index
98 * of wilc->vif[], because we add 1 when pass to wilc device in the function
100 * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
102 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
105 struct wilc_vif *vif;
107 if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
110 wilc_for_each_vif(wilc, vif) {
111 if (vif->idx == index)
118 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
121 u8 abort_running_scan;
123 struct host_if_drv *hif_drv = vif->hif_drv;
124 struct wilc_user_scan_req *scan_req;
126 if (evt == SCAN_EVENT_ABORTED) {
127 abort_running_scan = 1;
128 wid.id = WID_ABORT_RUNNING_SCAN;
130 wid.val = (s8 *)&abort_running_scan;
131 wid.size = sizeof(char);
133 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
135 netdev_err(vif->ndev, "Failed to set abort running\n");
141 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
145 scan_req = &hif_drv->usr_scan_req;
146 if (scan_req->scan_result) {
147 scan_req->scan_result(evt, NULL, scan_req->priv);
148 scan_req->scan_result = NULL;
154 int wilc_scan(struct wilc_vif *vif, u8 scan_source,
155 u8 scan_type, u8 *ch_freq_list,
156 void (*scan_result_fn)(enum scan_event,
157 struct wilc_rcvd_net_info *,
159 struct cfg80211_scan_request *request)
162 struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
167 u8 *search_ssid_vals = NULL;
168 const u8 ch_list_len = request->n_channels;
169 struct host_if_drv *hif_drv = vif->hif_drv;
171 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
172 hif_drv->hif_state < HOST_IF_CONNECTED) {
173 netdev_err(vif->ndev, "Already scan\n");
178 if (vif->connecting) {
179 netdev_err(vif->ndev, "Don't do obss scan\n");
184 hif_drv->usr_scan_req.ch_cnt = 0;
186 if (request->n_ssids) {
187 for (i = 0; i < request->n_ssids; i++)
188 valuesize += ((request->ssids[i].ssid_len) + 1);
189 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
190 if (search_ssid_vals) {
191 wid_list[index].id = WID_SSID_PROBE_REQ;
192 wid_list[index].type = WID_STR;
193 wid_list[index].val = search_ssid_vals;
194 buffer = wid_list[index].val;
196 *buffer++ = request->n_ssids;
198 for (i = 0; i < request->n_ssids; i++) {
199 *buffer++ = request->ssids[i].ssid_len;
200 memcpy(buffer, request->ssids[i].ssid,
201 request->ssids[i].ssid_len);
202 buffer += request->ssids[i].ssid_len;
204 wid_list[index].size = (s32)(valuesize + 1);
209 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
210 wid_list[index].type = WID_BIN_DATA;
211 wid_list[index].val = (s8 *)request->ie;
212 wid_list[index].size = request->ie_len;
215 wid_list[index].id = WID_SCAN_TYPE;
216 wid_list[index].type = WID_CHAR;
217 wid_list[index].size = sizeof(char);
218 wid_list[index].val = (s8 *)&scan_type;
221 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
222 wid_list[index].id = WID_PASSIVE_SCAN_TIME;
223 wid_list[index].type = WID_SHORT;
224 wid_list[index].size = sizeof(u16);
225 wid_list[index].val = (s8 *)&request->duration;
228 scan_timeout = (request->duration * ch_list_len) + 500;
230 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
233 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
234 wid_list[index].type = WID_BIN_DATA;
236 if (ch_freq_list && ch_list_len > 0) {
237 for (i = 0; i < ch_list_len; i++) {
238 if (ch_freq_list[i] > 0)
239 ch_freq_list[i] -= 1;
243 wid_list[index].val = ch_freq_list;
244 wid_list[index].size = ch_list_len;
247 wid_list[index].id = WID_START_SCAN_REQ;
248 wid_list[index].type = WID_CHAR;
249 wid_list[index].size = sizeof(char);
250 wid_list[index].val = (s8 *)&scan_source;
253 hif_drv->usr_scan_req.scan_result = scan_result_fn;
254 hif_drv->usr_scan_req.priv = &vif->priv;
256 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
258 netdev_err(vif->ndev, "Failed to send scan parameters\n");
262 hif_drv->scan_timer_vif = vif;
263 mod_timer(&hif_drv->scan_timer,
264 jiffies + msecs_to_jiffies(scan_timeout));
268 kfree(search_ssid_vals);
273 static int wilc_send_connect_wid(struct wilc_vif *vif)
276 struct wid wid_list[5];
278 struct host_if_drv *hif_drv = vif->hif_drv;
279 struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
280 struct wilc_join_bss_param *bss_param = conn_attr->param;
283 wid_list[wid_cnt].id = WID_SET_MFP;
284 wid_list[wid_cnt].type = WID_CHAR;
285 wid_list[wid_cnt].size = sizeof(char);
286 wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type;
289 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
290 wid_list[wid_cnt].type = WID_BIN_DATA;
291 wid_list[wid_cnt].val = conn_attr->req_ies;
292 wid_list[wid_cnt].size = conn_attr->req_ies_len;
295 wid_list[wid_cnt].id = WID_11I_MODE;
296 wid_list[wid_cnt].type = WID_CHAR;
297 wid_list[wid_cnt].size = sizeof(char);
298 wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
301 wid_list[wid_cnt].id = WID_AUTH_TYPE;
302 wid_list[wid_cnt].type = WID_CHAR;
303 wid_list[wid_cnt].size = sizeof(char);
304 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
307 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
308 wid_list[wid_cnt].type = WID_STR;
309 wid_list[wid_cnt].size = sizeof(*bss_param);
310 wid_list[wid_cnt].val = (u8 *)bss_param;
313 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
315 netdev_err(vif->ndev, "failed to send config packet\n");
318 if (conn_attr->auth_type == WILC_FW_AUTH_SAE)
319 hif_drv->hif_state = HOST_IF_EXTERNAL_AUTH;
321 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
328 kfree(conn_attr->req_ies);
329 conn_attr->req_ies = NULL;
334 static void handle_connect_timeout(struct work_struct *work)
336 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
337 struct wilc_vif *vif = msg->vif;
340 u16 dummy_reason_code = 0;
341 struct host_if_drv *hif_drv = vif->hif_drv;
344 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
348 hif_drv->hif_state = HOST_IF_IDLE;
350 if (hif_drv->conn_info.conn_result) {
351 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
352 WILC_MAC_STATUS_DISCONNECTED,
353 hif_drv->conn_info.priv);
356 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
359 wid.id = WID_DISCONNECT;
361 wid.val = (s8 *)&dummy_reason_code;
362 wid.size = sizeof(char);
364 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
366 netdev_err(vif->ndev, "Failed to send disconnect\n");
368 hif_drv->conn_info.req_ies_len = 0;
369 kfree(hif_drv->conn_info.req_ies);
370 hif_drv->conn_info.req_ies = NULL;
376 struct wilc_join_bss_param *
377 wilc_parse_join_bss_param(struct cfg80211_bss *bss,
378 struct cfg80211_crypto_settings *crypto)
380 const u8 *ies_data, *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
381 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
382 struct ieee80211_p2p_noa_attr noa_attr;
383 const struct cfg80211_bss_ies *ies;
384 struct wilc_join_bss_param *param;
389 param = kzalloc(sizeof(*param), GFP_KERNEL);
394 ies = rcu_dereference(bss->ies);
395 ies_data = kmemdup(ies->data, ies->len, GFP_ATOMIC);
404 param->beacon_period = cpu_to_le16(bss->beacon_interval);
405 param->cap_info = cpu_to_le16(bss->capability);
406 param->bss_type = WILC_FW_BSS_TYPE_INFRA;
407 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
408 ether_addr_copy(param->bssid, bss->bssid);
410 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies_data, ies_len);
412 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
413 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
416 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies_data, ies_len);
417 if (tim_elm && tim_elm[1] >= 2)
418 param->dtim_period = tim_elm[3];
420 memset(param->p_suites, 0xFF, 3);
421 memset(param->akm_suites, 0xFF, 3);
423 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies_data, ies_len);
425 rates_len = rates_ie[1];
426 if (rates_len > WILC_MAX_RATES_SUPPORTED)
427 rates_len = WILC_MAX_RATES_SUPPORTED;
428 param->supp_rates[0] = rates_len;
429 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
432 if (rates_len < WILC_MAX_RATES_SUPPORTED) {
433 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
436 u8 ext_rates = supp_rates_ie[1];
438 if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
439 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
441 param->supp_rates[0] += ext_rates;
443 memcpy(¶m->supp_rates[rates_len + 1],
445 (param->supp_rates[0] - rates_len));
449 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies_data, ies_len);
451 param->ht_capable = true;
453 ret = cfg80211_get_p2p_attr(ies_data, ies_len,
454 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
455 (u8 *)&noa_attr, sizeof(noa_attr));
457 param->tsf_lo = cpu_to_le32(ies->tsf);
458 param->noa_enabled = 1;
459 param->idx = noa_attr.index;
460 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
461 param->opp_enabled = 1;
462 param->opp_en.ct_window = noa_attr.oppps_ctwindow;
463 param->opp_en.cnt = noa_attr.desc[0].count;
464 param->opp_en.duration = noa_attr.desc[0].duration;
465 param->opp_en.interval = noa_attr.desc[0].interval;
466 param->opp_en.start_time = noa_attr.desc[0].start_time;
468 param->opp_enabled = 0;
469 param->opp_dis.cnt = noa_attr.desc[0].count;
470 param->opp_dis.duration = noa_attr.desc[0].duration;
471 param->opp_dis.interval = noa_attr.desc[0].interval;
472 param->opp_dis.start_time = noa_attr.desc[0].start_time;
475 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
476 WLAN_OUI_TYPE_MICROSOFT_WMM,
479 struct ieee80211_wmm_param_ie *ie;
481 ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
482 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
484 param->wmm_cap = true;
485 if (ie->qos_info & BIT(7))
486 param->uapsd_cap = true;
490 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
491 WLAN_OUI_TYPE_MICROSOFT_WPA,
494 param->mode_802_11i = 1;
495 param->rsn_found = true;
498 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies_data, ies_len);
500 int rsn_ie_len = sizeof(struct element) + rsn_ie[1];
503 param->mode_802_11i = 2;
504 param->rsn_found = true;
506 /* extract RSN capabilities */
507 if (offset < rsn_ie_len) {
508 /* skip over pairwise suites */
509 offset += (rsn_ie[offset] * 4) + 2;
511 if (offset < rsn_ie_len) {
512 /* skip over authentication suites */
513 offset += (rsn_ie[offset] * 4) + 2;
515 if (offset + 1 < rsn_ie_len)
516 memcpy(param->rsn_cap, &rsn_ie[offset], 2);
521 if (param->rsn_found) {
524 param->rsn_grp_policy = crypto->cipher_group & 0xFF;
525 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
526 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
528 for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
529 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
533 return (void *)param;
536 static void handle_rcvd_ntwrk_info(struct work_struct *work)
538 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
539 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
540 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
546 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
547 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
548 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
549 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
553 ies = rcvd_info->mgmt->u.beacon.variable;
554 ies_len = rcvd_info->frame_len - offset;
558 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
559 if (ch_elm && ch_elm[1] > 0)
560 rcvd_info->ch = ch_elm[2];
562 if (scan_req->scan_result)
563 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
567 kfree(rcvd_info->mgmt);
571 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
573 u32 max_assoc_resp_info_len,
574 u32 *rcvd_assoc_resp_info_len)
579 wid.id = WID_ASSOC_RES_INFO;
581 wid.val = assoc_resp_info;
582 wid.size = max_assoc_resp_info_len;
584 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
586 *rcvd_assoc_resp_info_len = 0;
587 netdev_err(vif->ndev, "Failed to send association response\n");
591 *rcvd_assoc_resp_info_len = wid.size;
594 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
595 struct wilc_conn_info *ret_conn_info)
599 struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
601 ret_conn_info->status = le16_to_cpu(res->status_code);
602 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
603 ies = &buffer[sizeof(*res)];
604 ies_len = buffer_len - sizeof(*res);
606 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
607 if (!ret_conn_info->resp_ies)
610 ret_conn_info->resp_ies_len = ies_len;
616 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
619 struct host_if_drv *hif_drv = vif->hif_drv;
620 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
622 if (mac_status == WILC_MAC_STATUS_CONNECTED) {
623 u32 assoc_resp_info_len;
625 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
627 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
628 WILC_MAX_ASSOC_RESP_FRAME_SIZE,
629 &assoc_resp_info_len);
631 if (assoc_resp_info_len != 0) {
634 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
638 netdev_err(vif->ndev,
639 "wilc_parse_assoc_resp_info() returned error %d\n",
644 del_timer(&hif_drv->connect_timer);
645 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
646 hif_drv->conn_info.priv);
648 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
649 conn_info->status == WLAN_STATUS_SUCCESS) {
650 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
651 hif_drv->hif_state = HOST_IF_CONNECTED;
653 hif_drv->hif_state = HOST_IF_IDLE;
656 kfree(conn_info->resp_ies);
657 conn_info->resp_ies = NULL;
658 conn_info->resp_ies_len = 0;
660 kfree(conn_info->req_ies);
661 conn_info->req_ies = NULL;
662 conn_info->req_ies_len = 0;
665 void wilc_handle_disconnect(struct wilc_vif *vif)
667 struct host_if_drv *hif_drv = vif->hif_drv;
669 if (hif_drv->usr_scan_req.scan_result) {
670 del_timer(&hif_drv->scan_timer);
671 handle_scan_done(vif, SCAN_EVENT_ABORTED);
674 if (hif_drv->conn_info.conn_result)
675 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
676 0, hif_drv->conn_info.priv);
678 eth_zero_addr(hif_drv->assoc_bssid);
680 hif_drv->conn_info.req_ies_len = 0;
681 kfree(hif_drv->conn_info.req_ies);
682 hif_drv->conn_info.req_ies = NULL;
683 hif_drv->hif_state = HOST_IF_IDLE;
686 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
688 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
689 struct wilc_vif *vif = msg->vif;
690 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
691 struct host_if_drv *hif_drv = vif->hif_drv;
694 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
698 if (!hif_drv->conn_info.conn_result) {
699 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
704 if (hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) {
705 cfg80211_external_auth_request(vif->ndev, &vif->auth,
707 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
708 } else if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
709 host_int_parse_assoc_resp_info(vif, mac_info->status);
710 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
711 if (hif_drv->hif_state == HOST_IF_CONNECTED) {
712 wilc_handle_disconnect(vif);
713 } else if (hif_drv->usr_scan_req.scan_result) {
714 del_timer(&hif_drv->scan_timer);
715 handle_scan_done(vif, SCAN_EVENT_ABORTED);
723 int wilc_disconnect(struct wilc_vif *vif)
726 struct host_if_drv *hif_drv = vif->hif_drv;
727 struct wilc_user_scan_req *scan_req;
728 struct wilc_conn_info *conn_info;
730 u16 dummy_reason_code = 0;
732 wid.id = WID_DISCONNECT;
734 wid.val = (s8 *)&dummy_reason_code;
735 wid.size = sizeof(char);
737 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
739 netdev_err(vif->ndev, "Failed to send disconnect\n");
743 scan_req = &hif_drv->usr_scan_req;
744 conn_info = &hif_drv->conn_info;
746 if (scan_req->scan_result) {
747 del_timer(&hif_drv->scan_timer);
748 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->priv);
749 scan_req->scan_result = NULL;
752 if (conn_info->conn_result) {
753 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
754 hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH)
755 del_timer(&hif_drv->connect_timer);
757 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
760 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
763 hif_drv->hif_state = HOST_IF_IDLE;
765 eth_zero_addr(hif_drv->assoc_bssid);
767 conn_info->req_ies_len = 0;
768 kfree(conn_info->req_ies);
769 conn_info->req_ies = NULL;
774 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
776 struct wid wid_list[5];
777 u32 wid_cnt = 0, result;
779 wid_list[wid_cnt].id = WID_LINKSPEED;
780 wid_list[wid_cnt].type = WID_CHAR;
781 wid_list[wid_cnt].size = sizeof(char);
782 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
785 wid_list[wid_cnt].id = WID_RSSI;
786 wid_list[wid_cnt].type = WID_CHAR;
787 wid_list[wid_cnt].size = sizeof(char);
788 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
791 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
792 wid_list[wid_cnt].type = WID_INT;
793 wid_list[wid_cnt].size = sizeof(u32);
794 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
797 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
798 wid_list[wid_cnt].type = WID_INT;
799 wid_list[wid_cnt].size = sizeof(u32);
800 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
803 wid_list[wid_cnt].id = WID_FAILED_COUNT;
804 wid_list[wid_cnt].type = WID_INT;
805 wid_list[wid_cnt].size = sizeof(u32);
806 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
809 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
811 netdev_err(vif->ndev, "Failed to send scan parameters\n");
815 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
816 stats->link_speed != DEFAULT_LINK_SPEED)
817 wilc_enable_tcp_ack_filter(vif, true);
818 else if (stats->link_speed != DEFAULT_LINK_SPEED)
819 wilc_enable_tcp_ack_filter(vif, false);
824 static void handle_get_statistics(struct work_struct *work)
826 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
827 struct wilc_vif *vif = msg->vif;
828 struct rf_info *stats = (struct rf_info *)msg->body.data;
830 wilc_get_statistics(vif, stats);
835 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
836 struct station_parameters *params)
838 ether_addr_copy(cur_byte, mac);
839 cur_byte += ETH_ALEN;
841 put_unaligned_le16(params->aid, cur_byte);
844 *cur_byte++ = params->link_sta_params.supported_rates_len;
845 if (params->link_sta_params.supported_rates_len > 0)
846 memcpy(cur_byte, params->link_sta_params.supported_rates,
847 params->link_sta_params.supported_rates_len);
848 cur_byte += params->link_sta_params.supported_rates_len;
850 if (params->link_sta_params.ht_capa) {
852 memcpy(cur_byte, params->link_sta_params.ht_capa,
853 sizeof(struct ieee80211_ht_cap));
857 cur_byte += sizeof(struct ieee80211_ht_cap);
859 put_unaligned_le16(params->sta_flags_mask, cur_byte);
861 put_unaligned_le16(params->sta_flags_set, cur_byte);
864 static int handle_remain_on_chan(struct wilc_vif *vif,
865 struct wilc_remain_ch *hif_remain_ch)
868 u8 remain_on_chan_flag;
870 struct host_if_drv *hif_drv = vif->hif_drv;
872 if (hif_drv->usr_scan_req.scan_result)
875 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
881 remain_on_chan_flag = true;
882 wid.id = WID_REMAIN_ON_CHAN;
885 wid.val = kmalloc(wid.size, GFP_KERNEL);
889 wid.val[0] = remain_on_chan_flag;
890 wid.val[1] = (s8)hif_remain_ch->ch;
892 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
897 hif_drv->remain_on_ch.vif = hif_remain_ch->vif;
898 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
899 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
900 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
901 hif_drv->remain_on_ch_timer_vif = vif;
906 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
908 u8 remain_on_chan_flag;
911 struct host_if_drv *hif_drv = vif->hif_drv;
913 if (vif->priv.p2p_listen_state) {
914 remain_on_chan_flag = false;
915 wid.id = WID_REMAIN_ON_CHAN;
919 wid.val = kmalloc(wid.size, GFP_KERNEL);
923 wid.val[0] = remain_on_chan_flag;
924 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
926 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
929 netdev_err(vif->ndev, "Failed to set remain channel\n");
933 if (hif_drv->remain_on_ch.expired) {
934 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.vif,
938 netdev_dbg(vif->ndev, "Not in listen state\n");
944 static void wilc_handle_listen_state_expired(struct work_struct *work)
946 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
948 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
952 static void listen_timer_cb(struct timer_list *t)
954 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
956 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
958 struct host_if_msg *msg;
960 del_timer(&vif->hif_drv->remain_on_ch_timer);
962 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
966 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
968 result = wilc_enqueue_work(msg);
970 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
975 static void handle_set_mcast_filter(struct work_struct *work)
977 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
978 struct wilc_vif *vif = msg->vif;
979 struct wilc_set_multicast *set_mc = &msg->body.mc_info;
984 wid.id = WID_SETUP_MULTICAST_FILTER;
986 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
987 wid.val = kmalloc(wid.size, GFP_KERNEL);
992 put_unaligned_le32(set_mc->enabled, cur_byte);
995 put_unaligned_le32(set_mc->cnt, cur_byte);
998 if (set_mc->cnt > 0 && set_mc->mc_list)
999 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
1001 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1003 netdev_err(vif->ndev, "Failed to send setup multicast\n");
1006 kfree(set_mc->mc_list);
1011 void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled)
1015 u8 wowlan_trigger = 0;
1020 wid.id = WID_WOWLAN_TRIGGER;
1021 wid.type = WID_CHAR;
1022 wid.val = &wowlan_trigger;
1023 wid.size = sizeof(char);
1025 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1027 pr_err("Failed to send wowlan trigger config packet\n");
1030 int wilc_set_external_auth_param(struct wilc_vif *vif,
1031 struct cfg80211_external_auth_params *auth)
1035 struct wilc_external_auth_param *param;
1037 wid.id = WID_EXTERNAL_AUTH_PARAM;
1038 wid.type = WID_BIN_DATA;
1039 wid.size = sizeof(*param);
1040 param = kzalloc(sizeof(*param), GFP_KERNEL);
1044 wid.val = (u8 *)param;
1045 param->action = auth->action;
1046 ether_addr_copy(param->bssid, auth->bssid);
1047 memcpy(param->ssid, auth->ssid.ssid, auth->ssid.ssid_len);
1048 param->ssid_len = auth->ssid.ssid_len;
1049 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1055 static void handle_scan_timer(struct work_struct *work)
1057 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1059 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
1063 static void handle_scan_complete(struct work_struct *work)
1065 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1067 del_timer(&msg->vif->hif_drv->scan_timer);
1069 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1074 static void timer_scan_cb(struct timer_list *t)
1076 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
1077 struct wilc_vif *vif = hif_drv->scan_timer_vif;
1078 struct host_if_msg *msg;
1081 msg = wilc_alloc_work(vif, handle_scan_timer, false);
1085 result = wilc_enqueue_work(msg);
1090 static void timer_connect_cb(struct timer_list *t)
1092 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1094 struct wilc_vif *vif = hif_drv->connect_timer_vif;
1095 struct host_if_msg *msg;
1098 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1102 result = wilc_enqueue_work(msg);
1107 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1108 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1109 u8 mode, u8 cipher_mode, u8 index)
1112 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1114 if (mode == WILC_AP_MODE) {
1115 struct wid wid_list[2];
1116 struct wilc_ap_wpa_ptk *key_buf;
1118 wid_list[0].id = WID_11I_MODE;
1119 wid_list[0].type = WID_CHAR;
1120 wid_list[0].size = sizeof(char);
1121 wid_list[0].val = (s8 *)&cipher_mode;
1123 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1127 ether_addr_copy(key_buf->mac_addr, mac_addr);
1128 key_buf->index = index;
1129 key_buf->key_len = t_key_len;
1130 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1133 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1134 WILC_RX_MIC_KEY_LEN);
1137 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1138 tx_mic, WILC_TX_MIC_KEY_LEN);
1140 wid_list[1].id = WID_ADD_PTK;
1141 wid_list[1].type = WID_STR;
1142 wid_list[1].size = sizeof(*key_buf) + t_key_len;
1143 wid_list[1].val = (u8 *)key_buf;
1144 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1145 ARRAY_SIZE(wid_list));
1147 } else if (mode == WILC_STATION_MODE) {
1149 struct wilc_sta_wpa_ptk *key_buf;
1151 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1155 ether_addr_copy(key_buf->mac_addr, mac_addr);
1156 key_buf->key_len = t_key_len;
1157 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1160 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1161 WILC_RX_MIC_KEY_LEN);
1164 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1165 tx_mic, WILC_TX_MIC_KEY_LEN);
1167 wid.id = WID_ADD_PTK;
1169 wid.size = sizeof(*key_buf) + t_key_len;
1170 wid.val = (s8 *)key_buf;
1171 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1178 int wilc_add_igtk(struct wilc_vif *vif, const u8 *igtk, u8 igtk_key_len,
1179 const u8 *pn, u8 pn_len, const u8 *mac_addr, u8 mode, u8 index)
1182 u8 t_key_len = igtk_key_len;
1184 struct wilc_wpa_igtk *key_buf;
1186 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1190 key_buf->index = index;
1192 memcpy(&key_buf->pn[0], pn, pn_len);
1193 key_buf->pn_len = pn_len;
1195 memcpy(&key_buf->key[0], igtk, igtk_key_len);
1196 key_buf->key_len = t_key_len;
1198 wid.id = WID_ADD_IGTK;
1200 wid.size = sizeof(*key_buf) + t_key_len;
1201 wid.val = (s8 *)key_buf;
1202 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1208 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1209 u8 index, u32 key_rsc_len, const u8 *key_rsc,
1210 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1214 struct wilc_gtk_key *gtk_key;
1215 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1217 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1221 /* fill bssid value only in station mode */
1222 if (mode == WILC_STATION_MODE &&
1223 vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1224 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1227 memcpy(gtk_key->rsc, key_rsc, 8);
1228 gtk_key->index = index;
1229 gtk_key->key_len = t_key_len;
1230 memcpy(>k_key->key[0], rx_gtk, gtk_key_len);
1233 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1236 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1237 tx_mic, WILC_TX_MIC_KEY_LEN);
1239 if (mode == WILC_AP_MODE) {
1240 struct wid wid_list[2];
1242 wid_list[0].id = WID_11I_MODE;
1243 wid_list[0].type = WID_CHAR;
1244 wid_list[0].size = sizeof(char);
1245 wid_list[0].val = (s8 *)&cipher_mode;
1247 wid_list[1].id = WID_ADD_RX_GTK;
1248 wid_list[1].type = WID_STR;
1249 wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1250 wid_list[1].val = (u8 *)gtk_key;
1252 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1253 ARRAY_SIZE(wid_list));
1254 } else if (mode == WILC_STATION_MODE) {
1257 wid.id = WID_ADD_RX_GTK;
1259 wid.size = sizeof(*gtk_key) + t_key_len;
1260 wid.val = (u8 *)gtk_key;
1261 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1268 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1272 wid.id = WID_PMKID_INFO;
1274 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1275 wid.val = (u8 *)pmkid;
1277 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1280 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1285 wid.id = WID_MAC_ADDR;
1287 wid.size = ETH_ALEN;
1290 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1292 netdev_err(vif->ndev, "Failed to get mac address\n");
1297 int wilc_set_mac_address(struct wilc_vif *vif, const u8 *mac_addr)
1302 wid.id = WID_MAC_ADDR;
1304 wid.size = ETH_ALEN;
1305 wid.val = (u8 *)mac_addr;
1307 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1309 netdev_err(vif->ndev, "Failed to set mac address\n");
1314 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1318 struct host_if_drv *hif_drv = vif->hif_drv;
1319 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1322 ether_addr_copy(conn_info->bssid, bssid);
1325 conn_info->req_ies_len = ies_len;
1326 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1327 if (!conn_info->req_ies)
1331 result = wilc_send_connect_wid(vif);
1335 hif_drv->connect_timer_vif = vif;
1336 mod_timer(&hif_drv->connect_timer,
1337 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1342 kfree(conn_info->req_ies);
1347 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1352 wid.id = WID_CURRENT_CHANNEL;
1353 wid.type = WID_CHAR;
1354 wid.size = sizeof(char);
1357 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1359 netdev_err(vif->ndev, "Failed to set channel\n");
1364 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1369 struct wilc_drv_handler drv;
1371 wid.id = WID_SET_OPERATION_MODE;
1373 wid.size = sizeof(drv);
1374 wid.val = (u8 *)&drv;
1376 drv.handler = cpu_to_le32(index);
1377 drv.mode = (ifc_id | (mode << 1));
1379 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1381 netdev_err(vif->ndev, "Failed to set driver handler\n");
1386 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1391 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1393 wid.size = ETH_ALEN;
1394 wid.val = kzalloc(wid.size, GFP_KERNEL);
1398 ether_addr_copy(wid.val, mac);
1399 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1402 netdev_err(vif->ndev, "Failed to set inactive mac\n");
1406 wid.id = WID_GET_INACTIVE_TIME;
1408 wid.val = (s8 *)out_val;
1409 wid.size = sizeof(u32);
1410 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1412 netdev_err(vif->ndev, "Failed to get inactive time\n");
1417 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1423 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1428 wid.type = WID_CHAR;
1429 wid.size = sizeof(char);
1430 wid.val = rssi_level;
1431 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1433 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1438 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1441 struct host_if_msg *msg;
1443 msg = wilc_alloc_work(vif, handle_get_statistics, false);
1445 return PTR_ERR(msg);
1447 msg->body.data = (char *)stats;
1449 result = wilc_enqueue_work(msg);
1451 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1459 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1461 struct wid wid_list[4];
1464 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1465 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1466 wid_list[i].val = (s8 *)¶m->short_retry_limit;
1467 wid_list[i].type = WID_SHORT;
1468 wid_list[i].size = sizeof(u16);
1471 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1472 wid_list[i].id = WID_LONG_RETRY_LIMIT;
1473 wid_list[i].val = (s8 *)¶m->long_retry_limit;
1474 wid_list[i].type = WID_SHORT;
1475 wid_list[i].size = sizeof(u16);
1478 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1479 wid_list[i].id = WID_FRAG_THRESHOLD;
1480 wid_list[i].val = (s8 *)¶m->frag_threshold;
1481 wid_list[i].type = WID_SHORT;
1482 wid_list[i].size = sizeof(u16);
1485 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1486 wid_list[i].id = WID_RTS_THRESHOLD;
1487 wid_list[i].val = (s8 *)¶m->rts_threshold;
1488 wid_list[i].type = WID_SHORT;
1489 wid_list[i].size = sizeof(u16);
1493 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1496 static void get_periodic_rssi(struct timer_list *t)
1498 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1500 if (!vif->hif_drv) {
1501 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1505 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1506 wilc_get_stats_async(vif, &vif->periodic_stat);
1508 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1511 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1513 struct host_if_drv *hif_drv;
1514 struct wilc_vif *vif = netdev_priv(dev);
1516 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1520 *hif_drv_handler = hif_drv;
1522 vif->hif_drv = hif_drv;
1524 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1525 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1527 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1528 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1529 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1531 hif_drv->hif_state = HOST_IF_IDLE;
1533 hif_drv->p2p_timeout = 0;
1538 int wilc_deinit(struct wilc_vif *vif)
1541 struct host_if_drv *hif_drv = vif->hif_drv;
1544 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1548 mutex_lock(&vif->wilc->deinit_lock);
1550 timer_shutdown_sync(&hif_drv->scan_timer);
1551 timer_shutdown_sync(&hif_drv->connect_timer);
1552 del_timer_sync(&vif->periodic_rssi);
1553 timer_shutdown_sync(&hif_drv->remain_on_ch_timer);
1555 if (hif_drv->usr_scan_req.scan_result) {
1556 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1557 hif_drv->usr_scan_req.priv);
1558 hif_drv->usr_scan_req.scan_result = NULL;
1561 hif_drv->hif_state = HOST_IF_IDLE;
1564 vif->hif_drv = NULL;
1565 mutex_unlock(&vif->wilc->deinit_lock);
1569 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1571 struct host_if_drv *hif_drv;
1572 struct host_if_msg *msg;
1573 struct wilc_vif *vif;
1578 id = get_unaligned_le32(&buffer[length - 4]);
1579 srcu_idx = srcu_read_lock(&wilc->srcu);
1580 vif = wilc_get_vif_from_idx(wilc, id);
1584 hif_drv = vif->hif_drv;
1586 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1590 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1594 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1595 msg->body.net_info.rssi = buffer[8];
1596 msg->body.net_info.mgmt = kmemdup(&buffer[9],
1597 msg->body.net_info.frame_len,
1599 if (!msg->body.net_info.mgmt) {
1604 result = wilc_enqueue_work(msg);
1606 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1607 kfree(msg->body.net_info.mgmt);
1611 srcu_read_unlock(&wilc->srcu, srcu_idx);
1614 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1616 struct host_if_drv *hif_drv;
1617 struct host_if_msg *msg;
1618 struct wilc_vif *vif;
1623 mutex_lock(&wilc->deinit_lock);
1625 id = get_unaligned_le32(&buffer[length - 4]);
1626 srcu_idx = srcu_read_lock(&wilc->srcu);
1627 vif = wilc_get_vif_from_idx(wilc, id);
1631 hif_drv = vif->hif_drv;
1637 if (!hif_drv->conn_info.conn_result) {
1638 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1642 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1646 msg->body.mac_info.status = buffer[7];
1647 result = wilc_enqueue_work(msg);
1649 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1653 srcu_read_unlock(&wilc->srcu, srcu_idx);
1654 mutex_unlock(&wilc->deinit_lock);
1657 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1659 struct host_if_drv *hif_drv;
1660 struct wilc_vif *vif;
1665 id = get_unaligned_le32(&buffer[length - 4]);
1666 srcu_idx = srcu_read_lock(&wilc->srcu);
1667 vif = wilc_get_vif_from_idx(wilc, id);
1671 hif_drv = vif->hif_drv;
1676 if (hif_drv->usr_scan_req.scan_result) {
1677 struct host_if_msg *msg;
1679 msg = wilc_alloc_work(vif, handle_scan_complete, false);
1683 result = wilc_enqueue_work(msg);
1685 netdev_err(vif->ndev, "%s: enqueue work failed\n",
1691 srcu_read_unlock(&wilc->srcu, srcu_idx);
1694 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie, u16 chan,
1695 void (*expired)(struct wilc_vif *, u64))
1697 struct wilc_remain_ch roc;
1701 roc.expired = expired;
1703 roc.cookie = cookie;
1704 result = handle_remain_on_chan(vif, &roc);
1706 netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1712 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1714 if (!vif->hif_drv) {
1715 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1719 del_timer(&vif->hif_drv->remain_on_ch_timer);
1721 return wilc_handle_roc_expired(vif, cookie);
1724 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1728 struct wilc_reg_frame reg_frame;
1730 wid.id = WID_REGISTER_FRAME;
1732 wid.size = sizeof(reg_frame);
1733 wid.val = (u8 *)®_frame;
1735 memset(®_frame, 0x0, sizeof(reg_frame));
1740 switch (frame_type) {
1741 case IEEE80211_STYPE_ACTION:
1742 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1745 case IEEE80211_STYPE_PROBE_REQ:
1746 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1749 case IEEE80211_STYPE_AUTH:
1750 reg_frame.reg_id = WILC_FW_AUTH_REQ_IDX;
1756 reg_frame.frame_type = cpu_to_le16(frame_type);
1757 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1759 netdev_err(vif->ndev, "Failed to frame register\n");
1762 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1763 struct cfg80211_beacon_data *params)
1769 wid.id = WID_ADD_BEACON;
1771 wid.size = params->head_len + params->tail_len + 16;
1772 wid.val = kzalloc(wid.size, GFP_KERNEL);
1777 put_unaligned_le32(interval, cur_byte);
1779 put_unaligned_le32(dtim_period, cur_byte);
1781 put_unaligned_le32(params->head_len, cur_byte);
1784 if (params->head_len > 0)
1785 memcpy(cur_byte, params->head, params->head_len);
1786 cur_byte += params->head_len;
1788 put_unaligned_le32(params->tail_len, cur_byte);
1791 if (params->tail_len > 0)
1792 memcpy(cur_byte, params->tail, params->tail_len);
1794 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1796 netdev_err(vif->ndev, "Failed to send add beacon\n");
1803 int wilc_del_beacon(struct wilc_vif *vif)
1809 wid.id = WID_DEL_BEACON;
1810 wid.type = WID_CHAR;
1811 wid.size = sizeof(char);
1812 wid.val = &del_beacon;
1814 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1816 netdev_err(vif->ndev, "Failed to send delete beacon\n");
1821 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1822 struct station_parameters *params)
1828 wid.id = WID_ADD_STA;
1830 wid.size = WILC_ADD_STA_LENGTH +
1831 params->link_sta_params.supported_rates_len;
1832 wid.val = kmalloc(wid.size, GFP_KERNEL);
1837 wilc_hif_pack_sta_param(cur_byte, mac, params);
1839 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1841 netdev_err(vif->ndev, "Failed to send add station\n");
1848 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1853 wid.id = WID_REMOVE_STA;
1855 wid.size = ETH_ALEN;
1856 wid.val = kzalloc(wid.size, GFP_KERNEL);
1861 eth_broadcast_addr(wid.val);
1863 ether_addr_copy(wid.val, mac_addr);
1865 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1867 netdev_err(vif->ndev, "Failed to del station\n");
1874 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1880 struct wilc_del_all_sta del_sta;
1882 memset(&del_sta, 0x0, sizeof(del_sta));
1883 for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1884 if (!is_zero_ether_addr(mac_addr[i])) {
1886 ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1893 del_sta.assoc_sta = assoc_sta;
1895 wid.id = WID_DEL_ALL_STA;
1897 wid.size = (assoc_sta * ETH_ALEN) + 1;
1898 wid.val = (u8 *)&del_sta;
1900 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1902 netdev_err(vif->ndev, "Failed to send delete all station\n");
1907 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1908 struct station_parameters *params)
1914 wid.id = WID_EDIT_STA;
1916 wid.size = WILC_ADD_STA_LENGTH +
1917 params->link_sta_params.supported_rates_len;
1918 wid.val = kmalloc(wid.size, GFP_KERNEL);
1923 wilc_hif_pack_sta_param(cur_byte, mac, params);
1925 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1927 netdev_err(vif->ndev, "Failed to send edit station\n");
1933 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1935 struct wilc *wilc = vif->wilc;
1941 power_mode = WILC_FW_MIN_FAST_PS;
1943 power_mode = WILC_FW_NO_POWERSAVE;
1945 wid.id = WID_POWER_MANAGEMENT;
1946 wid.val = &power_mode;
1947 wid.size = sizeof(char);
1948 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1950 netdev_err(vif->ndev, "Failed to send power management\n");
1952 wilc->power_save_mode = enabled;
1957 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1961 struct host_if_msg *msg;
1963 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1965 return PTR_ERR(msg);
1967 msg->body.mc_info.enabled = enabled;
1968 msg->body.mc_info.cnt = count;
1969 msg->body.mc_info.mc_list = mc_list;
1971 result = wilc_enqueue_work(msg);
1973 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1979 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
1983 wid.id = WID_TX_POWER;
1984 wid.type = WID_CHAR;
1985 wid.val = &tx_power;
1986 wid.size = sizeof(char);
1988 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1991 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
1995 wid.id = WID_TX_POWER;
1996 wid.type = WID_CHAR;
1998 wid.size = sizeof(char);
2000 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
2003 int wilc_set_default_mgmt_key_index(struct wilc_vif *vif, u8 index)
2008 wid.id = WID_DEFAULT_MGMT_KEY_ID;
2009 wid.type = WID_CHAR;
2010 wid.size = sizeof(char);
2012 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
2014 netdev_err(vif->ndev,
2015 "Failed to send default mgmt key index\n");