1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #include "wilc_wfi_netdevice.h"
9 #define HOST_IF_SCAN_TIMEOUT 4000
10 #define HOST_IF_CONNECT_TIMEOUT 9500
12 #define FALSE_FRMWR_CHANNEL 100
14 #define REAL_JOIN_REQ 0
16 struct host_if_wpa_attr {
26 struct host_if_wep_attr {
31 enum authtype auth_type;
34 union host_if_key_attr {
35 struct host_if_wep_attr wep;
36 struct host_if_wpa_attr wpa;
37 struct host_if_pmkid_attr pmkid;
43 union host_if_key_attr attr;
53 wilc_scan_result result;
55 struct hidden_network hidden_network;
65 wilc_connect_result result;
67 enum authtype auth_type;
72 struct rcvd_async_info {
90 struct set_multicast {
96 u8 del_all_sta[MAX_NUM_STA][ETH_ALEN];
101 u8 mac_addr[ETH_ALEN];
104 struct power_mgmt_param {
114 struct sta_inactive_t {
124 struct scan_attr scan_info;
125 struct connect_attr con_info;
126 struct rcvd_net_info net_info;
127 struct rcvd_async_info async_info;
128 struct key_attr key_info;
129 struct cfg_param_attr cfg_info;
130 struct channel_attr channel_info;
131 struct beacon_attr beacon_info;
132 struct add_sta_param add_sta_info;
133 struct del_sta del_sta_info;
134 struct add_sta_param edit_sta_info;
135 struct power_mgmt_param pwr_mgmt_info;
136 struct sta_inactive_t mac_info;
137 struct set_ip_addr ip_info;
138 struct drv_handler drv;
139 struct set_multicast multicast_info;
141 struct get_mac_addr get_mac_info;
142 struct ba_session_info session_info;
143 struct remain_ch remain_on_ch;
144 struct reg_frame reg_frame;
146 struct del_all_sta del_all_sta_info;
147 struct tx_power tx_power;
151 union message_body body;
152 struct wilc_vif *vif;
153 struct work_struct work;
154 void (*fn)(struct work_struct *ws);
155 struct completion work_comp;
159 struct join_bss_param {
160 enum bss_types bss_type;
165 char ssid[MAX_SSID_LEN];
167 u8 supp_rates[MAX_RATES_SUPPORTED + 1];
174 u8 rsn_pcip_policy[3];
175 u8 rsn_auth_policy[3];
188 static struct host_if_drv *terminated_handle;
189 bool wilc_optaining_ip;
190 static u8 p2p_listen_state;
191 static struct workqueue_struct *hif_workqueue;
192 static struct completion hif_driver_comp;
193 static struct mutex hif_deinit_lock;
194 static struct timer_list periodic_rssi;
195 static struct wilc_vif *periodic_rssi_vif;
197 u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
199 static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
201 static u8 set_ip[2][4];
202 static u8 get_ip[2][4];
203 static u32 clients_count;
205 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
207 /* 'msg' should be free by the caller for syc */
208 static struct host_if_msg*
209 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
212 struct host_if_msg *msg;
215 return ERR_PTR(-EINVAL);
217 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
219 return ERR_PTR(-ENOMEM);
222 msg->is_sync = is_sync;
224 init_completion(&msg->work_comp);
229 static int wilc_enqueue_work(struct host_if_msg *msg)
231 INIT_WORK(&msg->work, msg->fn);
232 if (!hif_workqueue || !queue_work(hif_workqueue, &msg->work))
238 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
239 * special purpose in wilc device, so we add 1 to the index to starts from 1.
240 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
242 int wilc_get_vif_idx(struct wilc_vif *vif)
247 /* We need to minus 1 from idx which is from wilc device to get real index
248 * of wilc->vif[], because we add 1 when pass to wilc device in the function
250 * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
252 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
256 if (index < 0 || index >= NUM_CONCURRENT_IFC)
259 return wilc->vif[index];
262 static void handle_set_channel(struct work_struct *work)
264 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
265 struct wilc_vif *vif = msg->vif;
266 struct channel_attr *hif_set_ch = &msg->body.channel_info;
270 wid.id = WID_CURRENT_CHANNEL;
272 wid.val = (char *)&hif_set_ch->set_ch;
273 wid.size = sizeof(char);
275 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
276 wilc_get_vif_idx(vif));
279 netdev_err(vif->ndev, "Failed to set channel\n");
283 static void handle_set_wfi_drv_handler(struct work_struct *work)
285 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
286 struct wilc_vif *vif = msg->vif;
287 struct drv_handler *hif_drv_handler = &msg->body.drv;
290 u8 *currbyte, *buffer;
291 struct host_if_drv *hif_drv;
293 if (!vif->hif_drv || !hif_drv_handler)
296 hif_drv = vif->hif_drv;
298 buffer = kzalloc(DRV_HANDLER_SIZE, GFP_KERNEL);
303 *currbyte = hif_drv->driver_handler_id & DRV_HANDLER_MASK;
305 *currbyte = (u32)0 & DRV_HANDLER_MASK;
307 *currbyte = (u32)0 & DRV_HANDLER_MASK;
309 *currbyte = (u32)0 & DRV_HANDLER_MASK;
311 *currbyte = (hif_drv_handler->name | (hif_drv_handler->mode << 1));
313 wid.id = WID_SET_DRV_HANDLER;
315 wid.val = (s8 *)buffer;
316 wid.size = DRV_HANDLER_SIZE;
318 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
319 hif_drv->driver_handler_id);
321 netdev_err(vif->ndev, "Failed to set driver handler\n");
323 complete(&hif_driver_comp);
330 static void handle_set_operation_mode(struct work_struct *work)
332 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
333 struct wilc_vif *vif = msg->vif;
334 struct op_mode *hif_op_mode = &msg->body.mode;
338 wid.id = WID_SET_OPERATION_MODE;
340 wid.val = (s8 *)&hif_op_mode->mode;
341 wid.size = sizeof(u32);
343 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
344 wilc_get_vif_idx(vif));
346 if (hif_op_mode->mode == IDLE_MODE)
347 complete(&hif_driver_comp);
350 netdev_err(vif->ndev, "Failed to set operation mode\n");
355 static void handle_set_ip_address(struct work_struct *work)
357 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
358 struct wilc_vif *vif = msg->vif;
359 u8 *ip_addr = msg->body.ip_info.ip_addr;
360 u8 idx = msg->body.ip_info.idx;
363 char firmware_ip_addr[4] = {0};
365 if (ip_addr[0] < 192)
368 memcpy(set_ip[idx], ip_addr, IP_ALEN);
370 wid.id = WID_IP_ADDRESS;
375 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
376 wilc_get_vif_idx(vif));
378 host_int_get_ipaddress(vif, firmware_ip_addr, idx);
381 netdev_err(vif->ndev, "Failed to set IP address\n");
385 static void handle_get_ip_address(struct work_struct *work)
387 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
388 struct wilc_vif *vif = msg->vif;
389 u8 idx = msg->body.ip_info.idx;
393 wid.id = WID_IP_ADDRESS;
395 wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
398 ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
399 wilc_get_vif_idx(vif));
401 memcpy(get_ip[idx], wid.val, IP_ALEN);
405 if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
406 wilc_setup_ipaddress(vif, set_ip[idx], idx);
409 netdev_err(vif->ndev, "Failed to get IP address\n");
413 static void handle_get_mac_address(struct work_struct *work)
415 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
416 struct wilc_vif *vif = msg->vif;
417 struct get_mac_addr *get_mac_addr = &msg->body.get_mac_info;
421 wid.id = WID_MAC_ADDR;
423 wid.val = get_mac_addr->mac_addr;
426 ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
427 wilc_get_vif_idx(vif));
430 netdev_err(vif->ndev, "Failed to get mac address\n");
431 complete(&msg->work_comp);
432 /* free 'msg' data later, in caller */
435 static void handle_cfg_param(struct work_struct *work)
437 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
438 struct wilc_vif *vif = msg->vif;
439 struct cfg_param_attr *param = &msg->body.cfg_info;
441 struct wid wid_list[32];
442 struct host_if_drv *hif_drv = vif->hif_drv;
445 mutex_lock(&hif_drv->cfg_values_lock);
447 if (param->flag & BSS_TYPE) {
448 u8 bss_type = param->bss_type;
451 wid_list[i].id = WID_BSS_TYPE;
452 wid_list[i].val = (s8 *)¶m->bss_type;
453 wid_list[i].type = WID_CHAR;
454 wid_list[i].size = sizeof(char);
455 hif_drv->cfg_values.bss_type = bss_type;
457 netdev_err(vif->ndev, "check value 6 over\n");
462 if (param->flag & AUTH_TYPE) {
463 u8 auth_type = param->auth_type;
465 if (auth_type == 1 || auth_type == 2 || auth_type == 5) {
466 wid_list[i].id = WID_AUTH_TYPE;
467 wid_list[i].val = (s8 *)¶m->auth_type;
468 wid_list[i].type = WID_CHAR;
469 wid_list[i].size = sizeof(char);
470 hif_drv->cfg_values.auth_type = auth_type;
472 netdev_err(vif->ndev, "Impossible value\n");
477 if (param->flag & AUTHEN_TIMEOUT) {
478 if (param->auth_timeout > 0) {
479 wid_list[i].id = WID_AUTH_TIMEOUT;
480 wid_list[i].val = (s8 *)¶m->auth_timeout;
481 wid_list[i].type = WID_SHORT;
482 wid_list[i].size = sizeof(u16);
483 hif_drv->cfg_values.auth_timeout = param->auth_timeout;
485 netdev_err(vif->ndev, "Range(1 ~ 65535) over\n");
490 if (param->flag & POWER_MANAGEMENT) {
491 u8 pm_mode = param->power_mgmt_mode;
494 wid_list[i].id = WID_POWER_MANAGEMENT;
495 wid_list[i].val = (s8 *)¶m->power_mgmt_mode;
496 wid_list[i].type = WID_CHAR;
497 wid_list[i].size = sizeof(char);
498 hif_drv->cfg_values.power_mgmt_mode = pm_mode;
500 netdev_err(vif->ndev, "Invalid power mode\n");
505 if (param->flag & RETRY_SHORT) {
506 u16 retry_limit = param->short_retry_limit;
508 if (retry_limit > 0 && retry_limit < 256) {
509 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
510 wid_list[i].val = (s8 *)¶m->short_retry_limit;
511 wid_list[i].type = WID_SHORT;
512 wid_list[i].size = sizeof(u16);
513 hif_drv->cfg_values.short_retry_limit = retry_limit;
515 netdev_err(vif->ndev, "Range(1~256) over\n");
520 if (param->flag & RETRY_LONG) {
521 u16 limit = param->long_retry_limit;
523 if (limit > 0 && limit < 256) {
524 wid_list[i].id = WID_LONG_RETRY_LIMIT;
525 wid_list[i].val = (s8 *)¶m->long_retry_limit;
526 wid_list[i].type = WID_SHORT;
527 wid_list[i].size = sizeof(u16);
528 hif_drv->cfg_values.long_retry_limit = limit;
530 netdev_err(vif->ndev, "Range(1~256) over\n");
535 if (param->flag & FRAG_THRESHOLD) {
536 u16 frag_th = param->frag_threshold;
538 if (frag_th > 255 && frag_th < 7937) {
539 wid_list[i].id = WID_FRAG_THRESHOLD;
540 wid_list[i].val = (s8 *)¶m->frag_threshold;
541 wid_list[i].type = WID_SHORT;
542 wid_list[i].size = sizeof(u16);
543 hif_drv->cfg_values.frag_threshold = frag_th;
545 netdev_err(vif->ndev, "Threshold Range fail\n");
550 if (param->flag & RTS_THRESHOLD) {
551 u16 rts_th = param->rts_threshold;
554 wid_list[i].id = WID_RTS_THRESHOLD;
555 wid_list[i].val = (s8 *)¶m->rts_threshold;
556 wid_list[i].type = WID_SHORT;
557 wid_list[i].size = sizeof(u16);
558 hif_drv->cfg_values.rts_threshold = rts_th;
560 netdev_err(vif->ndev, "Threshold Range fail\n");
565 if (param->flag & PREAMBLE) {
566 u16 preamble_type = param->preamble_type;
568 if (param->preamble_type < 3) {
569 wid_list[i].id = WID_PREAMBLE;
570 wid_list[i].val = (s8 *)¶m->preamble_type;
571 wid_list[i].type = WID_CHAR;
572 wid_list[i].size = sizeof(char);
573 hif_drv->cfg_values.preamble_type = preamble_type;
575 netdev_err(vif->ndev, "Preamble Range(0~2) over\n");
580 if (param->flag & SHORT_SLOT_ALLOWED) {
581 u8 slot_allowed = param->short_slot_allowed;
583 if (slot_allowed < 2) {
584 wid_list[i].id = WID_SHORT_SLOT_ALLOWED;
585 wid_list[i].val = (s8 *)¶m->short_slot_allowed;
586 wid_list[i].type = WID_CHAR;
587 wid_list[i].size = sizeof(char);
588 hif_drv->cfg_values.short_slot_allowed = slot_allowed;
590 netdev_err(vif->ndev, "Short slot(2) over\n");
595 if (param->flag & TXOP_PROT_DISABLE) {
596 u8 prot_disabled = param->txop_prot_disabled;
598 if (param->txop_prot_disabled < 2) {
599 wid_list[i].id = WID_11N_TXOP_PROT_DISABLE;
600 wid_list[i].val = (s8 *)¶m->txop_prot_disabled;
601 wid_list[i].type = WID_CHAR;
602 wid_list[i].size = sizeof(char);
603 hif_drv->cfg_values.txop_prot_disabled = prot_disabled;
605 netdev_err(vif->ndev, "TXOP prot disable\n");
610 if (param->flag & BEACON_INTERVAL) {
611 u16 beacon_interval = param->beacon_interval;
613 if (beacon_interval > 0) {
614 wid_list[i].id = WID_BEACON_INTERVAL;
615 wid_list[i].val = (s8 *)¶m->beacon_interval;
616 wid_list[i].type = WID_SHORT;
617 wid_list[i].size = sizeof(u16);
618 hif_drv->cfg_values.beacon_interval = beacon_interval;
620 netdev_err(vif->ndev, "Beacon interval(1~65535)fail\n");
625 if (param->flag & DTIM_PERIOD) {
626 if (param->dtim_period > 0 && param->dtim_period < 256) {
627 wid_list[i].id = WID_DTIM_PERIOD;
628 wid_list[i].val = (s8 *)¶m->dtim_period;
629 wid_list[i].type = WID_CHAR;
630 wid_list[i].size = sizeof(char);
631 hif_drv->cfg_values.dtim_period = param->dtim_period;
633 netdev_err(vif->ndev, "DTIM range(1~255) fail\n");
638 if (param->flag & SITE_SURVEY) {
639 enum site_survey enabled = param->site_survey_enabled;
642 wid_list[i].id = WID_SITE_SURVEY;
643 wid_list[i].val = (s8 *)¶m->site_survey_enabled;
644 wid_list[i].type = WID_CHAR;
645 wid_list[i].size = sizeof(char);
646 hif_drv->cfg_values.site_survey_enabled = enabled;
648 netdev_err(vif->ndev, "Site survey disable\n");
653 if (param->flag & SITE_SURVEY_SCAN_TIME) {
654 u16 scan_time = param->site_survey_scan_time;
657 wid_list[i].id = WID_SITE_SURVEY_SCAN_TIME;
658 wid_list[i].val = (s8 *)¶m->site_survey_scan_time;
659 wid_list[i].type = WID_SHORT;
660 wid_list[i].size = sizeof(u16);
661 hif_drv->cfg_values.site_survey_scan_time = scan_time;
663 netdev_err(vif->ndev, "Site scan time(1~65535) over\n");
668 if (param->flag & ACTIVE_SCANTIME) {
669 u16 active_scan_time = param->active_scan_time;
671 if (active_scan_time > 0) {
672 wid_list[i].id = WID_ACTIVE_SCAN_TIME;
673 wid_list[i].val = (s8 *)¶m->active_scan_time;
674 wid_list[i].type = WID_SHORT;
675 wid_list[i].size = sizeof(u16);
676 hif_drv->cfg_values.active_scan_time = active_scan_time;
678 netdev_err(vif->ndev, "Active time(1~65535) over\n");
683 if (param->flag & PASSIVE_SCANTIME) {
684 u16 time = param->passive_scan_time;
687 wid_list[i].id = WID_PASSIVE_SCAN_TIME;
688 wid_list[i].val = (s8 *)¶m->passive_scan_time;
689 wid_list[i].type = WID_SHORT;
690 wid_list[i].size = sizeof(u16);
691 hif_drv->cfg_values.passive_scan_time = time;
693 netdev_err(vif->ndev, "Passive time(1~65535) over\n");
698 if (param->flag & CURRENT_TX_RATE) {
699 enum current_tx_rate curr_tx_rate = param->curr_tx_rate;
701 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1 ||
702 curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5 ||
703 curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6 ||
704 curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12 ||
705 curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24 ||
706 curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 ||
707 curr_tx_rate == MBPS_54) {
708 wid_list[i].id = WID_CURRENT_TX_RATE;
709 wid_list[i].val = (s8 *)&curr_tx_rate;
710 wid_list[i].type = WID_SHORT;
711 wid_list[i].size = sizeof(u16);
712 hif_drv->cfg_values.curr_tx_rate = (u8)curr_tx_rate;
714 netdev_err(vif->ndev, "out of TX rate\n");
720 ret = wilc_send_config_pkt(vif, SET_CFG, wid_list,
721 i, wilc_get_vif_idx(vif));
724 netdev_err(vif->ndev, "Error in setting CFG params\n");
727 mutex_unlock(&hif_drv->cfg_values_lock);
731 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
734 u8 abort_running_scan;
736 struct host_if_drv *hif_drv = vif->hif_drv;
737 struct user_scan_req *scan_req;
739 if (evt == SCAN_EVENT_ABORTED) {
740 abort_running_scan = 1;
741 wid.id = WID_ABORT_RUNNING_SCAN;
743 wid.val = (s8 *)&abort_running_scan;
744 wid.size = sizeof(char);
746 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
747 wilc_get_vif_idx(vif));
750 netdev_err(vif->ndev, "Failed to set abort running\n");
756 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
760 scan_req = &hif_drv->usr_scan_req;
761 if (scan_req->scan_result) {
762 scan_req->scan_result(evt, NULL, scan_req->arg, NULL);
763 scan_req->scan_result = NULL;
769 static void handle_scan(struct work_struct *work)
771 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
772 struct wilc_vif *vif = msg->vif;
773 struct scan_attr *scan_info = &msg->body.scan_info;
775 struct wid wid_list[5];
780 u8 *hdn_ntwk_wid_val = NULL;
781 struct host_if_drv *hif_drv = vif->hif_drv;
782 struct hidden_network *hidden_net = &scan_info->hidden_network;
784 hif_drv->usr_scan_req.scan_result = scan_info->result;
785 hif_drv->usr_scan_req.arg = scan_info->arg;
787 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
788 hif_drv->hif_state < HOST_IF_CONNECTED) {
789 netdev_err(vif->ndev, "Already scan\n");
794 if (wilc_optaining_ip || wilc_connecting) {
795 netdev_err(vif->ndev, "Don't do obss scan\n");
800 hif_drv->usr_scan_req.ch_cnt = 0;
802 wid_list[index].id = WID_SSID_PROBE_REQ;
803 wid_list[index].type = WID_STR;
805 for (i = 0; i < hidden_net->n_ssids; i++)
806 valuesize += ((hidden_net->net_info[i].ssid_len) + 1);
807 hdn_ntwk_wid_val = kmalloc(valuesize + 1, GFP_KERNEL);
808 wid_list[index].val = hdn_ntwk_wid_val;
809 if (wid_list[index].val) {
810 buffer = wid_list[index].val;
812 *buffer++ = hidden_net->n_ssids;
814 for (i = 0; i < hidden_net->n_ssids; i++) {
815 *buffer++ = hidden_net->net_info[i].ssid_len;
816 memcpy(buffer, hidden_net->net_info[i].ssid,
817 hidden_net->net_info[i].ssid_len);
818 buffer += hidden_net->net_info[i].ssid_len;
821 wid_list[index].size = (s32)(valuesize + 1);
825 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
826 wid_list[index].type = WID_BIN_DATA;
827 wid_list[index].val = scan_info->ies;
828 wid_list[index].size = scan_info->ies_len;
831 wid_list[index].id = WID_SCAN_TYPE;
832 wid_list[index].type = WID_CHAR;
833 wid_list[index].size = sizeof(char);
834 wid_list[index].val = (s8 *)&scan_info->type;
837 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
838 wid_list[index].type = WID_BIN_DATA;
840 if (scan_info->ch_freq_list &&
841 scan_info->ch_list_len > 0) {
844 for (i = 0; i < scan_info->ch_list_len; i++) {
845 if (scan_info->ch_freq_list[i] > 0)
846 scan_info->ch_freq_list[i] -= 1;
850 wid_list[index].val = scan_info->ch_freq_list;
851 wid_list[index].size = scan_info->ch_list_len;
854 wid_list[index].id = WID_START_SCAN_REQ;
855 wid_list[index].type = WID_CHAR;
856 wid_list[index].size = sizeof(char);
857 wid_list[index].val = (s8 *)&scan_info->src;
860 result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
862 wilc_get_vif_idx(vif));
865 netdev_err(vif->ndev, "Failed to send scan parameters\n");
869 del_timer(&hif_drv->scan_timer);
870 handle_scan_done(vif, SCAN_EVENT_ABORTED);
873 kfree(scan_info->ch_freq_list);
874 scan_info->ch_freq_list = NULL;
876 kfree(scan_info->ies);
877 scan_info->ies = NULL;
878 kfree(scan_info->hidden_network.net_info);
879 scan_info->hidden_network.net_info = NULL;
881 kfree(hdn_ntwk_wid_val);
886 u8 wilc_connected_ssid[6] = {0};
887 static void handle_connect(struct work_struct *work)
889 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
890 struct wilc_vif *vif = msg->vif;
891 struct connect_attr *conn_attr = &msg->body.con_info;
893 struct wid wid_list[8];
894 u32 wid_cnt = 0, dummyval = 0;
896 struct join_bss_param *bss_param;
897 struct host_if_drv *hif_drv = vif->hif_drv;
899 if (msg->vif->hif_drv->usr_scan_req.scan_result) {
900 result = wilc_enqueue_work(msg);
904 usleep_range(2 * 1000, 2 * 1000);
908 if (memcmp(conn_attr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
909 netdev_err(vif->ndev, "Discard connect request\n");
913 bss_param = conn_attr->params;
915 netdev_err(vif->ndev, "Required BSSID not found\n");
920 if (conn_attr->bssid) {
921 hif_drv->usr_conn_req.bssid = kmemdup(conn_attr->bssid, 6,
923 if (!hif_drv->usr_conn_req.bssid) {
929 hif_drv->usr_conn_req.ssid_len = conn_attr->ssid_len;
930 if (conn_attr->ssid) {
931 hif_drv->usr_conn_req.ssid = kmalloc(conn_attr->ssid_len + 1,
933 if (!hif_drv->usr_conn_req.ssid) {
937 memcpy(hif_drv->usr_conn_req.ssid,
939 conn_attr->ssid_len);
940 hif_drv->usr_conn_req.ssid[conn_attr->ssid_len] = '\0';
943 hif_drv->usr_conn_req.ies_len = conn_attr->ies_len;
944 if (conn_attr->ies) {
945 hif_drv->usr_conn_req.ies = kmemdup(conn_attr->ies,
948 if (!hif_drv->usr_conn_req.ies) {
954 hif_drv->usr_conn_req.security = conn_attr->security;
955 hif_drv->usr_conn_req.auth_type = conn_attr->auth_type;
956 hif_drv->usr_conn_req.conn_result = conn_attr->result;
957 hif_drv->usr_conn_req.arg = conn_attr->arg;
959 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
960 wid_list[wid_cnt].type = WID_INT;
961 wid_list[wid_cnt].size = sizeof(u32);
962 wid_list[wid_cnt].val = (s8 *)(&(dummyval));
965 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
966 wid_list[wid_cnt].type = WID_INT;
967 wid_list[wid_cnt].size = sizeof(u32);
968 wid_list[wid_cnt].val = (s8 *)(&(dummyval));
971 wid_list[wid_cnt].id = WID_FAILED_COUNT;
972 wid_list[wid_cnt].type = WID_INT;
973 wid_list[wid_cnt].size = sizeof(u32);
974 wid_list[wid_cnt].val = (s8 *)(&(dummyval));
977 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
978 wid_list[wid_cnt].type = WID_BIN_DATA;
979 wid_list[wid_cnt].val = hif_drv->usr_conn_req.ies;
980 wid_list[wid_cnt].size = hif_drv->usr_conn_req.ies_len;
983 wid_list[wid_cnt].id = WID_11I_MODE;
984 wid_list[wid_cnt].type = WID_CHAR;
985 wid_list[wid_cnt].size = sizeof(char);
986 wid_list[wid_cnt].val = (s8 *)&hif_drv->usr_conn_req.security;
989 wid_list[wid_cnt].id = WID_AUTH_TYPE;
990 wid_list[wid_cnt].type = WID_CHAR;
991 wid_list[wid_cnt].size = sizeof(char);
992 wid_list[wid_cnt].val = (s8 *)&hif_drv->usr_conn_req.auth_type;
995 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
996 wid_list[wid_cnt].type = WID_STR;
997 wid_list[wid_cnt].size = 112;
998 wid_list[wid_cnt].val = kmalloc(wid_list[wid_cnt].size, GFP_KERNEL);
1000 if (!wid_list[wid_cnt].val) {
1005 cur_byte = wid_list[wid_cnt].val;
1007 if (conn_attr->ssid) {
1008 memcpy(cur_byte, conn_attr->ssid, conn_attr->ssid_len);
1009 cur_byte[conn_attr->ssid_len] = '\0';
1011 cur_byte += MAX_SSID_LEN;
1012 *(cur_byte++) = INFRASTRUCTURE;
1014 if (conn_attr->ch >= 1 && conn_attr->ch <= 14) {
1015 *(cur_byte++) = conn_attr->ch;
1017 netdev_err(vif->ndev, "Channel out of range\n");
1018 *(cur_byte++) = 0xFF;
1020 *(cur_byte++) = (bss_param->cap_info) & 0xFF;
1021 *(cur_byte++) = ((bss_param->cap_info) >> 8) & 0xFF;
1023 if (conn_attr->bssid)
1024 memcpy(cur_byte, conn_attr->bssid, 6);
1027 if (conn_attr->bssid)
1028 memcpy(cur_byte, conn_attr->bssid, 6);
1031 *(cur_byte++) = (bss_param->beacon_period) & 0xFF;
1032 *(cur_byte++) = ((bss_param->beacon_period) >> 8) & 0xFF;
1033 *(cur_byte++) = bss_param->dtim_period;
1035 memcpy(cur_byte, bss_param->supp_rates, MAX_RATES_SUPPORTED + 1);
1036 cur_byte += (MAX_RATES_SUPPORTED + 1);
1038 *(cur_byte++) = bss_param->wmm_cap;
1039 *(cur_byte++) = bss_param->uapsd_cap;
1041 *(cur_byte++) = bss_param->ht_capable;
1042 hif_drv->usr_conn_req.ht_capable = bss_param->ht_capable;
1044 *(cur_byte++) = bss_param->rsn_found;
1045 *(cur_byte++) = bss_param->rsn_grp_policy;
1046 *(cur_byte++) = bss_param->mode_802_11i;
1048 memcpy(cur_byte, bss_param->rsn_pcip_policy,
1049 sizeof(bss_param->rsn_pcip_policy));
1050 cur_byte += sizeof(bss_param->rsn_pcip_policy);
1052 memcpy(cur_byte, bss_param->rsn_auth_policy,
1053 sizeof(bss_param->rsn_auth_policy));
1054 cur_byte += sizeof(bss_param->rsn_auth_policy);
1056 memcpy(cur_byte, bss_param->rsn_cap, sizeof(bss_param->rsn_cap));
1057 cur_byte += sizeof(bss_param->rsn_cap);
1059 *(cur_byte++) = REAL_JOIN_REQ;
1060 *(cur_byte++) = bss_param->noa_enabled;
1062 if (bss_param->noa_enabled) {
1063 *(cur_byte++) = (bss_param->tsf) & 0xFF;
1064 *(cur_byte++) = ((bss_param->tsf) >> 8) & 0xFF;
1065 *(cur_byte++) = ((bss_param->tsf) >> 16) & 0xFF;
1066 *(cur_byte++) = ((bss_param->tsf) >> 24) & 0xFF;
1068 *(cur_byte++) = bss_param->opp_enabled;
1069 *(cur_byte++) = bss_param->idx;
1071 if (bss_param->opp_enabled)
1072 *(cur_byte++) = bss_param->ct_window;
1074 *(cur_byte++) = bss_param->cnt;
1076 memcpy(cur_byte, bss_param->duration,
1077 sizeof(bss_param->duration));
1078 cur_byte += sizeof(bss_param->duration);
1080 memcpy(cur_byte, bss_param->interval,
1081 sizeof(bss_param->interval));
1082 cur_byte += sizeof(bss_param->interval);
1084 memcpy(cur_byte, bss_param->start_time,
1085 sizeof(bss_param->start_time));
1086 cur_byte += sizeof(bss_param->start_time);
1089 cur_byte = wid_list[wid_cnt].val;
1092 if (conn_attr->bssid)
1093 memcpy(wilc_connected_ssid,
1094 conn_attr->bssid, ETH_ALEN);
1096 result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
1098 wilc_get_vif_idx(vif));
1100 netdev_err(vif->ndev, "failed to send config packet\n");
1104 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
1109 struct connect_info conn_info;
1111 del_timer(&hif_drv->connect_timer);
1113 memset(&conn_info, 0, sizeof(struct connect_info));
1115 if (conn_attr->result) {
1116 if (conn_attr->bssid)
1117 memcpy(conn_info.bssid, conn_attr->bssid, 6);
1119 if (conn_attr->ies) {
1120 conn_info.req_ies_len = conn_attr->ies_len;
1121 conn_info.req_ies = kmalloc(conn_attr->ies_len,
1123 memcpy(conn_info.req_ies,
1125 conn_attr->ies_len);
1128 conn_attr->result(CONN_DISCONN_EVENT_CONN_RESP,
1129 &conn_info, MAC_STATUS_DISCONNECTED,
1130 NULL, conn_attr->arg);
1131 hif_drv->hif_state = HOST_IF_IDLE;
1132 kfree(conn_info.req_ies);
1133 conn_info.req_ies = NULL;
1136 netdev_err(vif->ndev, "Connect callback is NULL\n");
1140 kfree(conn_attr->bssid);
1141 conn_attr->bssid = NULL;
1143 kfree(conn_attr->ssid);
1144 conn_attr->ssid = NULL;
1146 kfree(conn_attr->ies);
1147 conn_attr->ies = NULL;
1153 static void handle_connect_timeout(struct work_struct *work)
1155 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1156 struct wilc_vif *vif = msg->vif;
1158 struct connect_info info;
1160 u16 dummy_reason_code = 0;
1161 struct host_if_drv *hif_drv = vif->hif_drv;
1164 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
1168 hif_drv->hif_state = HOST_IF_IDLE;
1170 memset(&info, 0, sizeof(struct connect_info));
1172 if (hif_drv->usr_conn_req.conn_result) {
1173 if (hif_drv->usr_conn_req.bssid) {
1175 hif_drv->usr_conn_req.bssid, 6);
1178 if (hif_drv->usr_conn_req.ies) {
1179 info.req_ies_len = hif_drv->usr_conn_req.ies_len;
1180 info.req_ies = kmemdup(hif_drv->usr_conn_req.ies,
1181 hif_drv->usr_conn_req.ies_len,
1187 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1189 MAC_STATUS_DISCONNECTED,
1191 hif_drv->usr_conn_req.arg);
1193 kfree(info.req_ies);
1194 info.req_ies = NULL;
1196 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1199 wid.id = WID_DISCONNECT;
1200 wid.type = WID_CHAR;
1201 wid.val = (s8 *)&dummy_reason_code;
1202 wid.size = sizeof(char);
1204 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1205 wilc_get_vif_idx(vif));
1207 netdev_err(vif->ndev, "Failed to send disconnect\n");
1209 hif_drv->usr_conn_req.ssid_len = 0;
1210 kfree(hif_drv->usr_conn_req.ssid);
1211 hif_drv->usr_conn_req.ssid = NULL;
1212 kfree(hif_drv->usr_conn_req.bssid);
1213 hif_drv->usr_conn_req.bssid = NULL;
1214 hif_drv->usr_conn_req.ies_len = 0;
1215 kfree(hif_drv->usr_conn_req.ies);
1216 hif_drv->usr_conn_req.ies = NULL;
1218 eth_zero_addr(wilc_connected_ssid);
1224 static void host_int_fill_join_bss_param(struct join_bss_param *param, u8 *ies,
1225 u16 *out_index, u8 *pcipher_tc,
1226 u8 *auth_total_cnt, u32 tsf_lo,
1234 u16 index = *out_index;
1236 if (ies[index] == WLAN_EID_SUPP_RATES) {
1237 *rates_no = ies[index + 1];
1238 param->supp_rates[0] = *rates_no;
1241 for (i = 0; i < *rates_no; i++)
1242 param->supp_rates[i + 1] = ies[index + i];
1245 } else if (ies[index] == WLAN_EID_EXT_SUPP_RATES) {
1246 ext_rates_no = ies[index + 1];
1247 if (ext_rates_no > (MAX_RATES_SUPPORTED - *rates_no))
1248 param->supp_rates[0] = MAX_RATES_SUPPORTED;
1250 param->supp_rates[0] += ext_rates_no;
1252 for (i = 0; i < (param->supp_rates[0] - *rates_no); i++)
1253 param->supp_rates[*rates_no + i + 1] = ies[index + i];
1255 index += ext_rates_no;
1256 } else if (ies[index] == WLAN_EID_HT_CAPABILITY) {
1257 param->ht_capable = true;
1258 index += ies[index + 1] + 2;
1259 } else if ((ies[index] == WLAN_EID_VENDOR_SPECIFIC) &&
1260 (ies[index + 2] == 0x00) && (ies[index + 3] == 0x50) &&
1261 (ies[index + 4] == 0xF2) && (ies[index + 5] == 0x02) &&
1262 ((ies[index + 6] == 0x00) || (ies[index + 6] == 0x01)) &&
1263 (ies[index + 7] == 0x01)) {
1264 param->wmm_cap = true;
1266 if (ies[index + 8] & BIT(7))
1267 param->uapsd_cap = true;
1268 index += ies[index + 1] + 2;
1269 } else if ((ies[index] == WLAN_EID_VENDOR_SPECIFIC) &&
1270 (ies[index + 2] == 0x50) && (ies[index + 3] == 0x6f) &&
1271 (ies[index + 4] == 0x9a) &&
1272 (ies[index + 5] == 0x09) && (ies[index + 6] == 0x0c)) {
1275 param->tsf = tsf_lo;
1276 param->noa_enabled = 1;
1277 param->idx = ies[index + 9];
1279 if (ies[index + 10] & BIT(7)) {
1280 param->opp_enabled = 1;
1281 param->ct_window = ies[index + 10];
1283 param->opp_enabled = 0;
1286 param->cnt = ies[index + 11];
1287 p2p_cnt = index + 12;
1289 memcpy(param->duration, ies + p2p_cnt, 4);
1292 memcpy(param->interval, ies + p2p_cnt, 4);
1295 memcpy(param->start_time, ies + p2p_cnt, 4);
1297 index += ies[index + 1] + 2;
1298 } else if ((ies[index] == WLAN_EID_RSN) ||
1299 ((ies[index] == WLAN_EID_VENDOR_SPECIFIC) &&
1300 (ies[index + 2] == 0x00) &&
1301 (ies[index + 3] == 0x50) && (ies[index + 4] == 0xF2) &&
1302 (ies[index + 5] == 0x01))) {
1303 u16 rsn_idx = index;
1305 if (ies[rsn_idx] == WLAN_EID_RSN) {
1306 param->mode_802_11i = 2;
1308 if (param->mode_802_11i == 0)
1309 param->mode_802_11i = 1;
1314 param->rsn_grp_policy = ies[rsn_idx];
1316 offset = ies[rsn_idx] * 4;
1317 pcipher_cnt = (ies[rsn_idx] > 3) ? 3 : ies[rsn_idx];
1322 for (; i < (pcipher_cnt + *pcipher_tc) && i < 3; i++, j++) {
1323 u8 *policy = ¶m->rsn_pcip_policy[i];
1325 *policy = ies[rsn_idx + ((j + 1) * 4) - 1];
1328 *pcipher_tc += pcipher_cnt;
1331 offset = ies[rsn_idx] * 4;
1333 auth_cnt = (ies[rsn_idx] > 3) ? 3 : ies[rsn_idx];
1335 i = *auth_total_cnt;
1337 for (; i < (*auth_total_cnt + auth_cnt); i++, j++) {
1338 u8 *policy = ¶m->rsn_auth_policy[i];
1340 *policy = ies[rsn_idx + ((j + 1) * 4) - 1];
1343 *auth_total_cnt += auth_cnt;
1346 if (ies[index] == WLAN_EID_RSN) {
1347 param->rsn_cap[0] = ies[rsn_idx];
1348 param->rsn_cap[1] = ies[rsn_idx + 1];
1351 param->rsn_found = true;
1352 index += ies[index + 1] + 2;
1354 index += ies[index + 1] + 2;
1360 static void *host_int_parse_join_bss_param(struct network_info *info)
1362 struct join_bss_param *param;
1365 u8 pcipher_total_cnt = 0;
1366 u8 auth_total_cnt = 0;
1368 param = kzalloc(sizeof(*param), GFP_KERNEL);
1372 param->dtim_period = info->dtim_period;
1373 param->beacon_period = info->beacon_period;
1374 param->cap_info = info->cap_info;
1375 memcpy(param->bssid, info->bssid, 6);
1376 memcpy((u8 *)param->ssid, info->ssid, info->ssid_len + 1);
1377 param->ssid_len = info->ssid_len;
1378 memset(param->rsn_pcip_policy, 0xFF, 3);
1379 memset(param->rsn_auth_policy, 0xFF, 3);
1381 while (index < info->ies_len)
1382 host_int_fill_join_bss_param(param, info->ies, &index,
1384 &auth_total_cnt, info->tsf_lo,
1387 return (void *)param;
1390 static void handle_rcvd_ntwrk_info(struct work_struct *work)
1392 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1393 struct wilc_vif *vif = msg->vif;
1394 struct rcvd_net_info *rcvd_info = &msg->body.net_info;
1397 struct network_info *info = NULL;
1399 struct host_if_drv *hif_drv = vif->hif_drv;
1400 struct user_scan_req *scan_req = &hif_drv->usr_scan_req;
1404 if (!scan_req->scan_result)
1407 wilc_parse_network_info(rcvd_info->buffer, &info);
1408 if (!info || !scan_req->scan_result) {
1409 netdev_err(vif->ndev, "%s: info or scan result NULL\n",
1414 for (i = 0; i < scan_req->ch_cnt; i++) {
1415 if (memcmp(scan_req->net_info[i].bssid, info->bssid, 6) == 0) {
1416 if (info->rssi <= scan_req->net_info[i].rssi) {
1419 scan_req->net_info[i].rssi = info->rssi;
1427 if (scan_req->ch_cnt < MAX_NUM_SCANNED_NETWORKS) {
1428 scan_req->net_info[scan_req->ch_cnt].rssi = info->rssi;
1430 memcpy(scan_req->net_info[scan_req->ch_cnt].bssid,
1435 info->new_network = true;
1436 params = host_int_parse_join_bss_param(info);
1438 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, info,
1439 scan_req->arg, params);
1442 info->new_network = false;
1443 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, info,
1444 scan_req->arg, NULL);
1448 kfree(rcvd_info->buffer);
1449 rcvd_info->buffer = NULL;
1459 static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
1460 u8 *assoc_resp_info,
1461 u32 max_assoc_resp_info_len,
1462 u32 *rcvd_assoc_resp_info_len)
1467 wid.id = WID_ASSOC_RES_INFO;
1469 wid.val = assoc_resp_info;
1470 wid.size = max_assoc_resp_info_len;
1472 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
1473 wilc_get_vif_idx(vif));
1475 *rcvd_assoc_resp_info_len = 0;
1476 netdev_err(vif->ndev, "Failed to send association response\n");
1480 *rcvd_assoc_resp_info_len = wid.size;
1484 static inline void host_int_free_user_conn_req(struct host_if_drv *hif_drv)
1486 hif_drv->usr_conn_req.ssid_len = 0;
1487 kfree(hif_drv->usr_conn_req.ssid);
1488 hif_drv->usr_conn_req.ssid = NULL;
1489 kfree(hif_drv->usr_conn_req.bssid);
1490 hif_drv->usr_conn_req.bssid = NULL;
1491 hif_drv->usr_conn_req.ies_len = 0;
1492 kfree(hif_drv->usr_conn_req.ies);
1493 hif_drv->usr_conn_req.ies = NULL;
1496 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
1499 struct connect_info conn_info;
1500 struct host_if_drv *hif_drv = vif->hif_drv;
1502 memset(&conn_info, 0, sizeof(struct connect_info));
1504 if (mac_status == MAC_STATUS_CONNECTED) {
1505 u32 assoc_resp_info_len;
1507 memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1509 host_int_get_assoc_res_info(vif, rcv_assoc_resp,
1510 MAX_ASSOC_RESP_FRAME_SIZE,
1511 &assoc_resp_info_len);
1513 if (assoc_resp_info_len != 0) {
1516 err = wilc_parse_assoc_resp_info(rcv_assoc_resp,
1517 assoc_resp_info_len,
1520 netdev_err(vif->ndev,
1521 "wilc_parse_assoc_resp_info() returned error %d\n",
1526 if (mac_status == MAC_STATUS_CONNECTED &&
1527 conn_info.status != WLAN_STATUS_SUCCESS) {
1528 netdev_err(vif->ndev,
1529 "Received MAC status is MAC_STATUS_CONNECTED, Assoc Resp is not SUCCESS\n");
1530 eth_zero_addr(wilc_connected_ssid);
1531 } else if (mac_status == MAC_STATUS_DISCONNECTED) {
1532 netdev_err(vif->ndev, "Received MAC status is MAC_STATUS_DISCONNECTED\n");
1533 eth_zero_addr(wilc_connected_ssid);
1536 if (hif_drv->usr_conn_req.bssid) {
1537 memcpy(conn_info.bssid, hif_drv->usr_conn_req.bssid, 6);
1539 if (mac_status == MAC_STATUS_CONNECTED &&
1540 conn_info.status == WLAN_STATUS_SUCCESS) {
1541 memcpy(hif_drv->assoc_bssid,
1542 hif_drv->usr_conn_req.bssid, ETH_ALEN);
1546 if (hif_drv->usr_conn_req.ies) {
1547 conn_info.req_ies = kmemdup(hif_drv->usr_conn_req.ies,
1548 hif_drv->usr_conn_req.ies_len,
1550 if (conn_info.req_ies)
1551 conn_info.req_ies_len = hif_drv->usr_conn_req.ies_len;
1554 del_timer(&hif_drv->connect_timer);
1555 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1556 &conn_info, mac_status, NULL,
1557 hif_drv->usr_conn_req.arg);
1559 if (mac_status == MAC_STATUS_CONNECTED &&
1560 conn_info.status == WLAN_STATUS_SUCCESS) {
1561 wilc_set_power_mgmt(vif, 0, 0);
1563 hif_drv->hif_state = HOST_IF_CONNECTED;
1565 wilc_optaining_ip = true;
1566 mod_timer(&wilc_during_ip_timer,
1567 jiffies + msecs_to_jiffies(10000));
1569 hif_drv->hif_state = HOST_IF_IDLE;
1572 kfree(conn_info.resp_ies);
1573 conn_info.resp_ies = NULL;
1575 kfree(conn_info.req_ies);
1576 conn_info.req_ies = NULL;
1577 host_int_free_user_conn_req(hif_drv);
1580 static inline void host_int_handle_disconnect(struct wilc_vif *vif)
1582 struct disconnect_info disconn_info;
1583 struct host_if_drv *hif_drv = vif->hif_drv;
1584 wilc_connect_result conn_result = hif_drv->usr_conn_req.conn_result;
1586 memset(&disconn_info, 0, sizeof(struct disconnect_info));
1588 if (hif_drv->usr_scan_req.scan_result) {
1589 del_timer(&hif_drv->scan_timer);
1590 handle_scan_done(vif, SCAN_EVENT_ABORTED);
1593 disconn_info.reason = 0;
1594 disconn_info.ie = NULL;
1595 disconn_info.ie_len = 0;
1598 wilc_optaining_ip = false;
1599 wilc_set_power_mgmt(vif, 0, 0);
1601 conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 0,
1602 &disconn_info, hif_drv->usr_conn_req.arg);
1604 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1607 eth_zero_addr(hif_drv->assoc_bssid);
1609 host_int_free_user_conn_req(hif_drv);
1610 hif_drv->hif_state = HOST_IF_IDLE;
1613 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
1615 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1616 struct wilc_vif *vif = msg->vif;
1617 struct rcvd_async_info *rcvd_info = &msg->body.async_info;
1620 struct host_if_drv *hif_drv = vif->hif_drv;
1622 if (!rcvd_info->buffer) {
1623 netdev_err(vif->ndev, "%s: buffer is NULL\n", __func__);
1628 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
1629 goto free_rcvd_info;
1632 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
1633 hif_drv->hif_state == HOST_IF_CONNECTED ||
1634 hif_drv->usr_scan_req.scan_result) {
1635 if (!hif_drv->usr_conn_req.conn_result) {
1636 netdev_err(vif->ndev, "%s: conn_result is NULL\n",
1638 goto free_rcvd_info;
1641 msg_type = rcvd_info->buffer[0];
1643 if ('I' != msg_type) {
1644 netdev_err(vif->ndev, "Received Message incorrect.\n");
1645 goto free_rcvd_info;
1648 mac_status = rcvd_info->buffer[7];
1649 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
1650 host_int_parse_assoc_resp_info(vif, mac_status);
1651 } else if ((mac_status == MAC_STATUS_DISCONNECTED) &&
1652 (hif_drv->hif_state == HOST_IF_CONNECTED)) {
1653 host_int_handle_disconnect(vif);
1654 } else if ((mac_status == MAC_STATUS_DISCONNECTED) &&
1655 (hif_drv->usr_scan_req.scan_result)) {
1656 del_timer(&hif_drv->scan_timer);
1657 if (hif_drv->usr_scan_req.scan_result)
1658 handle_scan_done(vif, SCAN_EVENT_ABORTED);
1663 kfree(rcvd_info->buffer);
1664 rcvd_info->buffer = NULL;
1670 static int wilc_pmksa_key_copy(struct wilc_vif *vif, struct key_attr *hif_key)
1677 key_buf = kmalloc((hif_key->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1,
1682 key_buf[0] = hif_key->attr.pmkid.numpmkid;
1684 for (i = 0; i < hif_key->attr.pmkid.numpmkid; i++) {
1685 memcpy(key_buf + ((PMKSA_KEY_LEN * i) + 1),
1686 hif_key->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
1687 memcpy(key_buf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1),
1688 hif_key->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
1691 wid.id = WID_PMKID_INFO;
1693 wid.val = (s8 *)key_buf;
1694 wid.size = (hif_key->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
1696 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1697 wilc_get_vif_idx(vif));
1704 static void handle_key(struct work_struct *work)
1706 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1707 struct wilc_vif *vif = msg->vif;
1708 struct key_attr *hif_key = &msg->body.key_info;
1711 struct wid wid_list[5];
1713 struct host_if_drv *hif_drv = vif->hif_drv;
1715 switch (hif_key->type) {
1718 if (hif_key->action & ADDKEY_AP) {
1719 wid_list[0].id = WID_11I_MODE;
1720 wid_list[0].type = WID_CHAR;
1721 wid_list[0].size = sizeof(char);
1722 wid_list[0].val = (s8 *)&hif_key->attr.wep.mode;
1724 wid_list[1].id = WID_AUTH_TYPE;
1725 wid_list[1].type = WID_CHAR;
1726 wid_list[1].size = sizeof(char);
1727 wid_list[1].val = (s8 *)&hif_key->attr.wep.auth_type;
1729 key_buf = kmalloc(hif_key->attr.wep.key_len + 2,
1736 key_buf[0] = hif_key->attr.wep.index;
1737 key_buf[1] = hif_key->attr.wep.key_len;
1739 memcpy(&key_buf[2], hif_key->attr.wep.key,
1740 hif_key->attr.wep.key_len);
1742 wid_list[2].id = WID_WEP_KEY_VALUE;
1743 wid_list[2].type = WID_STR;
1744 wid_list[2].size = hif_key->attr.wep.key_len + 2;
1745 wid_list[2].val = (s8 *)key_buf;
1747 result = wilc_send_config_pkt(vif, SET_CFG,
1749 wilc_get_vif_idx(vif));
1751 } else if (hif_key->action & ADDKEY) {
1752 key_buf = kmalloc(hif_key->attr.wep.key_len + 2,
1758 key_buf[0] = hif_key->attr.wep.index;
1759 memcpy(key_buf + 1, &hif_key->attr.wep.key_len, 1);
1760 memcpy(key_buf + 2, hif_key->attr.wep.key,
1761 hif_key->attr.wep.key_len);
1763 wid.id = WID_ADD_WEP_KEY;
1765 wid.val = (s8 *)key_buf;
1766 wid.size = hif_key->attr.wep.key_len + 2;
1768 result = wilc_send_config_pkt(vif, SET_CFG,
1770 wilc_get_vif_idx(vif));
1772 } else if (hif_key->action & REMOVEKEY) {
1773 wid.id = WID_REMOVE_WEP_KEY;
1776 wid.val = (s8 *)&hif_key->attr.wep.index;
1779 result = wilc_send_config_pkt(vif, SET_CFG,
1781 wilc_get_vif_idx(vif));
1782 } else if (hif_key->action & DEFAULTKEY) {
1783 wid.id = WID_KEY_ID;
1784 wid.type = WID_CHAR;
1785 wid.val = (s8 *)&hif_key->attr.wep.index;
1786 wid.size = sizeof(char);
1788 result = wilc_send_config_pkt(vif, SET_CFG,
1790 wilc_get_vif_idx(vif));
1793 complete(&msg->work_comp);
1797 if (hif_key->action & ADDKEY_AP) {
1798 key_buf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1801 goto out_wpa_rx_gtk;
1804 if (hif_key->attr.wpa.seq)
1805 memcpy(key_buf + 6, hif_key->attr.wpa.seq, 8);
1807 memcpy(key_buf + 14, &hif_key->attr.wpa.index, 1);
1808 memcpy(key_buf + 15, &hif_key->attr.wpa.key_len, 1);
1809 memcpy(key_buf + 16, hif_key->attr.wpa.key,
1810 hif_key->attr.wpa.key_len);
1812 wid_list[0].id = WID_11I_MODE;
1813 wid_list[0].type = WID_CHAR;
1814 wid_list[0].size = sizeof(char);
1815 wid_list[0].val = (s8 *)&hif_key->attr.wpa.mode;
1817 wid_list[1].id = WID_ADD_RX_GTK;
1818 wid_list[1].type = WID_STR;
1819 wid_list[1].val = (s8 *)key_buf;
1820 wid_list[1].size = RX_MIC_KEY_MSG_LEN;
1822 result = wilc_send_config_pkt(vif, SET_CFG,
1824 wilc_get_vif_idx(vif));
1827 } else if (hif_key->action & ADDKEY) {
1828 key_buf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1831 goto out_wpa_rx_gtk;
1834 if (hif_drv->hif_state == HOST_IF_CONNECTED)
1835 memcpy(key_buf, hif_drv->assoc_bssid, ETH_ALEN);
1837 netdev_err(vif->ndev, "Couldn't handle\n");
1839 memcpy(key_buf + 6, hif_key->attr.wpa.seq, 8);
1840 memcpy(key_buf + 14, &hif_key->attr.wpa.index, 1);
1841 memcpy(key_buf + 15, &hif_key->attr.wpa.key_len, 1);
1842 memcpy(key_buf + 16, hif_key->attr.wpa.key,
1843 hif_key->attr.wpa.key_len);
1845 wid.id = WID_ADD_RX_GTK;
1847 wid.val = (s8 *)key_buf;
1848 wid.size = RX_MIC_KEY_MSG_LEN;
1850 result = wilc_send_config_pkt(vif, SET_CFG,
1852 wilc_get_vif_idx(vif));
1857 complete(&msg->work_comp);
1861 if (hif_key->action & ADDKEY_AP) {
1862 key_buf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1868 memcpy(key_buf, hif_key->attr.wpa.mac_addr, 6);
1869 memcpy(key_buf + 6, &hif_key->attr.wpa.index, 1);
1870 memcpy(key_buf + 7, &hif_key->attr.wpa.key_len, 1);
1871 memcpy(key_buf + 8, hif_key->attr.wpa.key,
1872 hif_key->attr.wpa.key_len);
1874 wid_list[0].id = WID_11I_MODE;
1875 wid_list[0].type = WID_CHAR;
1876 wid_list[0].size = sizeof(char);
1877 wid_list[0].val = (s8 *)&hif_key->attr.wpa.mode;
1879 wid_list[1].id = WID_ADD_PTK;
1880 wid_list[1].type = WID_STR;
1881 wid_list[1].val = (s8 *)key_buf;
1882 wid_list[1].size = PTK_KEY_MSG_LEN + 1;
1884 result = wilc_send_config_pkt(vif, SET_CFG,
1886 wilc_get_vif_idx(vif));
1888 } else if (hif_key->action & ADDKEY) {
1889 key_buf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1895 memcpy(key_buf, hif_key->attr.wpa.mac_addr, 6);
1896 memcpy(key_buf + 6, &hif_key->attr.wpa.key_len, 1);
1897 memcpy(key_buf + 7, hif_key->attr.wpa.key,
1898 hif_key->attr.wpa.key_len);
1900 wid.id = WID_ADD_PTK;
1902 wid.val = (s8 *)key_buf;
1903 wid.size = PTK_KEY_MSG_LEN;
1905 result = wilc_send_config_pkt(vif, SET_CFG,
1907 wilc_get_vif_idx(vif));
1912 complete(&msg->work_comp);
1916 result = wilc_pmksa_key_copy(vif, hif_key);
1917 /*free 'msg', this case it not a sync call*/
1923 netdev_err(vif->ndev, "Failed to send key config packet\n");
1925 /* free 'msg' data in caller sync call */
1928 static void handle_disconnect(struct work_struct *work)
1930 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1931 struct wilc_vif *vif = msg->vif;
1933 struct host_if_drv *hif_drv = vif->hif_drv;
1934 struct disconnect_info disconn_info;
1935 struct user_scan_req *scan_req;
1936 struct user_conn_req *conn_req;
1938 u16 dummy_reason_code = 0;
1940 wid.id = WID_DISCONNECT;
1941 wid.type = WID_CHAR;
1942 wid.val = (s8 *)&dummy_reason_code;
1943 wid.size = sizeof(char);
1945 wilc_optaining_ip = false;
1946 wilc_set_power_mgmt(vif, 0, 0);
1948 eth_zero_addr(wilc_connected_ssid);
1950 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1951 wilc_get_vif_idx(vif));
1954 netdev_err(vif->ndev, "Failed to send dissconect\n");
1958 memset(&disconn_info, 0, sizeof(struct disconnect_info));
1960 disconn_info.reason = 0;
1961 disconn_info.ie = NULL;
1962 disconn_info.ie_len = 0;
1963 scan_req = &hif_drv->usr_scan_req;
1964 conn_req = &hif_drv->usr_conn_req;
1966 if (scan_req->scan_result) {
1967 del_timer(&hif_drv->scan_timer);
1968 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg,
1970 scan_req->scan_result = NULL;
1973 if (conn_req->conn_result) {
1974 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
1975 del_timer(&hif_drv->connect_timer);
1977 conn_req->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
1978 0, &disconn_info, conn_req->arg);
1980 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1983 hif_drv->hif_state = HOST_IF_IDLE;
1985 eth_zero_addr(hif_drv->assoc_bssid);
1987 conn_req->ssid_len = 0;
1988 kfree(conn_req->ssid);
1989 conn_req->ssid = NULL;
1990 kfree(conn_req->bssid);
1991 conn_req->bssid = NULL;
1992 conn_req->ies_len = 0;
1993 kfree(conn_req->ies);
1994 conn_req->ies = NULL;
1998 complete(&msg->work_comp);
1999 /* free 'msg' in caller after receiving completion */
2002 void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
2006 if (vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
2007 vif->hif_drv->hif_state == HOST_IF_CONNECTING)
2008 wilc_disconnect(vif, 1);
2011 static void handle_get_rssi(struct work_struct *work)
2013 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2014 struct wilc_vif *vif = msg->vif;
2019 wid.type = WID_CHAR;
2020 wid.val = msg->body.data;
2021 wid.size = sizeof(char);
2023 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2024 wilc_get_vif_idx(vif));
2026 netdev_err(vif->ndev, "Failed to get RSSI value\n");
2028 complete(&msg->work_comp);
2029 /* free 'msg' data in caller */
2032 static void handle_get_statistics(struct work_struct *work)
2034 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2035 struct wilc_vif *vif = msg->vif;
2036 struct wid wid_list[5];
2037 u32 wid_cnt = 0, result;
2038 struct rf_info *stats = (struct rf_info *)msg->body.data;
2040 wid_list[wid_cnt].id = WID_LINKSPEED;
2041 wid_list[wid_cnt].type = WID_CHAR;
2042 wid_list[wid_cnt].size = sizeof(char);
2043 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
2046 wid_list[wid_cnt].id = WID_RSSI;
2047 wid_list[wid_cnt].type = WID_CHAR;
2048 wid_list[wid_cnt].size = sizeof(char);
2049 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
2052 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
2053 wid_list[wid_cnt].type = WID_INT;
2054 wid_list[wid_cnt].size = sizeof(u32);
2055 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
2058 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
2059 wid_list[wid_cnt].type = WID_INT;
2060 wid_list[wid_cnt].size = sizeof(u32);
2061 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
2064 wid_list[wid_cnt].id = WID_FAILED_COUNT;
2065 wid_list[wid_cnt].type = WID_INT;
2066 wid_list[wid_cnt].size = sizeof(u32);
2067 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
2070 result = wilc_send_config_pkt(vif, GET_CFG, wid_list,
2072 wilc_get_vif_idx(vif));
2075 netdev_err(vif->ndev, "Failed to send scan parameters\n");
2077 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
2078 stats->link_speed != DEFAULT_LINK_SPEED)
2079 wilc_enable_tcp_ack_filter(true);
2080 else if (stats->link_speed != DEFAULT_LINK_SPEED)
2081 wilc_enable_tcp_ack_filter(false);
2083 /* free 'msg' for async command, for sync caller will free it */
2085 complete(&msg->work_comp);
2090 static void handle_get_inactive_time(struct work_struct *work)
2092 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2093 struct wilc_vif *vif = msg->vif;
2094 struct sta_inactive_t *hif_sta_inactive = &msg->body.mac_info;
2098 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
2100 wid.size = ETH_ALEN;
2101 wid.val = kmalloc(wid.size, GFP_KERNEL);
2105 ether_addr_copy(wid.val, hif_sta_inactive->mac);
2107 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2108 wilc_get_vif_idx(vif));
2112 netdev_err(vif->ndev, "Failed to set inactive mac\n");
2116 wid.id = WID_GET_INACTIVE_TIME;
2118 wid.val = (s8 *)&hif_sta_inactive->inactive_time;
2119 wid.size = sizeof(u32);
2121 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2122 wilc_get_vif_idx(vif));
2125 netdev_err(vif->ndev, "Failed to get inactive time\n");
2128 /* free 'msg' data in caller */
2129 complete(&msg->work_comp);
2132 static void handle_add_beacon(struct work_struct *work)
2134 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2135 struct wilc_vif *vif = msg->vif;
2136 struct beacon_attr *param = &msg->body.beacon_info;
2141 wid.id = WID_ADD_BEACON;
2143 wid.size = param->head_len + param->tail_len + 16;
2144 wid.val = kmalloc(wid.size, GFP_KERNEL);
2149 *cur_byte++ = (param->interval & 0xFF);
2150 *cur_byte++ = ((param->interval >> 8) & 0xFF);
2151 *cur_byte++ = ((param->interval >> 16) & 0xFF);
2152 *cur_byte++ = ((param->interval >> 24) & 0xFF);
2154 *cur_byte++ = (param->dtim_period & 0xFF);
2155 *cur_byte++ = ((param->dtim_period >> 8) & 0xFF);
2156 *cur_byte++ = ((param->dtim_period >> 16) & 0xFF);
2157 *cur_byte++ = ((param->dtim_period >> 24) & 0xFF);
2159 *cur_byte++ = (param->head_len & 0xFF);
2160 *cur_byte++ = ((param->head_len >> 8) & 0xFF);
2161 *cur_byte++ = ((param->head_len >> 16) & 0xFF);
2162 *cur_byte++ = ((param->head_len >> 24) & 0xFF);
2164 memcpy(cur_byte, param->head, param->head_len);
2165 cur_byte += param->head_len;
2167 *cur_byte++ = (param->tail_len & 0xFF);
2168 *cur_byte++ = ((param->tail_len >> 8) & 0xFF);
2169 *cur_byte++ = ((param->tail_len >> 16) & 0xFF);
2170 *cur_byte++ = ((param->tail_len >> 24) & 0xFF);
2173 memcpy(cur_byte, param->tail, param->tail_len);
2174 cur_byte += param->tail_len;
2176 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2177 wilc_get_vif_idx(vif));
2179 netdev_err(vif->ndev, "Failed to send add beacon\n");
2188 static void handle_del_beacon(struct work_struct *work)
2190 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2191 struct wilc_vif *vif = msg->vif;
2196 wid.id = WID_DEL_BEACON;
2197 wid.type = WID_CHAR;
2198 wid.size = sizeof(char);
2199 wid.val = &del_beacon;
2201 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2202 wilc_get_vif_idx(vif));
2204 netdev_err(vif->ndev, "Failed to send delete beacon\n");
2208 static u32 wilc_hif_pack_sta_param(u8 *buff, struct add_sta_param *param)
2214 memcpy(cur_byte, param->bssid, ETH_ALEN);
2215 cur_byte += ETH_ALEN;
2217 *cur_byte++ = param->aid & 0xFF;
2218 *cur_byte++ = (param->aid >> 8) & 0xFF;
2220 *cur_byte++ = param->rates_len;
2221 if (param->rates_len > 0)
2222 memcpy(cur_byte, param->rates, param->rates_len);
2223 cur_byte += param->rates_len;
2225 *cur_byte++ = param->ht_supported;
2226 memcpy(cur_byte, ¶m->ht_capa, sizeof(struct ieee80211_ht_cap));
2227 cur_byte += sizeof(struct ieee80211_ht_cap);
2229 *cur_byte++ = param->flags_mask & 0xFF;
2230 *cur_byte++ = (param->flags_mask >> 8) & 0xFF;
2232 *cur_byte++ = param->flags_set & 0xFF;
2233 *cur_byte++ = (param->flags_set >> 8) & 0xFF;
2235 return cur_byte - buff;
2238 static void handle_add_station(struct work_struct *work)
2240 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2241 struct wilc_vif *vif = msg->vif;
2242 struct add_sta_param *param = &msg->body.add_sta_info;
2247 wid.id = WID_ADD_STA;
2249 wid.size = WILC_ADD_STA_LENGTH + param->rates_len;
2251 wid.val = kmalloc(wid.size, GFP_KERNEL);
2256 cur_byte += wilc_hif_pack_sta_param(cur_byte, param);
2258 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2259 wilc_get_vif_idx(vif));
2261 netdev_err(vif->ndev, "Failed to send add station\n");
2264 kfree(param->rates);
2269 static void handle_del_all_sta(struct work_struct *work)
2271 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2272 struct wilc_vif *vif = msg->vif;
2273 struct del_all_sta *param = &msg->body.del_all_sta_info;
2278 u8 zero_buff[6] = {0};
2280 wid.id = WID_DEL_ALL_STA;
2282 wid.size = (param->assoc_sta * ETH_ALEN) + 1;
2284 wid.val = kmalloc((param->assoc_sta * ETH_ALEN) + 1, GFP_KERNEL);
2288 curr_byte = wid.val;
2290 *(curr_byte++) = param->assoc_sta;
2292 for (i = 0; i < MAX_NUM_STA; i++) {
2293 if (memcmp(param->del_all_sta[i], zero_buff, ETH_ALEN))
2294 memcpy(curr_byte, param->del_all_sta[i], ETH_ALEN);
2298 curr_byte += ETH_ALEN;
2301 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2302 wilc_get_vif_idx(vif));
2304 netdev_err(vif->ndev, "Failed to send delete all station\n");
2309 /* free 'msg' data in caller */
2310 complete(&msg->work_comp);
2313 static void handle_del_station(struct work_struct *work)
2315 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2316 struct wilc_vif *vif = msg->vif;
2317 struct del_sta *param = &msg->body.del_sta_info;
2321 wid.id = WID_REMOVE_STA;
2323 wid.size = ETH_ALEN;
2325 wid.val = kmalloc(wid.size, GFP_KERNEL);
2329 ether_addr_copy(wid.val, param->mac_addr);
2331 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2332 wilc_get_vif_idx(vif));
2334 netdev_err(vif->ndev, "Failed to del station\n");
2341 static void handle_edit_station(struct work_struct *work)
2343 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2344 struct wilc_vif *vif = msg->vif;
2345 struct add_sta_param *param = &msg->body.edit_sta_info;
2350 wid.id = WID_EDIT_STA;
2352 wid.size = WILC_ADD_STA_LENGTH + param->rates_len;
2354 wid.val = kmalloc(wid.size, GFP_KERNEL);
2359 cur_byte += wilc_hif_pack_sta_param(cur_byte, param);
2361 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2362 wilc_get_vif_idx(vif));
2364 netdev_err(vif->ndev, "Failed to send edit station\n");
2367 kfree(param->rates);
2372 static int handle_remain_on_chan(struct wilc_vif *vif,
2373 struct remain_ch *hif_remain_ch)
2376 u8 remain_on_chan_flag;
2378 struct host_if_drv *hif_drv = vif->hif_drv;
2380 if (!hif_drv->remain_on_ch_pending) {
2381 hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
2382 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
2383 hif_drv->remain_on_ch.ready = hif_remain_ch->ready;
2384 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
2385 hif_drv->remain_on_ch.id = hif_remain_ch->id;
2387 hif_remain_ch->ch = hif_drv->remain_on_ch.ch;
2390 if (hif_drv->usr_scan_req.scan_result) {
2391 hif_drv->remain_on_ch_pending = 1;
2395 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
2400 if (wilc_optaining_ip || wilc_connecting) {
2405 remain_on_chan_flag = true;
2406 wid.id = WID_REMAIN_ON_CHAN;
2409 wid.val = kmalloc(wid.size, GFP_KERNEL);
2415 wid.val[0] = remain_on_chan_flag;
2416 wid.val[1] = (s8)hif_remain_ch->ch;
2418 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2419 wilc_get_vif_idx(vif));
2422 netdev_err(vif->ndev, "Failed to set remain on channel\n");
2425 p2p_listen_state = 1;
2426 hif_drv->remain_on_ch_timer_vif = vif;
2427 mod_timer(&hif_drv->remain_on_ch_timer,
2428 jiffies + msecs_to_jiffies(hif_remain_ch->duration));
2430 if (hif_drv->remain_on_ch.ready)
2431 hif_drv->remain_on_ch.ready(hif_drv->remain_on_ch.arg);
2433 if (hif_drv->remain_on_ch_pending)
2434 hif_drv->remain_on_ch_pending = 0;
2439 static void handle_register_frame(struct work_struct *work)
2441 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2442 struct wilc_vif *vif = msg->vif;
2443 struct reg_frame *hif_reg_frame = &msg->body.reg_frame;
2448 wid.id = WID_REGISTER_FRAME;
2450 wid.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2456 *cur_byte++ = hif_reg_frame->reg;
2457 *cur_byte++ = hif_reg_frame->reg_id;
2458 memcpy(cur_byte, &hif_reg_frame->frame_type, sizeof(u16));
2460 wid.size = sizeof(u16) + 2;
2462 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2463 wilc_get_vif_idx(vif));
2466 netdev_err(vif->ndev, "Failed to frame register\n");
2472 static void handle_listen_state_expired(struct work_struct *work)
2474 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2475 struct wilc_vif *vif = msg->vif;
2476 struct remain_ch *hif_remain_ch = &msg->body.remain_on_ch;
2477 u8 remain_on_chan_flag;
2480 struct host_if_drv *hif_drv = vif->hif_drv;
2482 if (p2p_listen_state) {
2483 remain_on_chan_flag = false;
2484 wid.id = WID_REMAIN_ON_CHAN;
2487 wid.val = kmalloc(wid.size, GFP_KERNEL);
2492 wid.val[0] = remain_on_chan_flag;
2493 wid.val[1] = FALSE_FRMWR_CHANNEL;
2495 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2496 wilc_get_vif_idx(vif));
2499 netdev_err(vif->ndev, "Failed to set remain channel\n");
2503 if (hif_drv->remain_on_ch.expired) {
2504 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
2507 p2p_listen_state = 0;
2509 netdev_dbg(vif->ndev, "Not in listen state\n");
2516 static void listen_timer_cb(struct timer_list *t)
2518 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
2519 remain_on_ch_timer);
2520 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
2522 struct host_if_msg *msg;
2524 del_timer(&vif->hif_drv->remain_on_ch_timer);
2526 msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
2530 msg->body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
2532 result = wilc_enqueue_work(msg);
2534 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
2539 static void handle_power_management(struct work_struct *work)
2541 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2542 struct wilc_vif *vif = msg->vif;
2543 struct power_mgmt_param *pm_param = &msg->body.pwr_mgmt_info;
2548 wid.id = WID_POWER_MANAGEMENT;
2550 if (pm_param->enabled)
2551 power_mode = MIN_FAST_PS;
2553 power_mode = NO_POWERSAVE;
2555 wid.val = &power_mode;
2556 wid.size = sizeof(char);
2558 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2559 wilc_get_vif_idx(vif));
2561 netdev_err(vif->ndev, "Failed to send power management\n");
2565 static void handle_set_mcast_filter(struct work_struct *work)
2567 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2568 struct wilc_vif *vif = msg->vif;
2569 struct set_multicast *hif_set_mc = &msg->body.multicast_info;
2574 wid.id = WID_SETUP_MULTICAST_FILTER;
2576 wid.size = sizeof(struct set_multicast) + (hif_set_mc->cnt * ETH_ALEN);
2577 wid.val = kmalloc(wid.size, GFP_KERNEL);
2582 *cur_byte++ = (hif_set_mc->enabled & 0xFF);
2587 *cur_byte++ = (hif_set_mc->cnt & 0xFF);
2588 *cur_byte++ = ((hif_set_mc->cnt >> 8) & 0xFF);
2589 *cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF);
2590 *cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF);
2592 if (hif_set_mc->cnt > 0)
2593 memcpy(cur_byte, wilc_multicast_mac_addr_list,
2594 ((hif_set_mc->cnt) * ETH_ALEN));
2596 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2597 wilc_get_vif_idx(vif));
2599 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2606 static void handle_set_tx_pwr(struct work_struct *work)
2608 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2609 struct wilc_vif *vif = msg->vif;
2610 u8 tx_pwr = msg->body.tx_power.tx_pwr;
2614 wid.id = WID_TX_POWER;
2615 wid.type = WID_CHAR;
2617 wid.size = sizeof(char);
2619 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2620 wilc_get_vif_idx(vif));
2622 netdev_err(vif->ndev, "Failed to set TX PWR\n");
2626 /* Note: 'msg' will be free after using data */
2627 static void handle_get_tx_pwr(struct work_struct *work)
2629 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2630 struct wilc_vif *vif = msg->vif;
2631 u8 *tx_pwr = &msg->body.tx_power.tx_pwr;
2635 wid.id = WID_TX_POWER;
2636 wid.type = WID_CHAR;
2637 wid.val = (s8 *)tx_pwr;
2638 wid.size = sizeof(char);
2640 ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2641 wilc_get_vif_idx(vif));
2643 netdev_err(vif->ndev, "Failed to get TX PWR\n");
2645 complete(&msg->work_comp);
2648 static void handle_scan_timer(struct work_struct *work)
2650 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2652 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
2656 static void handle_remain_on_chan_work(struct work_struct *work)
2658 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2660 handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
2664 static void handle_hif_exit_work(struct work_struct *work)
2666 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2668 /* free 'msg' data in caller */
2669 complete(&msg->work_comp);
2672 static void handle_scan_complete(struct work_struct *work)
2674 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2675 struct wilc *wilc = msg->vif->wilc;
2677 del_timer(&msg->vif->hif_drv->scan_timer);
2679 if (!wilc_wlan_get_num_conn_ifcs(wilc))
2680 wilc_chip_sleep_manually(wilc);
2682 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
2684 if (msg->vif->hif_drv->remain_on_ch_pending)
2685 handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
2689 static void timer_scan_cb(struct timer_list *t)
2691 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
2692 struct wilc_vif *vif = hif_drv->scan_timer_vif;
2693 struct host_if_msg *msg;
2696 msg = wilc_alloc_work(vif, handle_scan_timer, false);
2700 result = wilc_enqueue_work(msg);
2705 static void timer_connect_cb(struct timer_list *t)
2707 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
2709 struct wilc_vif *vif = hif_drv->connect_timer_vif;
2710 struct host_if_msg *msg;
2713 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
2717 result = wilc_enqueue_work(msg);
2722 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
2725 struct host_if_msg *msg;
2726 struct host_if_drv *hif_drv = vif->hif_drv;
2730 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
2734 msg = wilc_alloc_work(vif, handle_key, true);
2736 return PTR_ERR(msg);
2738 msg->body.key_info.type = WEP;
2739 msg->body.key_info.action = REMOVEKEY;
2740 msg->body.key_info.attr.wep.index = index;
2742 result = wilc_enqueue_work(msg);
2744 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
2746 wait_for_completion(&msg->work_comp);
2752 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
2755 struct host_if_msg *msg;
2756 struct host_if_drv *hif_drv = vif->hif_drv;
2760 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
2764 msg = wilc_alloc_work(vif, handle_key, true);
2766 return PTR_ERR(msg);
2768 msg->body.key_info.type = WEP;
2769 msg->body.key_info.action = DEFAULTKEY;
2770 msg->body.key_info.attr.wep.index = index;
2772 result = wilc_enqueue_work(msg);
2774 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
2776 wait_for_completion(&msg->work_comp);
2782 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
2786 struct host_if_msg *msg;
2787 struct host_if_drv *hif_drv = vif->hif_drv;
2790 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
2794 msg = wilc_alloc_work(vif, handle_key, true);
2796 return PTR_ERR(msg);
2798 msg->body.key_info.type = WEP;
2799 msg->body.key_info.action = ADDKEY;
2800 msg->body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2801 if (!msg->body.key_info.attr.wep.key) {
2806 msg->body.key_info.attr.wep.key_len = len;
2807 msg->body.key_info.attr.wep.index = index;
2809 result = wilc_enqueue_work(msg);
2813 wait_for_completion(&msg->work_comp);
2816 kfree(msg->body.key_info.attr.wep.key);
2823 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
2824 u8 index, u8 mode, enum authtype auth_type)
2827 struct host_if_msg *msg;
2828 struct host_if_drv *hif_drv = vif->hif_drv;
2831 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
2835 msg = wilc_alloc_work(vif, handle_key, true);
2837 return PTR_ERR(msg);
2839 msg->body.key_info.type = WEP;
2840 msg->body.key_info.action = ADDKEY_AP;
2841 msg->body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2842 if (!msg->body.key_info.attr.wep.key) {
2847 msg->body.key_info.attr.wep.key_len = len;
2848 msg->body.key_info.attr.wep.index = index;
2849 msg->body.key_info.attr.wep.mode = mode;
2850 msg->body.key_info.attr.wep.auth_type = auth_type;
2852 result = wilc_enqueue_work(msg);
2856 wait_for_completion(&msg->work_comp);
2859 kfree(msg->body.key_info.attr.wep.key);
2866 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
2867 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
2868 u8 mode, u8 cipher_mode, u8 index)
2871 struct host_if_msg *msg;
2872 struct host_if_drv *hif_drv = vif->hif_drv;
2873 u8 key_len = ptk_key_len;
2876 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
2881 key_len += RX_MIC_KEY_LEN;
2884 key_len += TX_MIC_KEY_LEN;
2886 msg = wilc_alloc_work(vif, handle_key, true);
2888 return PTR_ERR(msg);
2890 msg->body.key_info.type = WPA_PTK;
2891 if (mode == AP_MODE) {
2892 msg->body.key_info.action = ADDKEY_AP;
2893 msg->body.key_info.attr.wpa.index = index;
2895 if (mode == STATION_MODE)
2896 msg->body.key_info.action = ADDKEY;
2898 msg->body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
2899 if (!msg->body.key_info.attr.wpa.key) {
2905 memcpy(msg->body.key_info.attr.wpa.key + 16, rx_mic,
2909 memcpy(msg->body.key_info.attr.wpa.key + 24, tx_mic,
2912 msg->body.key_info.attr.wpa.key_len = key_len;
2913 msg->body.key_info.attr.wpa.mac_addr = mac_addr;
2914 msg->body.key_info.attr.wpa.mode = cipher_mode;
2916 result = wilc_enqueue_work(msg);
2918 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
2922 wait_for_completion(&msg->work_comp);
2925 kfree(msg->body.key_info.attr.wpa.key);
2932 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
2933 u8 index, u32 key_rsc_len, const u8 *key_rsc,
2934 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
2938 struct host_if_msg *msg;
2939 struct host_if_drv *hif_drv = vif->hif_drv;
2940 u8 key_len = gtk_key_len;
2943 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
2947 msg = wilc_alloc_work(vif, handle_key, true);
2949 return PTR_ERR(msg);
2952 key_len += RX_MIC_KEY_LEN;
2955 key_len += TX_MIC_KEY_LEN;
2958 msg->body.key_info.attr.wpa.seq = kmemdup(key_rsc,
2961 if (!msg->body.key_info.attr.wpa.seq) {
2967 msg->body.key_info.type = WPA_RX_GTK;
2969 if (mode == AP_MODE) {
2970 msg->body.key_info.action = ADDKEY_AP;
2971 msg->body.key_info.attr.wpa.mode = cipher_mode;
2973 if (mode == STATION_MODE)
2974 msg->body.key_info.action = ADDKEY;
2976 msg->body.key_info.attr.wpa.key = kmemdup(rx_gtk, key_len, GFP_KERNEL);
2977 if (!msg->body.key_info.attr.wpa.key) {
2983 memcpy(msg->body.key_info.attr.wpa.key + 16, rx_mic,
2987 memcpy(msg->body.key_info.attr.wpa.key + 24, tx_mic,
2990 msg->body.key_info.attr.wpa.index = index;
2991 msg->body.key_info.attr.wpa.key_len = key_len;
2992 msg->body.key_info.attr.wpa.seq_len = key_rsc_len;
2994 result = wilc_enqueue_work(msg);
2996 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3000 wait_for_completion(&msg->work_comp);
3003 kfree(msg->body.key_info.attr.wpa.key);
3006 kfree(msg->body.key_info.attr.wpa.seq);
3013 int wilc_set_pmkid_info(struct wilc_vif *vif,
3014 struct host_if_pmkid_attr *pmkid)
3017 struct host_if_msg *msg;
3020 msg = wilc_alloc_work(vif, handle_key, false);
3022 return PTR_ERR(msg);
3024 msg->body.key_info.type = PMKSA;
3025 msg->body.key_info.action = ADDKEY;
3027 for (i = 0; i < pmkid->numpmkid; i++) {
3028 memcpy(msg->body.key_info.attr.pmkid.pmkidlist[i].bssid,
3029 &pmkid->pmkidlist[i].bssid, ETH_ALEN);
3030 memcpy(msg->body.key_info.attr.pmkid.pmkidlist[i].pmkid,
3031 &pmkid->pmkidlist[i].pmkid, PMKID_LEN);
3034 result = wilc_enqueue_work(msg);
3036 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3043 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
3046 struct host_if_msg *msg;
3048 msg = wilc_alloc_work(vif, handle_get_mac_address, true);
3050 return PTR_ERR(msg);
3052 msg->body.get_mac_info.mac_addr = mac_addr;
3054 result = wilc_enqueue_work(msg);
3056 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3058 wait_for_completion(&msg->work_comp);
3065 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
3066 size_t ssid_len, const u8 *ies, size_t ies_len,
3067 wilc_connect_result connect_result, void *user_arg,
3068 u8 security, enum authtype auth_type,
3069 u8 channel, void *join_params)
3072 struct host_if_msg *msg;
3073 struct host_if_drv *hif_drv = vif->hif_drv;
3075 if (!hif_drv || !connect_result) {
3076 netdev_err(vif->ndev,
3077 "%s: hif driver or connect result is NULL",
3083 netdev_err(vif->ndev, "%s: joinparams is NULL\n", __func__);
3087 msg = wilc_alloc_work(vif, handle_connect, false);
3089 return PTR_ERR(msg);
3091 msg->body.con_info.security = security;
3092 msg->body.con_info.auth_type = auth_type;
3093 msg->body.con_info.ch = channel;
3094 msg->body.con_info.result = connect_result;
3095 msg->body.con_info.arg = user_arg;
3096 msg->body.con_info.params = join_params;
3099 msg->body.con_info.bssid = kmemdup(bssid, 6, GFP_KERNEL);
3100 if (!msg->body.con_info.bssid) {
3107 msg->body.con_info.ssid_len = ssid_len;
3108 msg->body.con_info.ssid = kmemdup(ssid, ssid_len, GFP_KERNEL);
3109 if (!msg->body.con_info.ssid) {
3116 msg->body.con_info.ies_len = ies_len;
3117 msg->body.con_info.ies = kmemdup(ies, ies_len, GFP_KERNEL);
3118 if (!msg->body.con_info.ies) {
3123 if (hif_drv->hif_state < HOST_IF_CONNECTING)
3124 hif_drv->hif_state = HOST_IF_CONNECTING;
3126 result = wilc_enqueue_work(msg);
3128 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3132 hif_drv->connect_timer_vif = vif;
3133 mod_timer(&hif_drv->connect_timer,
3134 jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3139 kfree(msg->body.con_info.ies);
3142 kfree(msg->body.con_info.ssid);
3145 kfree(msg->body.con_info.bssid);
3152 int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
3155 struct host_if_msg *msg;
3156 struct host_if_drv *hif_drv = vif->hif_drv;
3159 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3163 msg = wilc_alloc_work(vif, handle_disconnect, true);
3165 return PTR_ERR(msg);
3167 result = wilc_enqueue_work(msg);
3169 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3171 wait_for_completion(&msg->work_comp);
3177 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
3180 struct host_if_msg *msg;
3182 msg = wilc_alloc_work(vif, handle_set_channel, false);
3184 return PTR_ERR(msg);
3186 msg->body.channel_info.set_ch = channel;
3188 result = wilc_enqueue_work(msg);
3190 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3197 int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
3201 struct host_if_msg *msg;
3203 msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, false);
3205 return PTR_ERR(msg);
3207 msg->body.drv.handler = index;
3208 msg->body.drv.mode = mode;
3209 msg->body.drv.name = ifc_id;
3211 result = wilc_enqueue_work(msg);
3213 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3220 int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
3223 struct host_if_msg *msg;
3225 msg = wilc_alloc_work(vif, handle_set_operation_mode, false);
3227 return PTR_ERR(msg);
3229 msg->body.mode.mode = mode;
3230 result = wilc_enqueue_work(msg);
3232 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3239 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
3243 struct host_if_msg *msg;
3244 struct host_if_drv *hif_drv = vif->hif_drv;
3247 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3251 msg = wilc_alloc_work(vif, handle_get_inactive_time, true);
3253 return PTR_ERR(msg);
3255 memcpy(msg->body.mac_info.mac, mac, ETH_ALEN);
3257 result = wilc_enqueue_work(msg);
3259 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3261 wait_for_completion(&msg->work_comp);
3263 *out_val = msg->body.mac_info.inactive_time;
3269 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
3272 struct host_if_msg *msg;
3275 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
3279 msg = wilc_alloc_work(vif, handle_get_rssi, true);
3281 return PTR_ERR(msg);
3283 msg->body.data = kzalloc(sizeof(s8), GFP_KERNEL);
3284 if (!msg->body.data) {
3289 result = wilc_enqueue_work(msg);
3291 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3293 wait_for_completion(&msg->work_comp);
3294 *rssi_level = *msg->body.data;
3297 kfree(msg->body.data);
3304 wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats, bool is_sync)
3307 struct host_if_msg *msg;
3309 msg = wilc_alloc_work(vif, handle_get_statistics, is_sync);
3311 return PTR_ERR(msg);
3313 msg->body.data = (char *)stats;
3315 result = wilc_enqueue_work(msg);
3317 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3323 wait_for_completion(&msg->work_comp);
3330 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
3331 u8 *ch_freq_list, u8 ch_list_len, const u8 *ies,
3332 size_t ies_len, wilc_scan_result scan_result, void *user_arg,
3333 struct hidden_network *hidden_network)
3336 struct host_if_msg *msg;
3337 struct scan_attr *scan_info;
3338 struct host_if_drv *hif_drv = vif->hif_drv;
3340 if (!hif_drv || !scan_result) {
3341 netdev_err(vif->ndev, "hif_drv or scan_result = NULL\n");
3345 msg = wilc_alloc_work(vif, handle_scan, false);
3347 return PTR_ERR(msg);
3349 scan_info = &msg->body.scan_info;
3351 if (hidden_network) {
3352 scan_info->hidden_network.net_info = hidden_network->net_info;
3353 scan_info->hidden_network.n_ssids = hidden_network->n_ssids;
3356 scan_info->src = scan_source;
3357 scan_info->type = scan_type;
3358 scan_info->result = scan_result;
3359 scan_info->arg = user_arg;
3361 scan_info->ch_list_len = ch_list_len;
3362 scan_info->ch_freq_list = kmemdup(ch_freq_list,
3365 if (!scan_info->ch_freq_list) {
3370 scan_info->ies_len = ies_len;
3371 scan_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
3372 if (!scan_info->ies) {
3374 goto free_freq_list;
3377 result = wilc_enqueue_work(msg);
3379 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3383 hif_drv->scan_timer_vif = vif;
3384 mod_timer(&hif_drv->scan_timer,
3385 jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
3390 kfree(scan_info->ies);
3393 kfree(scan_info->ch_freq_list);
3400 int wilc_hif_set_cfg(struct wilc_vif *vif,
3401 struct cfg_param_attr *cfg_param)
3403 struct host_if_msg *msg;
3404 struct host_if_drv *hif_drv = vif->hif_drv;
3408 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3412 msg = wilc_alloc_work(vif, handle_cfg_param, false);
3414 return PTR_ERR(msg);
3416 msg->body.cfg_info = *cfg_param;
3417 result = wilc_enqueue_work(msg);
3424 static void get_periodic_rssi(struct timer_list *unused)
3426 struct wilc_vif *vif = periodic_rssi_vif;
3428 if (!vif->hif_drv) {
3429 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3433 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
3434 wilc_get_statistics(vif, &vif->wilc->dummy_statistics, false);
3436 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3439 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3441 struct host_if_drv *hif_drv;
3442 struct wilc_vif *vif = netdev_priv(dev);
3443 struct wilc *wilc = vif->wilc;
3446 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
3450 *hif_drv_handler = hif_drv;
3451 for (i = 0; i < wilc->vif_num; i++)
3452 if (dev == wilc->vif[i]->ndev) {
3453 wilc->vif[i]->hif_drv = hif_drv;
3454 hif_drv->driver_handler_id = i + 1;
3458 wilc_optaining_ip = false;
3460 if (clients_count == 0) {
3461 init_completion(&hif_driver_comp);
3462 mutex_init(&hif_deinit_lock);
3465 if (clients_count == 0) {
3466 hif_workqueue = create_singlethread_workqueue("WILC_wq");
3467 if (!hif_workqueue) {
3468 netdev_err(vif->ndev, "Failed to create workqueue\n");
3473 periodic_rssi_vif = vif;
3474 timer_setup(&periodic_rssi, get_periodic_rssi, 0);
3475 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3478 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
3479 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
3480 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
3482 mutex_init(&hif_drv->cfg_values_lock);
3483 mutex_lock(&hif_drv->cfg_values_lock);
3485 hif_drv->hif_state = HOST_IF_IDLE;
3486 hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF;
3487 hif_drv->cfg_values.scan_source = DEFAULT_SCAN;
3488 hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME;
3489 hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME;
3490 hif_drv->cfg_values.curr_tx_rate = AUTORATE;
3492 hif_drv->p2p_timeout = 0;
3494 mutex_unlock(&hif_drv->cfg_values_lock);
3501 int wilc_deinit(struct wilc_vif *vif)
3504 struct host_if_drv *hif_drv = vif->hif_drv;
3507 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3511 mutex_lock(&hif_deinit_lock);
3513 terminated_handle = hif_drv;
3515 del_timer_sync(&hif_drv->scan_timer);
3516 del_timer_sync(&hif_drv->connect_timer);
3517 del_timer_sync(&periodic_rssi);
3518 del_timer_sync(&hif_drv->remain_on_ch_timer);
3520 wilc_set_wfi_drv_handler(vif, 0, 0, 0);
3521 wait_for_completion(&hif_driver_comp);
3523 if (hif_drv->usr_scan_req.scan_result) {
3524 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
3525 hif_drv->usr_scan_req.arg,
3527 hif_drv->usr_scan_req.scan_result = NULL;
3530 hif_drv->hif_state = HOST_IF_IDLE;
3532 if (clients_count == 1) {
3533 struct host_if_msg *msg;
3535 msg = wilc_alloc_work(vif, handle_hif_exit_work, true);
3537 result = wilc_enqueue_work(msg);
3539 netdev_err(vif->ndev, "deinit : Error(%d)\n",
3542 wait_for_completion(&msg->work_comp);
3545 destroy_workqueue(hif_workqueue);
3551 terminated_handle = NULL;
3552 mutex_unlock(&hif_deinit_lock);
3556 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
3559 struct host_if_msg *msg;
3561 struct host_if_drv *hif_drv;
3562 struct wilc_vif *vif;
3564 id = buffer[length - 4];
3565 id |= (buffer[length - 3] << 8);
3566 id |= (buffer[length - 2] << 16);
3567 id |= (buffer[length - 1] << 24);
3568 vif = wilc_get_vif_from_idx(wilc, id);
3571 hif_drv = vif->hif_drv;
3573 if (!hif_drv || hif_drv == terminated_handle) {
3574 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
3578 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
3582 msg->body.net_info.len = length;
3583 msg->body.net_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
3584 if (!msg->body.net_info.buffer) {
3589 result = wilc_enqueue_work(msg);
3591 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3592 kfree(msg->body.net_info.buffer);
3597 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
3600 struct host_if_msg *msg;
3602 struct host_if_drv *hif_drv;
3603 struct wilc_vif *vif;
3605 mutex_lock(&hif_deinit_lock);
3607 id = buffer[length - 4];
3608 id |= (buffer[length - 3] << 8);
3609 id |= (buffer[length - 2] << 16);
3610 id |= (buffer[length - 1] << 24);
3611 vif = wilc_get_vif_from_idx(wilc, id);
3613 mutex_unlock(&hif_deinit_lock);
3617 hif_drv = vif->hif_drv;
3619 if (!hif_drv || hif_drv == terminated_handle) {
3620 mutex_unlock(&hif_deinit_lock);
3624 if (!hif_drv->usr_conn_req.conn_result) {
3625 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
3626 mutex_unlock(&hif_deinit_lock);
3630 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
3632 mutex_unlock(&hif_deinit_lock);
3636 msg->body.async_info.len = length;
3637 msg->body.async_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
3638 if (!msg->body.async_info.buffer) {
3640 mutex_unlock(&hif_deinit_lock);
3644 result = wilc_enqueue_work(msg);
3646 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3647 kfree(msg->body.async_info.buffer);
3651 mutex_unlock(&hif_deinit_lock);
3654 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
3658 struct host_if_drv *hif_drv;
3659 struct wilc_vif *vif;
3661 id = buffer[length - 4];
3662 id |= buffer[length - 3] << 8;
3663 id |= buffer[length - 2] << 16;
3664 id |= buffer[length - 1] << 24;
3665 vif = wilc_get_vif_from_idx(wilc, id);
3668 hif_drv = vif->hif_drv;
3670 if (!hif_drv || hif_drv == terminated_handle)
3673 if (hif_drv->usr_scan_req.scan_result) {
3674 struct host_if_msg *msg;
3676 msg = wilc_alloc_work(vif, handle_scan_complete, false);
3680 result = wilc_enqueue_work(msg);
3682 netdev_err(vif->ndev, "%s: enqueue work failed\n",
3689 int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
3690 u32 duration, u16 chan,
3691 wilc_remain_on_chan_expired expired,
3692 wilc_remain_on_chan_ready ready,
3696 struct host_if_msg *msg;
3698 msg = wilc_alloc_work(vif, handle_remain_on_chan_work, false);
3700 return PTR_ERR(msg);
3702 msg->body.remain_on_ch.ch = chan;
3703 msg->body.remain_on_ch.expired = expired;
3704 msg->body.remain_on_ch.ready = ready;
3705 msg->body.remain_on_ch.arg = user_arg;
3706 msg->body.remain_on_ch.duration = duration;
3707 msg->body.remain_on_ch.id = session_id;
3709 result = wilc_enqueue_work(msg);
3711 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3718 int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
3721 struct host_if_msg *msg;
3722 struct host_if_drv *hif_drv = vif->hif_drv;
3725 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
3729 del_timer(&hif_drv->remain_on_ch_timer);
3731 msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
3733 return PTR_ERR(msg);
3735 msg->body.remain_on_ch.id = session_id;
3737 result = wilc_enqueue_work(msg);
3739 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3746 int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
3749 struct host_if_msg *msg;
3751 msg = wilc_alloc_work(vif, handle_register_frame, false);
3753 return PTR_ERR(msg);
3755 switch (frame_type) {
3757 msg->body.reg_frame.reg_id = ACTION_FRM_IDX;
3761 msg->body.reg_frame.reg_id = PROBE_REQ_IDX;
3767 msg->body.reg_frame.frame_type = frame_type;
3768 msg->body.reg_frame.reg = reg;
3770 result = wilc_enqueue_work(msg);
3772 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3779 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
3780 u32 head_len, u8 *head, u32 tail_len, u8 *tail)
3783 struct host_if_msg *msg;
3784 struct beacon_attr *beacon_info;
3786 msg = wilc_alloc_work(vif, handle_add_beacon, false);
3788 return PTR_ERR(msg);
3790 beacon_info = &msg->body.beacon_info;
3791 beacon_info->interval = interval;
3792 beacon_info->dtim_period = dtim_period;
3793 beacon_info->head_len = head_len;
3794 beacon_info->head = kmemdup(head, head_len, GFP_KERNEL);
3795 if (!beacon_info->head) {
3799 beacon_info->tail_len = tail_len;
3802 beacon_info->tail = kmemdup(tail, tail_len, GFP_KERNEL);
3803 if (!beacon_info->tail) {
3808 beacon_info->tail = NULL;
3811 result = wilc_enqueue_work(msg);
3813 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3817 kfree(beacon_info->head);
3818 kfree(beacon_info->tail);
3825 int wilc_del_beacon(struct wilc_vif *vif)
3828 struct host_if_msg *msg;
3830 msg = wilc_alloc_work(vif, handle_del_beacon, false);
3832 return PTR_ERR(msg);
3834 result = wilc_enqueue_work(msg);
3836 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3843 int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
3846 struct host_if_msg *msg;
3847 struct add_sta_param *add_sta_info;
3849 msg = wilc_alloc_work(vif, handle_add_station, false);
3851 return PTR_ERR(msg);
3853 add_sta_info = &msg->body.add_sta_info;
3854 memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3855 if (add_sta_info->rates_len > 0) {
3856 add_sta_info->rates = kmemdup(sta_param->rates,
3857 add_sta_info->rates_len,
3859 if (!add_sta_info->rates) {
3865 result = wilc_enqueue_work(msg);
3867 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3868 kfree(add_sta_info->rates);
3874 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
3877 struct host_if_msg *msg;
3878 struct del_sta *del_sta_info;
3880 msg = wilc_alloc_work(vif, handle_del_station, false);
3882 return PTR_ERR(msg);
3884 del_sta_info = &msg->body.del_sta_info;
3887 eth_broadcast_addr(del_sta_info->mac_addr);
3889 memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN);
3891 result = wilc_enqueue_work(msg);
3893 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3899 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
3902 struct host_if_msg *msg;
3903 struct del_all_sta *del_all_sta_info;
3904 u8 zero_addr[ETH_ALEN] = {0};
3908 msg = wilc_alloc_work(vif, handle_del_all_sta, true);
3910 return PTR_ERR(msg);
3912 del_all_sta_info = &msg->body.del_all_sta_info;
3914 for (i = 0; i < MAX_NUM_STA; i++) {
3915 if (memcmp(mac_addr[i], zero_addr, ETH_ALEN)) {
3916 memcpy(del_all_sta_info->del_all_sta[i], mac_addr[i],
3926 del_all_sta_info->assoc_sta = assoc_sta;
3927 result = wilc_enqueue_work(msg);
3930 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3932 wait_for_completion(&msg->work_comp);
3939 int wilc_edit_station(struct wilc_vif *vif,
3940 struct add_sta_param *sta_param)
3943 struct host_if_msg *msg;
3944 struct add_sta_param *add_sta_info;
3946 msg = wilc_alloc_work(vif, handle_edit_station, false);
3948 return PTR_ERR(msg);
3950 add_sta_info = &msg->body.add_sta_info;
3951 memcpy(add_sta_info, sta_param, sizeof(*add_sta_info));
3952 if (add_sta_info->rates_len > 0) {
3953 add_sta_info->rates = kmemdup(sta_param->rates,
3954 add_sta_info->rates_len,
3956 if (!add_sta_info->rates) {
3962 result = wilc_enqueue_work(msg);
3964 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3965 kfree(add_sta_info->rates);
3972 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
3975 struct host_if_msg *msg;
3977 if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
3980 msg = wilc_alloc_work(vif, handle_power_management, false);
3982 return PTR_ERR(msg);
3984 msg->body.pwr_mgmt_info.enabled = enabled;
3985 msg->body.pwr_mgmt_info.timeout = timeout;
3987 result = wilc_enqueue_work(msg);
3989 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3995 int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
3999 struct host_if_msg *msg;
4001 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
4003 return PTR_ERR(msg);
4005 msg->body.multicast_info.enabled = enabled;
4006 msg->body.multicast_info.cnt = count;
4008 result = wilc_enqueue_work(msg);
4010 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4016 int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4019 struct host_if_msg *msg;
4021 msg = wilc_alloc_work(vif, handle_set_ip_address, false);
4023 return PTR_ERR(msg);
4025 msg->body.ip_info.ip_addr = ip_addr;
4026 msg->body.ip_info.idx = idx;
4028 result = wilc_enqueue_work(msg);
4030 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4037 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4040 struct host_if_msg *msg;
4042 msg = wilc_alloc_work(vif, handle_get_ip_address, false);
4044 return PTR_ERR(msg);
4046 msg->body.ip_info.ip_addr = ip_addr;
4047 msg->body.ip_info.idx = idx;
4049 result = wilc_enqueue_work(msg);
4051 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4058 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
4061 struct host_if_msg *msg;
4063 msg = wilc_alloc_work(vif, handle_set_tx_pwr, false);
4065 return PTR_ERR(msg);
4067 msg->body.tx_power.tx_pwr = tx_power;
4069 ret = wilc_enqueue_work(msg);
4071 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4078 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
4081 struct host_if_msg *msg;
4083 msg = wilc_alloc_work(vif, handle_get_tx_pwr, true);
4085 return PTR_ERR(msg);
4087 ret = wilc_enqueue_work(msg);
4089 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4091 wait_for_completion(&msg->work_comp);
4092 *tx_power = msg->body.tx_power.tx_pwr;
4095 /* free 'msg' after copying data */