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 wilc_del_all_sta {
28 u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
31 union wilc_message_body {
32 struct wilc_rcvd_net_info net_info;
33 struct wilc_rcvd_mac_info mac_info;
34 struct wilc_set_multicast mc_info;
35 struct wilc_remain_ch remain_on_ch;
40 union wilc_message_body body;
42 struct work_struct work;
43 void (*fn)(struct work_struct *ws);
44 struct completion work_comp;
48 /* 'msg' should be free by the caller for syc */
49 static struct host_if_msg*
50 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
53 struct host_if_msg *msg;
56 return ERR_PTR(-EINVAL);
58 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
60 return ERR_PTR(-ENOMEM);
63 msg->is_sync = is_sync;
65 init_completion(&msg->work_comp);
70 static int wilc_enqueue_work(struct host_if_msg *msg)
72 INIT_WORK(&msg->work, msg->fn);
74 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
77 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
83 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
84 * special purpose in wilc device, so we add 1 to the index to starts from 1.
85 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
87 int wilc_get_vif_idx(struct wilc_vif *vif)
92 /* We need to minus 1 from idx which is from wilc device to get real index
93 * of wilc->vif[], because we add 1 when pass to wilc device in the function
95 * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
97 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
100 struct wilc_vif *vif;
102 if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
105 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
106 if (vif->idx == index)
113 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
116 u8 abort_running_scan;
118 struct host_if_drv *hif_drv = vif->hif_drv;
119 struct wilc_user_scan_req *scan_req;
121 if (evt == SCAN_EVENT_ABORTED) {
122 abort_running_scan = 1;
123 wid.id = WID_ABORT_RUNNING_SCAN;
125 wid.val = (s8 *)&abort_running_scan;
126 wid.size = sizeof(char);
128 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
130 netdev_err(vif->ndev, "Failed to set abort running\n");
136 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
140 scan_req = &hif_drv->usr_scan_req;
141 if (scan_req->scan_result) {
142 scan_req->scan_result(evt, NULL, scan_req->arg);
143 scan_req->scan_result = NULL;
149 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
150 u8 *ch_freq_list, u8 ch_list_len,
151 void (*scan_result_fn)(enum scan_event,
152 struct wilc_rcvd_net_info *, void *),
153 void *user_arg, struct cfg80211_scan_request *request)
156 struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
161 u8 *search_ssid_vals = NULL;
162 struct host_if_drv *hif_drv = vif->hif_drv;
164 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
165 hif_drv->hif_state < HOST_IF_CONNECTED) {
166 netdev_err(vif->ndev, "Already scan\n");
171 if (vif->connecting) {
172 netdev_err(vif->ndev, "Don't do obss scan\n");
177 hif_drv->usr_scan_req.ch_cnt = 0;
179 if (request->n_ssids) {
180 for (i = 0; i < request->n_ssids; i++)
181 valuesize += ((request->ssids[i].ssid_len) + 1);
182 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
183 if (search_ssid_vals) {
184 wid_list[index].id = WID_SSID_PROBE_REQ;
185 wid_list[index].type = WID_STR;
186 wid_list[index].val = search_ssid_vals;
187 buffer = wid_list[index].val;
189 *buffer++ = request->n_ssids;
191 for (i = 0; i < request->n_ssids; i++) {
192 *buffer++ = request->ssids[i].ssid_len;
193 memcpy(buffer, request->ssids[i].ssid,
194 request->ssids[i].ssid_len);
195 buffer += request->ssids[i].ssid_len;
197 wid_list[index].size = (s32)(valuesize + 1);
202 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
203 wid_list[index].type = WID_BIN_DATA;
204 wid_list[index].val = (s8 *)request->ie;
205 wid_list[index].size = request->ie_len;
208 wid_list[index].id = WID_SCAN_TYPE;
209 wid_list[index].type = WID_CHAR;
210 wid_list[index].size = sizeof(char);
211 wid_list[index].val = (s8 *)&scan_type;
214 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
215 wid_list[index].id = WID_PASSIVE_SCAN_TIME;
216 wid_list[index].type = WID_SHORT;
217 wid_list[index].size = sizeof(u16);
218 wid_list[index].val = (s8 *)&request->duration;
221 scan_timeout = (request->duration * ch_list_len) + 500;
223 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
226 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
227 wid_list[index].type = WID_BIN_DATA;
229 if (ch_freq_list && ch_list_len > 0) {
230 for (i = 0; i < ch_list_len; i++) {
231 if (ch_freq_list[i] > 0)
232 ch_freq_list[i] -= 1;
236 wid_list[index].val = ch_freq_list;
237 wid_list[index].size = ch_list_len;
240 wid_list[index].id = WID_START_SCAN_REQ;
241 wid_list[index].type = WID_CHAR;
242 wid_list[index].size = sizeof(char);
243 wid_list[index].val = (s8 *)&scan_source;
246 hif_drv->usr_scan_req.scan_result = scan_result_fn;
247 hif_drv->usr_scan_req.arg = user_arg;
249 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
251 netdev_err(vif->ndev, "Failed to send scan parameters\n");
255 hif_drv->scan_timer_vif = vif;
256 mod_timer(&hif_drv->scan_timer,
257 jiffies + msecs_to_jiffies(scan_timeout));
261 kfree(search_ssid_vals);
266 static int wilc_send_connect_wid(struct wilc_vif *vif)
269 struct wid wid_list[4];
271 struct host_if_drv *hif_drv = vif->hif_drv;
272 struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
273 struct wilc_join_bss_param *bss_param = conn_attr->param;
275 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
276 wid_list[wid_cnt].type = WID_BIN_DATA;
277 wid_list[wid_cnt].val = conn_attr->req_ies;
278 wid_list[wid_cnt].size = conn_attr->req_ies_len;
281 wid_list[wid_cnt].id = WID_11I_MODE;
282 wid_list[wid_cnt].type = WID_CHAR;
283 wid_list[wid_cnt].size = sizeof(char);
284 wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
287 wid_list[wid_cnt].id = WID_AUTH_TYPE;
288 wid_list[wid_cnt].type = WID_CHAR;
289 wid_list[wid_cnt].size = sizeof(char);
290 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
293 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
294 wid_list[wid_cnt].type = WID_STR;
295 wid_list[wid_cnt].size = sizeof(*bss_param);
296 wid_list[wid_cnt].val = (u8 *)bss_param;
299 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
301 netdev_err(vif->ndev, "failed to send config packet\n");
304 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
311 kfree(conn_attr->req_ies);
312 conn_attr->req_ies = NULL;
317 static void handle_connect_timeout(struct work_struct *work)
319 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
320 struct wilc_vif *vif = msg->vif;
323 u16 dummy_reason_code = 0;
324 struct host_if_drv *hif_drv = vif->hif_drv;
327 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
331 hif_drv->hif_state = HOST_IF_IDLE;
333 if (hif_drv->conn_info.conn_result) {
334 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
335 WILC_MAC_STATUS_DISCONNECTED,
336 hif_drv->conn_info.arg);
339 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
342 wid.id = WID_DISCONNECT;
344 wid.val = (s8 *)&dummy_reason_code;
345 wid.size = sizeof(char);
347 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
349 netdev_err(vif->ndev, "Failed to send disconnect\n");
351 hif_drv->conn_info.req_ies_len = 0;
352 kfree(hif_drv->conn_info.req_ies);
353 hif_drv->conn_info.req_ies = NULL;
359 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
360 struct cfg80211_crypto_settings *crypto)
362 struct wilc_join_bss_param *param;
363 struct ieee80211_p2p_noa_attr noa_attr;
365 const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
366 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
368 const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
370 param = kzalloc(sizeof(*param), GFP_KERNEL);
374 param->beacon_period = cpu_to_le16(bss->beacon_interval);
375 param->cap_info = cpu_to_le16(bss->capability);
376 param->bss_type = WILC_FW_BSS_TYPE_INFRA;
377 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
378 ether_addr_copy(param->bssid, bss->bssid);
380 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
382 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
383 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
386 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
387 if (tim_elm && tim_elm[1] >= 2)
388 param->dtim_period = tim_elm[3];
390 memset(param->p_suites, 0xFF, 3);
391 memset(param->akm_suites, 0xFF, 3);
393 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
395 rates_len = rates_ie[1];
396 if (rates_len > WILC_MAX_RATES_SUPPORTED)
397 rates_len = WILC_MAX_RATES_SUPPORTED;
398 param->supp_rates[0] = rates_len;
399 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
402 if (rates_len < WILC_MAX_RATES_SUPPORTED) {
403 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
404 ies->data, ies->len);
406 u8 ext_rates = supp_rates_ie[1];
408 if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
409 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
411 param->supp_rates[0] += ext_rates;
413 memcpy(¶m->supp_rates[rates_len + 1],
415 (param->supp_rates[0] - rates_len));
419 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
421 param->ht_capable = true;
423 ret = cfg80211_get_p2p_attr(ies->data, ies->len,
424 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
425 (u8 *)&noa_attr, sizeof(noa_attr));
427 param->tsf_lo = cpu_to_le32(ies->tsf);
428 param->noa_enabled = 1;
429 param->idx = noa_attr.index;
430 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
431 param->opp_enabled = 1;
432 param->opp_en.ct_window = noa_attr.oppps_ctwindow;
433 param->opp_en.cnt = noa_attr.desc[0].count;
434 param->opp_en.duration = noa_attr.desc[0].duration;
435 param->opp_en.interval = noa_attr.desc[0].interval;
436 param->opp_en.start_time = noa_attr.desc[0].start_time;
438 param->opp_enabled = 0;
439 param->opp_dis.cnt = noa_attr.desc[0].count;
440 param->opp_dis.duration = noa_attr.desc[0].duration;
441 param->opp_dis.interval = noa_attr.desc[0].interval;
442 param->opp_dis.start_time = noa_attr.desc[0].start_time;
445 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
446 WLAN_OUI_TYPE_MICROSOFT_WMM,
447 ies->data, ies->len);
449 struct ieee80211_wmm_param_ie *ie;
451 ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
452 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
454 param->wmm_cap = true;
455 if (ie->qos_info & BIT(7))
456 param->uapsd_cap = true;
460 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
461 WLAN_OUI_TYPE_MICROSOFT_WPA,
462 ies->data, ies->len);
464 param->mode_802_11i = 1;
465 param->rsn_found = true;
468 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
472 param->mode_802_11i = 2;
473 param->rsn_found = true;
474 /* extract RSN capabilities */
475 offset += (rsn_ie[offset] * 4) + 2;
476 offset += (rsn_ie[offset] * 4) + 2;
477 memcpy(param->rsn_cap, &rsn_ie[offset], 2);
480 if (param->rsn_found) {
483 param->rsn_grp_policy = crypto->cipher_group & 0xFF;
484 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
485 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
487 for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
488 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
491 return (void *)param;
494 static void handle_rcvd_ntwrk_info(struct work_struct *work)
496 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
497 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
498 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
504 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
505 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
506 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
507 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
511 ies = rcvd_info->mgmt->u.beacon.variable;
512 ies_len = rcvd_info->frame_len - offset;
516 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
517 if (ch_elm && ch_elm[1] > 0)
518 rcvd_info->ch = ch_elm[2];
520 if (scan_req->scan_result)
521 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
525 kfree(rcvd_info->mgmt);
529 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
531 u32 max_assoc_resp_info_len,
532 u32 *rcvd_assoc_resp_info_len)
537 wid.id = WID_ASSOC_RES_INFO;
539 wid.val = assoc_resp_info;
540 wid.size = max_assoc_resp_info_len;
542 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
544 *rcvd_assoc_resp_info_len = 0;
545 netdev_err(vif->ndev, "Failed to send association response\n");
549 *rcvd_assoc_resp_info_len = wid.size;
552 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
553 struct wilc_conn_info *ret_conn_info)
557 struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
559 ret_conn_info->status = le16_to_cpu(res->status_code);
560 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
561 ies = &buffer[sizeof(*res)];
562 ies_len = buffer_len - sizeof(*res);
564 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
565 if (!ret_conn_info->resp_ies)
568 ret_conn_info->resp_ies_len = ies_len;
574 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
577 struct host_if_drv *hif_drv = vif->hif_drv;
578 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
580 if (mac_status == WILC_MAC_STATUS_CONNECTED) {
581 u32 assoc_resp_info_len;
583 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
585 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
586 WILC_MAX_ASSOC_RESP_FRAME_SIZE,
587 &assoc_resp_info_len);
589 if (assoc_resp_info_len != 0) {
592 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
596 netdev_err(vif->ndev,
597 "wilc_parse_assoc_resp_info() returned error %d\n",
602 del_timer(&hif_drv->connect_timer);
603 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
604 hif_drv->conn_info.arg);
606 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
607 conn_info->status == WLAN_STATUS_SUCCESS) {
608 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
609 hif_drv->hif_state = HOST_IF_CONNECTED;
611 hif_drv->hif_state = HOST_IF_IDLE;
614 kfree(conn_info->resp_ies);
615 conn_info->resp_ies = NULL;
616 conn_info->resp_ies_len = 0;
618 kfree(conn_info->req_ies);
619 conn_info->req_ies = NULL;
620 conn_info->req_ies_len = 0;
623 static inline void host_int_handle_disconnect(struct wilc_vif *vif)
625 struct host_if_drv *hif_drv = vif->hif_drv;
627 if (hif_drv->usr_scan_req.scan_result) {
628 del_timer(&hif_drv->scan_timer);
629 handle_scan_done(vif, SCAN_EVENT_ABORTED);
632 if (hif_drv->conn_info.conn_result)
633 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
634 0, hif_drv->conn_info.arg);
636 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
638 eth_zero_addr(hif_drv->assoc_bssid);
640 hif_drv->conn_info.req_ies_len = 0;
641 kfree(hif_drv->conn_info.req_ies);
642 hif_drv->conn_info.req_ies = NULL;
643 hif_drv->hif_state = HOST_IF_IDLE;
646 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
648 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
649 struct wilc_vif *vif = msg->vif;
650 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
651 struct host_if_drv *hif_drv = vif->hif_drv;
654 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
658 if (!hif_drv->conn_info.conn_result) {
659 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
663 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
664 host_int_parse_assoc_resp_info(vif, mac_info->status);
665 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
666 if (hif_drv->hif_state == HOST_IF_CONNECTED) {
667 host_int_handle_disconnect(vif);
668 } else if (hif_drv->usr_scan_req.scan_result) {
669 del_timer(&hif_drv->scan_timer);
670 handle_scan_done(vif, SCAN_EVENT_ABORTED);
678 int wilc_disconnect(struct wilc_vif *vif)
681 struct host_if_drv *hif_drv = vif->hif_drv;
682 struct wilc_user_scan_req *scan_req;
683 struct wilc_conn_info *conn_info;
685 u16 dummy_reason_code = 0;
687 wid.id = WID_DISCONNECT;
689 wid.val = (s8 *)&dummy_reason_code;
690 wid.size = sizeof(char);
692 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
694 netdev_err(vif->ndev, "Failed to send disconnect\n");
698 scan_req = &hif_drv->usr_scan_req;
699 conn_info = &hif_drv->conn_info;
701 if (scan_req->scan_result) {
702 del_timer(&hif_drv->scan_timer);
703 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
704 scan_req->scan_result = NULL;
707 if (conn_info->conn_result) {
708 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
709 del_timer(&hif_drv->connect_timer);
711 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
714 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
717 hif_drv->hif_state = HOST_IF_IDLE;
719 eth_zero_addr(hif_drv->assoc_bssid);
721 conn_info->req_ies_len = 0;
722 kfree(conn_info->req_ies);
723 conn_info->req_ies = NULL;
728 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
730 struct wid wid_list[5];
731 u32 wid_cnt = 0, result;
733 wid_list[wid_cnt].id = WID_LINKSPEED;
734 wid_list[wid_cnt].type = WID_CHAR;
735 wid_list[wid_cnt].size = sizeof(char);
736 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
739 wid_list[wid_cnt].id = WID_RSSI;
740 wid_list[wid_cnt].type = WID_CHAR;
741 wid_list[wid_cnt].size = sizeof(char);
742 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
745 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
746 wid_list[wid_cnt].type = WID_INT;
747 wid_list[wid_cnt].size = sizeof(u32);
748 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
751 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
752 wid_list[wid_cnt].type = WID_INT;
753 wid_list[wid_cnt].size = sizeof(u32);
754 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
757 wid_list[wid_cnt].id = WID_FAILED_COUNT;
758 wid_list[wid_cnt].type = WID_INT;
759 wid_list[wid_cnt].size = sizeof(u32);
760 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
763 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
765 netdev_err(vif->ndev, "Failed to send scan parameters\n");
769 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
770 stats->link_speed != DEFAULT_LINK_SPEED)
771 wilc_enable_tcp_ack_filter(vif, true);
772 else if (stats->link_speed != DEFAULT_LINK_SPEED)
773 wilc_enable_tcp_ack_filter(vif, false);
778 static void handle_get_statistics(struct work_struct *work)
780 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
781 struct wilc_vif *vif = msg->vif;
782 struct rf_info *stats = (struct rf_info *)msg->body.data;
784 wilc_get_statistics(vif, stats);
789 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
790 struct station_parameters *params)
792 ether_addr_copy(cur_byte, mac);
793 cur_byte += ETH_ALEN;
795 put_unaligned_le16(params->aid, cur_byte);
798 *cur_byte++ = params->supported_rates_len;
799 if (params->supported_rates_len > 0)
800 memcpy(cur_byte, params->supported_rates,
801 params->supported_rates_len);
802 cur_byte += params->supported_rates_len;
804 if (params->ht_capa) {
806 memcpy(cur_byte, params->ht_capa,
807 sizeof(struct ieee80211_ht_cap));
811 cur_byte += sizeof(struct ieee80211_ht_cap);
813 put_unaligned_le16(params->sta_flags_mask, cur_byte);
815 put_unaligned_le16(params->sta_flags_set, cur_byte);
818 static int handle_remain_on_chan(struct wilc_vif *vif,
819 struct wilc_remain_ch *hif_remain_ch)
822 u8 remain_on_chan_flag;
824 struct host_if_drv *hif_drv = vif->hif_drv;
826 if (hif_drv->usr_scan_req.scan_result)
829 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
835 remain_on_chan_flag = true;
836 wid.id = WID_REMAIN_ON_CHAN;
839 wid.val = kmalloc(wid.size, GFP_KERNEL);
843 wid.val[0] = remain_on_chan_flag;
844 wid.val[1] = (s8)hif_remain_ch->ch;
846 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
851 hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
852 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
853 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
854 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
855 hif_drv->remain_on_ch_timer_vif = vif;
860 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
862 u8 remain_on_chan_flag;
865 struct host_if_drv *hif_drv = vif->hif_drv;
867 if (vif->priv.p2p_listen_state) {
868 remain_on_chan_flag = false;
869 wid.id = WID_REMAIN_ON_CHAN;
873 wid.val = kmalloc(wid.size, GFP_KERNEL);
877 wid.val[0] = remain_on_chan_flag;
878 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
880 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
883 netdev_err(vif->ndev, "Failed to set remain channel\n");
887 if (hif_drv->remain_on_ch.expired) {
888 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
892 netdev_dbg(vif->ndev, "Not in listen state\n");
898 static void wilc_handle_listen_state_expired(struct work_struct *work)
900 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
902 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
906 static void listen_timer_cb(struct timer_list *t)
908 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
910 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
912 struct host_if_msg *msg;
914 del_timer(&vif->hif_drv->remain_on_ch_timer);
916 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
920 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
922 result = wilc_enqueue_work(msg);
924 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
929 static void handle_set_mcast_filter(struct work_struct *work)
931 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
932 struct wilc_vif *vif = msg->vif;
933 struct wilc_set_multicast *set_mc = &msg->body.mc_info;
938 wid.id = WID_SETUP_MULTICAST_FILTER;
940 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
941 wid.val = kmalloc(wid.size, GFP_KERNEL);
946 put_unaligned_le32(set_mc->enabled, cur_byte);
949 put_unaligned_le32(set_mc->cnt, cur_byte);
952 if (set_mc->cnt > 0 && set_mc->mc_list)
953 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
955 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
957 netdev_err(vif->ndev, "Failed to send setup multicast\n");
960 kfree(set_mc->mc_list);
965 static void handle_scan_timer(struct work_struct *work)
967 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
969 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
973 static void handle_scan_complete(struct work_struct *work)
975 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
977 del_timer(&msg->vif->hif_drv->scan_timer);
979 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
984 static void timer_scan_cb(struct timer_list *t)
986 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
987 struct wilc_vif *vif = hif_drv->scan_timer_vif;
988 struct host_if_msg *msg;
991 msg = wilc_alloc_work(vif, handle_scan_timer, false);
995 result = wilc_enqueue_work(msg);
1000 static void timer_connect_cb(struct timer_list *t)
1002 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1004 struct wilc_vif *vif = hif_drv->connect_timer_vif;
1005 struct host_if_msg *msg;
1008 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1012 result = wilc_enqueue_work(msg);
1017 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
1022 wid.id = WID_REMOVE_WEP_KEY;
1024 wid.size = sizeof(char);
1027 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1029 netdev_err(vif->ndev,
1030 "Failed to send remove wep key config packet\n");
1034 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
1039 wid.id = WID_KEY_ID;
1040 wid.type = WID_CHAR;
1041 wid.size = sizeof(char);
1043 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1045 netdev_err(vif->ndev,
1046 "Failed to send wep default key config packet\n");
1051 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
1056 struct wilc_wep_key *wep_key;
1058 wid.id = WID_ADD_WEP_KEY;
1060 wid.size = sizeof(*wep_key) + len;
1061 wep_key = kzalloc(wid.size, GFP_KERNEL);
1065 wid.val = (u8 *)wep_key;
1067 wep_key->index = index;
1068 wep_key->key_len = len;
1069 memcpy(wep_key->key, key, len);
1071 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1073 netdev_err(vif->ndev,
1074 "Failed to add wep key config packet\n");
1080 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
1081 u8 index, u8 mode, enum authtype auth_type)
1083 struct wid wid_list[3];
1085 struct wilc_wep_key *wep_key;
1087 wid_list[0].id = WID_11I_MODE;
1088 wid_list[0].type = WID_CHAR;
1089 wid_list[0].size = sizeof(char);
1090 wid_list[0].val = &mode;
1092 wid_list[1].id = WID_AUTH_TYPE;
1093 wid_list[1].type = WID_CHAR;
1094 wid_list[1].size = sizeof(char);
1095 wid_list[1].val = (s8 *)&auth_type;
1097 wid_list[2].id = WID_WEP_KEY_VALUE;
1098 wid_list[2].type = WID_STR;
1099 wid_list[2].size = sizeof(*wep_key) + len;
1100 wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
1104 wid_list[2].val = (u8 *)wep_key;
1106 wep_key->index = index;
1107 wep_key->key_len = len;
1108 memcpy(wep_key->key, key, len);
1109 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1110 ARRAY_SIZE(wid_list));
1112 netdev_err(vif->ndev,
1113 "Failed to add wep ap key config packet\n");
1119 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1120 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1121 u8 mode, u8 cipher_mode, u8 index)
1124 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1126 if (mode == WILC_AP_MODE) {
1127 struct wid wid_list[2];
1128 struct wilc_ap_wpa_ptk *key_buf;
1130 wid_list[0].id = WID_11I_MODE;
1131 wid_list[0].type = WID_CHAR;
1132 wid_list[0].size = sizeof(char);
1133 wid_list[0].val = (s8 *)&cipher_mode;
1135 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1139 ether_addr_copy(key_buf->mac_addr, mac_addr);
1140 key_buf->index = index;
1141 key_buf->key_len = t_key_len;
1142 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1145 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1146 WILC_RX_MIC_KEY_LEN);
1149 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1150 tx_mic, WILC_TX_MIC_KEY_LEN);
1152 wid_list[1].id = WID_ADD_PTK;
1153 wid_list[1].type = WID_STR;
1154 wid_list[1].size = sizeof(*key_buf) + t_key_len;
1155 wid_list[1].val = (u8 *)key_buf;
1156 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1157 ARRAY_SIZE(wid_list));
1159 } else if (mode == WILC_STATION_MODE) {
1161 struct wilc_sta_wpa_ptk *key_buf;
1163 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1167 ether_addr_copy(key_buf->mac_addr, mac_addr);
1168 key_buf->key_len = t_key_len;
1169 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1172 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1173 WILC_RX_MIC_KEY_LEN);
1176 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1177 tx_mic, WILC_TX_MIC_KEY_LEN);
1179 wid.id = WID_ADD_PTK;
1181 wid.size = sizeof(*key_buf) + t_key_len;
1182 wid.val = (s8 *)key_buf;
1183 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1190 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1191 u8 index, u32 key_rsc_len, const u8 *key_rsc,
1192 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1196 struct wilc_gtk_key *gtk_key;
1197 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1199 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1203 /* fill bssid value only in station mode */
1204 if (mode == WILC_STATION_MODE &&
1205 vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1206 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1209 memcpy(gtk_key->rsc, key_rsc, 8);
1210 gtk_key->index = index;
1211 gtk_key->key_len = t_key_len;
1212 memcpy(>k_key->key[0], rx_gtk, gtk_key_len);
1215 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1218 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1219 tx_mic, WILC_TX_MIC_KEY_LEN);
1221 if (mode == WILC_AP_MODE) {
1222 struct wid wid_list[2];
1224 wid_list[0].id = WID_11I_MODE;
1225 wid_list[0].type = WID_CHAR;
1226 wid_list[0].size = sizeof(char);
1227 wid_list[0].val = (s8 *)&cipher_mode;
1229 wid_list[1].id = WID_ADD_RX_GTK;
1230 wid_list[1].type = WID_STR;
1231 wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1232 wid_list[1].val = (u8 *)gtk_key;
1234 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1235 ARRAY_SIZE(wid_list));
1236 } else if (mode == WILC_STATION_MODE) {
1239 wid.id = WID_ADD_RX_GTK;
1241 wid.size = sizeof(*gtk_key) + t_key_len;
1242 wid.val = (u8 *)gtk_key;
1243 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1250 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1254 wid.id = WID_PMKID_INFO;
1256 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1257 wid.val = (u8 *)pmkid;
1259 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1262 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1267 wid.id = WID_MAC_ADDR;
1269 wid.size = ETH_ALEN;
1272 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1274 netdev_err(vif->ndev, "Failed to get mac address\n");
1279 int wilc_set_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1284 wid.id = WID_MAC_ADDR;
1286 wid.size = ETH_ALEN;
1289 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1291 netdev_err(vif->ndev, "Failed to get mac address\n");
1296 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1300 struct host_if_drv *hif_drv = vif->hif_drv;
1301 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1304 ether_addr_copy(conn_info->bssid, bssid);
1307 conn_info->req_ies_len = ies_len;
1308 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1309 if (!conn_info->req_ies)
1313 result = wilc_send_connect_wid(vif);
1317 hif_drv->connect_timer_vif = vif;
1318 mod_timer(&hif_drv->connect_timer,
1319 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1324 kfree(conn_info->req_ies);
1329 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1334 wid.id = WID_CURRENT_CHANNEL;
1335 wid.type = WID_CHAR;
1336 wid.size = sizeof(char);
1339 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1341 netdev_err(vif->ndev, "Failed to set channel\n");
1346 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1351 struct wilc_drv_handler drv;
1353 wid.id = WID_SET_OPERATION_MODE;
1355 wid.size = sizeof(drv);
1356 wid.val = (u8 *)&drv;
1358 drv.handler = cpu_to_le32(index);
1359 drv.mode = (ifc_id | (mode << 1));
1361 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1363 netdev_err(vif->ndev, "Failed to set driver handler\n");
1368 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1373 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1375 wid.size = ETH_ALEN;
1376 wid.val = kzalloc(wid.size, GFP_KERNEL);
1380 ether_addr_copy(wid.val, mac);
1381 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1384 netdev_err(vif->ndev, "Failed to set inactive mac\n");
1388 wid.id = WID_GET_INACTIVE_TIME;
1390 wid.val = (s8 *)out_val;
1391 wid.size = sizeof(u32);
1392 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1394 netdev_err(vif->ndev, "Failed to get inactive time\n");
1399 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1405 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1410 wid.type = WID_CHAR;
1411 wid.size = sizeof(char);
1412 wid.val = rssi_level;
1413 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1415 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1420 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1423 struct host_if_msg *msg;
1425 msg = wilc_alloc_work(vif, handle_get_statistics, false);
1427 return PTR_ERR(msg);
1429 msg->body.data = (char *)stats;
1431 result = wilc_enqueue_work(msg);
1433 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1441 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1443 struct wid wid_list[4];
1446 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1447 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1448 wid_list[i].val = (s8 *)¶m->short_retry_limit;
1449 wid_list[i].type = WID_SHORT;
1450 wid_list[i].size = sizeof(u16);
1453 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1454 wid_list[i].id = WID_LONG_RETRY_LIMIT;
1455 wid_list[i].val = (s8 *)¶m->long_retry_limit;
1456 wid_list[i].type = WID_SHORT;
1457 wid_list[i].size = sizeof(u16);
1460 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1461 wid_list[i].id = WID_FRAG_THRESHOLD;
1462 wid_list[i].val = (s8 *)¶m->frag_threshold;
1463 wid_list[i].type = WID_SHORT;
1464 wid_list[i].size = sizeof(u16);
1467 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1468 wid_list[i].id = WID_RTS_THRESHOLD;
1469 wid_list[i].val = (s8 *)¶m->rts_threshold;
1470 wid_list[i].type = WID_SHORT;
1471 wid_list[i].size = sizeof(u16);
1475 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1478 static void get_periodic_rssi(struct timer_list *t)
1480 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1482 if (!vif->hif_drv) {
1483 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1487 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1488 wilc_get_stats_async(vif, &vif->periodic_stat);
1490 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1493 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1495 struct host_if_drv *hif_drv;
1496 struct wilc_vif *vif = netdev_priv(dev);
1497 struct wilc *wilc = vif->wilc;
1499 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1503 *hif_drv_handler = hif_drv;
1505 vif->hif_drv = hif_drv;
1507 if (wilc->clients_count == 0)
1508 mutex_init(&wilc->deinit_lock);
1510 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1511 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1513 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1514 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1515 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1517 hif_drv->hif_state = HOST_IF_IDLE;
1519 hif_drv->p2p_timeout = 0;
1521 wilc->clients_count++;
1526 int wilc_deinit(struct wilc_vif *vif)
1529 struct host_if_drv *hif_drv = vif->hif_drv;
1532 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1536 mutex_lock(&vif->wilc->deinit_lock);
1538 del_timer_sync(&hif_drv->scan_timer);
1539 del_timer_sync(&hif_drv->connect_timer);
1540 del_timer_sync(&vif->periodic_rssi);
1541 del_timer_sync(&hif_drv->remain_on_ch_timer);
1543 if (hif_drv->usr_scan_req.scan_result) {
1544 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1545 hif_drv->usr_scan_req.arg);
1546 hif_drv->usr_scan_req.scan_result = NULL;
1549 hif_drv->hif_state = HOST_IF_IDLE;
1552 vif->hif_drv = NULL;
1553 vif->wilc->clients_count--;
1554 mutex_unlock(&vif->wilc->deinit_lock);
1558 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1561 struct host_if_msg *msg;
1563 struct host_if_drv *hif_drv;
1564 struct wilc_vif *vif;
1566 id = get_unaligned_le32(&buffer[length - 4]);
1567 vif = wilc_get_vif_from_idx(wilc, id);
1570 hif_drv = vif->hif_drv;
1573 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1577 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1581 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1582 msg->body.net_info.rssi = buffer[8];
1583 msg->body.net_info.mgmt = kmemdup(&buffer[9],
1584 msg->body.net_info.frame_len,
1586 if (!msg->body.net_info.mgmt) {
1591 result = wilc_enqueue_work(msg);
1593 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1594 kfree(msg->body.net_info.mgmt);
1599 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1602 struct host_if_msg *msg;
1604 struct host_if_drv *hif_drv;
1605 struct wilc_vif *vif;
1607 mutex_lock(&wilc->deinit_lock);
1609 id = get_unaligned_le32(&buffer[length - 4]);
1610 vif = wilc_get_vif_from_idx(wilc, id);
1612 mutex_unlock(&wilc->deinit_lock);
1616 hif_drv = vif->hif_drv;
1619 mutex_unlock(&wilc->deinit_lock);
1623 if (!hif_drv->conn_info.conn_result) {
1624 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1625 mutex_unlock(&wilc->deinit_lock);
1629 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1631 mutex_unlock(&wilc->deinit_lock);
1635 msg->body.mac_info.status = buffer[7];
1636 result = wilc_enqueue_work(msg);
1638 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1642 mutex_unlock(&wilc->deinit_lock);
1645 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1649 struct host_if_drv *hif_drv;
1650 struct wilc_vif *vif;
1652 id = get_unaligned_le32(&buffer[length - 4]);
1653 vif = wilc_get_vif_from_idx(wilc, id);
1656 hif_drv = vif->hif_drv;
1661 if (hif_drv->usr_scan_req.scan_result) {
1662 struct host_if_msg *msg;
1664 msg = wilc_alloc_work(vif, handle_scan_complete, false);
1668 result = wilc_enqueue_work(msg);
1670 netdev_err(vif->ndev, "%s: enqueue work failed\n",
1677 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
1678 u32 duration, u16 chan,
1679 void (*expired)(void *, u64),
1682 struct wilc_remain_ch roc;
1686 roc.expired = expired;
1688 roc.duration = duration;
1689 roc.cookie = cookie;
1690 result = handle_remain_on_chan(vif, &roc);
1692 netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1698 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1700 if (!vif->hif_drv) {
1701 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1705 del_timer(&vif->hif_drv->remain_on_ch_timer);
1707 return wilc_handle_roc_expired(vif, cookie);
1710 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1714 struct wilc_reg_frame reg_frame;
1716 wid.id = WID_REGISTER_FRAME;
1718 wid.size = sizeof(reg_frame);
1719 wid.val = (u8 *)®_frame;
1721 memset(®_frame, 0x0, sizeof(reg_frame));
1726 switch (frame_type) {
1727 case IEEE80211_STYPE_ACTION:
1728 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1731 case IEEE80211_STYPE_PROBE_REQ:
1732 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1738 reg_frame.frame_type = cpu_to_le16(frame_type);
1739 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1741 netdev_err(vif->ndev, "Failed to frame register\n");
1744 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1745 struct cfg80211_beacon_data *params)
1751 wid.id = WID_ADD_BEACON;
1753 wid.size = params->head_len + params->tail_len + 16;
1754 wid.val = kzalloc(wid.size, GFP_KERNEL);
1759 put_unaligned_le32(interval, cur_byte);
1761 put_unaligned_le32(dtim_period, cur_byte);
1763 put_unaligned_le32(params->head_len, cur_byte);
1766 if (params->head_len > 0)
1767 memcpy(cur_byte, params->head, params->head_len);
1768 cur_byte += params->head_len;
1770 put_unaligned_le32(params->tail_len, cur_byte);
1773 if (params->tail_len > 0)
1774 memcpy(cur_byte, params->tail, params->tail_len);
1776 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1778 netdev_err(vif->ndev, "Failed to send add beacon\n");
1785 int wilc_del_beacon(struct wilc_vif *vif)
1791 wid.id = WID_DEL_BEACON;
1792 wid.type = WID_CHAR;
1793 wid.size = sizeof(char);
1794 wid.val = &del_beacon;
1796 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1798 netdev_err(vif->ndev, "Failed to send delete beacon\n");
1803 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1804 struct station_parameters *params)
1810 wid.id = WID_ADD_STA;
1812 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1813 wid.val = kmalloc(wid.size, GFP_KERNEL);
1818 wilc_hif_pack_sta_param(cur_byte, mac, params);
1820 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1822 netdev_err(vif->ndev, "Failed to send add station\n");
1829 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1834 wid.id = WID_REMOVE_STA;
1836 wid.size = ETH_ALEN;
1837 wid.val = kzalloc(wid.size, GFP_KERNEL);
1842 eth_broadcast_addr(wid.val);
1844 ether_addr_copy(wid.val, mac_addr);
1846 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1848 netdev_err(vif->ndev, "Failed to del station\n");
1855 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1861 struct wilc_del_all_sta del_sta;
1863 memset(&del_sta, 0x0, sizeof(del_sta));
1864 for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1865 if (!is_zero_ether_addr(mac_addr[i])) {
1867 ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1874 del_sta.assoc_sta = assoc_sta;
1876 wid.id = WID_DEL_ALL_STA;
1878 wid.size = (assoc_sta * ETH_ALEN) + 1;
1879 wid.val = (u8 *)&del_sta;
1881 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1883 netdev_err(vif->ndev, "Failed to send delete all station\n");
1888 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1889 struct station_parameters *params)
1895 wid.id = WID_EDIT_STA;
1897 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1898 wid.val = kmalloc(wid.size, GFP_KERNEL);
1903 wilc_hif_pack_sta_param(cur_byte, mac, params);
1905 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1907 netdev_err(vif->ndev, "Failed to send edit station\n");
1913 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1920 power_mode = WILC_FW_MIN_FAST_PS;
1922 power_mode = WILC_FW_NO_POWERSAVE;
1924 wid.id = WID_POWER_MANAGEMENT;
1925 wid.val = &power_mode;
1926 wid.size = sizeof(char);
1927 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1929 netdev_err(vif->ndev, "Failed to send power management\n");
1934 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1938 struct host_if_msg *msg;
1940 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1942 return PTR_ERR(msg);
1944 msg->body.mc_info.enabled = enabled;
1945 msg->body.mc_info.cnt = count;
1946 msg->body.mc_info.mc_list = mc_list;
1948 result = wilc_enqueue_work(msg);
1950 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1956 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
1960 wid.id = WID_TX_POWER;
1961 wid.type = WID_CHAR;
1962 wid.val = &tx_power;
1963 wid.size = sizeof(char);
1965 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1968 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
1972 wid.id = WID_TX_POWER;
1973 wid.type = WID_CHAR;
1975 wid.size = sizeof(char);
1977 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);