staging: wilc1000: change handle_get_ip_address's return type to void
[linux-2.6/btrfs-unstable.git] / drivers / staging / wilc1000 / host_interface.c
blobce1cd688dd294bf4a3c2991fcffaaa3155624d1a
1 #include <linux/slab.h>
2 #include <linux/time.h>
3 #include <linux/kthread.h>
4 #include <linux/delay.h>
5 #include <linux/completion.h>
6 #include "host_interface.h"
7 #include "coreconfigurator.h"
8 #include "wilc_wlan.h"
9 #include "wilc_wlan_if.h"
10 #include "wilc_msgqueue.h"
11 #include <linux/etherdevice.h>
12 #include "wilc_wfi_netdevice.h"
14 #define HOST_IF_MSG_SCAN 0
15 #define HOST_IF_MSG_CONNECT 1
16 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO 2
17 #define HOST_IF_MSG_KEY 3
18 #define HOST_IF_MSG_RCVD_NTWRK_INFO 4
19 #define HOST_IF_MSG_RCVD_SCAN_COMPLETE 5
20 #define HOST_IF_MSG_CFG_PARAMS 6
21 #define HOST_IF_MSG_SET_CHANNEL 7
22 #define HOST_IF_MSG_DISCONNECT 8
23 #define HOST_IF_MSG_GET_RSSI 9
24 #define HOST_IF_MSG_ADD_BEACON 11
25 #define HOST_IF_MSG_DEL_BEACON 12
26 #define HOST_IF_MSG_ADD_STATION 13
27 #define HOST_IF_MSG_DEL_STATION 14
28 #define HOST_IF_MSG_EDIT_STATION 15
29 #define HOST_IF_MSG_SCAN_TIMER_FIRED 16
30 #define HOST_IF_MSG_CONNECT_TIMER_FIRED 17
31 #define HOST_IF_MSG_POWER_MGMT 18
32 #define HOST_IF_MSG_GET_INACTIVETIME 19
33 #define HOST_IF_MSG_REMAIN_ON_CHAN 20
34 #define HOST_IF_MSG_REGISTER_FRAME 21
35 #define HOST_IF_MSG_LISTEN_TIMER_FIRED 22
36 #define HOST_IF_MSG_SET_WFIDRV_HANDLER 24
37 #define HOST_IF_MSG_GET_MAC_ADDRESS 26
38 #define HOST_IF_MSG_SET_OPERATION_MODE 27
39 #define HOST_IF_MSG_SET_IPADDRESS 28
40 #define HOST_IF_MSG_GET_IPADDRESS 29
41 #define HOST_IF_MSG_GET_STATISTICS 31
42 #define HOST_IF_MSG_SET_MULTICAST_FILTER 32
43 #define HOST_IF_MSG_DEL_BA_SESSION 34
44 #define HOST_IF_MSG_DEL_ALL_STA 36
45 #define HOST_IF_MSG_SET_TX_POWER 38
46 #define HOST_IF_MSG_GET_TX_POWER 39
47 #define HOST_IF_MSG_EXIT 100
49 #define HOST_IF_SCAN_TIMEOUT 4000
50 #define HOST_IF_CONNECT_TIMEOUT 9500
52 #define BA_SESSION_DEFAULT_BUFFER_SIZE 16
53 #define BA_SESSION_DEFAULT_TIMEOUT 1000
54 #define BLOCK_ACK_REQ_SIZE 0x14
55 #define FALSE_FRMWR_CHANNEL 100
57 #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
58 #define DEFAULT_LINK_SPEED 72
60 struct host_if_wpa_attr {
61 u8 *key;
62 const u8 *mac_addr;
63 u8 *seq;
64 u8 seq_len;
65 u8 index;
66 u8 key_len;
67 u8 mode;
70 struct host_if_wep_attr {
71 u8 *key;
72 u8 key_len;
73 u8 index;
74 u8 mode;
75 enum AUTHTYPE auth_type;
78 union host_if_key_attr {
79 struct host_if_wep_attr wep;
80 struct host_if_wpa_attr wpa;
81 struct host_if_pmkid_attr pmkid;
84 struct key_attr {
85 enum KEY_TYPE type;
86 u8 action;
87 union host_if_key_attr attr;
90 struct scan_attr {
91 u8 src;
92 u8 type;
93 u8 *ch_freq_list;
94 u8 ch_list_len;
95 u8 *ies;
96 size_t ies_len;
97 wilc_scan_result result;
98 void *arg;
99 struct hidden_network hidden_network;
102 struct connect_attr {
103 u8 *bssid;
104 u8 *ssid;
105 size_t ssid_len;
106 u8 *ies;
107 size_t ies_len;
108 u8 security;
109 wilc_connect_result result;
110 void *arg;
111 enum AUTHTYPE auth_type;
112 u8 ch;
113 void *params;
116 struct rcvd_async_info {
117 u8 *buffer;
118 u32 len;
121 struct channel_attr {
122 u8 set_ch;
125 struct beacon_attr {
126 u32 interval;
127 u32 dtim_period;
128 u32 head_len;
129 u8 *head;
130 u32 tail_len;
131 u8 *tail;
134 struct set_multicast {
135 bool enabled;
136 u32 cnt;
139 struct del_all_sta {
140 u8 del_all_sta[MAX_NUM_STA][ETH_ALEN];
141 u8 assoc_sta;
144 struct del_sta {
145 u8 mac_addr[ETH_ALEN];
148 struct power_mgmt_param {
149 bool enabled;
150 u32 timeout;
153 struct set_ip_addr {
154 u8 *ip_addr;
155 u8 idx;
158 struct sta_inactive_t {
159 u8 mac[6];
162 struct tx_power {
163 u8 tx_pwr;
166 union message_body {
167 struct scan_attr scan_info;
168 struct connect_attr con_info;
169 struct rcvd_net_info net_info;
170 struct rcvd_async_info async_info;
171 struct key_attr key_info;
172 struct cfg_param_attr cfg_info;
173 struct channel_attr channel_info;
174 struct beacon_attr beacon_info;
175 struct add_sta_param add_sta_info;
176 struct del_sta del_sta_info;
177 struct add_sta_param edit_sta_info;
178 struct power_mgmt_param pwr_mgmt_info;
179 struct sta_inactive_t mac_info;
180 struct set_ip_addr ip_info;
181 struct drv_handler drv;
182 struct set_multicast multicast_info;
183 struct op_mode mode;
184 struct set_mac_addr set_mac_info;
185 struct get_mac_addr get_mac_info;
186 struct ba_session_info session_info;
187 struct remain_ch remain_on_ch;
188 struct reg_frame reg_frame;
189 char *data;
190 struct del_all_sta del_all_sta_info;
191 struct tx_power tx_power;
194 struct host_if_msg {
195 u16 id;
196 union message_body body;
197 struct wilc_vif *vif;
200 struct join_bss_param {
201 BSSTYPE_T bss_type;
202 u8 dtim_period;
203 u16 beacon_period;
204 u16 cap_info;
205 u8 bssid[6];
206 char ssid[MAX_SSID_LEN];
207 u8 ssid_len;
208 u8 supp_rates[MAX_RATES_SUPPORTED + 1];
209 u8 ht_capable;
210 u8 wmm_cap;
211 u8 uapsd_cap;
212 bool rsn_found;
213 u8 rsn_grp_policy;
214 u8 mode_802_11i;
215 u8 rsn_pcip_policy[3];
216 u8 rsn_auth_policy[3];
217 u8 rsn_cap[2];
218 u32 tsf;
219 u8 noa_enabled;
220 u8 opp_enabled;
221 u8 ct_window;
222 u8 cnt;
223 u8 idx;
224 u8 duration[4];
225 u8 interval[4];
226 u8 start_time[4];
229 static struct host_if_drv *terminated_handle;
230 bool wilc_optaining_ip;
231 static u8 P2P_LISTEN_STATE;
232 static struct task_struct *hif_thread_handler;
233 static struct message_queue hif_msg_q;
234 static struct completion hif_thread_comp;
235 static struct completion hif_driver_comp;
236 static struct completion hif_wait_response;
237 static struct mutex hif_deinit_lock;
238 static struct timer_list periodic_rssi;
240 u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
242 static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
244 static bool scan_while_connected;
246 static s8 rssi;
247 static u8 set_ip[2][4];
248 static u8 get_ip[2][4];
249 static u32 inactive_time;
250 static u8 del_beacon;
251 static u32 clients_count;
253 static u8 *join_req;
254 static u8 *info_element;
255 static u8 mode_11i;
256 static u8 auth_type;
257 static u32 join_req_size;
258 static u32 info_element_size;
259 static struct wilc_vif *join_req_vif;
260 #define REAL_JOIN_REQ 0
261 #define FLUSHED_JOIN_REQ 1
262 #define FLUSHED_BYTE_POS 79
264 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
265 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
266 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
268 /* The u8IfIdx starts from 0 to NUM_CONCURRENT_IFC -1, but 0 index used as
269 * special purpose in wilc device, so we add 1 to the index to starts from 1.
270 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
272 int wilc_get_vif_idx(struct wilc_vif *vif)
274 return vif->idx + 1;
277 /* We need to minus 1 from idx which is from wilc device to get real index
278 * of wilc->vif[], because we add 1 when pass to wilc device in the function
279 * wilc_get_vif_idx.
280 * As a result, the index should be between 0 and NUM_CONCURRENT_IFC -1.
282 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
284 int index = idx - 1;
286 if (index < 0 || index >= NUM_CONCURRENT_IFC)
287 return NULL;
289 return wilc->vif[index];
292 static void handle_set_channel(struct wilc_vif *vif,
293 struct channel_attr *hif_set_ch)
295 int ret = 0;
296 struct wid wid;
298 wid.id = (u16)WID_CURRENT_CHANNEL;
299 wid.type = WID_CHAR;
300 wid.val = (char *)&hif_set_ch->set_ch;
301 wid.size = sizeof(char);
303 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
304 wilc_get_vif_idx(vif));
306 if (ret)
307 netdev_err(vif->ndev, "Failed to set channel\n");
310 static void handle_set_wfi_drv_handler(struct wilc_vif *vif,
311 struct drv_handler *hif_drv_handler)
313 int ret = 0;
314 struct wid wid;
316 wid.id = (u16)WID_SET_DRV_HANDLER;
317 wid.type = WID_STR;
318 wid.val = (s8 *)hif_drv_handler;
319 wid.size = sizeof(*hif_drv_handler);
321 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
322 hif_drv_handler->handler);
324 if (!hif_drv_handler->handler)
325 complete(&hif_driver_comp);
327 if (ret)
328 netdev_err(vif->ndev, "Failed to set driver handler\n");
331 static void handle_set_operation_mode(struct wilc_vif *vif,
332 struct op_mode *hif_op_mode)
334 int ret = 0;
335 struct wid wid;
337 wid.id = (u16)WID_SET_OPERATION_MODE;
338 wid.type = WID_INT;
339 wid.val = (s8 *)&hif_op_mode->mode;
340 wid.size = sizeof(u32);
342 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
343 wilc_get_vif_idx(vif));
345 if ((hif_op_mode->mode) == IDLE_MODE)
346 complete(&hif_driver_comp);
348 if (ret)
349 netdev_err(vif->ndev, "Failed to set driver handler\n");
352 static void handle_set_ip_address(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
354 int ret = 0;
355 struct wid wid;
356 char firmware_ip_addr[4] = {0};
358 if (ip_addr[0] < 192)
359 ip_addr[0] = 0;
361 memcpy(set_ip[idx], ip_addr, IP_ALEN);
363 wid.id = (u16)WID_IP_ADDRESS;
364 wid.type = WID_STR;
365 wid.val = (u8 *)ip_addr;
366 wid.size = IP_ALEN;
368 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
369 wilc_get_vif_idx(vif));
371 host_int_get_ipaddress(vif, firmware_ip_addr, idx);
373 if (ret)
374 netdev_err(vif->ndev, "Failed to set IP address\n");
377 static void handle_get_ip_address(struct wilc_vif *vif, u8 idx)
379 s32 result = 0;
380 struct wid wid;
382 wid.id = (u16)WID_IP_ADDRESS;
383 wid.type = WID_STR;
384 wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
385 wid.size = IP_ALEN;
387 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
388 wilc_get_vif_idx(vif));
390 memcpy(get_ip[idx], wid.val, IP_ALEN);
392 kfree(wid.val);
394 if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
395 wilc_setup_ipaddress(vif, set_ip[idx], idx);
397 if (result != 0)
398 netdev_err(vif->ndev, "Failed to get IP address\n");
401 static s32 handle_get_mac_address(struct wilc_vif *vif,
402 struct get_mac_addr *get_mac_addr)
404 s32 result = 0;
405 struct wid wid;
407 wid.id = (u16)WID_MAC_ADDR;
408 wid.type = WID_STR;
409 wid.val = get_mac_addr->mac_addr;
410 wid.size = ETH_ALEN;
412 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
413 wilc_get_vif_idx(vif));
415 if (result) {
416 netdev_err(vif->ndev, "Failed to get mac address\n");
417 result = -EFAULT;
419 complete(&hif_wait_response);
421 return result;
424 static s32 handle_cfg_param(struct wilc_vif *vif,
425 struct cfg_param_attr *cfg_param_attr)
427 s32 result = 0;
428 struct wid wid_list[32];
429 struct host_if_drv *hif_drv = vif->hif_drv;
430 int i = 0;
432 mutex_lock(&hif_drv->cfg_values_lock);
434 if (cfg_param_attr->flag & BSS_TYPE) {
435 if (cfg_param_attr->bss_type < 6) {
436 wid_list[i].id = WID_BSS_TYPE;
437 wid_list[i].val = (s8 *)&cfg_param_attr->bss_type;
438 wid_list[i].type = WID_CHAR;
439 wid_list[i].size = sizeof(char);
440 hif_drv->cfg_values.bss_type = (u8)cfg_param_attr->bss_type;
441 } else {
442 netdev_err(vif->ndev, "check value 6 over\n");
443 result = -EINVAL;
444 goto unlock;
446 i++;
448 if (cfg_param_attr->flag & AUTH_TYPE) {
449 if (cfg_param_attr->auth_type == 1 ||
450 cfg_param_attr->auth_type == 2 ||
451 cfg_param_attr->auth_type == 5) {
452 wid_list[i].id = WID_AUTH_TYPE;
453 wid_list[i].val = (s8 *)&cfg_param_attr->auth_type;
454 wid_list[i].type = WID_CHAR;
455 wid_list[i].size = sizeof(char);
456 hif_drv->cfg_values.auth_type = (u8)cfg_param_attr->auth_type;
457 } else {
458 netdev_err(vif->ndev, "Impossible value\n");
459 result = -EINVAL;
460 goto unlock;
462 i++;
464 if (cfg_param_attr->flag & AUTHEN_TIMEOUT) {
465 if (cfg_param_attr->auth_timeout > 0 &&
466 cfg_param_attr->auth_timeout < 65536) {
467 wid_list[i].id = WID_AUTH_TIMEOUT;
468 wid_list[i].val = (s8 *)&cfg_param_attr->auth_timeout;
469 wid_list[i].type = WID_SHORT;
470 wid_list[i].size = sizeof(u16);
471 hif_drv->cfg_values.auth_timeout = cfg_param_attr->auth_timeout;
472 } else {
473 netdev_err(vif->ndev, "Range(1 ~ 65535) over\n");
474 result = -EINVAL;
475 goto unlock;
477 i++;
479 if (cfg_param_attr->flag & POWER_MANAGEMENT) {
480 if (cfg_param_attr->power_mgmt_mode < 5) {
481 wid_list[i].id = WID_POWER_MANAGEMENT;
482 wid_list[i].val = (s8 *)&cfg_param_attr->power_mgmt_mode;
483 wid_list[i].type = WID_CHAR;
484 wid_list[i].size = sizeof(char);
485 hif_drv->cfg_values.power_mgmt_mode = (u8)cfg_param_attr->power_mgmt_mode;
486 } else {
487 netdev_err(vif->ndev, "Invalid power mode\n");
488 result = -EINVAL;
489 goto unlock;
491 i++;
493 if (cfg_param_attr->flag & RETRY_SHORT) {
494 if (cfg_param_attr->short_retry_limit > 0 &&
495 cfg_param_attr->short_retry_limit < 256) {
496 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
497 wid_list[i].val = (s8 *)&cfg_param_attr->short_retry_limit;
498 wid_list[i].type = WID_SHORT;
499 wid_list[i].size = sizeof(u16);
500 hif_drv->cfg_values.short_retry_limit = cfg_param_attr->short_retry_limit;
501 } else {
502 netdev_err(vif->ndev, "Range(1~256) over\n");
503 result = -EINVAL;
504 goto unlock;
506 i++;
508 if (cfg_param_attr->flag & RETRY_LONG) {
509 if (cfg_param_attr->long_retry_limit > 0 &&
510 cfg_param_attr->long_retry_limit < 256) {
511 wid_list[i].id = WID_LONG_RETRY_LIMIT;
512 wid_list[i].val = (s8 *)&cfg_param_attr->long_retry_limit;
513 wid_list[i].type = WID_SHORT;
514 wid_list[i].size = sizeof(u16);
515 hif_drv->cfg_values.long_retry_limit = cfg_param_attr->long_retry_limit;
516 } else {
517 netdev_err(vif->ndev, "Range(1~256) over\n");
518 result = -EINVAL;
519 goto unlock;
521 i++;
523 if (cfg_param_attr->flag & FRAG_THRESHOLD) {
524 if (cfg_param_attr->frag_threshold > 255 &&
525 cfg_param_attr->frag_threshold < 7937) {
526 wid_list[i].id = WID_FRAG_THRESHOLD;
527 wid_list[i].val = (s8 *)&cfg_param_attr->frag_threshold;
528 wid_list[i].type = WID_SHORT;
529 wid_list[i].size = sizeof(u16);
530 hif_drv->cfg_values.frag_threshold = cfg_param_attr->frag_threshold;
531 } else {
532 netdev_err(vif->ndev, "Threshold Range fail\n");
533 result = -EINVAL;
534 goto unlock;
536 i++;
538 if (cfg_param_attr->flag & RTS_THRESHOLD) {
539 if (cfg_param_attr->rts_threshold > 255 &&
540 cfg_param_attr->rts_threshold < 65536) {
541 wid_list[i].id = WID_RTS_THRESHOLD;
542 wid_list[i].val = (s8 *)&cfg_param_attr->rts_threshold;
543 wid_list[i].type = WID_SHORT;
544 wid_list[i].size = sizeof(u16);
545 hif_drv->cfg_values.rts_threshold = cfg_param_attr->rts_threshold;
546 } else {
547 netdev_err(vif->ndev, "Threshold Range fail\n");
548 result = -EINVAL;
549 goto unlock;
551 i++;
553 if (cfg_param_attr->flag & PREAMBLE) {
554 if (cfg_param_attr->preamble_type < 3) {
555 wid_list[i].id = WID_PREAMBLE;
556 wid_list[i].val = (s8 *)&cfg_param_attr->preamble_type;
557 wid_list[i].type = WID_CHAR;
558 wid_list[i].size = sizeof(char);
559 hif_drv->cfg_values.preamble_type = cfg_param_attr->preamble_type;
560 } else {
561 netdev_err(vif->ndev, "Preamle Range(0~2) over\n");
562 result = -EINVAL;
563 goto unlock;
565 i++;
567 if (cfg_param_attr->flag & SHORT_SLOT_ALLOWED) {
568 if (cfg_param_attr->short_slot_allowed < 2) {
569 wid_list[i].id = WID_SHORT_SLOT_ALLOWED;
570 wid_list[i].val = (s8 *)&cfg_param_attr->short_slot_allowed;
571 wid_list[i].type = WID_CHAR;
572 wid_list[i].size = sizeof(char);
573 hif_drv->cfg_values.short_slot_allowed = (u8)cfg_param_attr->short_slot_allowed;
574 } else {
575 netdev_err(vif->ndev, "Short slot(2) over\n");
576 result = -EINVAL;
577 goto unlock;
579 i++;
581 if (cfg_param_attr->flag & TXOP_PROT_DISABLE) {
582 if (cfg_param_attr->txop_prot_disabled < 2) {
583 wid_list[i].id = WID_11N_TXOP_PROT_DISABLE;
584 wid_list[i].val = (s8 *)&cfg_param_attr->txop_prot_disabled;
585 wid_list[i].type = WID_CHAR;
586 wid_list[i].size = sizeof(char);
587 hif_drv->cfg_values.txop_prot_disabled = (u8)cfg_param_attr->txop_prot_disabled;
588 } else {
589 netdev_err(vif->ndev, "TXOP prot disable\n");
590 result = -EINVAL;
591 goto unlock;
593 i++;
595 if (cfg_param_attr->flag & BEACON_INTERVAL) {
596 if (cfg_param_attr->beacon_interval > 0 &&
597 cfg_param_attr->beacon_interval < 65536) {
598 wid_list[i].id = WID_BEACON_INTERVAL;
599 wid_list[i].val = (s8 *)&cfg_param_attr->beacon_interval;
600 wid_list[i].type = WID_SHORT;
601 wid_list[i].size = sizeof(u16);
602 hif_drv->cfg_values.beacon_interval = cfg_param_attr->beacon_interval;
603 } else {
604 netdev_err(vif->ndev, "Beacon interval(1~65535)fail\n");
605 result = -EINVAL;
606 goto unlock;
608 i++;
610 if (cfg_param_attr->flag & DTIM_PERIOD) {
611 if (cfg_param_attr->dtim_period > 0 &&
612 cfg_param_attr->dtim_period < 256) {
613 wid_list[i].id = WID_DTIM_PERIOD;
614 wid_list[i].val = (s8 *)&cfg_param_attr->dtim_period;
615 wid_list[i].type = WID_CHAR;
616 wid_list[i].size = sizeof(char);
617 hif_drv->cfg_values.dtim_period = cfg_param_attr->dtim_period;
618 } else {
619 netdev_err(vif->ndev, "DTIM range(1~255) fail\n");
620 result = -EINVAL;
621 goto unlock;
623 i++;
625 if (cfg_param_attr->flag & SITE_SURVEY) {
626 if (cfg_param_attr->site_survey_enabled < 3) {
627 wid_list[i].id = WID_SITE_SURVEY;
628 wid_list[i].val = (s8 *)&cfg_param_attr->site_survey_enabled;
629 wid_list[i].type = WID_CHAR;
630 wid_list[i].size = sizeof(char);
631 hif_drv->cfg_values.site_survey_enabled = (u8)cfg_param_attr->site_survey_enabled;
632 } else {
633 netdev_err(vif->ndev, "Site survey disable\n");
634 result = -EINVAL;
635 goto unlock;
637 i++;
639 if (cfg_param_attr->flag & SITE_SURVEY_SCAN_TIME) {
640 if (cfg_param_attr->site_survey_scan_time > 0 &&
641 cfg_param_attr->site_survey_scan_time < 65536) {
642 wid_list[i].id = WID_SITE_SURVEY_SCAN_TIME;
643 wid_list[i].val = (s8 *)&cfg_param_attr->site_survey_scan_time;
644 wid_list[i].type = WID_SHORT;
645 wid_list[i].size = sizeof(u16);
646 hif_drv->cfg_values.site_survey_scan_time = cfg_param_attr->site_survey_scan_time;
647 } else {
648 netdev_err(vif->ndev, "Site scan time(1~65535) over\n");
649 result = -EINVAL;
650 goto unlock;
652 i++;
654 if (cfg_param_attr->flag & ACTIVE_SCANTIME) {
655 if (cfg_param_attr->active_scan_time > 0 &&
656 cfg_param_attr->active_scan_time < 65536) {
657 wid_list[i].id = WID_ACTIVE_SCAN_TIME;
658 wid_list[i].val = (s8 *)&cfg_param_attr->active_scan_time;
659 wid_list[i].type = WID_SHORT;
660 wid_list[i].size = sizeof(u16);
661 hif_drv->cfg_values.active_scan_time = cfg_param_attr->active_scan_time;
662 } else {
663 netdev_err(vif->ndev, "Active time(1~65535) over\n");
664 result = -EINVAL;
665 goto unlock;
667 i++;
669 if (cfg_param_attr->flag & PASSIVE_SCANTIME) {
670 if (cfg_param_attr->passive_scan_time > 0 &&
671 cfg_param_attr->passive_scan_time < 65536) {
672 wid_list[i].id = WID_PASSIVE_SCAN_TIME;
673 wid_list[i].val = (s8 *)&cfg_param_attr->passive_scan_time;
674 wid_list[i].type = WID_SHORT;
675 wid_list[i].size = sizeof(u16);
676 hif_drv->cfg_values.passive_scan_time = cfg_param_attr->passive_scan_time;
677 } else {
678 netdev_err(vif->ndev, "Passive time(1~65535) over\n");
679 result = -EINVAL;
680 goto unlock;
682 i++;
684 if (cfg_param_attr->flag & CURRENT_TX_RATE) {
685 enum CURRENT_TXRATE curr_tx_rate = cfg_param_attr->curr_tx_rate;
687 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1 ||
688 curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5 ||
689 curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6 ||
690 curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12 ||
691 curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24 ||
692 curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 ||
693 curr_tx_rate == MBPS_54) {
694 wid_list[i].id = WID_CURRENT_TX_RATE;
695 wid_list[i].val = (s8 *)&curr_tx_rate;
696 wid_list[i].type = WID_SHORT;
697 wid_list[i].size = sizeof(u16);
698 hif_drv->cfg_values.curr_tx_rate = (u8)curr_tx_rate;
699 } else {
700 netdev_err(vif->ndev, "out of TX rate\n");
701 result = -EINVAL;
702 goto unlock;
704 i++;
707 result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
708 i, wilc_get_vif_idx(vif));
710 if (result)
711 netdev_err(vif->ndev, "Error in setting CFG params\n");
713 unlock:
714 mutex_unlock(&hif_drv->cfg_values_lock);
715 return result;
718 static s32 handle_scan(struct wilc_vif *vif, struct scan_attr *scan_info)
720 s32 result = 0;
721 struct wid wid_list[5];
722 u32 index = 0;
723 u32 i;
724 u8 *buffer;
725 u8 valuesize = 0;
726 u8 *pu8HdnNtwrksWidVal = NULL;
727 struct host_if_drv *hif_drv = vif->hif_drv;
729 hif_drv->usr_scan_req.scan_result = scan_info->result;
730 hif_drv->usr_scan_req.arg = scan_info->arg;
732 if ((hif_drv->hif_state >= HOST_IF_SCANNING) &&
733 (hif_drv->hif_state < HOST_IF_CONNECTED)) {
734 netdev_err(vif->ndev, "Already scan\n");
735 result = -EBUSY;
736 goto ERRORHANDLER;
739 if (wilc_optaining_ip || wilc_connecting) {
740 netdev_err(vif->ndev, "Don't do obss scan\n");
741 result = -EBUSY;
742 goto ERRORHANDLER;
745 hif_drv->usr_scan_req.rcvd_ch_cnt = 0;
747 wid_list[index].id = (u16)WID_SSID_PROBE_REQ;
748 wid_list[index].type = WID_STR;
750 for (i = 0; i < scan_info->hidden_network.n_ssids; i++)
751 valuesize += ((scan_info->hidden_network.net_info[i].ssid_len) + 1);
752 pu8HdnNtwrksWidVal = kmalloc(valuesize + 1, GFP_KERNEL);
753 wid_list[index].val = pu8HdnNtwrksWidVal;
754 if (wid_list[index].val) {
755 buffer = wid_list[index].val;
757 *buffer++ = scan_info->hidden_network.n_ssids;
759 for (i = 0; i < scan_info->hidden_network.n_ssids; i++) {
760 *buffer++ = scan_info->hidden_network.net_info[i].ssid_len;
761 memcpy(buffer, scan_info->hidden_network.net_info[i].ssid, scan_info->hidden_network.net_info[i].ssid_len);
762 buffer += scan_info->hidden_network.net_info[i].ssid_len;
765 wid_list[index].size = (s32)(valuesize + 1);
766 index++;
769 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
770 wid_list[index].type = WID_BIN_DATA;
771 wid_list[index].val = scan_info->ies;
772 wid_list[index].size = scan_info->ies_len;
773 index++;
775 wid_list[index].id = WID_SCAN_TYPE;
776 wid_list[index].type = WID_CHAR;
777 wid_list[index].size = sizeof(char);
778 wid_list[index].val = (s8 *)&scan_info->type;
779 index++;
781 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
782 wid_list[index].type = WID_BIN_DATA;
784 if (scan_info->ch_freq_list &&
785 scan_info->ch_list_len > 0) {
786 int i;
788 for (i = 0; i < scan_info->ch_list_len; i++) {
789 if (scan_info->ch_freq_list[i] > 0)
790 scan_info->ch_freq_list[i] = scan_info->ch_freq_list[i] - 1;
794 wid_list[index].val = scan_info->ch_freq_list;
795 wid_list[index].size = scan_info->ch_list_len;
796 index++;
798 wid_list[index].id = WID_START_SCAN_REQ;
799 wid_list[index].type = WID_CHAR;
800 wid_list[index].size = sizeof(char);
801 wid_list[index].val = (s8 *)&scan_info->src;
802 index++;
804 if (hif_drv->hif_state == HOST_IF_CONNECTED)
805 scan_while_connected = true;
806 else if (hif_drv->hif_state == HOST_IF_IDLE)
807 scan_while_connected = false;
809 result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
810 index,
811 wilc_get_vif_idx(vif));
813 if (result)
814 netdev_err(vif->ndev, "Failed to send scan parameters\n");
816 ERRORHANDLER:
817 if (result) {
818 del_timer(&hif_drv->scan_timer);
819 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
822 kfree(scan_info->ch_freq_list);
823 scan_info->ch_freq_list = NULL;
825 kfree(scan_info->ies);
826 scan_info->ies = NULL;
827 kfree(scan_info->hidden_network.net_info);
828 scan_info->hidden_network.net_info = NULL;
830 kfree(pu8HdnNtwrksWidVal);
832 return result;
835 static s32 Handle_ScanDone(struct wilc_vif *vif,
836 enum scan_event enuEvent)
838 s32 result = 0;
839 u8 u8abort_running_scan;
840 struct wid wid;
841 struct host_if_drv *hif_drv = vif->hif_drv;
843 if (enuEvent == SCAN_EVENT_ABORTED) {
844 u8abort_running_scan = 1;
845 wid.id = (u16)WID_ABORT_RUNNING_SCAN;
846 wid.type = WID_CHAR;
847 wid.val = (s8 *)&u8abort_running_scan;
848 wid.size = sizeof(char);
850 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
851 wilc_get_vif_idx(vif));
853 if (result) {
854 netdev_err(vif->ndev, "Failed to set abort running\n");
855 result = -EFAULT;
859 if (!hif_drv) {
860 netdev_err(vif->ndev, "Driver handler is NULL\n");
861 return result;
864 if (hif_drv->usr_scan_req.scan_result) {
865 hif_drv->usr_scan_req.scan_result(enuEvent, NULL,
866 hif_drv->usr_scan_req.arg, NULL);
867 hif_drv->usr_scan_req.scan_result = NULL;
870 return result;
873 u8 wilc_connected_ssid[6] = {0};
874 static s32 Handle_Connect(struct wilc_vif *vif,
875 struct connect_attr *pstrHostIFconnectAttr)
877 s32 result = 0;
878 struct wid strWIDList[8];
879 u32 u32WidsCount = 0, dummyval = 0;
880 u8 *pu8CurrByte = NULL;
881 struct join_bss_param *ptstrJoinBssParam;
882 struct host_if_drv *hif_drv = vif->hif_drv;
884 if (memcmp(pstrHostIFconnectAttr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
885 result = 0;
886 netdev_err(vif->ndev, "Discard connect request\n");
887 return result;
890 ptstrJoinBssParam = pstrHostIFconnectAttr->params;
891 if (!ptstrJoinBssParam) {
892 netdev_err(vif->ndev, "Required BSSID not found\n");
893 result = -ENOENT;
894 goto ERRORHANDLER;
897 if (pstrHostIFconnectAttr->bssid) {
898 hif_drv->usr_conn_req.bssid = kmalloc(6, GFP_KERNEL);
899 memcpy(hif_drv->usr_conn_req.bssid, pstrHostIFconnectAttr->bssid, 6);
902 hif_drv->usr_conn_req.ssid_len = pstrHostIFconnectAttr->ssid_len;
903 if (pstrHostIFconnectAttr->ssid) {
904 hif_drv->usr_conn_req.ssid = kmalloc(pstrHostIFconnectAttr->ssid_len + 1, GFP_KERNEL);
905 memcpy(hif_drv->usr_conn_req.ssid,
906 pstrHostIFconnectAttr->ssid,
907 pstrHostIFconnectAttr->ssid_len);
908 hif_drv->usr_conn_req.ssid[pstrHostIFconnectAttr->ssid_len] = '\0';
911 hif_drv->usr_conn_req.ies_len = pstrHostIFconnectAttr->ies_len;
912 if (pstrHostIFconnectAttr->ies) {
913 hif_drv->usr_conn_req.ies = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
914 memcpy(hif_drv->usr_conn_req.ies,
915 pstrHostIFconnectAttr->ies,
916 pstrHostIFconnectAttr->ies_len);
919 hif_drv->usr_conn_req.security = pstrHostIFconnectAttr->security;
920 hif_drv->usr_conn_req.auth_type = pstrHostIFconnectAttr->auth_type;
921 hif_drv->usr_conn_req.conn_result = pstrHostIFconnectAttr->result;
922 hif_drv->usr_conn_req.arg = pstrHostIFconnectAttr->arg;
924 strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
925 strWIDList[u32WidsCount].type = WID_INT;
926 strWIDList[u32WidsCount].size = sizeof(u32);
927 strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
928 u32WidsCount++;
930 strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
931 strWIDList[u32WidsCount].type = WID_INT;
932 strWIDList[u32WidsCount].size = sizeof(u32);
933 strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
934 u32WidsCount++;
936 strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
937 strWIDList[u32WidsCount].type = WID_INT;
938 strWIDList[u32WidsCount].size = sizeof(u32);
939 strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
940 u32WidsCount++;
943 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
944 strWIDList[u32WidsCount].type = WID_BIN_DATA;
945 strWIDList[u32WidsCount].val = hif_drv->usr_conn_req.ies;
946 strWIDList[u32WidsCount].size = hif_drv->usr_conn_req.ies_len;
947 u32WidsCount++;
949 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
950 info_element_size = hif_drv->usr_conn_req.ies_len;
951 info_element = kmalloc(info_element_size, GFP_KERNEL);
952 memcpy(info_element, hif_drv->usr_conn_req.ies,
953 info_element_size);
956 strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
957 strWIDList[u32WidsCount].type = WID_CHAR;
958 strWIDList[u32WidsCount].size = sizeof(char);
959 strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.security;
960 u32WidsCount++;
962 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
963 mode_11i = hif_drv->usr_conn_req.security;
965 strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
966 strWIDList[u32WidsCount].type = WID_CHAR;
967 strWIDList[u32WidsCount].size = sizeof(char);
968 strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.auth_type;
969 u32WidsCount++;
971 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
972 auth_type = (u8)hif_drv->usr_conn_req.auth_type;
974 strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
975 strWIDList[u32WidsCount].type = WID_STR;
976 strWIDList[u32WidsCount].size = 112;
977 strWIDList[u32WidsCount].val = kmalloc(strWIDList[u32WidsCount].size, GFP_KERNEL);
979 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
980 join_req_size = strWIDList[u32WidsCount].size;
981 join_req = kmalloc(join_req_size, GFP_KERNEL);
983 if (!strWIDList[u32WidsCount].val) {
984 result = -EFAULT;
985 goto ERRORHANDLER;
988 pu8CurrByte = strWIDList[u32WidsCount].val;
990 if (pstrHostIFconnectAttr->ssid) {
991 memcpy(pu8CurrByte, pstrHostIFconnectAttr->ssid, pstrHostIFconnectAttr->ssid_len);
992 pu8CurrByte[pstrHostIFconnectAttr->ssid_len] = '\0';
994 pu8CurrByte += MAX_SSID_LEN;
995 *(pu8CurrByte++) = INFRASTRUCTURE;
997 if ((pstrHostIFconnectAttr->ch >= 1) && (pstrHostIFconnectAttr->ch <= 14)) {
998 *(pu8CurrByte++) = pstrHostIFconnectAttr->ch;
999 } else {
1000 netdev_err(vif->ndev, "Channel out of range\n");
1001 *(pu8CurrByte++) = 0xFF;
1003 *(pu8CurrByte++) = (ptstrJoinBssParam->cap_info) & 0xFF;
1004 *(pu8CurrByte++) = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
1006 if (pstrHostIFconnectAttr->bssid)
1007 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1008 pu8CurrByte += 6;
1010 if (pstrHostIFconnectAttr->bssid)
1011 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1012 pu8CurrByte += 6;
1014 *(pu8CurrByte++) = (ptstrJoinBssParam->beacon_period) & 0xFF;
1015 *(pu8CurrByte++) = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1016 *(pu8CurrByte++) = ptstrJoinBssParam->dtim_period;
1018 memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1019 pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1021 *(pu8CurrByte++) = ptstrJoinBssParam->wmm_cap;
1022 *(pu8CurrByte++) = ptstrJoinBssParam->uapsd_cap;
1024 *(pu8CurrByte++) = ptstrJoinBssParam->ht_capable;
1025 hif_drv->usr_conn_req.ht_capable = ptstrJoinBssParam->ht_capable;
1027 *(pu8CurrByte++) = ptstrJoinBssParam->rsn_found;
1028 *(pu8CurrByte++) = ptstrJoinBssParam->rsn_grp_policy;
1029 *(pu8CurrByte++) = ptstrJoinBssParam->mode_802_11i;
1031 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1032 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1034 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1035 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1037 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1038 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1040 *(pu8CurrByte++) = REAL_JOIN_REQ;
1041 *(pu8CurrByte++) = ptstrJoinBssParam->noa_enabled;
1043 if (ptstrJoinBssParam->noa_enabled) {
1044 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1045 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1046 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1047 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1049 *(pu8CurrByte++) = ptstrJoinBssParam->opp_enabled;
1050 *(pu8CurrByte++) = ptstrJoinBssParam->idx;
1052 if (ptstrJoinBssParam->opp_enabled)
1053 *(pu8CurrByte++) = ptstrJoinBssParam->ct_window;
1055 *(pu8CurrByte++) = ptstrJoinBssParam->cnt;
1057 memcpy(pu8CurrByte, ptstrJoinBssParam->duration, sizeof(ptstrJoinBssParam->duration));
1058 pu8CurrByte += sizeof(ptstrJoinBssParam->duration);
1060 memcpy(pu8CurrByte, ptstrJoinBssParam->interval, sizeof(ptstrJoinBssParam->interval));
1061 pu8CurrByte += sizeof(ptstrJoinBssParam->interval);
1063 memcpy(pu8CurrByte, ptstrJoinBssParam->start_time, sizeof(ptstrJoinBssParam->start_time));
1064 pu8CurrByte += sizeof(ptstrJoinBssParam->start_time);
1067 pu8CurrByte = strWIDList[u32WidsCount].val;
1068 u32WidsCount++;
1070 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1071 memcpy(join_req, pu8CurrByte, join_req_size);
1072 join_req_vif = vif;
1075 if (pstrHostIFconnectAttr->bssid)
1076 memcpy(wilc_connected_ssid,
1077 pstrHostIFconnectAttr->bssid, ETH_ALEN);
1079 result = wilc_send_config_pkt(vif, SET_CFG, strWIDList,
1080 u32WidsCount,
1081 wilc_get_vif_idx(vif));
1082 if (result) {
1083 netdev_err(vif->ndev, "failed to send config packet\n");
1084 result = -EFAULT;
1085 goto ERRORHANDLER;
1086 } else {
1087 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
1090 ERRORHANDLER:
1091 if (result) {
1092 struct connect_info strConnectInfo;
1094 del_timer(&hif_drv->connect_timer);
1096 memset(&strConnectInfo, 0, sizeof(struct connect_info));
1098 if (pstrHostIFconnectAttr->result) {
1099 if (pstrHostIFconnectAttr->bssid)
1100 memcpy(strConnectInfo.bssid, pstrHostIFconnectAttr->bssid, 6);
1102 if (pstrHostIFconnectAttr->ies) {
1103 strConnectInfo.req_ies_len = pstrHostIFconnectAttr->ies_len;
1104 strConnectInfo.req_ies = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
1105 memcpy(strConnectInfo.req_ies,
1106 pstrHostIFconnectAttr->ies,
1107 pstrHostIFconnectAttr->ies_len);
1110 pstrHostIFconnectAttr->result(CONN_DISCONN_EVENT_CONN_RESP,
1111 &strConnectInfo,
1112 MAC_DISCONNECTED,
1113 NULL,
1114 pstrHostIFconnectAttr->arg);
1115 hif_drv->hif_state = HOST_IF_IDLE;
1116 kfree(strConnectInfo.req_ies);
1117 strConnectInfo.req_ies = NULL;
1119 } else {
1120 netdev_err(vif->ndev, "Connect callback is NULL\n");
1124 kfree(pstrHostIFconnectAttr->bssid);
1125 pstrHostIFconnectAttr->bssid = NULL;
1127 kfree(pstrHostIFconnectAttr->ssid);
1128 pstrHostIFconnectAttr->ssid = NULL;
1130 kfree(pstrHostIFconnectAttr->ies);
1131 pstrHostIFconnectAttr->ies = NULL;
1133 kfree(pu8CurrByte);
1134 return result;
1137 static s32 Handle_ConnectTimeout(struct wilc_vif *vif)
1139 s32 result = 0;
1140 struct connect_info strConnectInfo;
1141 struct wid wid;
1142 u16 u16DummyReasonCode = 0;
1143 struct host_if_drv *hif_drv = vif->hif_drv;
1145 if (!hif_drv) {
1146 netdev_err(vif->ndev, "Driver handler is NULL\n");
1147 return result;
1150 hif_drv->hif_state = HOST_IF_IDLE;
1152 scan_while_connected = false;
1154 memset(&strConnectInfo, 0, sizeof(struct connect_info));
1156 if (hif_drv->usr_conn_req.conn_result) {
1157 if (hif_drv->usr_conn_req.bssid) {
1158 memcpy(strConnectInfo.bssid,
1159 hif_drv->usr_conn_req.bssid, 6);
1162 if (hif_drv->usr_conn_req.ies) {
1163 strConnectInfo.req_ies_len = hif_drv->usr_conn_req.ies_len;
1164 strConnectInfo.req_ies = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL);
1165 memcpy(strConnectInfo.req_ies,
1166 hif_drv->usr_conn_req.ies,
1167 hif_drv->usr_conn_req.ies_len);
1170 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1171 &strConnectInfo,
1172 MAC_DISCONNECTED,
1173 NULL,
1174 hif_drv->usr_conn_req.arg);
1176 kfree(strConnectInfo.req_ies);
1177 strConnectInfo.req_ies = NULL;
1178 } else {
1179 netdev_err(vif->ndev, "Connect callback is NULL\n");
1182 wid.id = (u16)WID_DISCONNECT;
1183 wid.type = WID_CHAR;
1184 wid.val = (s8 *)&u16DummyReasonCode;
1185 wid.size = sizeof(char);
1187 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1188 wilc_get_vif_idx(vif));
1189 if (result)
1190 netdev_err(vif->ndev, "Failed to send dissconect\n");
1192 hif_drv->usr_conn_req.ssid_len = 0;
1193 kfree(hif_drv->usr_conn_req.ssid);
1194 hif_drv->usr_conn_req.ssid = NULL;
1195 kfree(hif_drv->usr_conn_req.bssid);
1196 hif_drv->usr_conn_req.bssid = NULL;
1197 hif_drv->usr_conn_req.ies_len = 0;
1198 kfree(hif_drv->usr_conn_req.ies);
1199 hif_drv->usr_conn_req.ies = NULL;
1201 eth_zero_addr(wilc_connected_ssid);
1203 if (join_req && join_req_vif == vif) {
1204 kfree(join_req);
1205 join_req = NULL;
1208 if (info_element && join_req_vif == vif) {
1209 kfree(info_element);
1210 info_element = NULL;
1213 return result;
1216 static s32 Handle_RcvdNtwrkInfo(struct wilc_vif *vif,
1217 struct rcvd_net_info *pstrRcvdNetworkInfo)
1219 u32 i;
1220 bool bNewNtwrkFound;
1221 s32 result = 0;
1222 struct network_info *pstrNetworkInfo = NULL;
1223 void *pJoinParams = NULL;
1224 struct host_if_drv *hif_drv = vif->hif_drv;
1226 bNewNtwrkFound = true;
1228 if (hif_drv->usr_scan_req.scan_result) {
1229 wilc_parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo);
1230 if ((!pstrNetworkInfo) ||
1231 (!hif_drv->usr_scan_req.scan_result)) {
1232 netdev_err(vif->ndev, "driver is null\n");
1233 result = -EINVAL;
1234 goto done;
1237 for (i = 0; i < hif_drv->usr_scan_req.rcvd_ch_cnt; i++) {
1238 if ((hif_drv->usr_scan_req.net_info[i].bssid) &&
1239 (pstrNetworkInfo->bssid)) {
1240 if (memcmp(hif_drv->usr_scan_req.net_info[i].bssid,
1241 pstrNetworkInfo->bssid, 6) == 0) {
1242 if (pstrNetworkInfo->rssi <= hif_drv->usr_scan_req.net_info[i].rssi) {
1243 goto done;
1244 } else {
1245 hif_drv->usr_scan_req.net_info[i].rssi = pstrNetworkInfo->rssi;
1246 bNewNtwrkFound = false;
1247 break;
1253 if (bNewNtwrkFound) {
1254 if (hif_drv->usr_scan_req.rcvd_ch_cnt < MAX_NUM_SCANNED_NETWORKS) {
1255 hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].rssi = pstrNetworkInfo->rssi;
1257 if (hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].bssid &&
1258 pstrNetworkInfo->bssid) {
1259 memcpy(hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].bssid,
1260 pstrNetworkInfo->bssid, 6);
1262 hif_drv->usr_scan_req.rcvd_ch_cnt++;
1264 pstrNetworkInfo->new_network = true;
1265 pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
1267 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1268 hif_drv->usr_scan_req.arg,
1269 pJoinParams);
1272 } else {
1273 pstrNetworkInfo->new_network = false;
1274 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1275 hif_drv->usr_scan_req.arg, NULL);
1279 done:
1280 kfree(pstrRcvdNetworkInfo->buffer);
1281 pstrRcvdNetworkInfo->buffer = NULL;
1283 if (pstrNetworkInfo) {
1284 kfree(pstrNetworkInfo->ies);
1285 kfree(pstrNetworkInfo);
1288 return result;
1291 static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
1292 u8 *pu8AssocRespInfo,
1293 u32 u32MaxAssocRespInfoLen,
1294 u32 *pu32RcvdAssocRespInfoLen);
1296 static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1297 struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
1299 s32 result = 0;
1300 u8 u8MsgType = 0;
1301 u8 u8MsgID = 0;
1302 u16 u16MsgLen = 0;
1303 u16 u16WidID = (u16)WID_NIL;
1304 u8 u8WidLen = 0;
1305 u8 u8MacStatus;
1306 u8 u8MacStatusReasonCode;
1307 u8 u8MacStatusAdditionalInfo;
1308 struct connect_info strConnectInfo;
1309 struct disconnect_info strDisconnectNotifInfo;
1310 s32 s32Err = 0;
1311 struct host_if_drv *hif_drv = vif->hif_drv;
1313 if (!hif_drv) {
1314 netdev_err(vif->ndev, "Driver handler is NULL\n");
1315 return -ENODEV;
1318 if ((hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) ||
1319 (hif_drv->hif_state == HOST_IF_CONNECTED) ||
1320 hif_drv->usr_scan_req.scan_result) {
1321 if (!pstrRcvdGnrlAsyncInfo->buffer ||
1322 !hif_drv->usr_conn_req.conn_result) {
1323 netdev_err(vif->ndev, "driver is null\n");
1324 return -EINVAL;
1327 u8MsgType = pstrRcvdGnrlAsyncInfo->buffer[0];
1329 if ('I' != u8MsgType) {
1330 netdev_err(vif->ndev, "Received Message incorrect.\n");
1331 return -EFAULT;
1334 u8MsgID = pstrRcvdGnrlAsyncInfo->buffer[1];
1335 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[2], pstrRcvdGnrlAsyncInfo->buffer[3]);
1336 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[4], pstrRcvdGnrlAsyncInfo->buffer[5]);
1337 u8WidLen = pstrRcvdGnrlAsyncInfo->buffer[6];
1338 u8MacStatus = pstrRcvdGnrlAsyncInfo->buffer[7];
1339 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->buffer[8];
1340 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->buffer[9];
1341 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
1342 u32 u32RcvdAssocRespInfoLen = 0;
1343 struct connect_resp_info *pstrConnectRespInfo = NULL;
1345 memset(&strConnectInfo, 0, sizeof(struct connect_info));
1347 if (u8MacStatus == MAC_CONNECTED) {
1348 memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1350 host_int_get_assoc_res_info(vif,
1351 rcv_assoc_resp,
1352 MAX_ASSOC_RESP_FRAME_SIZE,
1353 &u32RcvdAssocRespInfoLen);
1355 if (u32RcvdAssocRespInfoLen != 0) {
1356 s32Err = wilc_parse_assoc_resp_info(rcv_assoc_resp, u32RcvdAssocRespInfoLen,
1357 &pstrConnectRespInfo);
1358 if (s32Err) {
1359 netdev_err(vif->ndev, "wilc_parse_assoc_resp_info() returned error %d\n", s32Err);
1360 } else {
1361 strConnectInfo.status = pstrConnectRespInfo->status;
1363 if (strConnectInfo.status == SUCCESSFUL_STATUSCODE) {
1364 if (pstrConnectRespInfo->ies) {
1365 strConnectInfo.resp_ies_len = pstrConnectRespInfo->ies_len;
1366 strConnectInfo.resp_ies = kmalloc(pstrConnectRespInfo->ies_len, GFP_KERNEL);
1367 memcpy(strConnectInfo.resp_ies, pstrConnectRespInfo->ies,
1368 pstrConnectRespInfo->ies_len);
1372 if (pstrConnectRespInfo) {
1373 kfree(pstrConnectRespInfo->ies);
1374 kfree(pstrConnectRespInfo);
1380 if ((u8MacStatus == MAC_CONNECTED) &&
1381 (strConnectInfo.status != SUCCESSFUL_STATUSCODE)) {
1382 netdev_err(vif->ndev, "Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1383 eth_zero_addr(wilc_connected_ssid);
1384 } else if (u8MacStatus == MAC_DISCONNECTED) {
1385 netdev_err(vif->ndev, "Received MAC status is MAC_DISCONNECTED\n");
1386 eth_zero_addr(wilc_connected_ssid);
1389 if (hif_drv->usr_conn_req.bssid) {
1390 memcpy(strConnectInfo.bssid, hif_drv->usr_conn_req.bssid, 6);
1392 if ((u8MacStatus == MAC_CONNECTED) &&
1393 (strConnectInfo.status == SUCCESSFUL_STATUSCODE)) {
1394 memcpy(hif_drv->assoc_bssid,
1395 hif_drv->usr_conn_req.bssid, ETH_ALEN);
1399 if (hif_drv->usr_conn_req.ies) {
1400 strConnectInfo.req_ies_len = hif_drv->usr_conn_req.ies_len;
1401 strConnectInfo.req_ies = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL);
1402 memcpy(strConnectInfo.req_ies,
1403 hif_drv->usr_conn_req.ies,
1404 hif_drv->usr_conn_req.ies_len);
1407 del_timer(&hif_drv->connect_timer);
1408 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1409 &strConnectInfo,
1410 u8MacStatus,
1411 NULL,
1412 hif_drv->usr_conn_req.arg);
1414 if ((u8MacStatus == MAC_CONNECTED) &&
1415 (strConnectInfo.status == SUCCESSFUL_STATUSCODE)) {
1416 wilc_set_power_mgmt(vif, 0, 0);
1418 hif_drv->hif_state = HOST_IF_CONNECTED;
1420 wilc_optaining_ip = true;
1421 mod_timer(&wilc_during_ip_timer,
1422 jiffies + msecs_to_jiffies(10000));
1423 } else {
1424 hif_drv->hif_state = HOST_IF_IDLE;
1425 scan_while_connected = false;
1428 kfree(strConnectInfo.resp_ies);
1429 strConnectInfo.resp_ies = NULL;
1431 kfree(strConnectInfo.req_ies);
1432 strConnectInfo.req_ies = NULL;
1433 hif_drv->usr_conn_req.ssid_len = 0;
1434 kfree(hif_drv->usr_conn_req.ssid);
1435 hif_drv->usr_conn_req.ssid = NULL;
1436 kfree(hif_drv->usr_conn_req.bssid);
1437 hif_drv->usr_conn_req.bssid = NULL;
1438 hif_drv->usr_conn_req.ies_len = 0;
1439 kfree(hif_drv->usr_conn_req.ies);
1440 hif_drv->usr_conn_req.ies = NULL;
1441 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1442 (hif_drv->hif_state == HOST_IF_CONNECTED)) {
1443 memset(&strDisconnectNotifInfo, 0, sizeof(struct disconnect_info));
1445 if (hif_drv->usr_scan_req.scan_result) {
1446 del_timer(&hif_drv->scan_timer);
1447 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
1450 strDisconnectNotifInfo.reason = 0;
1451 strDisconnectNotifInfo.ie = NULL;
1452 strDisconnectNotifInfo.ie_len = 0;
1454 if (hif_drv->usr_conn_req.conn_result) {
1455 wilc_optaining_ip = false;
1456 wilc_set_power_mgmt(vif, 0, 0);
1458 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1459 NULL,
1461 &strDisconnectNotifInfo,
1462 hif_drv->usr_conn_req.arg);
1463 } else {
1464 netdev_err(vif->ndev, "Connect result NULL\n");
1467 eth_zero_addr(hif_drv->assoc_bssid);
1469 hif_drv->usr_conn_req.ssid_len = 0;
1470 kfree(hif_drv->usr_conn_req.ssid);
1471 hif_drv->usr_conn_req.ssid = NULL;
1472 kfree(hif_drv->usr_conn_req.bssid);
1473 hif_drv->usr_conn_req.bssid = NULL;
1474 hif_drv->usr_conn_req.ies_len = 0;
1475 kfree(hif_drv->usr_conn_req.ies);
1476 hif_drv->usr_conn_req.ies = NULL;
1478 if (join_req && join_req_vif == vif) {
1479 kfree(join_req);
1480 join_req = NULL;
1483 if (info_element && join_req_vif == vif) {
1484 kfree(info_element);
1485 info_element = NULL;
1488 hif_drv->hif_state = HOST_IF_IDLE;
1489 scan_while_connected = false;
1491 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1492 (hif_drv->usr_scan_req.scan_result)) {
1493 del_timer(&hif_drv->scan_timer);
1494 if (hif_drv->usr_scan_req.scan_result)
1495 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
1499 kfree(pstrRcvdGnrlAsyncInfo->buffer);
1500 pstrRcvdGnrlAsyncInfo->buffer = NULL;
1502 return result;
1505 static int Handle_Key(struct wilc_vif *vif,
1506 struct key_attr *pstrHostIFkeyAttr)
1508 s32 result = 0;
1509 struct wid wid;
1510 struct wid strWIDList[5];
1511 u8 i;
1512 u8 *pu8keybuf;
1513 s8 s8idxarray[1];
1514 s8 ret = 0;
1515 struct host_if_drv *hif_drv = vif->hif_drv;
1517 switch (pstrHostIFkeyAttr->type) {
1518 case WEP:
1520 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1521 strWIDList[0].id = (u16)WID_11I_MODE;
1522 strWIDList[0].type = WID_CHAR;
1523 strWIDList[0].size = sizeof(char);
1524 strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.mode;
1526 strWIDList[1].id = WID_AUTH_TYPE;
1527 strWIDList[1].type = WID_CHAR;
1528 strWIDList[1].size = sizeof(char);
1529 strWIDList[1].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.auth_type;
1531 pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2,
1532 GFP_KERNEL);
1533 if (!pu8keybuf)
1534 return -ENOMEM;
1536 pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1537 pu8keybuf[1] = pstrHostIFkeyAttr->attr.wep.key_len;
1539 memcpy(&pu8keybuf[2], pstrHostIFkeyAttr->attr.wep.key,
1540 pstrHostIFkeyAttr->attr.wep.key_len);
1542 kfree(pstrHostIFkeyAttr->attr.wep.key);
1544 strWIDList[2].id = (u16)WID_WEP_KEY_VALUE;
1545 strWIDList[2].type = WID_STR;
1546 strWIDList[2].size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1547 strWIDList[2].val = (s8 *)pu8keybuf;
1549 result = wilc_send_config_pkt(vif, SET_CFG,
1550 strWIDList, 3,
1551 wilc_get_vif_idx(vif));
1552 kfree(pu8keybuf);
1553 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1554 pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
1555 if (!pu8keybuf)
1556 return -ENOMEM;
1557 pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1558 memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
1559 memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
1560 pstrHostIFkeyAttr->attr.wep.key_len);
1561 kfree(pstrHostIFkeyAttr->attr.wep.key);
1563 wid.id = (u16)WID_ADD_WEP_KEY;
1564 wid.type = WID_STR;
1565 wid.val = (s8 *)pu8keybuf;
1566 wid.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1568 result = wilc_send_config_pkt(vif, SET_CFG,
1569 &wid, 1,
1570 wilc_get_vif_idx(vif));
1571 kfree(pu8keybuf);
1572 } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
1573 wid.id = (u16)WID_REMOVE_WEP_KEY;
1574 wid.type = WID_STR;
1576 s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
1577 wid.val = s8idxarray;
1578 wid.size = 1;
1580 result = wilc_send_config_pkt(vif, SET_CFG,
1581 &wid, 1,
1582 wilc_get_vif_idx(vif));
1583 } else if (pstrHostIFkeyAttr->action & DEFAULTKEY) {
1584 wid.id = (u16)WID_KEY_ID;
1585 wid.type = WID_CHAR;
1586 wid.val = (s8 *)&pstrHostIFkeyAttr->attr.wep.index;
1587 wid.size = sizeof(char);
1589 result = wilc_send_config_pkt(vif, SET_CFG,
1590 &wid, 1,
1591 wilc_get_vif_idx(vif));
1593 complete(&hif_drv->comp_test_key_block);
1594 break;
1596 case WPA_RX_GTK:
1597 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1598 pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1599 if (!pu8keybuf) {
1600 ret = -ENOMEM;
1601 goto _WPARxGtk_end_case_;
1604 if (pstrHostIFkeyAttr->attr.wpa.seq)
1605 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1607 memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1608 memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1609 memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1610 pstrHostIFkeyAttr->attr.wpa.key_len);
1612 strWIDList[0].id = (u16)WID_11I_MODE;
1613 strWIDList[0].type = WID_CHAR;
1614 strWIDList[0].size = sizeof(char);
1615 strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
1617 strWIDList[1].id = (u16)WID_ADD_RX_GTK;
1618 strWIDList[1].type = WID_STR;
1619 strWIDList[1].val = (s8 *)pu8keybuf;
1620 strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
1622 result = wilc_send_config_pkt(vif, SET_CFG,
1623 strWIDList, 2,
1624 wilc_get_vif_idx(vif));
1626 kfree(pu8keybuf);
1627 complete(&hif_drv->comp_test_key_block);
1628 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1629 pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1630 if (!pu8keybuf) {
1631 ret = -ENOMEM;
1632 goto _WPARxGtk_end_case_;
1635 if (hif_drv->hif_state == HOST_IF_CONNECTED)
1636 memcpy(pu8keybuf, hif_drv->assoc_bssid, ETH_ALEN);
1637 else
1638 netdev_err(vif->ndev, "Couldn't handle\n");
1640 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1641 memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1642 memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1643 memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1644 pstrHostIFkeyAttr->attr.wpa.key_len);
1646 wid.id = (u16)WID_ADD_RX_GTK;
1647 wid.type = WID_STR;
1648 wid.val = (s8 *)pu8keybuf;
1649 wid.size = RX_MIC_KEY_MSG_LEN;
1651 result = wilc_send_config_pkt(vif, SET_CFG,
1652 &wid, 1,
1653 wilc_get_vif_idx(vif));
1655 kfree(pu8keybuf);
1656 complete(&hif_drv->comp_test_key_block);
1658 _WPARxGtk_end_case_:
1659 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1660 kfree(pstrHostIFkeyAttr->attr.wpa.seq);
1661 if (ret)
1662 return ret;
1664 break;
1666 case WPA_PTK:
1667 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1668 pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1669 if (!pu8keybuf) {
1670 ret = -ENOMEM;
1671 goto _WPAPtk_end_case_;
1674 memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1675 memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1676 memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1677 memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
1678 pstrHostIFkeyAttr->attr.wpa.key_len);
1680 strWIDList[0].id = (u16)WID_11I_MODE;
1681 strWIDList[0].type = WID_CHAR;
1682 strWIDList[0].size = sizeof(char);
1683 strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
1685 strWIDList[1].id = (u16)WID_ADD_PTK;
1686 strWIDList[1].type = WID_STR;
1687 strWIDList[1].val = (s8 *)pu8keybuf;
1688 strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
1690 result = wilc_send_config_pkt(vif, SET_CFG,
1691 strWIDList, 2,
1692 wilc_get_vif_idx(vif));
1693 kfree(pu8keybuf);
1694 complete(&hif_drv->comp_test_key_block);
1695 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1696 pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1697 if (!pu8keybuf) {
1698 netdev_err(vif->ndev, "No buffer send PTK\n");
1699 ret = -ENOMEM;
1700 goto _WPAPtk_end_case_;
1703 memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1704 memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1705 memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
1706 pstrHostIFkeyAttr->attr.wpa.key_len);
1708 wid.id = (u16)WID_ADD_PTK;
1709 wid.type = WID_STR;
1710 wid.val = (s8 *)pu8keybuf;
1711 wid.size = PTK_KEY_MSG_LEN;
1713 result = wilc_send_config_pkt(vif, SET_CFG,
1714 &wid, 1,
1715 wilc_get_vif_idx(vif));
1716 kfree(pu8keybuf);
1717 complete(&hif_drv->comp_test_key_block);
1720 _WPAPtk_end_case_:
1721 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1722 if (ret)
1723 return ret;
1725 break;
1727 case PMKSA:
1728 pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
1729 if (!pu8keybuf) {
1730 netdev_err(vif->ndev, "No buffer to send PMKSA Key\n");
1731 return -ENOMEM;
1734 pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
1736 for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
1737 memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
1738 memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
1741 wid.id = (u16)WID_PMKID_INFO;
1742 wid.type = WID_STR;
1743 wid.val = (s8 *)pu8keybuf;
1744 wid.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
1746 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1747 wilc_get_vif_idx(vif));
1749 kfree(pu8keybuf);
1750 break;
1753 if (result)
1754 netdev_err(vif->ndev, "Failed to send key config packet\n");
1756 return result;
1759 static void Handle_Disconnect(struct wilc_vif *vif)
1761 struct wid wid;
1762 struct host_if_drv *hif_drv = vif->hif_drv;
1764 s32 result = 0;
1765 u16 u16DummyReasonCode = 0;
1767 wid.id = (u16)WID_DISCONNECT;
1768 wid.type = WID_CHAR;
1769 wid.val = (s8 *)&u16DummyReasonCode;
1770 wid.size = sizeof(char);
1772 wilc_optaining_ip = false;
1773 wilc_set_power_mgmt(vif, 0, 0);
1775 eth_zero_addr(wilc_connected_ssid);
1777 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1778 wilc_get_vif_idx(vif));
1780 if (result) {
1781 netdev_err(vif->ndev, "Failed to send dissconect\n");
1782 } else {
1783 struct disconnect_info strDisconnectNotifInfo;
1785 memset(&strDisconnectNotifInfo, 0, sizeof(struct disconnect_info));
1787 strDisconnectNotifInfo.reason = 0;
1788 strDisconnectNotifInfo.ie = NULL;
1789 strDisconnectNotifInfo.ie_len = 0;
1791 if (hif_drv->usr_scan_req.scan_result) {
1792 del_timer(&hif_drv->scan_timer);
1793 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED,
1794 NULL,
1795 hif_drv->usr_scan_req.arg,
1796 NULL);
1797 hif_drv->usr_scan_req.scan_result = NULL;
1800 if (hif_drv->usr_conn_req.conn_result) {
1801 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
1802 del_timer(&hif_drv->connect_timer);
1804 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1805 NULL,
1807 &strDisconnectNotifInfo,
1808 hif_drv->usr_conn_req.arg);
1809 } else {
1810 netdev_err(vif->ndev, "conn_result = NULL\n");
1813 scan_while_connected = false;
1815 hif_drv->hif_state = HOST_IF_IDLE;
1817 eth_zero_addr(hif_drv->assoc_bssid);
1819 hif_drv->usr_conn_req.ssid_len = 0;
1820 kfree(hif_drv->usr_conn_req.ssid);
1821 hif_drv->usr_conn_req.ssid = NULL;
1822 kfree(hif_drv->usr_conn_req.bssid);
1823 hif_drv->usr_conn_req.bssid = NULL;
1824 hif_drv->usr_conn_req.ies_len = 0;
1825 kfree(hif_drv->usr_conn_req.ies);
1826 hif_drv->usr_conn_req.ies = NULL;
1828 if (join_req && join_req_vif == vif) {
1829 kfree(join_req);
1830 join_req = NULL;
1833 if (info_element && join_req_vif == vif) {
1834 kfree(info_element);
1835 info_element = NULL;
1839 complete(&hif_drv->comp_test_disconn_block);
1842 void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
1844 if (!vif->hif_drv)
1845 return;
1846 if ((vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) ||
1847 (vif->hif_drv->hif_state == HOST_IF_CONNECTING))
1848 wilc_disconnect(vif, 1);
1851 static void Handle_GetRssi(struct wilc_vif *vif)
1853 s32 result = 0;
1854 struct wid wid;
1856 wid.id = (u16)WID_RSSI;
1857 wid.type = WID_CHAR;
1858 wid.val = &rssi;
1859 wid.size = sizeof(char);
1861 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
1862 wilc_get_vif_idx(vif));
1863 if (result) {
1864 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1865 result = -EFAULT;
1868 complete(&vif->hif_drv->comp_get_rssi);
1871 static s32 Handle_GetStatistics(struct wilc_vif *vif,
1872 struct rf_info *pstrStatistics)
1874 struct wid strWIDList[5];
1875 u32 u32WidsCount = 0, result = 0;
1877 strWIDList[u32WidsCount].id = WID_LINKSPEED;
1878 strWIDList[u32WidsCount].type = WID_CHAR;
1879 strWIDList[u32WidsCount].size = sizeof(char);
1880 strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->link_speed;
1881 u32WidsCount++;
1883 strWIDList[u32WidsCount].id = WID_RSSI;
1884 strWIDList[u32WidsCount].type = WID_CHAR;
1885 strWIDList[u32WidsCount].size = sizeof(char);
1886 strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rssi;
1887 u32WidsCount++;
1889 strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
1890 strWIDList[u32WidsCount].type = WID_INT;
1891 strWIDList[u32WidsCount].size = sizeof(u32);
1892 strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_cnt;
1893 u32WidsCount++;
1895 strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
1896 strWIDList[u32WidsCount].type = WID_INT;
1897 strWIDList[u32WidsCount].size = sizeof(u32);
1898 strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rx_cnt;
1899 u32WidsCount++;
1901 strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
1902 strWIDList[u32WidsCount].type = WID_INT;
1903 strWIDList[u32WidsCount].size = sizeof(u32);
1904 strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_fail_cnt;
1905 u32WidsCount++;
1907 result = wilc_send_config_pkt(vif, GET_CFG, strWIDList,
1908 u32WidsCount,
1909 wilc_get_vif_idx(vif));
1911 if (result)
1912 netdev_err(vif->ndev, "Failed to send scan parameters\n");
1914 if (pstrStatistics->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
1915 pstrStatistics->link_speed != DEFAULT_LINK_SPEED)
1916 wilc_enable_tcp_ack_filter(true);
1917 else if (pstrStatistics->link_speed != DEFAULT_LINK_SPEED)
1918 wilc_enable_tcp_ack_filter(false);
1920 if (pstrStatistics != &vif->wilc->dummy_statistics)
1921 complete(&hif_wait_response);
1922 return 0;
1925 static s32 Handle_Get_InActiveTime(struct wilc_vif *vif,
1926 struct sta_inactive_t *strHostIfStaInactiveT)
1928 s32 result = 0;
1929 u8 *stamac;
1930 struct wid wid;
1931 struct host_if_drv *hif_drv = vif->hif_drv;
1933 wid.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
1934 wid.type = WID_STR;
1935 wid.size = ETH_ALEN;
1936 wid.val = kmalloc(wid.size, GFP_KERNEL);
1938 stamac = wid.val;
1939 memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
1941 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1942 wilc_get_vif_idx(vif));
1944 if (result) {
1945 netdev_err(vif->ndev, "Failed to SET incative time\n");
1946 return -EFAULT;
1949 wid.id = (u16)WID_GET_INACTIVE_TIME;
1950 wid.type = WID_INT;
1951 wid.val = (s8 *)&inactive_time;
1952 wid.size = sizeof(u32);
1954 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
1955 wilc_get_vif_idx(vif));
1957 if (result) {
1958 netdev_err(vif->ndev, "Failed to get incative time\n");
1959 return -EFAULT;
1962 complete(&hif_drv->comp_inactive_time);
1964 return result;
1967 static void Handle_AddBeacon(struct wilc_vif *vif,
1968 struct beacon_attr *pstrSetBeaconParam)
1970 s32 result = 0;
1971 struct wid wid;
1972 u8 *pu8CurrByte;
1974 wid.id = (u16)WID_ADD_BEACON;
1975 wid.type = WID_BIN;
1976 wid.size = pstrSetBeaconParam->head_len + pstrSetBeaconParam->tail_len + 16;
1977 wid.val = kmalloc(wid.size, GFP_KERNEL);
1978 if (!wid.val)
1979 goto ERRORHANDLER;
1981 pu8CurrByte = wid.val;
1982 *pu8CurrByte++ = (pstrSetBeaconParam->interval & 0xFF);
1983 *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 8) & 0xFF);
1984 *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 16) & 0xFF);
1985 *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 24) & 0xFF);
1987 *pu8CurrByte++ = (pstrSetBeaconParam->dtim_period & 0xFF);
1988 *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 8) & 0xFF);
1989 *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 16) & 0xFF);
1990 *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 24) & 0xFF);
1992 *pu8CurrByte++ = (pstrSetBeaconParam->head_len & 0xFF);
1993 *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 8) & 0xFF);
1994 *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 16) & 0xFF);
1995 *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 24) & 0xFF);
1997 memcpy(pu8CurrByte, pstrSetBeaconParam->head, pstrSetBeaconParam->head_len);
1998 pu8CurrByte += pstrSetBeaconParam->head_len;
2000 *pu8CurrByte++ = (pstrSetBeaconParam->tail_len & 0xFF);
2001 *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 8) & 0xFF);
2002 *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 16) & 0xFF);
2003 *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 24) & 0xFF);
2005 if (pstrSetBeaconParam->tail)
2006 memcpy(pu8CurrByte, pstrSetBeaconParam->tail, pstrSetBeaconParam->tail_len);
2007 pu8CurrByte += pstrSetBeaconParam->tail_len;
2009 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2010 wilc_get_vif_idx(vif));
2011 if (result)
2012 netdev_err(vif->ndev, "Failed to send add beacon\n");
2014 ERRORHANDLER:
2015 kfree(wid.val);
2016 kfree(pstrSetBeaconParam->head);
2017 kfree(pstrSetBeaconParam->tail);
2020 static void Handle_DelBeacon(struct wilc_vif *vif)
2022 s32 result = 0;
2023 struct wid wid;
2024 u8 *pu8CurrByte;
2026 wid.id = (u16)WID_DEL_BEACON;
2027 wid.type = WID_CHAR;
2028 wid.size = sizeof(char);
2029 wid.val = &del_beacon;
2031 if (!wid.val)
2032 return;
2034 pu8CurrByte = wid.val;
2036 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2037 wilc_get_vif_idx(vif));
2038 if (result)
2039 netdev_err(vif->ndev, "Failed to send delete beacon\n");
2042 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
2043 struct add_sta_param *pstrStationParam)
2045 u8 *pu8CurrByte;
2047 pu8CurrByte = pu8Buffer;
2049 memcpy(pu8CurrByte, pstrStationParam->bssid, ETH_ALEN);
2050 pu8CurrByte += ETH_ALEN;
2052 *pu8CurrByte++ = pstrStationParam->aid & 0xFF;
2053 *pu8CurrByte++ = (pstrStationParam->aid >> 8) & 0xFF;
2055 *pu8CurrByte++ = pstrStationParam->rates_len;
2056 if (pstrStationParam->rates_len > 0)
2057 memcpy(pu8CurrByte, pstrStationParam->rates,
2058 pstrStationParam->rates_len);
2059 pu8CurrByte += pstrStationParam->rates_len;
2061 *pu8CurrByte++ = pstrStationParam->ht_supported;
2062 *pu8CurrByte++ = pstrStationParam->ht_capa_info & 0xFF;
2063 *pu8CurrByte++ = (pstrStationParam->ht_capa_info >> 8) & 0xFF;
2065 *pu8CurrByte++ = pstrStationParam->ht_ampdu_params;
2066 memcpy(pu8CurrByte, pstrStationParam->ht_supp_mcs_set,
2067 WILC_SUPP_MCS_SET_SIZE);
2068 pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
2070 *pu8CurrByte++ = pstrStationParam->ht_ext_params & 0xFF;
2071 *pu8CurrByte++ = (pstrStationParam->ht_ext_params >> 8) & 0xFF;
2073 *pu8CurrByte++ = pstrStationParam->ht_tx_bf_cap & 0xFF;
2074 *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 8) & 0xFF;
2075 *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 16) & 0xFF;
2076 *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 24) & 0xFF;
2078 *pu8CurrByte++ = pstrStationParam->ht_ante_sel;
2080 *pu8CurrByte++ = pstrStationParam->flags_mask & 0xFF;
2081 *pu8CurrByte++ = (pstrStationParam->flags_mask >> 8) & 0xFF;
2083 *pu8CurrByte++ = pstrStationParam->flags_set & 0xFF;
2084 *pu8CurrByte++ = (pstrStationParam->flags_set >> 8) & 0xFF;
2086 return pu8CurrByte - pu8Buffer;
2089 static void Handle_AddStation(struct wilc_vif *vif,
2090 struct add_sta_param *pstrStationParam)
2092 s32 result = 0;
2093 struct wid wid;
2094 u8 *pu8CurrByte;
2096 wid.id = (u16)WID_ADD_STA;
2097 wid.type = WID_BIN;
2098 wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len;
2100 wid.val = kmalloc(wid.size, GFP_KERNEL);
2101 if (!wid.val)
2102 goto ERRORHANDLER;
2104 pu8CurrByte = wid.val;
2105 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2107 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2108 wilc_get_vif_idx(vif));
2109 if (result != 0)
2110 netdev_err(vif->ndev, "Failed to send add station\n");
2112 ERRORHANDLER:
2113 kfree(pstrStationParam->rates);
2114 kfree(wid.val);
2117 static void Handle_DelAllSta(struct wilc_vif *vif,
2118 struct del_all_sta *pstrDelAllStaParam)
2120 s32 result = 0;
2121 struct wid wid;
2122 u8 *pu8CurrByte;
2123 u8 i;
2124 u8 au8Zero_Buff[6] = {0};
2126 wid.id = (u16)WID_DEL_ALL_STA;
2127 wid.type = WID_STR;
2128 wid.size = (pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1;
2130 wid.val = kmalloc((pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1, GFP_KERNEL);
2131 if (!wid.val)
2132 goto ERRORHANDLER;
2134 pu8CurrByte = wid.val;
2136 *(pu8CurrByte++) = pstrDelAllStaParam->assoc_sta;
2138 for (i = 0; i < MAX_NUM_STA; i++) {
2139 if (memcmp(pstrDelAllStaParam->del_all_sta[i], au8Zero_Buff, ETH_ALEN))
2140 memcpy(pu8CurrByte, pstrDelAllStaParam->del_all_sta[i], ETH_ALEN);
2141 else
2142 continue;
2144 pu8CurrByte += ETH_ALEN;
2147 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2148 wilc_get_vif_idx(vif));
2149 if (result)
2150 netdev_err(vif->ndev, "Failed to send add station\n");
2152 ERRORHANDLER:
2153 kfree(wid.val);
2155 complete(&hif_wait_response);
2158 static void Handle_DelStation(struct wilc_vif *vif,
2159 struct del_sta *pstrDelStaParam)
2161 s32 result = 0;
2162 struct wid wid;
2163 u8 *pu8CurrByte;
2165 wid.id = (u16)WID_REMOVE_STA;
2166 wid.type = WID_BIN;
2167 wid.size = ETH_ALEN;
2169 wid.val = kmalloc(wid.size, GFP_KERNEL);
2170 if (!wid.val)
2171 goto ERRORHANDLER;
2173 pu8CurrByte = wid.val;
2175 memcpy(pu8CurrByte, pstrDelStaParam->mac_addr, ETH_ALEN);
2177 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2178 wilc_get_vif_idx(vif));
2179 if (result)
2180 netdev_err(vif->ndev, "Failed to send add station\n");
2182 ERRORHANDLER:
2183 kfree(wid.val);
2186 static void Handle_EditStation(struct wilc_vif *vif,
2187 struct add_sta_param *pstrStationParam)
2189 s32 result = 0;
2190 struct wid wid;
2191 u8 *pu8CurrByte;
2193 wid.id = (u16)WID_EDIT_STA;
2194 wid.type = WID_BIN;
2195 wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len;
2197 wid.val = kmalloc(wid.size, GFP_KERNEL);
2198 if (!wid.val)
2199 goto ERRORHANDLER;
2201 pu8CurrByte = wid.val;
2202 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2204 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2205 wilc_get_vif_idx(vif));
2206 if (result)
2207 netdev_err(vif->ndev, "Failed to send edit station\n");
2209 ERRORHANDLER:
2210 kfree(pstrStationParam->rates);
2211 kfree(wid.val);
2214 static int Handle_RemainOnChan(struct wilc_vif *vif,
2215 struct remain_ch *pstrHostIfRemainOnChan)
2217 s32 result = 0;
2218 u8 u8remain_on_chan_flag;
2219 struct wid wid;
2220 struct host_if_drv *hif_drv = vif->hif_drv;
2222 if (!hif_drv->remain_on_ch_pending) {
2223 hif_drv->remain_on_ch.arg = pstrHostIfRemainOnChan->arg;
2224 hif_drv->remain_on_ch.expired = pstrHostIfRemainOnChan->expired;
2225 hif_drv->remain_on_ch.ready = pstrHostIfRemainOnChan->ready;
2226 hif_drv->remain_on_ch.ch = pstrHostIfRemainOnChan->ch;
2227 hif_drv->remain_on_ch.id = pstrHostIfRemainOnChan->id;
2228 } else {
2229 pstrHostIfRemainOnChan->ch = hif_drv->remain_on_ch.ch;
2232 if (hif_drv->usr_scan_req.scan_result) {
2233 hif_drv->remain_on_ch_pending = 1;
2234 result = -EBUSY;
2235 goto ERRORHANDLER;
2237 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
2238 result = -EBUSY;
2239 goto ERRORHANDLER;
2242 if (wilc_optaining_ip || wilc_connecting) {
2243 result = -EBUSY;
2244 goto ERRORHANDLER;
2247 u8remain_on_chan_flag = true;
2248 wid.id = (u16)WID_REMAIN_ON_CHAN;
2249 wid.type = WID_STR;
2250 wid.size = 2;
2251 wid.val = kmalloc(wid.size, GFP_KERNEL);
2252 if (!wid.val) {
2253 result = -ENOMEM;
2254 goto ERRORHANDLER;
2257 wid.val[0] = u8remain_on_chan_flag;
2258 wid.val[1] = (s8)pstrHostIfRemainOnChan->ch;
2260 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2261 wilc_get_vif_idx(vif));
2262 if (result != 0)
2263 netdev_err(vif->ndev, "Failed to set remain on channel\n");
2265 ERRORHANDLER:
2267 P2P_LISTEN_STATE = 1;
2268 hif_drv->remain_on_ch_timer.data = (unsigned long)vif;
2269 mod_timer(&hif_drv->remain_on_ch_timer,
2270 jiffies +
2271 msecs_to_jiffies(pstrHostIfRemainOnChan->duration));
2273 if (hif_drv->remain_on_ch.ready)
2274 hif_drv->remain_on_ch.ready(hif_drv->remain_on_ch.arg);
2276 if (hif_drv->remain_on_ch_pending)
2277 hif_drv->remain_on_ch_pending = 0;
2280 return result;
2283 static int Handle_RegisterFrame(struct wilc_vif *vif,
2284 struct reg_frame *pstrHostIfRegisterFrame)
2286 s32 result = 0;
2287 struct wid wid;
2288 u8 *pu8CurrByte;
2290 wid.id = (u16)WID_REGISTER_FRAME;
2291 wid.type = WID_STR;
2292 wid.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2293 if (!wid.val)
2294 return -ENOMEM;
2296 pu8CurrByte = wid.val;
2298 *pu8CurrByte++ = pstrHostIfRegisterFrame->reg;
2299 *pu8CurrByte++ = pstrHostIfRegisterFrame->reg_id;
2300 memcpy(pu8CurrByte, &pstrHostIfRegisterFrame->frame_type, sizeof(u16));
2302 wid.size = sizeof(u16) + 2;
2304 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2305 wilc_get_vif_idx(vif));
2306 if (result) {
2307 netdev_err(vif->ndev, "Failed to frame register\n");
2308 result = -EINVAL;
2311 return result;
2314 static u32 Handle_ListenStateExpired(struct wilc_vif *vif,
2315 struct remain_ch *pstrHostIfRemainOnChan)
2317 u8 u8remain_on_chan_flag;
2318 struct wid wid;
2319 s32 result = 0;
2320 struct host_if_drv *hif_drv = vif->hif_drv;
2322 if (P2P_LISTEN_STATE) {
2323 u8remain_on_chan_flag = false;
2324 wid.id = (u16)WID_REMAIN_ON_CHAN;
2325 wid.type = WID_STR;
2326 wid.size = 2;
2327 wid.val = kmalloc(wid.size, GFP_KERNEL);
2329 if (!wid.val) {
2330 netdev_err(vif->ndev, "Failed to allocate memory\n");
2331 return -ENOMEM;
2334 wid.val[0] = u8remain_on_chan_flag;
2335 wid.val[1] = FALSE_FRMWR_CHANNEL;
2337 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2338 wilc_get_vif_idx(vif));
2339 if (result != 0) {
2340 netdev_err(vif->ndev, "Failed to set remain channel\n");
2341 goto _done_;
2344 if (hif_drv->remain_on_ch.expired) {
2345 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
2346 pstrHostIfRemainOnChan->id);
2348 P2P_LISTEN_STATE = 0;
2349 } else {
2350 netdev_dbg(vif->ndev, "Not in listen state\n");
2351 result = -EFAULT;
2354 _done_:
2355 return result;
2358 static void ListenTimerCB(unsigned long arg)
2360 s32 result = 0;
2361 struct host_if_msg msg;
2362 struct wilc_vif *vif = (struct wilc_vif *)arg;
2364 del_timer(&vif->hif_drv->remain_on_ch_timer);
2366 memset(&msg, 0, sizeof(struct host_if_msg));
2367 msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
2368 msg.vif = vif;
2369 msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
2371 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2372 if (result)
2373 netdev_err(vif->ndev, "wilc_mq_send fail\n");
2376 static void Handle_PowerManagement(struct wilc_vif *vif,
2377 struct power_mgmt_param *strPowerMgmtParam)
2379 s32 result = 0;
2380 struct wid wid;
2381 s8 s8PowerMode;
2383 wid.id = (u16)WID_POWER_MANAGEMENT;
2385 if (strPowerMgmtParam->enabled)
2386 s8PowerMode = MIN_FAST_PS;
2387 else
2388 s8PowerMode = NO_POWERSAVE;
2390 wid.val = &s8PowerMode;
2391 wid.size = sizeof(char);
2393 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2394 wilc_get_vif_idx(vif));
2395 if (result)
2396 netdev_err(vif->ndev, "Failed to send power management\n");
2399 static void Handle_SetMulticastFilter(struct wilc_vif *vif,
2400 struct set_multicast *strHostIfSetMulti)
2402 s32 result = 0;
2403 struct wid wid;
2404 u8 *pu8CurrByte;
2406 wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
2407 wid.type = WID_BIN;
2408 wid.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN);
2409 wid.val = kmalloc(wid.size, GFP_KERNEL);
2410 if (!wid.val)
2411 goto ERRORHANDLER;
2413 pu8CurrByte = wid.val;
2414 *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
2415 *pu8CurrByte++ = 0;
2416 *pu8CurrByte++ = 0;
2417 *pu8CurrByte++ = 0;
2419 *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
2420 *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
2421 *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);
2422 *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 24) & 0xFF);
2424 if ((strHostIfSetMulti->cnt) > 0)
2425 memcpy(pu8CurrByte, wilc_multicast_mac_addr_list,
2426 ((strHostIfSetMulti->cnt) * ETH_ALEN));
2428 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2429 wilc_get_vif_idx(vif));
2430 if (result)
2431 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2433 ERRORHANDLER:
2434 kfree(wid.val);
2437 static void handle_set_tx_pwr(struct wilc_vif *vif, u8 tx_pwr)
2439 int ret;
2440 struct wid wid;
2442 wid.id = (u16)WID_TX_POWER;
2443 wid.type = WID_CHAR;
2444 wid.val = &tx_pwr;
2445 wid.size = sizeof(char);
2447 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2448 wilc_get_vif_idx(vif));
2449 if (ret)
2450 netdev_err(vif->ndev, "Failed to set TX PWR\n");
2453 static void handle_get_tx_pwr(struct wilc_vif *vif, u8 *tx_pwr)
2455 int ret = 0;
2456 struct wid wid;
2458 wid.id = (u16)WID_TX_POWER;
2459 wid.type = WID_CHAR;
2460 wid.val = (s8 *)tx_pwr;
2461 wid.size = sizeof(char);
2463 ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2464 wilc_get_vif_idx(vif));
2465 if (ret)
2466 netdev_err(vif->ndev, "Failed to get TX PWR\n");
2468 complete(&hif_wait_response);
2471 static int hostIFthread(void *pvArg)
2473 u32 u32Ret;
2474 struct host_if_msg msg;
2475 struct wilc *wilc = pvArg;
2476 struct wilc_vif *vif;
2478 memset(&msg, 0, sizeof(struct host_if_msg));
2480 while (1) {
2481 wilc_mq_recv(&hif_msg_q, &msg, sizeof(struct host_if_msg), &u32Ret);
2482 vif = msg.vif;
2483 if (msg.id == HOST_IF_MSG_EXIT)
2484 break;
2486 if ((!wilc_initialized)) {
2487 usleep_range(200 * 1000, 200 * 1000);
2488 wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2489 continue;
2492 if (msg.id == HOST_IF_MSG_CONNECT &&
2493 vif->hif_drv->usr_scan_req.scan_result) {
2494 wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2495 usleep_range(2 * 1000, 2 * 1000);
2496 continue;
2499 switch (msg.id) {
2500 case HOST_IF_MSG_SCAN:
2501 handle_scan(msg.vif, &msg.body.scan_info);
2502 break;
2504 case HOST_IF_MSG_CONNECT:
2505 Handle_Connect(msg.vif, &msg.body.con_info);
2506 break;
2508 case HOST_IF_MSG_RCVD_NTWRK_INFO:
2509 Handle_RcvdNtwrkInfo(msg.vif, &msg.body.net_info);
2510 break;
2512 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
2513 Handle_RcvdGnrlAsyncInfo(vif,
2514 &msg.body.async_info);
2515 break;
2517 case HOST_IF_MSG_KEY:
2518 Handle_Key(msg.vif, &msg.body.key_info);
2519 break;
2521 case HOST_IF_MSG_CFG_PARAMS:
2522 handle_cfg_param(msg.vif, &msg.body.cfg_info);
2523 break;
2525 case HOST_IF_MSG_SET_CHANNEL:
2526 handle_set_channel(msg.vif, &msg.body.channel_info);
2527 break;
2529 case HOST_IF_MSG_DISCONNECT:
2530 Handle_Disconnect(msg.vif);
2531 break;
2533 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
2534 del_timer(&vif->hif_drv->scan_timer);
2536 if (!wilc_wlan_get_num_conn_ifcs(wilc))
2537 wilc_chip_sleep_manually(wilc);
2539 Handle_ScanDone(msg.vif, SCAN_EVENT_DONE);
2541 if (vif->hif_drv->remain_on_ch_pending)
2542 Handle_RemainOnChan(msg.vif,
2543 &msg.body.remain_on_ch);
2545 break;
2547 case HOST_IF_MSG_GET_RSSI:
2548 Handle_GetRssi(msg.vif);
2549 break;
2551 case HOST_IF_MSG_GET_STATISTICS:
2552 Handle_GetStatistics(msg.vif,
2553 (struct rf_info *)msg.body.data);
2554 break;
2556 case HOST_IF_MSG_ADD_BEACON:
2557 Handle_AddBeacon(msg.vif, &msg.body.beacon_info);
2558 break;
2560 case HOST_IF_MSG_DEL_BEACON:
2561 Handle_DelBeacon(msg.vif);
2562 break;
2564 case HOST_IF_MSG_ADD_STATION:
2565 Handle_AddStation(msg.vif, &msg.body.add_sta_info);
2566 break;
2568 case HOST_IF_MSG_DEL_STATION:
2569 Handle_DelStation(msg.vif, &msg.body.del_sta_info);
2570 break;
2572 case HOST_IF_MSG_EDIT_STATION:
2573 Handle_EditStation(msg.vif, &msg.body.edit_sta_info);
2574 break;
2576 case HOST_IF_MSG_GET_INACTIVETIME:
2577 Handle_Get_InActiveTime(msg.vif, &msg.body.mac_info);
2578 break;
2580 case HOST_IF_MSG_SCAN_TIMER_FIRED:
2582 Handle_ScanDone(msg.vif, SCAN_EVENT_ABORTED);
2583 break;
2585 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
2586 Handle_ConnectTimeout(msg.vif);
2587 break;
2589 case HOST_IF_MSG_POWER_MGMT:
2590 Handle_PowerManagement(msg.vif,
2591 &msg.body.pwr_mgmt_info);
2592 break;
2594 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
2595 handle_set_wfi_drv_handler(msg.vif, &msg.body.drv);
2596 break;
2598 case HOST_IF_MSG_SET_OPERATION_MODE:
2599 handle_set_operation_mode(msg.vif, &msg.body.mode);
2600 break;
2602 case HOST_IF_MSG_SET_IPADDRESS:
2603 handle_set_ip_address(vif,
2604 msg.body.ip_info.ip_addr,
2605 msg.body.ip_info.idx);
2606 break;
2608 case HOST_IF_MSG_GET_IPADDRESS:
2609 handle_get_ip_address(vif, msg.body.ip_info.idx);
2610 break;
2612 case HOST_IF_MSG_GET_MAC_ADDRESS:
2613 handle_get_mac_address(msg.vif,
2614 &msg.body.get_mac_info);
2615 break;
2617 case HOST_IF_MSG_REMAIN_ON_CHAN:
2618 Handle_RemainOnChan(msg.vif, &msg.body.remain_on_ch);
2619 break;
2621 case HOST_IF_MSG_REGISTER_FRAME:
2622 Handle_RegisterFrame(msg.vif, &msg.body.reg_frame);
2623 break;
2625 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
2626 Handle_ListenStateExpired(msg.vif, &msg.body.remain_on_ch);
2627 break;
2629 case HOST_IF_MSG_SET_MULTICAST_FILTER:
2630 Handle_SetMulticastFilter(msg.vif, &msg.body.multicast_info);
2631 break;
2633 case HOST_IF_MSG_DEL_ALL_STA:
2634 Handle_DelAllSta(msg.vif, &msg.body.del_all_sta_info);
2635 break;
2637 case HOST_IF_MSG_SET_TX_POWER:
2638 handle_set_tx_pwr(msg.vif, msg.body.tx_power.tx_pwr);
2639 break;
2641 case HOST_IF_MSG_GET_TX_POWER:
2642 handle_get_tx_pwr(msg.vif, &msg.body.tx_power.tx_pwr);
2643 break;
2644 default:
2645 netdev_err(vif->ndev, "[Host Interface] undefined\n");
2646 break;
2650 complete(&hif_thread_comp);
2651 return 0;
2654 static void TimerCB_Scan(unsigned long arg)
2656 struct wilc_vif *vif = (struct wilc_vif *)arg;
2657 struct host_if_msg msg;
2659 memset(&msg, 0, sizeof(struct host_if_msg));
2660 msg.vif = vif;
2661 msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
2663 wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2666 static void TimerCB_Connect(unsigned long arg)
2668 struct wilc_vif *vif = (struct wilc_vif *)arg;
2669 struct host_if_msg msg;
2671 memset(&msg, 0, sizeof(struct host_if_msg));
2672 msg.vif = vif;
2673 msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
2675 wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2678 s32 wilc_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
2680 struct wid wid;
2682 wid.id = (u16)WID_REMOVE_KEY;
2683 wid.type = WID_STR;
2684 wid.val = (s8 *)pu8StaAddress;
2685 wid.size = 6;
2687 return 0;
2690 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
2692 int result = 0;
2693 struct host_if_msg msg;
2694 struct host_if_drv *hif_drv = vif->hif_drv;
2696 if (!hif_drv) {
2697 result = -EFAULT;
2698 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2699 return result;
2702 memset(&msg, 0, sizeof(struct host_if_msg));
2704 msg.id = HOST_IF_MSG_KEY;
2705 msg.body.key_info.type = WEP;
2706 msg.body.key_info.action = REMOVEKEY;
2707 msg.vif = vif;
2708 msg.body.key_info.attr.wep.index = index;
2710 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2711 if (result)
2712 netdev_err(vif->ndev, "Request to remove WEP key\n");
2713 else
2714 wait_for_completion(&hif_drv->comp_test_key_block);
2716 return result;
2719 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
2721 int result = 0;
2722 struct host_if_msg msg;
2723 struct host_if_drv *hif_drv = vif->hif_drv;
2725 if (!hif_drv) {
2726 result = -EFAULT;
2727 netdev_err(vif->ndev, "driver is null\n");
2728 return result;
2731 memset(&msg, 0, sizeof(struct host_if_msg));
2733 msg.id = HOST_IF_MSG_KEY;
2734 msg.body.key_info.type = WEP;
2735 msg.body.key_info.action = DEFAULTKEY;
2736 msg.vif = vif;
2737 msg.body.key_info.attr.wep.index = index;
2739 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2740 if (result)
2741 netdev_err(vif->ndev, "Default key index\n");
2742 else
2743 wait_for_completion(&hif_drv->comp_test_key_block);
2745 return result;
2748 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
2749 u8 index)
2751 int result = 0;
2752 struct host_if_msg msg;
2753 struct host_if_drv *hif_drv = vif->hif_drv;
2755 if (!hif_drv) {
2756 netdev_err(vif->ndev, "driver is null\n");
2757 return -EFAULT;
2760 memset(&msg, 0, sizeof(struct host_if_msg));
2762 msg.id = HOST_IF_MSG_KEY;
2763 msg.body.key_info.type = WEP;
2764 msg.body.key_info.action = ADDKEY;
2765 msg.vif = vif;
2766 msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2767 if (!msg.body.key_info.attr.wep.key)
2768 return -ENOMEM;
2770 msg.body.key_info.attr.wep.key_len = len;
2771 msg.body.key_info.attr.wep.index = index;
2773 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2774 if (result)
2775 netdev_err(vif->ndev, "STA - WEP Key\n");
2776 wait_for_completion(&hif_drv->comp_test_key_block);
2778 return result;
2781 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
2782 u8 index, u8 mode, enum AUTHTYPE auth_type)
2784 int result = 0;
2785 struct host_if_msg msg;
2786 struct host_if_drv *hif_drv = vif->hif_drv;
2788 if (!hif_drv) {
2789 netdev_err(vif->ndev, "driver is null\n");
2790 return -EFAULT;
2793 memset(&msg, 0, sizeof(struct host_if_msg));
2795 msg.id = HOST_IF_MSG_KEY;
2796 msg.body.key_info.type = WEP;
2797 msg.body.key_info.action = ADDKEY_AP;
2798 msg.vif = vif;
2799 msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2800 if (!msg.body.key_info.attr.wep.key)
2801 return -ENOMEM;
2803 msg.body.key_info.attr.wep.key_len = len;
2804 msg.body.key_info.attr.wep.index = index;
2805 msg.body.key_info.attr.wep.mode = mode;
2806 msg.body.key_info.attr.wep.auth_type = auth_type;
2808 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2810 if (result)
2811 netdev_err(vif->ndev, "AP - WEP Key\n");
2812 else
2813 wait_for_completion(&hif_drv->comp_test_key_block);
2815 return result;
2818 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
2819 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
2820 u8 mode, u8 cipher_mode, u8 index)
2822 int result = 0;
2823 struct host_if_msg msg;
2824 struct host_if_drv *hif_drv = vif->hif_drv;
2825 u8 key_len = ptk_key_len;
2827 if (!hif_drv) {
2828 netdev_err(vif->ndev, "driver is null\n");
2829 return -EFAULT;
2832 if (rx_mic)
2833 key_len += RX_MIC_KEY_LEN;
2835 if (tx_mic)
2836 key_len += TX_MIC_KEY_LEN;
2838 memset(&msg, 0, sizeof(struct host_if_msg));
2840 msg.id = HOST_IF_MSG_KEY;
2841 msg.body.key_info.type = WPA_PTK;
2842 if (mode == AP_MODE) {
2843 msg.body.key_info.action = ADDKEY_AP;
2844 msg.body.key_info.attr.wpa.index = index;
2846 if (mode == STATION_MODE)
2847 msg.body.key_info.action = ADDKEY;
2849 msg.body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
2850 if (!msg.body.key_info.attr.wpa.key)
2851 return -ENOMEM;
2853 if (rx_mic)
2854 memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic, RX_MIC_KEY_LEN);
2856 if (tx_mic)
2857 memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic, TX_MIC_KEY_LEN);
2859 msg.body.key_info.attr.wpa.key_len = key_len;
2860 msg.body.key_info.attr.wpa.mac_addr = mac_addr;
2861 msg.body.key_info.attr.wpa.mode = cipher_mode;
2862 msg.vif = vif;
2864 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2866 if (result)
2867 netdev_err(vif->ndev, "PTK Key\n");
2868 else
2869 wait_for_completion(&hif_drv->comp_test_key_block);
2871 return result;
2874 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
2875 u8 index, u32 key_rsc_len, const u8 *key_rsc,
2876 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
2877 u8 cipher_mode)
2879 int result = 0;
2880 struct host_if_msg msg;
2881 struct host_if_drv *hif_drv = vif->hif_drv;
2882 u8 key_len = gtk_key_len;
2884 if (!hif_drv) {
2885 netdev_err(vif->ndev, "driver is null\n");
2886 return -EFAULT;
2888 memset(&msg, 0, sizeof(struct host_if_msg));
2890 if (rx_mic)
2891 key_len += RX_MIC_KEY_LEN;
2893 if (tx_mic)
2894 key_len += TX_MIC_KEY_LEN;
2896 if (key_rsc) {
2897 msg.body.key_info.attr.wpa.seq = kmemdup(key_rsc,
2898 key_rsc_len,
2899 GFP_KERNEL);
2900 if (!msg.body.key_info.attr.wpa.seq)
2901 return -ENOMEM;
2904 msg.id = HOST_IF_MSG_KEY;
2905 msg.body.key_info.type = WPA_RX_GTK;
2906 msg.vif = vif;
2908 if (mode == AP_MODE) {
2909 msg.body.key_info.action = ADDKEY_AP;
2910 msg.body.key_info.attr.wpa.mode = cipher_mode;
2912 if (mode == STATION_MODE)
2913 msg.body.key_info.action = ADDKEY;
2915 msg.body.key_info.attr.wpa.key = kmemdup(rx_gtk,
2916 key_len,
2917 GFP_KERNEL);
2918 if (!msg.body.key_info.attr.wpa.key)
2919 return -ENOMEM;
2921 if (rx_mic)
2922 memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic,
2923 RX_MIC_KEY_LEN);
2925 if (tx_mic)
2926 memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic,
2927 TX_MIC_KEY_LEN);
2929 msg.body.key_info.attr.wpa.index = index;
2930 msg.body.key_info.attr.wpa.key_len = key_len;
2931 msg.body.key_info.attr.wpa.seq_len = key_rsc_len;
2933 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2934 if (result)
2935 netdev_err(vif->ndev, "RX GTK\n");
2936 else
2937 wait_for_completion(&hif_drv->comp_test_key_block);
2939 return result;
2942 int wilc_set_pmkid_info(struct wilc_vif *vif,
2943 struct host_if_pmkid_attr *pmkid)
2945 int result = 0;
2946 struct host_if_msg msg;
2947 int i;
2949 memset(&msg, 0, sizeof(struct host_if_msg));
2951 msg.id = HOST_IF_MSG_KEY;
2952 msg.body.key_info.type = PMKSA;
2953 msg.body.key_info.action = ADDKEY;
2954 msg.vif = vif;
2956 for (i = 0; i < pmkid->numpmkid; i++) {
2957 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid,
2958 &pmkid->pmkidlist[i].bssid, ETH_ALEN);
2959 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid,
2960 &pmkid->pmkidlist[i].pmkid, PMKID_LEN);
2963 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2964 if (result)
2965 netdev_err(vif->ndev, "PMKID Info\n");
2967 return result;
2970 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
2972 int result = 0;
2973 struct host_if_msg msg;
2975 memset(&msg, 0, sizeof(struct host_if_msg));
2977 msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
2978 msg.body.get_mac_info.mac_addr = mac_addr;
2979 msg.vif = vif;
2981 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2982 if (result) {
2983 netdev_err(vif->ndev, "Failed to send get mac address\n");
2984 return -EFAULT;
2987 wait_for_completion(&hif_wait_response);
2988 return result;
2991 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
2992 size_t ssid_len, const u8 *ies, size_t ies_len,
2993 wilc_connect_result connect_result, void *user_arg,
2994 u8 security, enum AUTHTYPE auth_type,
2995 u8 channel, void *join_params)
2997 int result = 0;
2998 struct host_if_msg msg;
2999 struct host_if_drv *hif_drv = vif->hif_drv;
3001 if (!hif_drv || !connect_result) {
3002 netdev_err(vif->ndev, "Driver is null\n");
3003 return -EFAULT;
3006 if (!join_params) {
3007 netdev_err(vif->ndev, "Unable to Join - JoinParams is NULL\n");
3008 return -EFAULT;
3011 memset(&msg, 0, sizeof(struct host_if_msg));
3013 msg.id = HOST_IF_MSG_CONNECT;
3015 msg.body.con_info.security = security;
3016 msg.body.con_info.auth_type = auth_type;
3017 msg.body.con_info.ch = channel;
3018 msg.body.con_info.result = connect_result;
3019 msg.body.con_info.arg = user_arg;
3020 msg.body.con_info.params = join_params;
3021 msg.vif = vif;
3023 if (bssid) {
3024 msg.body.con_info.bssid = kmemdup(bssid, 6, GFP_KERNEL);
3025 if (!msg.body.con_info.bssid)
3026 return -ENOMEM;
3029 if (ssid) {
3030 msg.body.con_info.ssid_len = ssid_len;
3031 msg.body.con_info.ssid = kmemdup(ssid, ssid_len, GFP_KERNEL);
3032 if (!msg.body.con_info.ssid)
3033 return -ENOMEM;
3036 if (ies) {
3037 msg.body.con_info.ies_len = ies_len;
3038 msg.body.con_info.ies = kmemdup(ies, ies_len, GFP_KERNEL);
3039 if (!msg.body.con_info.ies)
3040 return -ENOMEM;
3042 if (hif_drv->hif_state < HOST_IF_CONNECTING)
3043 hif_drv->hif_state = HOST_IF_CONNECTING;
3045 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3046 if (result) {
3047 netdev_err(vif->ndev, "send message: Set join request\n");
3048 return -EFAULT;
3051 hif_drv->connect_timer.data = (unsigned long)vif;
3052 mod_timer(&hif_drv->connect_timer,
3053 jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3055 return result;
3058 int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
3060 int result = 0;
3061 struct host_if_msg msg;
3062 struct host_if_drv *hif_drv = vif->hif_drv;
3064 if (!hif_drv) {
3065 netdev_err(vif->ndev, "Driver is null\n");
3066 return -EFAULT;
3069 memset(&msg, 0, sizeof(struct host_if_msg));
3071 msg.id = HOST_IF_MSG_DISCONNECT;
3072 msg.vif = vif;
3074 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3075 if (result)
3076 netdev_err(vif->ndev, "Failed to send message: disconnect\n");
3077 else
3078 wait_for_completion(&hif_drv->comp_test_disconn_block);
3080 return result;
3083 static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
3084 u8 *pu8AssocRespInfo,
3085 u32 u32MaxAssocRespInfoLen,
3086 u32 *pu32RcvdAssocRespInfoLen)
3088 s32 result = 0;
3089 struct wid wid;
3091 wid.id = (u16)WID_ASSOC_RES_INFO;
3092 wid.type = WID_STR;
3093 wid.val = pu8AssocRespInfo;
3094 wid.size = u32MaxAssocRespInfoLen;
3096 result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
3097 wilc_get_vif_idx(vif));
3098 if (result) {
3099 *pu32RcvdAssocRespInfoLen = 0;
3100 netdev_err(vif->ndev, "Failed to send association response\n");
3101 return -EINVAL;
3104 *pu32RcvdAssocRespInfoLen = wid.size;
3105 return result;
3108 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
3110 int result;
3111 struct host_if_msg msg;
3113 memset(&msg, 0, sizeof(struct host_if_msg));
3114 msg.id = HOST_IF_MSG_SET_CHANNEL;
3115 msg.body.channel_info.set_ch = channel;
3116 msg.vif = vif;
3118 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3119 if (result) {
3120 netdev_err(vif->ndev, "wilc mq send fail\n");
3121 return -EINVAL;
3124 return 0;
3127 int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mac_idx)
3129 int result = 0;
3130 struct host_if_msg msg;
3132 memset(&msg, 0, sizeof(struct host_if_msg));
3133 msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3134 msg.body.drv.handler = index;
3135 msg.body.drv.mac_idx = mac_idx;
3136 msg.vif = vif;
3138 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3139 if (result) {
3140 netdev_err(vif->ndev, "wilc mq send fail\n");
3141 result = -EINVAL;
3144 return result;
3147 int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
3149 int result = 0;
3150 struct host_if_msg msg;
3152 memset(&msg, 0, sizeof(struct host_if_msg));
3153 msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3154 msg.body.mode.mode = mode;
3155 msg.vif = vif;
3157 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3158 if (result) {
3159 netdev_err(vif->ndev, "wilc mq send fail\n");
3160 result = -EINVAL;
3163 return result;
3166 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
3167 u32 *pu32InactiveTime)
3169 s32 result = 0;
3170 struct host_if_msg msg;
3171 struct host_if_drv *hif_drv = vif->hif_drv;
3173 if (!hif_drv) {
3174 netdev_err(vif->ndev, "driver is null\n");
3175 return -EFAULT;
3178 memset(&msg, 0, sizeof(struct host_if_msg));
3179 memcpy(msg.body.mac_info.mac, mac, ETH_ALEN);
3181 msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3182 msg.vif = vif;
3184 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3185 if (result)
3186 netdev_err(vif->ndev, "Failed to send get host ch param\n");
3187 else
3188 wait_for_completion(&hif_drv->comp_inactive_time);
3190 *pu32InactiveTime = inactive_time;
3192 return result;
3195 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
3197 int result = 0;
3198 struct host_if_msg msg;
3199 struct host_if_drv *hif_drv = vif->hif_drv;
3201 memset(&msg, 0, sizeof(struct host_if_msg));
3202 msg.id = HOST_IF_MSG_GET_RSSI;
3203 msg.vif = vif;
3205 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3206 if (result) {
3207 netdev_err(vif->ndev, "Failed to send get host ch param\n");
3208 return -EFAULT;
3211 wait_for_completion(&hif_drv->comp_get_rssi);
3213 if (!rssi_level) {
3214 netdev_err(vif->ndev, "RSS pointer value is null\n");
3215 return -EFAULT;
3218 *rssi_level = rssi;
3220 return result;
3223 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
3225 int result = 0;
3226 struct host_if_msg msg;
3228 memset(&msg, 0, sizeof(struct host_if_msg));
3229 msg.id = HOST_IF_MSG_GET_STATISTICS;
3230 msg.body.data = (char *)stats;
3231 msg.vif = vif;
3233 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3234 if (result) {
3235 netdev_err(vif->ndev, "Failed to send get host channel\n");
3236 return -EFAULT;
3239 if (stats != &vif->wilc->dummy_statistics)
3240 wait_for_completion(&hif_wait_response);
3241 return result;
3244 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
3245 u8 *ch_freq_list, u8 ch_list_len, const u8 *ies,
3246 size_t ies_len, wilc_scan_result scan_result, void *user_arg,
3247 struct hidden_network *hidden_network)
3249 int result = 0;
3250 struct host_if_msg msg;
3251 struct scan_attr *scan_info = &msg.body.scan_info;
3252 struct host_if_drv *hif_drv = vif->hif_drv;
3254 if (!hif_drv || !scan_result) {
3255 netdev_err(vif->ndev, "hif_drv or scan_result = NULL\n");
3256 return -EFAULT;
3259 memset(&msg, 0, sizeof(struct host_if_msg));
3261 msg.id = HOST_IF_MSG_SCAN;
3263 if (hidden_network) {
3264 scan_info->hidden_network.net_info = hidden_network->net_info;
3265 scan_info->hidden_network.n_ssids = hidden_network->n_ssids;
3268 msg.vif = vif;
3269 scan_info->src = scan_source;
3270 scan_info->type = scan_type;
3271 scan_info->result = scan_result;
3272 scan_info->arg = user_arg;
3274 scan_info->ch_list_len = ch_list_len;
3275 scan_info->ch_freq_list = kmemdup(ch_freq_list,
3276 ch_list_len,
3277 GFP_KERNEL);
3278 if (!scan_info->ch_freq_list)
3279 return -ENOMEM;
3281 scan_info->ies_len = ies_len;
3282 scan_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
3283 if (!scan_info->ies)
3284 return -ENOMEM;
3286 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3287 if (result) {
3288 netdev_err(vif->ndev, "Error in sending message queue\n");
3289 return -EINVAL;
3292 hif_drv->scan_timer.data = (unsigned long)vif;
3293 mod_timer(&hif_drv->scan_timer,
3294 jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
3296 return result;
3299 int wilc_hif_set_cfg(struct wilc_vif *vif,
3300 struct cfg_param_attr *cfg_param)
3302 int result = 0;
3303 struct host_if_msg msg;
3304 struct host_if_drv *hif_drv = vif->hif_drv;
3306 if (!hif_drv) {
3307 netdev_err(vif->ndev, "hif_drv NULL\n");
3308 return -EFAULT;
3311 memset(&msg, 0, sizeof(struct host_if_msg));
3312 msg.id = HOST_IF_MSG_CFG_PARAMS;
3313 msg.body.cfg_info = *cfg_param;
3314 msg.vif = vif;
3316 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3318 return result;
3321 static void GetPeriodicRSSI(unsigned long arg)
3323 struct wilc_vif *vif = (struct wilc_vif *)arg;
3325 if (!vif->hif_drv) {
3326 netdev_err(vif->ndev, "Driver handler is NULL\n");
3327 return;
3330 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
3331 wilc_get_statistics(vif, &vif->wilc->dummy_statistics);
3333 periodic_rssi.data = (unsigned long)vif;
3334 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3337 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3339 int result = 0;
3340 struct host_if_drv *hif_drv;
3341 struct wilc_vif *vif;
3342 struct wilc *wilc;
3343 int i;
3345 vif = netdev_priv(dev);
3346 wilc = vif->wilc;
3348 scan_while_connected = false;
3350 init_completion(&hif_wait_response);
3352 hif_drv = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
3353 if (!hif_drv) {
3354 result = -ENOMEM;
3355 goto _fail_;
3357 *hif_drv_handler = hif_drv;
3358 for (i = 0; i < wilc->vif_num; i++)
3359 if (dev == wilc->vif[i]->ndev) {
3360 wilc->vif[i]->hif_drv = hif_drv;
3361 break;
3364 wilc_optaining_ip = false;
3366 if (clients_count == 0) {
3367 init_completion(&hif_thread_comp);
3368 init_completion(&hif_driver_comp);
3369 mutex_init(&hif_deinit_lock);
3372 init_completion(&hif_drv->comp_test_key_block);
3373 init_completion(&hif_drv->comp_test_disconn_block);
3374 init_completion(&hif_drv->comp_get_rssi);
3375 init_completion(&hif_drv->comp_inactive_time);
3377 if (clients_count == 0) {
3378 result = wilc_mq_create(&hif_msg_q);
3380 if (result < 0) {
3381 netdev_err(vif->ndev, "Failed to creat MQ\n");
3382 goto _fail_;
3385 hif_thread_handler = kthread_run(hostIFthread, wilc,
3386 "WILC_kthread");
3388 if (IS_ERR(hif_thread_handler)) {
3389 netdev_err(vif->ndev, "Failed to creat Thread\n");
3390 result = -EFAULT;
3391 goto _fail_mq_;
3393 setup_timer(&periodic_rssi, GetPeriodicRSSI,
3394 (unsigned long)vif);
3395 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3398 setup_timer(&hif_drv->scan_timer, TimerCB_Scan, 0);
3399 setup_timer(&hif_drv->connect_timer, TimerCB_Connect, 0);
3400 setup_timer(&hif_drv->remain_on_ch_timer, ListenTimerCB, 0);
3402 mutex_init(&hif_drv->cfg_values_lock);
3403 mutex_lock(&hif_drv->cfg_values_lock);
3405 hif_drv->hif_state = HOST_IF_IDLE;
3406 hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF;
3407 hif_drv->cfg_values.scan_source = DEFAULT_SCAN;
3408 hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME;
3409 hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME;
3410 hif_drv->cfg_values.curr_tx_rate = AUTORATE;
3412 hif_drv->p2p_timeout = 0;
3414 mutex_unlock(&hif_drv->cfg_values_lock);
3416 clients_count++;
3418 return result;
3420 _fail_mq_:
3421 wilc_mq_destroy(&hif_msg_q);
3422 _fail_:
3423 return result;
3426 int wilc_deinit(struct wilc_vif *vif)
3428 int result = 0;
3429 struct host_if_msg msg;
3430 struct host_if_drv *hif_drv = vif->hif_drv;
3432 if (!hif_drv) {
3433 netdev_err(vif->ndev, "hif_drv = NULL\n");
3434 return -EFAULT;
3437 mutex_lock(&hif_deinit_lock);
3439 terminated_handle = hif_drv;
3441 del_timer_sync(&hif_drv->scan_timer);
3442 del_timer_sync(&hif_drv->connect_timer);
3443 del_timer_sync(&periodic_rssi);
3444 del_timer_sync(&hif_drv->remain_on_ch_timer);
3446 wilc_set_wfi_drv_handler(vif, 0, 0);
3447 wait_for_completion(&hif_driver_comp);
3449 if (hif_drv->usr_scan_req.scan_result) {
3450 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
3451 hif_drv->usr_scan_req.arg, NULL);
3452 hif_drv->usr_scan_req.scan_result = NULL;
3455 hif_drv->hif_state = HOST_IF_IDLE;
3457 scan_while_connected = false;
3459 memset(&msg, 0, sizeof(struct host_if_msg));
3461 if (clients_count == 1) {
3462 msg.id = HOST_IF_MSG_EXIT;
3463 msg.vif = vif;
3465 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3466 if (result != 0)
3467 netdev_err(vif->ndev, "deinit : Error(%d)\n", result);
3468 else
3469 wait_for_completion(&hif_thread_comp);
3471 wilc_mq_destroy(&hif_msg_q);
3474 kfree(hif_drv);
3476 clients_count--;
3477 terminated_handle = NULL;
3478 mutex_unlock(&hif_deinit_lock);
3479 return result;
3482 void wilc_network_info_received(struct wilc *wilc, u8 *pu8Buffer,
3483 u32 u32Length)
3485 s32 result = 0;
3486 struct host_if_msg msg;
3487 int id;
3488 struct host_if_drv *hif_drv = NULL;
3489 struct wilc_vif *vif;
3491 id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3492 vif = wilc_get_vif_from_idx(wilc, id);
3493 if (!vif)
3494 return;
3495 hif_drv = vif->hif_drv;
3497 if (!hif_drv || hif_drv == terminated_handle) {
3498 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
3499 return;
3502 memset(&msg, 0, sizeof(struct host_if_msg));
3504 msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
3505 msg.vif = vif;
3507 msg.body.net_info.len = u32Length;
3508 msg.body.net_info.buffer = kmalloc(u32Length, GFP_KERNEL);
3509 memcpy(msg.body.net_info.buffer, pu8Buffer, u32Length);
3511 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3512 if (result)
3513 netdev_err(vif->ndev, "message parameters (%d)\n", result);
3516 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *pu8Buffer,
3517 u32 u32Length)
3519 s32 result = 0;
3520 struct host_if_msg msg;
3521 int id;
3522 struct host_if_drv *hif_drv = NULL;
3523 struct wilc_vif *vif;
3525 mutex_lock(&hif_deinit_lock);
3527 id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3528 vif = wilc_get_vif_from_idx(wilc, id);
3529 if (!vif) {
3530 mutex_unlock(&hif_deinit_lock);
3531 return;
3534 hif_drv = vif->hif_drv;
3536 if (!hif_drv || hif_drv == terminated_handle) {
3537 mutex_unlock(&hif_deinit_lock);
3538 return;
3541 if (!hif_drv->usr_conn_req.conn_result) {
3542 netdev_err(vif->ndev, "there is no current Connect Request\n");
3543 mutex_unlock(&hif_deinit_lock);
3544 return;
3547 memset(&msg, 0, sizeof(struct host_if_msg));
3549 msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
3550 msg.vif = vif;
3552 msg.body.async_info.len = u32Length;
3553 msg.body.async_info.buffer = kmalloc(u32Length, GFP_KERNEL);
3554 memcpy(msg.body.async_info.buffer, pu8Buffer, u32Length);
3556 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3557 if (result)
3558 netdev_err(vif->ndev, "synchronous info (%d)\n", result);
3560 mutex_unlock(&hif_deinit_lock);
3563 void wilc_scan_complete_received(struct wilc *wilc, u8 *pu8Buffer,
3564 u32 u32Length)
3566 s32 result = 0;
3567 struct host_if_msg msg;
3568 int id;
3569 struct host_if_drv *hif_drv = NULL;
3570 struct wilc_vif *vif;
3572 id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3573 vif = wilc_get_vif_from_idx(wilc, id);
3574 if (!vif)
3575 return;
3576 hif_drv = vif->hif_drv;
3578 if (!hif_drv || hif_drv == terminated_handle)
3579 return;
3581 if (hif_drv->usr_scan_req.scan_result) {
3582 memset(&msg, 0, sizeof(struct host_if_msg));
3584 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
3585 msg.vif = vif;
3587 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3588 if (result)
3589 netdev_err(vif->ndev, "complete param (%d)\n", result);
3593 int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
3594 u32 duration, u16 chan,
3595 wilc_remain_on_chan_expired expired,
3596 wilc_remain_on_chan_ready ready,
3597 void *user_arg)
3599 int result = 0;
3600 struct host_if_msg msg;
3602 memset(&msg, 0, sizeof(struct host_if_msg));
3604 msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
3605 msg.body.remain_on_ch.ch = chan;
3606 msg.body.remain_on_ch.expired = expired;
3607 msg.body.remain_on_ch.ready = ready;
3608 msg.body.remain_on_ch.arg = user_arg;
3609 msg.body.remain_on_ch.duration = duration;
3610 msg.body.remain_on_ch.id = session_id;
3611 msg.vif = vif;
3613 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3614 if (result)
3615 netdev_err(vif->ndev, "wilc mq send fail\n");
3617 return result;
3620 int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
3622 int result = 0;
3623 struct host_if_msg msg;
3624 struct host_if_drv *hif_drv = vif->hif_drv;
3626 if (!hif_drv) {
3627 netdev_err(vif->ndev, "driver is null\n");
3628 return -EFAULT;
3631 del_timer(&hif_drv->remain_on_ch_timer);
3633 memset(&msg, 0, sizeof(struct host_if_msg));
3634 msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
3635 msg.vif = vif;
3636 msg.body.remain_on_ch.id = session_id;
3638 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3639 if (result)
3640 netdev_err(vif->ndev, "wilc mq send fail\n");
3642 return result;
3645 int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
3647 int result = 0;
3648 struct host_if_msg msg;
3650 memset(&msg, 0, sizeof(struct host_if_msg));
3652 msg.id = HOST_IF_MSG_REGISTER_FRAME;
3653 switch (frame_type) {
3654 case ACTION:
3655 msg.body.reg_frame.reg_id = ACTION_FRM_IDX;
3656 break;
3658 case PROBE_REQ:
3659 msg.body.reg_frame.reg_id = PROBE_REQ_IDX;
3660 break;
3662 default:
3663 break;
3665 msg.body.reg_frame.frame_type = frame_type;
3666 msg.body.reg_frame.reg = reg;
3667 msg.vif = vif;
3669 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3670 if (result)
3671 netdev_err(vif->ndev, "wilc mq send fail\n");
3673 return result;
3676 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
3677 u32 head_len, u8 *head, u32 tail_len, u8 *tail)
3679 int result = 0;
3680 struct host_if_msg msg;
3681 struct beacon_attr *beacon_info = &msg.body.beacon_info;
3683 memset(&msg, 0, sizeof(struct host_if_msg));
3685 msg.id = HOST_IF_MSG_ADD_BEACON;
3686 msg.vif = vif;
3687 beacon_info->interval = interval;
3688 beacon_info->dtim_period = dtim_period;
3689 beacon_info->head_len = head_len;
3690 beacon_info->head = kmemdup(head, head_len, GFP_KERNEL);
3691 if (!beacon_info->head) {
3692 result = -ENOMEM;
3693 goto ERRORHANDLER;
3695 beacon_info->tail_len = tail_len;
3697 if (tail_len > 0) {
3698 beacon_info->tail = kmemdup(tail, tail_len, GFP_KERNEL);
3699 if (!beacon_info->tail) {
3700 result = -ENOMEM;
3701 goto ERRORHANDLER;
3703 } else {
3704 beacon_info->tail = NULL;
3707 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3708 if (result)
3709 netdev_err(vif->ndev, "wilc mq send fail\n");
3711 ERRORHANDLER:
3712 if (result) {
3713 kfree(beacon_info->head);
3715 kfree(beacon_info->tail);
3718 return result;
3721 int wilc_del_beacon(struct wilc_vif *vif)
3723 int result = 0;
3724 struct host_if_msg msg;
3726 msg.id = HOST_IF_MSG_DEL_BEACON;
3727 msg.vif = vif;
3729 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3730 if (result)
3731 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3733 return result;
3736 int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
3738 int result = 0;
3739 struct host_if_msg msg;
3740 struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
3742 memset(&msg, 0, sizeof(struct host_if_msg));
3744 msg.id = HOST_IF_MSG_ADD_STATION;
3745 msg.vif = vif;
3747 memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3748 if (add_sta_info->rates_len > 0) {
3749 add_sta_info->rates = kmemdup(sta_param->rates,
3750 add_sta_info->rates_len,
3751 GFP_KERNEL);
3752 if (!add_sta_info->rates)
3753 return -ENOMEM;
3756 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3757 if (result)
3758 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3759 return result;
3762 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
3764 int result = 0;
3765 struct host_if_msg msg;
3766 struct del_sta *del_sta_info = &msg.body.del_sta_info;
3768 memset(&msg, 0, sizeof(struct host_if_msg));
3770 msg.id = HOST_IF_MSG_DEL_STATION;
3771 msg.vif = vif;
3773 if (!mac_addr)
3774 eth_broadcast_addr(del_sta_info->mac_addr);
3775 else
3776 memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN);
3778 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3779 if (result)
3780 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3781 return result;
3784 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
3786 int result = 0;
3787 struct host_if_msg msg;
3788 struct del_all_sta *del_all_sta_info = &msg.body.del_all_sta_info;
3789 u8 zero_addr[ETH_ALEN] = {0};
3790 int i;
3791 u8 assoc_sta = 0;
3793 memset(&msg, 0, sizeof(struct host_if_msg));
3795 msg.id = HOST_IF_MSG_DEL_ALL_STA;
3796 msg.vif = vif;
3798 for (i = 0; i < MAX_NUM_STA; i++) {
3799 if (memcmp(mac_addr[i], zero_addr, ETH_ALEN)) {
3800 memcpy(del_all_sta_info->del_all_sta[i], mac_addr[i], ETH_ALEN);
3801 assoc_sta++;
3804 if (!assoc_sta)
3805 return result;
3807 del_all_sta_info->assoc_sta = assoc_sta;
3808 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3810 if (result)
3811 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3812 else
3813 wait_for_completion(&hif_wait_response);
3815 return result;
3818 int wilc_edit_station(struct wilc_vif *vif,
3819 struct add_sta_param *sta_param)
3821 int result = 0;
3822 struct host_if_msg msg;
3823 struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
3825 memset(&msg, 0, sizeof(struct host_if_msg));
3827 msg.id = HOST_IF_MSG_EDIT_STATION;
3828 msg.vif = vif;
3830 memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3831 if (add_sta_info->rates_len > 0) {
3832 add_sta_info->rates = kmemdup(sta_param->rates,
3833 add_sta_info->rates_len,
3834 GFP_KERNEL);
3835 if (!add_sta_info->rates)
3836 return -ENOMEM;
3839 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3840 if (result)
3841 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3843 return result;
3846 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
3848 int result = 0;
3849 struct host_if_msg msg;
3850 struct power_mgmt_param *pwr_mgmt_info = &msg.body.pwr_mgmt_info;
3852 if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
3853 return 0;
3855 memset(&msg, 0, sizeof(struct host_if_msg));
3857 msg.id = HOST_IF_MSG_POWER_MGMT;
3858 msg.vif = vif;
3860 pwr_mgmt_info->enabled = enabled;
3861 pwr_mgmt_info->timeout = timeout;
3863 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3864 if (result)
3865 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3866 return result;
3869 int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
3870 u32 count)
3872 int result = 0;
3873 struct host_if_msg msg;
3874 struct set_multicast *multicast_filter_param = &msg.body.multicast_info;
3876 memset(&msg, 0, sizeof(struct host_if_msg));
3878 msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
3879 msg.vif = vif;
3881 multicast_filter_param->enabled = enabled;
3882 multicast_filter_param->cnt = count;
3884 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3885 if (result)
3886 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3887 return result;
3890 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo)
3892 struct join_bss_param *pNewJoinBssParam = NULL;
3893 u8 *pu8IEs;
3894 u16 u16IEsLen;
3895 u16 index = 0;
3896 u8 suppRatesNo = 0;
3897 u8 extSuppRatesNo;
3898 u16 jumpOffset;
3899 u8 pcipherCount;
3900 u8 authCount;
3901 u8 pcipherTotalCount = 0;
3902 u8 authTotalCount = 0;
3903 u8 i, j;
3905 pu8IEs = ptstrNetworkInfo->ies;
3906 u16IEsLen = ptstrNetworkInfo->ies_len;
3908 pNewJoinBssParam = kzalloc(sizeof(struct join_bss_param), GFP_KERNEL);
3909 if (pNewJoinBssParam) {
3910 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->dtim_period;
3911 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->beacon_period;
3912 pNewJoinBssParam->cap_info = ptstrNetworkInfo->cap_info;
3913 memcpy(pNewJoinBssParam->bssid, ptstrNetworkInfo->bssid, 6);
3914 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->ssid,
3915 ptstrNetworkInfo->ssid_len + 1);
3916 pNewJoinBssParam->ssid_len = ptstrNetworkInfo->ssid_len;
3917 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
3918 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
3920 while (index < u16IEsLen) {
3921 if (pu8IEs[index] == SUPP_RATES_IE) {
3922 suppRatesNo = pu8IEs[index + 1];
3923 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
3924 index += 2;
3926 for (i = 0; i < suppRatesNo; i++)
3927 pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
3929 index += suppRatesNo;
3930 continue;
3931 } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
3932 extSuppRatesNo = pu8IEs[index + 1];
3933 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
3934 pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
3935 else
3936 pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
3937 index += 2;
3938 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++)
3939 pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
3941 index += extSuppRatesNo;
3942 continue;
3943 } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
3944 pNewJoinBssParam->ht_capable = true;
3945 index += pu8IEs[index + 1] + 2;
3946 continue;
3947 } else if ((pu8IEs[index] == WMM_IE) &&
3948 (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
3949 (pu8IEs[index + 4] == 0xF2) &&
3950 (pu8IEs[index + 5] == 0x02) &&
3951 ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
3952 (pu8IEs[index + 7] == 0x01)) {
3953 pNewJoinBssParam->wmm_cap = true;
3955 if (pu8IEs[index + 8] & BIT(7))
3956 pNewJoinBssParam->uapsd_cap = true;
3957 index += pu8IEs[index + 1] + 2;
3958 continue;
3959 } else if ((pu8IEs[index] == P2P_IE) &&
3960 (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
3961 (pu8IEs[index + 4] == 0x9a) &&
3962 (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
3963 u16 u16P2P_count;
3965 pNewJoinBssParam->tsf = ptstrNetworkInfo->tsf_lo;
3966 pNewJoinBssParam->noa_enabled = 1;
3967 pNewJoinBssParam->idx = pu8IEs[index + 9];
3969 if (pu8IEs[index + 10] & BIT(7)) {
3970 pNewJoinBssParam->opp_enabled = 1;
3971 pNewJoinBssParam->ct_window = pu8IEs[index + 10];
3972 } else {
3973 pNewJoinBssParam->opp_enabled = 0;
3976 pNewJoinBssParam->cnt = pu8IEs[index + 11];
3977 u16P2P_count = index + 12;
3979 memcpy(pNewJoinBssParam->duration, pu8IEs + u16P2P_count, 4);
3980 u16P2P_count += 4;
3982 memcpy(pNewJoinBssParam->interval, pu8IEs + u16P2P_count, 4);
3983 u16P2P_count += 4;
3985 memcpy(pNewJoinBssParam->start_time, pu8IEs + u16P2P_count, 4);
3987 index += pu8IEs[index + 1] + 2;
3988 continue;
3990 } else if ((pu8IEs[index] == RSN_IE) ||
3991 ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
3992 (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
3993 (pu8IEs[index + 5] == 0x01))) {
3994 u16 rsnIndex = index;
3996 if (pu8IEs[rsnIndex] == RSN_IE) {
3997 pNewJoinBssParam->mode_802_11i = 2;
3998 } else {
3999 if (pNewJoinBssParam->mode_802_11i == 0)
4000 pNewJoinBssParam->mode_802_11i = 1;
4001 rsnIndex += 4;
4004 rsnIndex += 7;
4005 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
4006 rsnIndex++;
4007 jumpOffset = pu8IEs[rsnIndex] * 4;
4008 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
4009 rsnIndex += 2;
4011 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++)
4012 pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
4014 pcipherTotalCount += pcipherCount;
4015 rsnIndex += jumpOffset;
4017 jumpOffset = pu8IEs[rsnIndex] * 4;
4019 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
4020 rsnIndex += 2;
4022 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++)
4023 pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
4025 authTotalCount += authCount;
4026 rsnIndex += jumpOffset;
4028 if (pu8IEs[index] == RSN_IE) {
4029 pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
4030 pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
4031 rsnIndex += 2;
4033 pNewJoinBssParam->rsn_found = true;
4034 index += pu8IEs[index + 1] + 2;
4035 continue;
4036 } else
4037 index += pu8IEs[index + 1] + 2;
4041 return (void *)pNewJoinBssParam;
4044 int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4046 int result = 0;
4047 struct host_if_msg msg;
4049 memset(&msg, 0, sizeof(struct host_if_msg));
4051 msg.id = HOST_IF_MSG_SET_IPADDRESS;
4053 msg.body.ip_info.ip_addr = ip_addr;
4054 msg.vif = vif;
4055 msg.body.ip_info.idx = idx;
4057 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4058 if (result)
4059 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4061 return result;
4064 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4066 int result = 0;
4067 struct host_if_msg msg;
4069 memset(&msg, 0, sizeof(struct host_if_msg));
4071 msg.id = HOST_IF_MSG_GET_IPADDRESS;
4073 msg.body.ip_info.ip_addr = ip_addr;
4074 msg.vif = vif;
4075 msg.body.ip_info.idx = idx;
4077 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4078 if (result)
4079 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4081 return result;
4084 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
4086 int ret = 0;
4087 struct host_if_msg msg;
4089 memset(&msg, 0, sizeof(struct host_if_msg));
4091 msg.id = HOST_IF_MSG_SET_TX_POWER;
4092 msg.body.tx_power.tx_pwr = tx_power;
4093 msg.vif = vif;
4095 ret = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4096 if (ret)
4097 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4099 return ret;
4102 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
4104 int ret = 0;
4105 struct host_if_msg msg;
4107 memset(&msg, 0, sizeof(struct host_if_msg));
4109 msg.id = HOST_IF_MSG_GET_TX_POWER;
4110 msg.vif = vif;
4112 ret = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4113 if (ret)
4114 netdev_err(vif->ndev, "Failed to get TX PWR\n");
4116 wait_for_completion(&hif_wait_response);
4117 *tx_power = msg.body.tx_power.tx_pwr;
4119 return ret;