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 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
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->arg);
148 scan_req->scan_result = NULL;
154 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
155 u8 *ch_freq_list, u8 ch_list_len,
156 void (*scan_result_fn)(enum scan_event,
157 struct wilc_rcvd_net_info *, void *),
158 void *user_arg, struct cfg80211_scan_request *request)
161 struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
166 u8 *search_ssid_vals = NULL;
167 struct host_if_drv *hif_drv = vif->hif_drv;
169 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
170 hif_drv->hif_state < HOST_IF_CONNECTED) {
171 netdev_err(vif->ndev, "Already scan\n");
176 if (vif->connecting) {
177 netdev_err(vif->ndev, "Don't do obss scan\n");
182 hif_drv->usr_scan_req.ch_cnt = 0;
184 if (request->n_ssids) {
185 for (i = 0; i < request->n_ssids; i++)
186 valuesize += ((request->ssids[i].ssid_len) + 1);
187 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
188 if (search_ssid_vals) {
189 wid_list[index].id = WID_SSID_PROBE_REQ;
190 wid_list[index].type = WID_STR;
191 wid_list[index].val = search_ssid_vals;
192 buffer = wid_list[index].val;
194 *buffer++ = request->n_ssids;
196 for (i = 0; i < request->n_ssids; i++) {
197 *buffer++ = request->ssids[i].ssid_len;
198 memcpy(buffer, request->ssids[i].ssid,
199 request->ssids[i].ssid_len);
200 buffer += request->ssids[i].ssid_len;
202 wid_list[index].size = (s32)(valuesize + 1);
207 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
208 wid_list[index].type = WID_BIN_DATA;
209 wid_list[index].val = (s8 *)request->ie;
210 wid_list[index].size = request->ie_len;
213 wid_list[index].id = WID_SCAN_TYPE;
214 wid_list[index].type = WID_CHAR;
215 wid_list[index].size = sizeof(char);
216 wid_list[index].val = (s8 *)&scan_type;
219 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
220 wid_list[index].id = WID_PASSIVE_SCAN_TIME;
221 wid_list[index].type = WID_SHORT;
222 wid_list[index].size = sizeof(u16);
223 wid_list[index].val = (s8 *)&request->duration;
226 scan_timeout = (request->duration * ch_list_len) + 500;
228 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
231 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
232 wid_list[index].type = WID_BIN_DATA;
234 if (ch_freq_list && ch_list_len > 0) {
235 for (i = 0; i < ch_list_len; i++) {
236 if (ch_freq_list[i] > 0)
237 ch_freq_list[i] -= 1;
241 wid_list[index].val = ch_freq_list;
242 wid_list[index].size = ch_list_len;
245 wid_list[index].id = WID_START_SCAN_REQ;
246 wid_list[index].type = WID_CHAR;
247 wid_list[index].size = sizeof(char);
248 wid_list[index].val = (s8 *)&scan_source;
251 hif_drv->usr_scan_req.scan_result = scan_result_fn;
252 hif_drv->usr_scan_req.arg = user_arg;
254 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
256 netdev_err(vif->ndev, "Failed to send scan parameters\n");
260 hif_drv->scan_timer_vif = vif;
261 mod_timer(&hif_drv->scan_timer,
262 jiffies + msecs_to_jiffies(scan_timeout));
266 kfree(search_ssid_vals);
271 static int wilc_send_connect_wid(struct wilc_vif *vif)
274 struct wid wid_list[4];
276 struct host_if_drv *hif_drv = vif->hif_drv;
277 struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
278 struct wilc_join_bss_param *bss_param = conn_attr->param;
280 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
281 wid_list[wid_cnt].type = WID_BIN_DATA;
282 wid_list[wid_cnt].val = conn_attr->req_ies;
283 wid_list[wid_cnt].size = conn_attr->req_ies_len;
286 wid_list[wid_cnt].id = WID_11I_MODE;
287 wid_list[wid_cnt].type = WID_CHAR;
288 wid_list[wid_cnt].size = sizeof(char);
289 wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
292 wid_list[wid_cnt].id = WID_AUTH_TYPE;
293 wid_list[wid_cnt].type = WID_CHAR;
294 wid_list[wid_cnt].size = sizeof(char);
295 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
298 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
299 wid_list[wid_cnt].type = WID_STR;
300 wid_list[wid_cnt].size = sizeof(*bss_param);
301 wid_list[wid_cnt].val = (u8 *)bss_param;
304 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
306 netdev_err(vif->ndev, "failed to send config packet\n");
309 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
316 kfree(conn_attr->req_ies);
317 conn_attr->req_ies = NULL;
322 static void handle_connect_timeout(struct work_struct *work)
324 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
325 struct wilc_vif *vif = msg->vif;
328 u16 dummy_reason_code = 0;
329 struct host_if_drv *hif_drv = vif->hif_drv;
332 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
336 hif_drv->hif_state = HOST_IF_IDLE;
338 if (hif_drv->conn_info.conn_result) {
339 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
340 WILC_MAC_STATUS_DISCONNECTED,
341 hif_drv->conn_info.arg);
344 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
347 wid.id = WID_DISCONNECT;
349 wid.val = (s8 *)&dummy_reason_code;
350 wid.size = sizeof(char);
352 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
354 netdev_err(vif->ndev, "Failed to send disconnect\n");
356 hif_drv->conn_info.req_ies_len = 0;
357 kfree(hif_drv->conn_info.req_ies);
358 hif_drv->conn_info.req_ies = NULL;
364 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
365 struct cfg80211_crypto_settings *crypto)
367 struct wilc_join_bss_param *param;
368 struct ieee80211_p2p_noa_attr noa_attr;
370 const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
371 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
373 const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
375 param = kzalloc(sizeof(*param), GFP_KERNEL);
379 param->beacon_period = cpu_to_le16(bss->beacon_interval);
380 param->cap_info = cpu_to_le16(bss->capability);
381 param->bss_type = WILC_FW_BSS_TYPE_INFRA;
382 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
383 ether_addr_copy(param->bssid, bss->bssid);
385 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
387 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
388 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
391 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
392 if (tim_elm && tim_elm[1] >= 2)
393 param->dtim_period = tim_elm[3];
395 memset(param->p_suites, 0xFF, 3);
396 memset(param->akm_suites, 0xFF, 3);
398 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
400 rates_len = rates_ie[1];
401 if (rates_len > WILC_MAX_RATES_SUPPORTED)
402 rates_len = WILC_MAX_RATES_SUPPORTED;
403 param->supp_rates[0] = rates_len;
404 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
407 if (rates_len < WILC_MAX_RATES_SUPPORTED) {
408 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
409 ies->data, ies->len);
411 u8 ext_rates = supp_rates_ie[1];
413 if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
414 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
416 param->supp_rates[0] += ext_rates;
418 memcpy(¶m->supp_rates[rates_len + 1],
420 (param->supp_rates[0] - rates_len));
424 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
426 param->ht_capable = true;
428 ret = cfg80211_get_p2p_attr(ies->data, ies->len,
429 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
430 (u8 *)&noa_attr, sizeof(noa_attr));
432 param->tsf_lo = cpu_to_le32(ies->tsf);
433 param->noa_enabled = 1;
434 param->idx = noa_attr.index;
435 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
436 param->opp_enabled = 1;
437 param->opp_en.ct_window = noa_attr.oppps_ctwindow;
438 param->opp_en.cnt = noa_attr.desc[0].count;
439 param->opp_en.duration = noa_attr.desc[0].duration;
440 param->opp_en.interval = noa_attr.desc[0].interval;
441 param->opp_en.start_time = noa_attr.desc[0].start_time;
443 param->opp_enabled = 0;
444 param->opp_dis.cnt = noa_attr.desc[0].count;
445 param->opp_dis.duration = noa_attr.desc[0].duration;
446 param->opp_dis.interval = noa_attr.desc[0].interval;
447 param->opp_dis.start_time = noa_attr.desc[0].start_time;
450 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
451 WLAN_OUI_TYPE_MICROSOFT_WMM,
452 ies->data, ies->len);
454 struct ieee80211_wmm_param_ie *ie;
456 ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
457 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
459 param->wmm_cap = true;
460 if (ie->qos_info & BIT(7))
461 param->uapsd_cap = true;
465 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
466 WLAN_OUI_TYPE_MICROSOFT_WPA,
467 ies->data, ies->len);
469 param->mode_802_11i = 1;
470 param->rsn_found = true;
473 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
477 param->mode_802_11i = 2;
478 param->rsn_found = true;
479 /* extract RSN capabilities */
480 offset += (rsn_ie[offset] * 4) + 2;
481 offset += (rsn_ie[offset] * 4) + 2;
482 memcpy(param->rsn_cap, &rsn_ie[offset], 2);
485 if (param->rsn_found) {
488 param->rsn_grp_policy = crypto->cipher_group & 0xFF;
489 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
490 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
492 for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
493 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
496 return (void *)param;
499 static void handle_rcvd_ntwrk_info(struct work_struct *work)
501 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
502 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
503 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
509 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
510 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
511 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
512 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
516 ies = rcvd_info->mgmt->u.beacon.variable;
517 ies_len = rcvd_info->frame_len - offset;
521 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
522 if (ch_elm && ch_elm[1] > 0)
523 rcvd_info->ch = ch_elm[2];
525 if (scan_req->scan_result)
526 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
530 kfree(rcvd_info->mgmt);
534 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
536 u32 max_assoc_resp_info_len,
537 u32 *rcvd_assoc_resp_info_len)
542 wid.id = WID_ASSOC_RES_INFO;
544 wid.val = assoc_resp_info;
545 wid.size = max_assoc_resp_info_len;
547 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
549 *rcvd_assoc_resp_info_len = 0;
550 netdev_err(vif->ndev, "Failed to send association response\n");
554 *rcvd_assoc_resp_info_len = wid.size;
557 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
558 struct wilc_conn_info *ret_conn_info)
562 struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
564 ret_conn_info->status = le16_to_cpu(res->status_code);
565 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
566 ies = &buffer[sizeof(*res)];
567 ies_len = buffer_len - sizeof(*res);
569 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
570 if (!ret_conn_info->resp_ies)
573 ret_conn_info->resp_ies_len = ies_len;
579 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
582 struct host_if_drv *hif_drv = vif->hif_drv;
583 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
585 if (mac_status == WILC_MAC_STATUS_CONNECTED) {
586 u32 assoc_resp_info_len;
588 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
590 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
591 WILC_MAX_ASSOC_RESP_FRAME_SIZE,
592 &assoc_resp_info_len);
594 if (assoc_resp_info_len != 0) {
597 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
601 netdev_err(vif->ndev,
602 "wilc_parse_assoc_resp_info() returned error %d\n",
607 del_timer(&hif_drv->connect_timer);
608 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
609 hif_drv->conn_info.arg);
611 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
612 conn_info->status == WLAN_STATUS_SUCCESS) {
613 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
614 hif_drv->hif_state = HOST_IF_CONNECTED;
616 hif_drv->hif_state = HOST_IF_IDLE;
619 kfree(conn_info->resp_ies);
620 conn_info->resp_ies = NULL;
621 conn_info->resp_ies_len = 0;
623 kfree(conn_info->req_ies);
624 conn_info->req_ies = NULL;
625 conn_info->req_ies_len = 0;
628 static inline void host_int_handle_disconnect(struct wilc_vif *vif)
630 struct host_if_drv *hif_drv = vif->hif_drv;
632 if (hif_drv->usr_scan_req.scan_result) {
633 del_timer(&hif_drv->scan_timer);
634 handle_scan_done(vif, SCAN_EVENT_ABORTED);
637 if (hif_drv->conn_info.conn_result)
638 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
639 0, hif_drv->conn_info.arg);
641 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
643 eth_zero_addr(hif_drv->assoc_bssid);
645 hif_drv->conn_info.req_ies_len = 0;
646 kfree(hif_drv->conn_info.req_ies);
647 hif_drv->conn_info.req_ies = NULL;
648 hif_drv->hif_state = HOST_IF_IDLE;
651 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
653 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
654 struct wilc_vif *vif = msg->vif;
655 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
656 struct host_if_drv *hif_drv = vif->hif_drv;
659 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
663 if (!hif_drv->conn_info.conn_result) {
664 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
668 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
669 host_int_parse_assoc_resp_info(vif, mac_info->status);
670 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
671 if (hif_drv->hif_state == HOST_IF_CONNECTED) {
672 host_int_handle_disconnect(vif);
673 } else if (hif_drv->usr_scan_req.scan_result) {
674 del_timer(&hif_drv->scan_timer);
675 handle_scan_done(vif, SCAN_EVENT_ABORTED);
683 int wilc_disconnect(struct wilc_vif *vif)
686 struct host_if_drv *hif_drv = vif->hif_drv;
687 struct wilc_user_scan_req *scan_req;
688 struct wilc_conn_info *conn_info;
690 u16 dummy_reason_code = 0;
692 wid.id = WID_DISCONNECT;
694 wid.val = (s8 *)&dummy_reason_code;
695 wid.size = sizeof(char);
697 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
699 netdev_err(vif->ndev, "Failed to send disconnect\n");
703 scan_req = &hif_drv->usr_scan_req;
704 conn_info = &hif_drv->conn_info;
706 if (scan_req->scan_result) {
707 del_timer(&hif_drv->scan_timer);
708 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
709 scan_req->scan_result = NULL;
712 if (conn_info->conn_result) {
713 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
714 del_timer(&hif_drv->connect_timer);
716 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
719 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
722 hif_drv->hif_state = HOST_IF_IDLE;
724 eth_zero_addr(hif_drv->assoc_bssid);
726 conn_info->req_ies_len = 0;
727 kfree(conn_info->req_ies);
728 conn_info->req_ies = NULL;
733 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
735 struct wid wid_list[5];
736 u32 wid_cnt = 0, result;
738 wid_list[wid_cnt].id = WID_LINKSPEED;
739 wid_list[wid_cnt].type = WID_CHAR;
740 wid_list[wid_cnt].size = sizeof(char);
741 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
744 wid_list[wid_cnt].id = WID_RSSI;
745 wid_list[wid_cnt].type = WID_CHAR;
746 wid_list[wid_cnt].size = sizeof(char);
747 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
750 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
751 wid_list[wid_cnt].type = WID_INT;
752 wid_list[wid_cnt].size = sizeof(u32);
753 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
756 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
757 wid_list[wid_cnt].type = WID_INT;
758 wid_list[wid_cnt].size = sizeof(u32);
759 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
762 wid_list[wid_cnt].id = WID_FAILED_COUNT;
763 wid_list[wid_cnt].type = WID_INT;
764 wid_list[wid_cnt].size = sizeof(u32);
765 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
768 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
770 netdev_err(vif->ndev, "Failed to send scan parameters\n");
774 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
775 stats->link_speed != DEFAULT_LINK_SPEED)
776 wilc_enable_tcp_ack_filter(vif, true);
777 else if (stats->link_speed != DEFAULT_LINK_SPEED)
778 wilc_enable_tcp_ack_filter(vif, false);
783 static void handle_get_statistics(struct work_struct *work)
785 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
786 struct wilc_vif *vif = msg->vif;
787 struct rf_info *stats = (struct rf_info *)msg->body.data;
789 wilc_get_statistics(vif, stats);
794 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
795 struct station_parameters *params)
797 ether_addr_copy(cur_byte, mac);
798 cur_byte += ETH_ALEN;
800 put_unaligned_le16(params->aid, cur_byte);
803 *cur_byte++ = params->supported_rates_len;
804 if (params->supported_rates_len > 0)
805 memcpy(cur_byte, params->supported_rates,
806 params->supported_rates_len);
807 cur_byte += params->supported_rates_len;
809 if (params->ht_capa) {
811 memcpy(cur_byte, params->ht_capa,
812 sizeof(struct ieee80211_ht_cap));
816 cur_byte += sizeof(struct ieee80211_ht_cap);
818 put_unaligned_le16(params->sta_flags_mask, cur_byte);
820 put_unaligned_le16(params->sta_flags_set, cur_byte);
823 static int handle_remain_on_chan(struct wilc_vif *vif,
824 struct wilc_remain_ch *hif_remain_ch)
827 u8 remain_on_chan_flag;
829 struct host_if_drv *hif_drv = vif->hif_drv;
831 if (hif_drv->usr_scan_req.scan_result)
834 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
840 remain_on_chan_flag = true;
841 wid.id = WID_REMAIN_ON_CHAN;
844 wid.val = kmalloc(wid.size, GFP_KERNEL);
848 wid.val[0] = remain_on_chan_flag;
849 wid.val[1] = (s8)hif_remain_ch->ch;
851 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
856 hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
857 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
858 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
859 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
860 hif_drv->remain_on_ch_timer_vif = vif;
865 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
867 u8 remain_on_chan_flag;
870 struct host_if_drv *hif_drv = vif->hif_drv;
872 if (vif->priv.p2p_listen_state) {
873 remain_on_chan_flag = false;
874 wid.id = WID_REMAIN_ON_CHAN;
878 wid.val = kmalloc(wid.size, GFP_KERNEL);
882 wid.val[0] = remain_on_chan_flag;
883 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
885 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
888 netdev_err(vif->ndev, "Failed to set remain channel\n");
892 if (hif_drv->remain_on_ch.expired) {
893 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
897 netdev_dbg(vif->ndev, "Not in listen state\n");
903 static void wilc_handle_listen_state_expired(struct work_struct *work)
905 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
907 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
911 static void listen_timer_cb(struct timer_list *t)
913 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
915 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
917 struct host_if_msg *msg;
919 del_timer(&vif->hif_drv->remain_on_ch_timer);
921 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
925 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
927 result = wilc_enqueue_work(msg);
929 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
934 static void handle_set_mcast_filter(struct work_struct *work)
936 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
937 struct wilc_vif *vif = msg->vif;
938 struct wilc_set_multicast *set_mc = &msg->body.mc_info;
943 wid.id = WID_SETUP_MULTICAST_FILTER;
945 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
946 wid.val = kmalloc(wid.size, GFP_KERNEL);
951 put_unaligned_le32(set_mc->enabled, cur_byte);
954 put_unaligned_le32(set_mc->cnt, cur_byte);
957 if (set_mc->cnt > 0 && set_mc->mc_list)
958 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
960 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
962 netdev_err(vif->ndev, "Failed to send setup multicast\n");
965 kfree(set_mc->mc_list);
970 void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled)
974 u8 wowlan_trigger = 0;
979 wid.id = WID_WOWLAN_TRIGGER;
981 wid.val = &wowlan_trigger;
982 wid.size = sizeof(char);
984 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
986 pr_err("Failed to send wowlan trigger config packet\n");
989 static void handle_scan_timer(struct work_struct *work)
991 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
993 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
997 static void handle_scan_complete(struct work_struct *work)
999 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1001 del_timer(&msg->vif->hif_drv->scan_timer);
1003 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1008 static void timer_scan_cb(struct timer_list *t)
1010 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
1011 struct wilc_vif *vif = hif_drv->scan_timer_vif;
1012 struct host_if_msg *msg;
1015 msg = wilc_alloc_work(vif, handle_scan_timer, false);
1019 result = wilc_enqueue_work(msg);
1024 static void timer_connect_cb(struct timer_list *t)
1026 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1028 struct wilc_vif *vif = hif_drv->connect_timer_vif;
1029 struct host_if_msg *msg;
1032 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1036 result = wilc_enqueue_work(msg);
1041 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
1046 wid.id = WID_REMOVE_WEP_KEY;
1048 wid.size = sizeof(char);
1051 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1053 netdev_err(vif->ndev,
1054 "Failed to send remove wep key config packet\n");
1058 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
1063 wid.id = WID_KEY_ID;
1064 wid.type = WID_CHAR;
1065 wid.size = sizeof(char);
1067 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1069 netdev_err(vif->ndev,
1070 "Failed to send wep default key config packet\n");
1075 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
1080 struct wilc_wep_key *wep_key;
1082 wid.id = WID_ADD_WEP_KEY;
1084 wid.size = sizeof(*wep_key) + len;
1085 wep_key = kzalloc(wid.size, GFP_KERNEL);
1089 wid.val = (u8 *)wep_key;
1091 wep_key->index = index;
1092 wep_key->key_len = len;
1093 memcpy(wep_key->key, key, len);
1095 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1097 netdev_err(vif->ndev,
1098 "Failed to add wep key config packet\n");
1104 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
1105 u8 index, u8 mode, enum authtype auth_type)
1107 struct wid wid_list[3];
1109 struct wilc_wep_key *wep_key;
1111 wid_list[0].id = WID_11I_MODE;
1112 wid_list[0].type = WID_CHAR;
1113 wid_list[0].size = sizeof(char);
1114 wid_list[0].val = &mode;
1116 wid_list[1].id = WID_AUTH_TYPE;
1117 wid_list[1].type = WID_CHAR;
1118 wid_list[1].size = sizeof(char);
1119 wid_list[1].val = (s8 *)&auth_type;
1121 wid_list[2].id = WID_WEP_KEY_VALUE;
1122 wid_list[2].type = WID_STR;
1123 wid_list[2].size = sizeof(*wep_key) + len;
1124 wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
1128 wid_list[2].val = (u8 *)wep_key;
1130 wep_key->index = index;
1131 wep_key->key_len = len;
1132 memcpy(wep_key->key, key, len);
1133 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1134 ARRAY_SIZE(wid_list));
1136 netdev_err(vif->ndev,
1137 "Failed to add wep ap key config packet\n");
1143 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1144 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1145 u8 mode, u8 cipher_mode, u8 index)
1148 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1150 if (mode == WILC_AP_MODE) {
1151 struct wid wid_list[2];
1152 struct wilc_ap_wpa_ptk *key_buf;
1154 wid_list[0].id = WID_11I_MODE;
1155 wid_list[0].type = WID_CHAR;
1156 wid_list[0].size = sizeof(char);
1157 wid_list[0].val = (s8 *)&cipher_mode;
1159 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1163 ether_addr_copy(key_buf->mac_addr, mac_addr);
1164 key_buf->index = index;
1165 key_buf->key_len = t_key_len;
1166 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1169 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1170 WILC_RX_MIC_KEY_LEN);
1173 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1174 tx_mic, WILC_TX_MIC_KEY_LEN);
1176 wid_list[1].id = WID_ADD_PTK;
1177 wid_list[1].type = WID_STR;
1178 wid_list[1].size = sizeof(*key_buf) + t_key_len;
1179 wid_list[1].val = (u8 *)key_buf;
1180 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1181 ARRAY_SIZE(wid_list));
1183 } else if (mode == WILC_STATION_MODE) {
1185 struct wilc_sta_wpa_ptk *key_buf;
1187 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1191 ether_addr_copy(key_buf->mac_addr, mac_addr);
1192 key_buf->key_len = t_key_len;
1193 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1196 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1197 WILC_RX_MIC_KEY_LEN);
1200 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1201 tx_mic, WILC_TX_MIC_KEY_LEN);
1203 wid.id = WID_ADD_PTK;
1205 wid.size = sizeof(*key_buf) + t_key_len;
1206 wid.val = (s8 *)key_buf;
1207 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1214 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1215 u8 index, u32 key_rsc_len, const u8 *key_rsc,
1216 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1220 struct wilc_gtk_key *gtk_key;
1221 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1223 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1227 /* fill bssid value only in station mode */
1228 if (mode == WILC_STATION_MODE &&
1229 vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1230 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1233 memcpy(gtk_key->rsc, key_rsc, 8);
1234 gtk_key->index = index;
1235 gtk_key->key_len = t_key_len;
1236 memcpy(>k_key->key[0], rx_gtk, gtk_key_len);
1239 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1242 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1243 tx_mic, WILC_TX_MIC_KEY_LEN);
1245 if (mode == WILC_AP_MODE) {
1246 struct wid wid_list[2];
1248 wid_list[0].id = WID_11I_MODE;
1249 wid_list[0].type = WID_CHAR;
1250 wid_list[0].size = sizeof(char);
1251 wid_list[0].val = (s8 *)&cipher_mode;
1253 wid_list[1].id = WID_ADD_RX_GTK;
1254 wid_list[1].type = WID_STR;
1255 wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1256 wid_list[1].val = (u8 *)gtk_key;
1258 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1259 ARRAY_SIZE(wid_list));
1260 } else if (mode == WILC_STATION_MODE) {
1263 wid.id = WID_ADD_RX_GTK;
1265 wid.size = sizeof(*gtk_key) + t_key_len;
1266 wid.val = (u8 *)gtk_key;
1267 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1274 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1278 wid.id = WID_PMKID_INFO;
1280 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1281 wid.val = (u8 *)pmkid;
1283 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1286 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1291 wid.id = WID_MAC_ADDR;
1293 wid.size = ETH_ALEN;
1296 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1298 netdev_err(vif->ndev, "Failed to get mac address\n");
1303 int wilc_set_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1308 wid.id = WID_MAC_ADDR;
1310 wid.size = ETH_ALEN;
1313 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1315 netdev_err(vif->ndev, "Failed to set mac address\n");
1320 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1324 struct host_if_drv *hif_drv = vif->hif_drv;
1325 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1328 ether_addr_copy(conn_info->bssid, bssid);
1331 conn_info->req_ies_len = ies_len;
1332 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1333 if (!conn_info->req_ies)
1337 result = wilc_send_connect_wid(vif);
1341 hif_drv->connect_timer_vif = vif;
1342 mod_timer(&hif_drv->connect_timer,
1343 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1348 kfree(conn_info->req_ies);
1353 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1358 wid.id = WID_CURRENT_CHANNEL;
1359 wid.type = WID_CHAR;
1360 wid.size = sizeof(char);
1363 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1365 netdev_err(vif->ndev, "Failed to set channel\n");
1370 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1375 struct wilc_drv_handler drv;
1377 wid.id = WID_SET_OPERATION_MODE;
1379 wid.size = sizeof(drv);
1380 wid.val = (u8 *)&drv;
1382 drv.handler = cpu_to_le32(index);
1383 drv.mode = (ifc_id | (mode << 1));
1385 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1387 netdev_err(vif->ndev, "Failed to set driver handler\n");
1392 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1397 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1399 wid.size = ETH_ALEN;
1400 wid.val = kzalloc(wid.size, GFP_KERNEL);
1404 ether_addr_copy(wid.val, mac);
1405 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1408 netdev_err(vif->ndev, "Failed to set inactive mac\n");
1412 wid.id = WID_GET_INACTIVE_TIME;
1414 wid.val = (s8 *)out_val;
1415 wid.size = sizeof(u32);
1416 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1418 netdev_err(vif->ndev, "Failed to get inactive time\n");
1423 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1429 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1434 wid.type = WID_CHAR;
1435 wid.size = sizeof(char);
1436 wid.val = rssi_level;
1437 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1439 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1444 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1447 struct host_if_msg *msg;
1449 msg = wilc_alloc_work(vif, handle_get_statistics, false);
1451 return PTR_ERR(msg);
1453 msg->body.data = (char *)stats;
1455 result = wilc_enqueue_work(msg);
1457 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1465 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1467 struct wid wid_list[4];
1470 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1471 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1472 wid_list[i].val = (s8 *)¶m->short_retry_limit;
1473 wid_list[i].type = WID_SHORT;
1474 wid_list[i].size = sizeof(u16);
1477 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1478 wid_list[i].id = WID_LONG_RETRY_LIMIT;
1479 wid_list[i].val = (s8 *)¶m->long_retry_limit;
1480 wid_list[i].type = WID_SHORT;
1481 wid_list[i].size = sizeof(u16);
1484 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1485 wid_list[i].id = WID_FRAG_THRESHOLD;
1486 wid_list[i].val = (s8 *)¶m->frag_threshold;
1487 wid_list[i].type = WID_SHORT;
1488 wid_list[i].size = sizeof(u16);
1491 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1492 wid_list[i].id = WID_RTS_THRESHOLD;
1493 wid_list[i].val = (s8 *)¶m->rts_threshold;
1494 wid_list[i].type = WID_SHORT;
1495 wid_list[i].size = sizeof(u16);
1499 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1502 static void get_periodic_rssi(struct timer_list *t)
1504 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1506 if (!vif->hif_drv) {
1507 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1511 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1512 wilc_get_stats_async(vif, &vif->periodic_stat);
1514 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1517 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1519 struct host_if_drv *hif_drv;
1520 struct wilc_vif *vif = netdev_priv(dev);
1522 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1526 *hif_drv_handler = hif_drv;
1528 vif->hif_drv = hif_drv;
1530 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1531 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1533 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1534 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1535 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1537 hif_drv->hif_state = HOST_IF_IDLE;
1539 hif_drv->p2p_timeout = 0;
1544 int wilc_deinit(struct wilc_vif *vif)
1547 struct host_if_drv *hif_drv = vif->hif_drv;
1550 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1554 mutex_lock(&vif->wilc->deinit_lock);
1556 del_timer_sync(&hif_drv->scan_timer);
1557 del_timer_sync(&hif_drv->connect_timer);
1558 del_timer_sync(&vif->periodic_rssi);
1559 del_timer_sync(&hif_drv->remain_on_ch_timer);
1561 if (hif_drv->usr_scan_req.scan_result) {
1562 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1563 hif_drv->usr_scan_req.arg);
1564 hif_drv->usr_scan_req.scan_result = NULL;
1567 hif_drv->hif_state = HOST_IF_IDLE;
1570 vif->hif_drv = NULL;
1571 mutex_unlock(&vif->wilc->deinit_lock);
1575 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1578 struct host_if_msg *msg;
1580 struct host_if_drv *hif_drv;
1581 struct wilc_vif *vif;
1583 id = get_unaligned_le32(&buffer[length - 4]);
1584 vif = wilc_get_vif_from_idx(wilc, id);
1587 hif_drv = vif->hif_drv;
1590 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1594 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1598 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1599 msg->body.net_info.rssi = buffer[8];
1600 msg->body.net_info.mgmt = kmemdup(&buffer[9],
1601 msg->body.net_info.frame_len,
1603 if (!msg->body.net_info.mgmt) {
1608 result = wilc_enqueue_work(msg);
1610 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1611 kfree(msg->body.net_info.mgmt);
1616 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1619 struct host_if_msg *msg;
1621 struct host_if_drv *hif_drv;
1622 struct wilc_vif *vif;
1624 mutex_lock(&wilc->deinit_lock);
1626 id = get_unaligned_le32(&buffer[length - 4]);
1627 vif = wilc_get_vif_from_idx(wilc, id);
1629 mutex_unlock(&wilc->deinit_lock);
1633 hif_drv = vif->hif_drv;
1636 mutex_unlock(&wilc->deinit_lock);
1640 if (!hif_drv->conn_info.conn_result) {
1641 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1642 mutex_unlock(&wilc->deinit_lock);
1646 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1648 mutex_unlock(&wilc->deinit_lock);
1652 msg->body.mac_info.status = buffer[7];
1653 result = wilc_enqueue_work(msg);
1655 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1659 mutex_unlock(&wilc->deinit_lock);
1662 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1666 struct host_if_drv *hif_drv;
1667 struct wilc_vif *vif;
1669 id = get_unaligned_le32(&buffer[length - 4]);
1670 vif = wilc_get_vif_from_idx(wilc, id);
1673 hif_drv = vif->hif_drv;
1678 if (hif_drv->usr_scan_req.scan_result) {
1679 struct host_if_msg *msg;
1681 msg = wilc_alloc_work(vif, handle_scan_complete, false);
1685 result = wilc_enqueue_work(msg);
1687 netdev_err(vif->ndev, "%s: enqueue work failed\n",
1694 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
1695 u32 duration, u16 chan,
1696 void (*expired)(void *, u64),
1699 struct wilc_remain_ch roc;
1703 roc.expired = expired;
1705 roc.duration = duration;
1706 roc.cookie = cookie;
1707 result = handle_remain_on_chan(vif, &roc);
1709 netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1715 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1717 if (!vif->hif_drv) {
1718 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1722 del_timer(&vif->hif_drv->remain_on_ch_timer);
1724 return wilc_handle_roc_expired(vif, cookie);
1727 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1731 struct wilc_reg_frame reg_frame;
1733 wid.id = WID_REGISTER_FRAME;
1735 wid.size = sizeof(reg_frame);
1736 wid.val = (u8 *)®_frame;
1738 memset(®_frame, 0x0, sizeof(reg_frame));
1743 switch (frame_type) {
1744 case IEEE80211_STYPE_ACTION:
1745 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1748 case IEEE80211_STYPE_PROBE_REQ:
1749 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1755 reg_frame.frame_type = cpu_to_le16(frame_type);
1756 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1758 netdev_err(vif->ndev, "Failed to frame register\n");
1761 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1762 struct cfg80211_beacon_data *params)
1768 wid.id = WID_ADD_BEACON;
1770 wid.size = params->head_len + params->tail_len + 16;
1771 wid.val = kzalloc(wid.size, GFP_KERNEL);
1776 put_unaligned_le32(interval, cur_byte);
1778 put_unaligned_le32(dtim_period, cur_byte);
1780 put_unaligned_le32(params->head_len, cur_byte);
1783 if (params->head_len > 0)
1784 memcpy(cur_byte, params->head, params->head_len);
1785 cur_byte += params->head_len;
1787 put_unaligned_le32(params->tail_len, cur_byte);
1790 if (params->tail_len > 0)
1791 memcpy(cur_byte, params->tail, params->tail_len);
1793 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1795 netdev_err(vif->ndev, "Failed to send add beacon\n");
1802 int wilc_del_beacon(struct wilc_vif *vif)
1808 wid.id = WID_DEL_BEACON;
1809 wid.type = WID_CHAR;
1810 wid.size = sizeof(char);
1811 wid.val = &del_beacon;
1813 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1815 netdev_err(vif->ndev, "Failed to send delete beacon\n");
1820 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1821 struct station_parameters *params)
1827 wid.id = WID_ADD_STA;
1829 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1830 wid.val = kmalloc(wid.size, GFP_KERNEL);
1835 wilc_hif_pack_sta_param(cur_byte, mac, params);
1837 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1839 netdev_err(vif->ndev, "Failed to send add station\n");
1846 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1851 wid.id = WID_REMOVE_STA;
1853 wid.size = ETH_ALEN;
1854 wid.val = kzalloc(wid.size, GFP_KERNEL);
1859 eth_broadcast_addr(wid.val);
1861 ether_addr_copy(wid.val, mac_addr);
1863 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1865 netdev_err(vif->ndev, "Failed to del station\n");
1872 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1878 struct wilc_del_all_sta del_sta;
1880 memset(&del_sta, 0x0, sizeof(del_sta));
1881 for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1882 if (!is_zero_ether_addr(mac_addr[i])) {
1884 ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1891 del_sta.assoc_sta = assoc_sta;
1893 wid.id = WID_DEL_ALL_STA;
1895 wid.size = (assoc_sta * ETH_ALEN) + 1;
1896 wid.val = (u8 *)&del_sta;
1898 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1900 netdev_err(vif->ndev, "Failed to send delete all station\n");
1905 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1906 struct station_parameters *params)
1912 wid.id = WID_EDIT_STA;
1914 wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
1915 wid.val = kmalloc(wid.size, GFP_KERNEL);
1920 wilc_hif_pack_sta_param(cur_byte, mac, params);
1922 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1924 netdev_err(vif->ndev, "Failed to send edit station\n");
1930 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1932 struct wilc *wilc = vif->wilc;
1938 power_mode = WILC_FW_MIN_FAST_PS;
1940 power_mode = WILC_FW_NO_POWERSAVE;
1942 wid.id = WID_POWER_MANAGEMENT;
1943 wid.val = &power_mode;
1944 wid.size = sizeof(char);
1945 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1947 netdev_err(vif->ndev, "Failed to send power management\n");
1949 wilc->power_save_mode = enabled;
1954 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1958 struct host_if_msg *msg;
1960 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1962 return PTR_ERR(msg);
1964 msg->body.mc_info.enabled = enabled;
1965 msg->body.mc_info.cnt = count;
1966 msg->body.mc_info.mc_list = mc_list;
1968 result = wilc_enqueue_work(msg);
1970 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1976 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
1980 wid.id = WID_TX_POWER;
1981 wid.type = WID_CHAR;
1982 wid.val = &tx_power;
1983 wid.size = sizeof(char);
1985 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1988 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
1992 wid.id = WID_TX_POWER;
1993 wid.type = WID_CHAR;
1995 wid.size = sizeof(char);
1997 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);