]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/wilc1000/host_interface.c
6efee28387aaaa21bb1cffe92188b0a61fb81362
[karo-tx-linux.git] / drivers / staging / wilc1000 / host_interface.c
1 #include <linux/slab.h>
2 #include <linux/time.h>
3 #include <linux/kthread.h>
4 #include <linux/delay.h>
5 #include "host_interface.h"
6 #include "coreconfigurator.h"
7 #include "wilc_wlan.h"
8 #include "wilc_wlan_if.h"
9 #include "wilc_msgqueue.h"
10 #include <linux/etherdevice.h>
11 #include "wilc_wfi_netdevice.h"
12
13 #define HOST_IF_MSG_SCAN                        0
14 #define HOST_IF_MSG_CONNECT                     1
15 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO        2
16 #define HOST_IF_MSG_KEY                         3
17 #define HOST_IF_MSG_RCVD_NTWRK_INFO             4
18 #define HOST_IF_MSG_RCVD_SCAN_COMPLETE          5
19 #define HOST_IF_MSG_CFG_PARAMS                  6
20 #define HOST_IF_MSG_SET_CHANNEL                 7
21 #define HOST_IF_MSG_DISCONNECT                  8
22 #define HOST_IF_MSG_GET_RSSI                    9
23 #define HOST_IF_MSG_ADD_BEACON                  11
24 #define HOST_IF_MSG_DEL_BEACON                  12
25 #define HOST_IF_MSG_ADD_STATION                 13
26 #define HOST_IF_MSG_DEL_STATION                 14
27 #define HOST_IF_MSG_EDIT_STATION                15
28 #define HOST_IF_MSG_SCAN_TIMER_FIRED            16
29 #define HOST_IF_MSG_CONNECT_TIMER_FIRED         17
30 #define HOST_IF_MSG_POWER_MGMT                  18
31 #define HOST_IF_MSG_GET_INACTIVETIME            19
32 #define HOST_IF_MSG_REMAIN_ON_CHAN              20
33 #define HOST_IF_MSG_REGISTER_FRAME              21
34 #define HOST_IF_MSG_LISTEN_TIMER_FIRED          22
35 #define HOST_IF_MSG_SET_WFIDRV_HANDLER          24
36 #define HOST_IF_MSG_SET_MAC_ADDRESS             25
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_Q_IDLE                      35
45 #define HOST_IF_MSG_DEL_ALL_STA                 36
46 #define HOST_IF_MSG_SET_TX_POWER                38
47 #define HOST_IF_MSG_GET_TX_POWER                39
48 #define HOST_IF_MSG_EXIT                        100
49
50 #define HOST_IF_SCAN_TIMEOUT                    4000
51 #define HOST_IF_CONNECT_TIMEOUT                 9500
52
53 #define BA_SESSION_DEFAULT_BUFFER_SIZE          16
54 #define BA_SESSION_DEFAULT_TIMEOUT              1000
55 #define BLOCK_ACK_REQ_SIZE                      0x14
56 #define FALSE_FRMWR_CHANNEL                     100
57
58 #define TCP_ACK_FILTER_LINK_SPEED_THRESH        54
59 #define DEFAULT_LINK_SPEED                      72
60
61 struct host_if_wpa_attr {
62         u8 *key;
63         const u8 *mac_addr;
64         u8 *seq;
65         u8 seq_len;
66         u8 index;
67         u8 key_len;
68         u8 mode;
69 };
70
71 struct host_if_wep_attr {
72         u8 *key;
73         u8 key_len;
74         u8 index;
75         u8 mode;
76         enum AUTHTYPE auth_type;
77 };
78
79 union host_if_key_attr {
80         struct host_if_wep_attr wep;
81         struct host_if_wpa_attr wpa;
82         struct host_if_pmkid_attr pmkid;
83 };
84
85 struct key_attr {
86         enum KEY_TYPE type;
87         u8 action;
88         union host_if_key_attr attr;
89 };
90
91 struct scan_attr {
92         u8 src;
93         u8 type;
94         u8 *ch_freq_list;
95         u8 ch_list_len;
96         u8 *ies;
97         size_t ies_len;
98         wilc_scan_result result;
99         void *arg;
100         struct hidden_network hidden_network;
101 };
102
103 struct connect_attr {
104         u8 *bssid;
105         u8 *ssid;
106         size_t ssid_len;
107         u8 *ies;
108         size_t ies_len;
109         u8 security;
110         wilc_connect_result result;
111         void *arg;
112         enum AUTHTYPE auth_type;
113         u8 ch;
114         void *params;
115 };
116
117 struct rcvd_async_info {
118         u8 *buffer;
119         u32 len;
120 };
121
122 struct channel_attr {
123         u8 set_ch;
124 };
125
126 struct beacon_attr {
127         u32 interval;
128         u32 dtim_period;
129         u32 head_len;
130         u8 *head;
131         u32 tail_len;
132         u8 *tail;
133 };
134
135 struct set_multicast {
136         bool enabled;
137         u32 cnt;
138 };
139
140 struct del_all_sta {
141         u8 del_all_sta[MAX_NUM_STA][ETH_ALEN];
142         u8 assoc_sta;
143 };
144
145 struct del_sta {
146         u8 mac_addr[ETH_ALEN];
147 };
148
149 struct power_mgmt_param {
150         bool enabled;
151         u32 timeout;
152 };
153
154 struct set_ip_addr {
155         u8 *ip_addr;
156         u8 idx;
157 };
158
159 struct sta_inactive_t {
160         u8 mac[6];
161 };
162
163 struct tx_power {
164         u8 tx_pwr;
165 };
166
167 union message_body {
168         struct scan_attr scan_info;
169         struct connect_attr con_info;
170         struct rcvd_net_info net_info;
171         struct rcvd_async_info async_info;
172         struct key_attr key_info;
173         struct cfg_param_attr cfg_info;
174         struct channel_attr channel_info;
175         struct beacon_attr beacon_info;
176         struct add_sta_param add_sta_info;
177         struct del_sta del_sta_info;
178         struct add_sta_param edit_sta_info;
179         struct power_mgmt_param pwr_mgmt_info;
180         struct sta_inactive_t mac_info;
181         struct set_ip_addr ip_info;
182         struct drv_handler drv;
183         struct set_multicast multicast_info;
184         struct op_mode mode;
185         struct set_mac_addr set_mac_info;
186         struct get_mac_addr get_mac_info;
187         struct ba_session_info session_info;
188         struct remain_ch remain_on_ch;
189         struct reg_frame reg_frame;
190         char *data;
191         struct del_all_sta del_all_sta_info;
192         struct tx_power tx_power;
193 };
194
195 struct host_if_msg {
196         u16 id;
197         union message_body body;
198         struct wilc_vif *vif;
199 };
200
201 struct join_bss_param {
202         BSSTYPE_T bss_type;
203         u8 dtim_period;
204         u16 beacon_period;
205         u16 cap_info;
206         u8 bssid[6];
207         char ssid[MAX_SSID_LEN];
208         u8 ssid_len;
209         u8 supp_rates[MAX_RATES_SUPPORTED + 1];
210         u8 ht_capable;
211         u8 wmm_cap;
212         u8 uapsd_cap;
213         bool rsn_found;
214         u8 rsn_grp_policy;
215         u8 mode_802_11i;
216         u8 rsn_pcip_policy[3];
217         u8 rsn_auth_policy[3];
218         u8 rsn_cap[2];
219         u32 tsf;
220         u8 noa_enabled;
221         u8 opp_enabled;
222         u8 ct_window;
223         u8 cnt;
224         u8 idx;
225         u8 duration[4];
226         u8 interval[4];
227         u8 start_time[4];
228 };
229
230 static struct host_if_drv *terminated_handle;
231 bool wilc_optaining_ip;
232 static u8 P2P_LISTEN_STATE;
233 static struct task_struct *hif_thread_handler;
234 static struct message_queue hif_msg_q;
235 static struct semaphore hif_sema_thread;
236 static struct semaphore hif_sema_driver;
237 static struct semaphore hif_sema_wait_response;
238 static struct semaphore hif_sema_deinit;
239 static struct timer_list periodic_rssi;
240
241 u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
242
243 static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
244
245 static bool scan_while_connected;
246
247 static s8 rssi;
248 static u8 set_ip[2][4];
249 static u8 get_ip[2][4];
250 static u32 inactive_time;
251 static u8 del_beacon;
252 static u32 clients_count;
253
254 static u8 *join_req;
255 static u8 *info_element;
256 static u8 mode_11i;
257 static u8 auth_type;
258 static u32 join_req_size;
259 static u32 info_element_size;
260 static struct wilc_vif *join_req_vif;
261 #define REAL_JOIN_REQ 0
262 #define FLUSHED_JOIN_REQ 1
263 #define FLUSHED_BYTE_POS 79
264
265 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
266 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
267
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.
271  */
272 int wilc_get_vif_idx(struct wilc_vif *vif)
273 {
274         return vif->idx + 1;
275 }
276
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.
281  */
282 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
283 {
284         int index = idx - 1;
285
286         if (index < 0 || index >= NUM_CONCURRENT_IFC)
287                 return NULL;
288
289         return wilc->vif[index];
290 }
291
292 static void handle_set_channel(struct wilc_vif *vif,
293                                struct channel_attr *hif_set_ch)
294 {
295         int ret = 0;
296         struct wid wid;
297
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);
302
303         ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
304                                    wilc_get_vif_idx(vif));
305
306         if (ret)
307                 netdev_err(vif->ndev, "Failed to set channel\n");
308 }
309
310 static s32 handle_set_wfi_drv_handler(struct wilc_vif *vif,
311                                       struct drv_handler *hif_drv_handler)
312 {
313         s32 result = 0;
314         struct wid wid;
315
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);
320
321         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
322                                       hif_drv_handler->handler);
323
324         if (!hif_drv_handler->handler)
325                 up(&hif_sema_driver);
326
327         if (result) {
328                 netdev_err(vif->ndev, "Failed to set driver handler\n");
329                 return -EINVAL;
330         }
331
332         return result;
333 }
334
335 static s32 handle_set_operation_mode(struct wilc_vif *vif,
336                                      struct op_mode *hif_op_mode)
337 {
338         s32 result = 0;
339         struct wid wid;
340
341         wid.id = (u16)WID_SET_OPERATION_MODE;
342         wid.type = WID_INT;
343         wid.val = (s8 *)&hif_op_mode->mode;
344         wid.size = sizeof(u32);
345
346         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
347                                       wilc_get_vif_idx(vif));
348
349         if ((hif_op_mode->mode) == IDLE_MODE)
350                 up(&hif_sema_driver);
351
352         if (result) {
353                 netdev_err(vif->ndev, "Failed to set driver handler\n");
354                 return -EINVAL;
355         }
356
357         return result;
358 }
359
360 static s32 handle_set_ip_address(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
361 {
362         s32 result = 0;
363         struct wid wid;
364         char firmware_ip_addr[4] = {0};
365
366         if (ip_addr[0] < 192)
367                 ip_addr[0] = 0;
368
369         memcpy(set_ip[idx], ip_addr, IP_ALEN);
370
371         wid.id = (u16)WID_IP_ADDRESS;
372         wid.type = WID_STR;
373         wid.val = (u8 *)ip_addr;
374         wid.size = IP_ALEN;
375
376         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
377                                       wilc_get_vif_idx(vif));
378
379         host_int_get_ipaddress(vif, firmware_ip_addr, idx);
380
381         if (result) {
382                 netdev_err(vif->ndev, "Failed to set IP address\n");
383                 return -EINVAL;
384         }
385
386         return result;
387 }
388
389 static s32 handle_get_ip_address(struct wilc_vif *vif, u8 idx)
390 {
391         s32 result = 0;
392         struct wid wid;
393
394         wid.id = (u16)WID_IP_ADDRESS;
395         wid.type = WID_STR;
396         wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
397         wid.size = IP_ALEN;
398
399         result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
400                                       wilc_get_vif_idx(vif));
401
402         memcpy(get_ip[idx], wid.val, IP_ALEN);
403
404         kfree(wid.val);
405
406         if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
407                 wilc_setup_ipaddress(vif, set_ip[idx], idx);
408
409         if (result != 0) {
410                 netdev_err(vif->ndev, "Failed to get IP address\n");
411                 return -EINVAL;
412         }
413
414         return result;
415 }
416
417 static void handle_set_mac_address(struct wilc_vif *vif,
418                                    struct set_mac_addr *set_mac_addr)
419 {
420         int ret = 0;
421         struct wid wid;
422         u8 *mac_buf;
423
424         mac_buf = kmemdup(set_mac_addr->mac_addr, ETH_ALEN, GFP_KERNEL);
425         if (!mac_buf)
426                 return;
427
428         wid.id = (u16)WID_MAC_ADDR;
429         wid.type = WID_STR;
430         wid.val = mac_buf;
431         wid.size = ETH_ALEN;
432
433         ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
434                                    wilc_get_vif_idx(vif));
435         if (ret)
436                 netdev_err(vif->ndev, "Failed to set mac address\n");
437
438         kfree(mac_buf);
439 }
440
441 static s32 handle_get_mac_address(struct wilc_vif *vif,
442                                   struct get_mac_addr *get_mac_addr)
443 {
444         s32 result = 0;
445         struct wid wid;
446
447         wid.id = (u16)WID_MAC_ADDR;
448         wid.type = WID_STR;
449         wid.val = get_mac_addr->mac_addr;
450         wid.size = ETH_ALEN;
451
452         result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
453                                       wilc_get_vif_idx(vif));
454
455         if (result) {
456                 netdev_err(vif->ndev, "Failed to get mac address\n");
457                 result = -EFAULT;
458         }
459         up(&hif_sema_wait_response);
460
461         return result;
462 }
463
464 static s32 handle_cfg_param(struct wilc_vif *vif,
465                             struct cfg_param_attr *cfg_param_attr)
466 {
467         s32 result = 0;
468         struct wid wid_list[32];
469         struct host_if_drv *hif_drv = vif->hif_drv;
470         int i = 0;
471
472         down(&hif_drv->sem_cfg_values);
473
474         if (cfg_param_attr->flag & BSS_TYPE) {
475                 if (cfg_param_attr->bss_type < 6) {
476                         wid_list[i].id = WID_BSS_TYPE;
477                         wid_list[i].val = (s8 *)&cfg_param_attr->bss_type;
478                         wid_list[i].type = WID_CHAR;
479                         wid_list[i].size = sizeof(char);
480                         hif_drv->cfg_values.bss_type = (u8)cfg_param_attr->bss_type;
481                 } else {
482                         netdev_err(vif->ndev, "check value 6 over\n");
483                         result = -EINVAL;
484                         goto ERRORHANDLER;
485                 }
486                 i++;
487         }
488         if (cfg_param_attr->flag & AUTH_TYPE) {
489                 if (cfg_param_attr->auth_type == 1 ||
490                     cfg_param_attr->auth_type == 2 ||
491                     cfg_param_attr->auth_type == 5) {
492                         wid_list[i].id = WID_AUTH_TYPE;
493                         wid_list[i].val = (s8 *)&cfg_param_attr->auth_type;
494                         wid_list[i].type = WID_CHAR;
495                         wid_list[i].size = sizeof(char);
496                         hif_drv->cfg_values.auth_type = (u8)cfg_param_attr->auth_type;
497                 } else {
498                         netdev_err(vif->ndev, "Impossible value\n");
499                         result = -EINVAL;
500                         goto ERRORHANDLER;
501                 }
502                 i++;
503         }
504         if (cfg_param_attr->flag & AUTHEN_TIMEOUT) {
505                 if (cfg_param_attr->auth_timeout > 0 &&
506                     cfg_param_attr->auth_timeout < 65536) {
507                         wid_list[i].id = WID_AUTH_TIMEOUT;
508                         wid_list[i].val = (s8 *)&cfg_param_attr->auth_timeout;
509                         wid_list[i].type = WID_SHORT;
510                         wid_list[i].size = sizeof(u16);
511                         hif_drv->cfg_values.auth_timeout = cfg_param_attr->auth_timeout;
512                 } else {
513                         netdev_err(vif->ndev, "Range(1 ~ 65535) over\n");
514                         result = -EINVAL;
515                         goto ERRORHANDLER;
516                 }
517                 i++;
518         }
519         if (cfg_param_attr->flag & POWER_MANAGEMENT) {
520                 if (cfg_param_attr->power_mgmt_mode < 5) {
521                         wid_list[i].id = WID_POWER_MANAGEMENT;
522                         wid_list[i].val = (s8 *)&cfg_param_attr->power_mgmt_mode;
523                         wid_list[i].type = WID_CHAR;
524                         wid_list[i].size = sizeof(char);
525                         hif_drv->cfg_values.power_mgmt_mode = (u8)cfg_param_attr->power_mgmt_mode;
526                 } else {
527                         netdev_err(vif->ndev, "Invalid power mode\n");
528                         result = -EINVAL;
529                         goto ERRORHANDLER;
530                 }
531                 i++;
532         }
533         if (cfg_param_attr->flag & RETRY_SHORT) {
534                 if (cfg_param_attr->short_retry_limit > 0 &&
535                     cfg_param_attr->short_retry_limit < 256) {
536                         wid_list[i].id = WID_SHORT_RETRY_LIMIT;
537                         wid_list[i].val = (s8 *)&cfg_param_attr->short_retry_limit;
538                         wid_list[i].type = WID_SHORT;
539                         wid_list[i].size = sizeof(u16);
540                         hif_drv->cfg_values.short_retry_limit = cfg_param_attr->short_retry_limit;
541                 } else {
542                         netdev_err(vif->ndev, "Range(1~256) over\n");
543                         result = -EINVAL;
544                         goto ERRORHANDLER;
545                 }
546                 i++;
547         }
548         if (cfg_param_attr->flag & RETRY_LONG) {
549                 if (cfg_param_attr->long_retry_limit > 0 &&
550                     cfg_param_attr->long_retry_limit < 256) {
551                         wid_list[i].id = WID_LONG_RETRY_LIMIT;
552                         wid_list[i].val = (s8 *)&cfg_param_attr->long_retry_limit;
553                         wid_list[i].type = WID_SHORT;
554                         wid_list[i].size = sizeof(u16);
555                         hif_drv->cfg_values.long_retry_limit = cfg_param_attr->long_retry_limit;
556                 } else {
557                         netdev_err(vif->ndev, "Range(1~256) over\n");
558                         result = -EINVAL;
559                         goto ERRORHANDLER;
560                 }
561                 i++;
562         }
563         if (cfg_param_attr->flag & FRAG_THRESHOLD) {
564                 if (cfg_param_attr->frag_threshold > 255 &&
565                     cfg_param_attr->frag_threshold < 7937) {
566                         wid_list[i].id = WID_FRAG_THRESHOLD;
567                         wid_list[i].val = (s8 *)&cfg_param_attr->frag_threshold;
568                         wid_list[i].type = WID_SHORT;
569                         wid_list[i].size = sizeof(u16);
570                         hif_drv->cfg_values.frag_threshold = cfg_param_attr->frag_threshold;
571                 } else {
572                         netdev_err(vif->ndev, "Threshold Range fail\n");
573                         result = -EINVAL;
574                         goto ERRORHANDLER;
575                 }
576                 i++;
577         }
578         if (cfg_param_attr->flag & RTS_THRESHOLD) {
579                 if (cfg_param_attr->rts_threshold > 255 &&
580                     cfg_param_attr->rts_threshold < 65536) {
581                         wid_list[i].id = WID_RTS_THRESHOLD;
582                         wid_list[i].val = (s8 *)&cfg_param_attr->rts_threshold;
583                         wid_list[i].type = WID_SHORT;
584                         wid_list[i].size = sizeof(u16);
585                         hif_drv->cfg_values.rts_threshold = cfg_param_attr->rts_threshold;
586                 } else {
587                         netdev_err(vif->ndev, "Threshold Range fail\n");
588                         result = -EINVAL;
589                         goto ERRORHANDLER;
590                 }
591                 i++;
592         }
593         if (cfg_param_attr->flag & PREAMBLE) {
594                 if (cfg_param_attr->preamble_type < 3) {
595                         wid_list[i].id = WID_PREAMBLE;
596                         wid_list[i].val = (s8 *)&cfg_param_attr->preamble_type;
597                         wid_list[i].type = WID_CHAR;
598                         wid_list[i].size = sizeof(char);
599                         hif_drv->cfg_values.preamble_type = cfg_param_attr->preamble_type;
600                 } else {
601                         netdev_err(vif->ndev, "Preamle Range(0~2) over\n");
602                         result = -EINVAL;
603                         goto ERRORHANDLER;
604                 }
605                 i++;
606         }
607         if (cfg_param_attr->flag & SHORT_SLOT_ALLOWED) {
608                 if (cfg_param_attr->short_slot_allowed < 2) {
609                         wid_list[i].id = WID_SHORT_SLOT_ALLOWED;
610                         wid_list[i].val = (s8 *)&cfg_param_attr->short_slot_allowed;
611                         wid_list[i].type = WID_CHAR;
612                         wid_list[i].size = sizeof(char);
613                         hif_drv->cfg_values.short_slot_allowed = (u8)cfg_param_attr->short_slot_allowed;
614                 } else {
615                         netdev_err(vif->ndev, "Short slot(2) over\n");
616                         result = -EINVAL;
617                         goto ERRORHANDLER;
618                 }
619                 i++;
620         }
621         if (cfg_param_attr->flag & TXOP_PROT_DISABLE) {
622                 if (cfg_param_attr->txop_prot_disabled < 2) {
623                         wid_list[i].id = WID_11N_TXOP_PROT_DISABLE;
624                         wid_list[i].val = (s8 *)&cfg_param_attr->txop_prot_disabled;
625                         wid_list[i].type = WID_CHAR;
626                         wid_list[i].size = sizeof(char);
627                         hif_drv->cfg_values.txop_prot_disabled = (u8)cfg_param_attr->txop_prot_disabled;
628                 } else {
629                         netdev_err(vif->ndev, "TXOP prot disable\n");
630                         result = -EINVAL;
631                         goto ERRORHANDLER;
632                 }
633                 i++;
634         }
635         if (cfg_param_attr->flag & BEACON_INTERVAL) {
636                 if (cfg_param_attr->beacon_interval > 0 &&
637                     cfg_param_attr->beacon_interval < 65536) {
638                         wid_list[i].id = WID_BEACON_INTERVAL;
639                         wid_list[i].val = (s8 *)&cfg_param_attr->beacon_interval;
640                         wid_list[i].type = WID_SHORT;
641                         wid_list[i].size = sizeof(u16);
642                         hif_drv->cfg_values.beacon_interval = cfg_param_attr->beacon_interval;
643                 } else {
644                         netdev_err(vif->ndev, "Beacon interval(1~65535)fail\n");
645                         result = -EINVAL;
646                         goto ERRORHANDLER;
647                 }
648                 i++;
649         }
650         if (cfg_param_attr->flag & DTIM_PERIOD) {
651                 if (cfg_param_attr->dtim_period > 0 &&
652                     cfg_param_attr->dtim_period < 256) {
653                         wid_list[i].id = WID_DTIM_PERIOD;
654                         wid_list[i].val = (s8 *)&cfg_param_attr->dtim_period;
655                         wid_list[i].type = WID_CHAR;
656                         wid_list[i].size = sizeof(char);
657                         hif_drv->cfg_values.dtim_period = cfg_param_attr->dtim_period;
658                 } else {
659                         netdev_err(vif->ndev, "DTIM range(1~255) fail\n");
660                         result = -EINVAL;
661                         goto ERRORHANDLER;
662                 }
663                 i++;
664         }
665         if (cfg_param_attr->flag & SITE_SURVEY) {
666                 if (cfg_param_attr->site_survey_enabled < 3) {
667                         wid_list[i].id = WID_SITE_SURVEY;
668                         wid_list[i].val = (s8 *)&cfg_param_attr->site_survey_enabled;
669                         wid_list[i].type = WID_CHAR;
670                         wid_list[i].size = sizeof(char);
671                         hif_drv->cfg_values.site_survey_enabled = (u8)cfg_param_attr->site_survey_enabled;
672                 } else {
673                         netdev_err(vif->ndev, "Site survey disable\n");
674                         result = -EINVAL;
675                         goto ERRORHANDLER;
676                 }
677                 i++;
678         }
679         if (cfg_param_attr->flag & SITE_SURVEY_SCAN_TIME) {
680                 if (cfg_param_attr->site_survey_scan_time > 0 &&
681                     cfg_param_attr->site_survey_scan_time < 65536) {
682                         wid_list[i].id = WID_SITE_SURVEY_SCAN_TIME;
683                         wid_list[i].val = (s8 *)&cfg_param_attr->site_survey_scan_time;
684                         wid_list[i].type = WID_SHORT;
685                         wid_list[i].size = sizeof(u16);
686                         hif_drv->cfg_values.site_survey_scan_time = cfg_param_attr->site_survey_scan_time;
687                 } else {
688                         netdev_err(vif->ndev, "Site scan time(1~65535) over\n");
689                         result = -EINVAL;
690                         goto ERRORHANDLER;
691                 }
692                 i++;
693         }
694         if (cfg_param_attr->flag & ACTIVE_SCANTIME) {
695                 if (cfg_param_attr->active_scan_time > 0 &&
696                     cfg_param_attr->active_scan_time < 65536) {
697                         wid_list[i].id = WID_ACTIVE_SCAN_TIME;
698                         wid_list[i].val = (s8 *)&cfg_param_attr->active_scan_time;
699                         wid_list[i].type = WID_SHORT;
700                         wid_list[i].size = sizeof(u16);
701                         hif_drv->cfg_values.active_scan_time = cfg_param_attr->active_scan_time;
702                 } else {
703                         netdev_err(vif->ndev, "Active time(1~65535) over\n");
704                         result = -EINVAL;
705                         goto ERRORHANDLER;
706                 }
707                 i++;
708         }
709         if (cfg_param_attr->flag & PASSIVE_SCANTIME) {
710                 if (cfg_param_attr->passive_scan_time > 0 &&
711                     cfg_param_attr->passive_scan_time < 65536) {
712                         wid_list[i].id = WID_PASSIVE_SCAN_TIME;
713                         wid_list[i].val = (s8 *)&cfg_param_attr->passive_scan_time;
714                         wid_list[i].type = WID_SHORT;
715                         wid_list[i].size = sizeof(u16);
716                         hif_drv->cfg_values.passive_scan_time = cfg_param_attr->passive_scan_time;
717                 } else {
718                         netdev_err(vif->ndev, "Passive time(1~65535) over\n");
719                         result = -EINVAL;
720                         goto ERRORHANDLER;
721                 }
722                 i++;
723         }
724         if (cfg_param_attr->flag & CURRENT_TX_RATE) {
725                 enum CURRENT_TXRATE curr_tx_rate = cfg_param_attr->curr_tx_rate;
726
727                 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1 ||
728                     curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5 ||
729                     curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6 ||
730                     curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12 ||
731                     curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24 ||
732                     curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 ||
733                     curr_tx_rate == MBPS_54) {
734                         wid_list[i].id = WID_CURRENT_TX_RATE;
735                         wid_list[i].val = (s8 *)&curr_tx_rate;
736                         wid_list[i].type = WID_SHORT;
737                         wid_list[i].size = sizeof(u16);
738                         hif_drv->cfg_values.curr_tx_rate = (u8)curr_tx_rate;
739                 } else {
740                         netdev_err(vif->ndev, "out of TX rate\n");
741                         result = -EINVAL;
742                         goto ERRORHANDLER;
743                 }
744                 i++;
745         }
746
747         result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
748                                       i, wilc_get_vif_idx(vif));
749
750         if (result)
751                 netdev_err(vif->ndev, "Error in setting CFG params\n");
752
753 ERRORHANDLER:
754         up(&hif_drv->sem_cfg_values);
755         return result;
756 }
757
758 static void Handle_wait_msg_q_empty(void)
759 {
760         wilc_initialized = 0;
761         up(&hif_sema_wait_response);
762 }
763
764 static s32 Handle_ScanDone(struct wilc_vif *vif,
765                            enum scan_event enuEvent);
766
767 static s32 Handle_Scan(struct wilc_vif *vif,
768                        struct scan_attr *pstrHostIFscanAttr)
769 {
770         s32 result = 0;
771         struct wid strWIDList[5];
772         u32 u32WidsCount = 0;
773         u32 i;
774         u8 *pu8Buffer;
775         u8 valuesize = 0;
776         u8 *pu8HdnNtwrksWidVal = NULL;
777         struct host_if_drv *hif_drv = vif->hif_drv;
778
779         hif_drv->usr_scan_req.scan_result = pstrHostIFscanAttr->result;
780         hif_drv->usr_scan_req.arg = pstrHostIFscanAttr->arg;
781
782         if ((hif_drv->hif_state >= HOST_IF_SCANNING) &&
783             (hif_drv->hif_state < HOST_IF_CONNECTED)) {
784                 netdev_err(vif->ndev, "Already scan\n");
785                 result = -EBUSY;
786                 goto ERRORHANDLER;
787         }
788
789         if (wilc_optaining_ip || wilc_connecting) {
790                 netdev_err(vif->ndev, "Don't do obss scan\n");
791                 result = -EBUSY;
792                 goto ERRORHANDLER;
793         }
794
795         hif_drv->usr_scan_req.rcvd_ch_cnt = 0;
796
797         strWIDList[u32WidsCount].id = (u16)WID_SSID_PROBE_REQ;
798         strWIDList[u32WidsCount].type = WID_STR;
799
800         for (i = 0; i < pstrHostIFscanAttr->hidden_network.n_ssids; i++)
801                 valuesize += ((pstrHostIFscanAttr->hidden_network.net_info[i].ssid_len) + 1);
802         pu8HdnNtwrksWidVal = kmalloc(valuesize + 1, GFP_KERNEL);
803         strWIDList[u32WidsCount].val = pu8HdnNtwrksWidVal;
804         if (strWIDList[u32WidsCount].val) {
805                 pu8Buffer = strWIDList[u32WidsCount].val;
806
807                 *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.n_ssids;
808
809                 for (i = 0; i < pstrHostIFscanAttr->hidden_network.n_ssids; i++) {
810                         *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.net_info[i].ssid_len;
811                         memcpy(pu8Buffer, pstrHostIFscanAttr->hidden_network.net_info[i].ssid, pstrHostIFscanAttr->hidden_network.net_info[i].ssid_len);
812                         pu8Buffer += pstrHostIFscanAttr->hidden_network.net_info[i].ssid_len;
813                 }
814
815                 strWIDList[u32WidsCount].size = (s32)(valuesize + 1);
816                 u32WidsCount++;
817         }
818
819         {
820                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_PROBE;
821                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
822                 strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ies;
823                 strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ies_len;
824                 u32WidsCount++;
825         }
826
827         strWIDList[u32WidsCount].id = WID_SCAN_TYPE;
828         strWIDList[u32WidsCount].type = WID_CHAR;
829         strWIDList[u32WidsCount].size = sizeof(char);
830         strWIDList[u32WidsCount].val = (s8 *)&pstrHostIFscanAttr->type;
831         u32WidsCount++;
832
833         strWIDList[u32WidsCount].id = WID_SCAN_CHANNEL_LIST;
834         strWIDList[u32WidsCount].type = WID_BIN_DATA;
835
836         if (pstrHostIFscanAttr->ch_freq_list &&
837             pstrHostIFscanAttr->ch_list_len > 0) {
838                 int i;
839
840                 for (i = 0; i < pstrHostIFscanAttr->ch_list_len; i++)   {
841                         if (pstrHostIFscanAttr->ch_freq_list[i] > 0)
842                                 pstrHostIFscanAttr->ch_freq_list[i] = pstrHostIFscanAttr->ch_freq_list[i] - 1;
843                 }
844         }
845
846         strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ch_freq_list;
847         strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ch_list_len;
848         u32WidsCount++;
849
850         strWIDList[u32WidsCount].id = WID_START_SCAN_REQ;
851         strWIDList[u32WidsCount].type = WID_CHAR;
852         strWIDList[u32WidsCount].size = sizeof(char);
853         strWIDList[u32WidsCount].val = (s8 *)&pstrHostIFscanAttr->src;
854         u32WidsCount++;
855
856         if (hif_drv->hif_state == HOST_IF_CONNECTED)
857                 scan_while_connected = true;
858         else if (hif_drv->hif_state == HOST_IF_IDLE)
859                 scan_while_connected = false;
860
861         result = wilc_send_config_pkt(vif, SET_CFG, strWIDList,
862                                       u32WidsCount,
863                                       wilc_get_vif_idx(vif));
864
865         if (result)
866                 netdev_err(vif->ndev, "Failed to send scan parameters\n");
867
868 ERRORHANDLER:
869         if (result) {
870                 del_timer(&hif_drv->scan_timer);
871                 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
872         }
873
874         kfree(pstrHostIFscanAttr->ch_freq_list);
875         pstrHostIFscanAttr->ch_freq_list = NULL;
876
877         kfree(pstrHostIFscanAttr->ies);
878         pstrHostIFscanAttr->ies = NULL;
879         kfree(pstrHostIFscanAttr->hidden_network.net_info);
880         pstrHostIFscanAttr->hidden_network.net_info = NULL;
881
882         kfree(pu8HdnNtwrksWidVal);
883
884         return result;
885 }
886
887 static s32 Handle_ScanDone(struct wilc_vif *vif,
888                            enum scan_event enuEvent)
889 {
890         s32 result = 0;
891         u8 u8abort_running_scan;
892         struct wid wid;
893         struct host_if_drv *hif_drv = vif->hif_drv;
894
895         if (enuEvent == SCAN_EVENT_ABORTED) {
896                 u8abort_running_scan = 1;
897                 wid.id = (u16)WID_ABORT_RUNNING_SCAN;
898                 wid.type = WID_CHAR;
899                 wid.val = (s8 *)&u8abort_running_scan;
900                 wid.size = sizeof(char);
901
902                 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
903                                               wilc_get_vif_idx(vif));
904
905                 if (result) {
906                         netdev_err(vif->ndev, "Failed to set abort running\n");
907                         result = -EFAULT;
908                 }
909         }
910
911         if (!hif_drv) {
912                 netdev_err(vif->ndev, "Driver handler is NULL\n");
913                 return result;
914         }
915
916         if (hif_drv->usr_scan_req.scan_result) {
917                 hif_drv->usr_scan_req.scan_result(enuEvent, NULL,
918                                                   hif_drv->usr_scan_req.arg, NULL);
919                 hif_drv->usr_scan_req.scan_result = NULL;
920         }
921
922         return result;
923 }
924
925 u8 wilc_connected_ssid[6] = {0};
926 static s32 Handle_Connect(struct wilc_vif *vif,
927                           struct connect_attr *pstrHostIFconnectAttr)
928 {
929         s32 result = 0;
930         struct wid strWIDList[8];
931         u32 u32WidsCount = 0, dummyval = 0;
932         u8 *pu8CurrByte = NULL;
933         struct join_bss_param *ptstrJoinBssParam;
934         struct host_if_drv *hif_drv = vif->hif_drv;
935
936         if (memcmp(pstrHostIFconnectAttr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
937                 result = 0;
938                 netdev_err(vif->ndev, "Discard connect request\n");
939                 return result;
940         }
941
942         ptstrJoinBssParam = pstrHostIFconnectAttr->params;
943         if (!ptstrJoinBssParam) {
944                 netdev_err(vif->ndev, "Required BSSID not found\n");
945                 result = -ENOENT;
946                 goto ERRORHANDLER;
947         }
948
949         if (pstrHostIFconnectAttr->bssid) {
950                 hif_drv->usr_conn_req.bssid = kmalloc(6, GFP_KERNEL);
951                 memcpy(hif_drv->usr_conn_req.bssid, pstrHostIFconnectAttr->bssid, 6);
952         }
953
954         hif_drv->usr_conn_req.ssid_len = pstrHostIFconnectAttr->ssid_len;
955         if (pstrHostIFconnectAttr->ssid) {
956                 hif_drv->usr_conn_req.ssid = kmalloc(pstrHostIFconnectAttr->ssid_len + 1, GFP_KERNEL);
957                 memcpy(hif_drv->usr_conn_req.ssid,
958                        pstrHostIFconnectAttr->ssid,
959                        pstrHostIFconnectAttr->ssid_len);
960                 hif_drv->usr_conn_req.ssid[pstrHostIFconnectAttr->ssid_len] = '\0';
961         }
962
963         hif_drv->usr_conn_req.ies_len = pstrHostIFconnectAttr->ies_len;
964         if (pstrHostIFconnectAttr->ies) {
965                 hif_drv->usr_conn_req.ies = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
966                 memcpy(hif_drv->usr_conn_req.ies,
967                        pstrHostIFconnectAttr->ies,
968                        pstrHostIFconnectAttr->ies_len);
969         }
970
971         hif_drv->usr_conn_req.security = pstrHostIFconnectAttr->security;
972         hif_drv->usr_conn_req.auth_type = pstrHostIFconnectAttr->auth_type;
973         hif_drv->usr_conn_req.conn_result = pstrHostIFconnectAttr->result;
974         hif_drv->usr_conn_req.arg = pstrHostIFconnectAttr->arg;
975
976         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
977         strWIDList[u32WidsCount].type = WID_INT;
978         strWIDList[u32WidsCount].size = sizeof(u32);
979         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
980         u32WidsCount++;
981
982         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
983         strWIDList[u32WidsCount].type = WID_INT;
984         strWIDList[u32WidsCount].size = sizeof(u32);
985         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
986         u32WidsCount++;
987
988         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
989         strWIDList[u32WidsCount].type = WID_INT;
990         strWIDList[u32WidsCount].size = sizeof(u32);
991         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
992         u32WidsCount++;
993
994         {
995                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
996                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
997                 strWIDList[u32WidsCount].val = hif_drv->usr_conn_req.ies;
998                 strWIDList[u32WidsCount].size = hif_drv->usr_conn_req.ies_len;
999                 u32WidsCount++;
1000
1001                 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1002                         info_element_size = hif_drv->usr_conn_req.ies_len;
1003                         info_element = kmalloc(info_element_size, GFP_KERNEL);
1004                         memcpy(info_element, hif_drv->usr_conn_req.ies,
1005                                info_element_size);
1006                 }
1007         }
1008         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1009         strWIDList[u32WidsCount].type = WID_CHAR;
1010         strWIDList[u32WidsCount].size = sizeof(char);
1011         strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.security;
1012         u32WidsCount++;
1013
1014         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
1015                 mode_11i = hif_drv->usr_conn_req.security;
1016
1017         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1018         strWIDList[u32WidsCount].type = WID_CHAR;
1019         strWIDList[u32WidsCount].size = sizeof(char);
1020         strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.auth_type;
1021         u32WidsCount++;
1022
1023         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
1024                 auth_type = (u8)hif_drv->usr_conn_req.auth_type;
1025
1026         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1027         strWIDList[u32WidsCount].type = WID_STR;
1028         strWIDList[u32WidsCount].size = 112;
1029         strWIDList[u32WidsCount].val = kmalloc(strWIDList[u32WidsCount].size, GFP_KERNEL);
1030
1031         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1032                 join_req_size = strWIDList[u32WidsCount].size;
1033                 join_req = kmalloc(join_req_size, GFP_KERNEL);
1034         }
1035         if (!strWIDList[u32WidsCount].val) {
1036                 result = -EFAULT;
1037                 goto ERRORHANDLER;
1038         }
1039
1040         pu8CurrByte = strWIDList[u32WidsCount].val;
1041
1042         if (pstrHostIFconnectAttr->ssid) {
1043                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->ssid, pstrHostIFconnectAttr->ssid_len);
1044                 pu8CurrByte[pstrHostIFconnectAttr->ssid_len] = '\0';
1045         }
1046         pu8CurrByte += MAX_SSID_LEN;
1047         *(pu8CurrByte++) = INFRASTRUCTURE;
1048
1049         if ((pstrHostIFconnectAttr->ch >= 1) && (pstrHostIFconnectAttr->ch <= 14)) {
1050                 *(pu8CurrByte++) = pstrHostIFconnectAttr->ch;
1051         } else {
1052                 netdev_err(vif->ndev, "Channel out of range\n");
1053                 *(pu8CurrByte++) = 0xFF;
1054         }
1055         *(pu8CurrByte++)  = (ptstrJoinBssParam->cap_info) & 0xFF;
1056         *(pu8CurrByte++)  = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
1057
1058         if (pstrHostIFconnectAttr->bssid)
1059                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1060         pu8CurrByte += 6;
1061
1062         if (pstrHostIFconnectAttr->bssid)
1063                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1064         pu8CurrByte += 6;
1065
1066         *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
1067         *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1068         *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
1069
1070         memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1071         pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1072
1073         *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
1074         *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
1075
1076         *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
1077         hif_drv->usr_conn_req.ht_capable = ptstrJoinBssParam->ht_capable;
1078
1079         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
1080         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
1081         *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
1082
1083         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1084         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1085
1086         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1087         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1088
1089         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1090         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1091
1092         *(pu8CurrByte++) = REAL_JOIN_REQ;
1093         *(pu8CurrByte++) = ptstrJoinBssParam->noa_enabled;
1094
1095         if (ptstrJoinBssParam->noa_enabled) {
1096                 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1097                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1098                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1099                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1100
1101                 *(pu8CurrByte++) = ptstrJoinBssParam->opp_enabled;
1102                 *(pu8CurrByte++) = ptstrJoinBssParam->idx;
1103
1104                 if (ptstrJoinBssParam->opp_enabled)
1105                         *(pu8CurrByte++) = ptstrJoinBssParam->ct_window;
1106
1107                 *(pu8CurrByte++) = ptstrJoinBssParam->cnt;
1108
1109                 memcpy(pu8CurrByte, ptstrJoinBssParam->duration, sizeof(ptstrJoinBssParam->duration));
1110                 pu8CurrByte += sizeof(ptstrJoinBssParam->duration);
1111
1112                 memcpy(pu8CurrByte, ptstrJoinBssParam->interval, sizeof(ptstrJoinBssParam->interval));
1113                 pu8CurrByte += sizeof(ptstrJoinBssParam->interval);
1114
1115                 memcpy(pu8CurrByte, ptstrJoinBssParam->start_time, sizeof(ptstrJoinBssParam->start_time));
1116                 pu8CurrByte += sizeof(ptstrJoinBssParam->start_time);
1117         }
1118
1119         pu8CurrByte = strWIDList[u32WidsCount].val;
1120         u32WidsCount++;
1121
1122         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1123                 memcpy(join_req, pu8CurrByte, join_req_size);
1124                 join_req_vif = vif;
1125         }
1126
1127         if (pstrHostIFconnectAttr->bssid)
1128                 memcpy(wilc_connected_ssid,
1129                        pstrHostIFconnectAttr->bssid, ETH_ALEN);
1130
1131         result = wilc_send_config_pkt(vif, SET_CFG, strWIDList,
1132                                       u32WidsCount,
1133                                       wilc_get_vif_idx(vif));
1134         if (result) {
1135                 netdev_err(vif->ndev, "failed to send config packet\n");
1136                 result = -EFAULT;
1137                 goto ERRORHANDLER;
1138         } else {
1139                 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
1140         }
1141
1142 ERRORHANDLER:
1143         if (result) {
1144                 struct connect_info strConnectInfo;
1145
1146                 del_timer(&hif_drv->connect_timer);
1147
1148                 memset(&strConnectInfo, 0, sizeof(struct connect_info));
1149
1150                 if (pstrHostIFconnectAttr->result) {
1151                         if (pstrHostIFconnectAttr->bssid)
1152                                 memcpy(strConnectInfo.bssid, pstrHostIFconnectAttr->bssid, 6);
1153
1154                         if (pstrHostIFconnectAttr->ies) {
1155                                 strConnectInfo.req_ies_len = pstrHostIFconnectAttr->ies_len;
1156                                 strConnectInfo.req_ies = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
1157                                 memcpy(strConnectInfo.req_ies,
1158                                        pstrHostIFconnectAttr->ies,
1159                                        pstrHostIFconnectAttr->ies_len);
1160                         }
1161
1162                         pstrHostIFconnectAttr->result(CONN_DISCONN_EVENT_CONN_RESP,
1163                                                                &strConnectInfo,
1164                                                                MAC_DISCONNECTED,
1165                                                                NULL,
1166                                                                pstrHostIFconnectAttr->arg);
1167                         hif_drv->hif_state = HOST_IF_IDLE;
1168                         kfree(strConnectInfo.req_ies);
1169                         strConnectInfo.req_ies = NULL;
1170
1171                 } else {
1172                         netdev_err(vif->ndev, "Connect callback is NULL\n");
1173                 }
1174         }
1175
1176         kfree(pstrHostIFconnectAttr->bssid);
1177         pstrHostIFconnectAttr->bssid = NULL;
1178
1179         kfree(pstrHostIFconnectAttr->ssid);
1180         pstrHostIFconnectAttr->ssid = NULL;
1181
1182         kfree(pstrHostIFconnectAttr->ies);
1183         pstrHostIFconnectAttr->ies = NULL;
1184
1185         kfree(pu8CurrByte);
1186         return result;
1187 }
1188
1189 static s32 Handle_ConnectTimeout(struct wilc_vif *vif)
1190 {
1191         s32 result = 0;
1192         struct connect_info strConnectInfo;
1193         struct wid wid;
1194         u16 u16DummyReasonCode = 0;
1195         struct host_if_drv *hif_drv = vif->hif_drv;
1196
1197         if (!hif_drv) {
1198                 netdev_err(vif->ndev, "Driver handler is NULL\n");
1199                 return result;
1200         }
1201
1202         hif_drv->hif_state = HOST_IF_IDLE;
1203
1204         scan_while_connected = false;
1205
1206         memset(&strConnectInfo, 0, sizeof(struct connect_info));
1207
1208         if (hif_drv->usr_conn_req.conn_result) {
1209                 if (hif_drv->usr_conn_req.bssid) {
1210                         memcpy(strConnectInfo.bssid,
1211                                hif_drv->usr_conn_req.bssid, 6);
1212                 }
1213
1214                 if (hif_drv->usr_conn_req.ies) {
1215                         strConnectInfo.req_ies_len = hif_drv->usr_conn_req.ies_len;
1216                         strConnectInfo.req_ies = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL);
1217                         memcpy(strConnectInfo.req_ies,
1218                                hif_drv->usr_conn_req.ies,
1219                                hif_drv->usr_conn_req.ies_len);
1220                 }
1221
1222                 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1223                                                   &strConnectInfo,
1224                                                   MAC_DISCONNECTED,
1225                                                   NULL,
1226                                                   hif_drv->usr_conn_req.arg);
1227
1228                 kfree(strConnectInfo.req_ies);
1229                 strConnectInfo.req_ies = NULL;
1230         } else {
1231                 netdev_err(vif->ndev, "Connect callback is NULL\n");
1232         }
1233
1234         wid.id = (u16)WID_DISCONNECT;
1235         wid.type = WID_CHAR;
1236         wid.val = (s8 *)&u16DummyReasonCode;
1237         wid.size = sizeof(char);
1238
1239         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1240                                       wilc_get_vif_idx(vif));
1241         if (result)
1242                 netdev_err(vif->ndev, "Failed to send dissconect\n");
1243
1244         hif_drv->usr_conn_req.ssid_len = 0;
1245         kfree(hif_drv->usr_conn_req.ssid);
1246         hif_drv->usr_conn_req.ssid = NULL;
1247         kfree(hif_drv->usr_conn_req.bssid);
1248         hif_drv->usr_conn_req.bssid = NULL;
1249         hif_drv->usr_conn_req.ies_len = 0;
1250         kfree(hif_drv->usr_conn_req.ies);
1251         hif_drv->usr_conn_req.ies = NULL;
1252
1253         eth_zero_addr(wilc_connected_ssid);
1254
1255         if (join_req && join_req_vif == vif) {
1256                 kfree(join_req);
1257                 join_req = NULL;
1258         }
1259
1260         if (info_element && join_req_vif == vif) {
1261                 kfree(info_element);
1262                 info_element = NULL;
1263         }
1264
1265         return result;
1266 }
1267
1268 static s32 Handle_RcvdNtwrkInfo(struct wilc_vif *vif,
1269                                 struct rcvd_net_info *pstrRcvdNetworkInfo)
1270 {
1271         u32 i;
1272         bool bNewNtwrkFound;
1273         s32 result = 0;
1274         struct network_info *pstrNetworkInfo = NULL;
1275         void *pJoinParams = NULL;
1276         struct host_if_drv *hif_drv = vif->hif_drv;
1277
1278         bNewNtwrkFound = true;
1279
1280         if (hif_drv->usr_scan_req.scan_result) {
1281                 wilc_parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo);
1282                 if ((!pstrNetworkInfo) ||
1283                     (!hif_drv->usr_scan_req.scan_result)) {
1284                         netdev_err(vif->ndev, "driver is null\n");
1285                         result = -EINVAL;
1286                         goto done;
1287                 }
1288
1289                 for (i = 0; i < hif_drv->usr_scan_req.rcvd_ch_cnt; i++) {
1290                         if ((hif_drv->usr_scan_req.net_info[i].bssid) &&
1291                             (pstrNetworkInfo->bssid)) {
1292                                 if (memcmp(hif_drv->usr_scan_req.net_info[i].bssid,
1293                                            pstrNetworkInfo->bssid, 6) == 0) {
1294                                         if (pstrNetworkInfo->rssi <= hif_drv->usr_scan_req.net_info[i].rssi) {
1295                                                 goto done;
1296                                         } else {
1297                                                 hif_drv->usr_scan_req.net_info[i].rssi = pstrNetworkInfo->rssi;
1298                                                 bNewNtwrkFound = false;
1299                                                 break;
1300                                         }
1301                                 }
1302                         }
1303                 }
1304
1305                 if (bNewNtwrkFound) {
1306                         if (hif_drv->usr_scan_req.rcvd_ch_cnt < MAX_NUM_SCANNED_NETWORKS) {
1307                                 hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].rssi = pstrNetworkInfo->rssi;
1308
1309                                 if (hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].bssid &&
1310                                     pstrNetworkInfo->bssid) {
1311                                         memcpy(hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].bssid,
1312                                                pstrNetworkInfo->bssid, 6);
1313
1314                                         hif_drv->usr_scan_req.rcvd_ch_cnt++;
1315
1316                                         pstrNetworkInfo->new_network = true;
1317                                         pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
1318
1319                                         hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1320                                                                           hif_drv->usr_scan_req.arg,
1321                                                                           pJoinParams);
1322                                 }
1323                         }
1324                 } else {
1325                         pstrNetworkInfo->new_network = false;
1326                         hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1327                                                           hif_drv->usr_scan_req.arg, NULL);
1328                 }
1329         }
1330
1331 done:
1332         kfree(pstrRcvdNetworkInfo->buffer);
1333         pstrRcvdNetworkInfo->buffer = NULL;
1334
1335         if (pstrNetworkInfo) {
1336                 kfree(pstrNetworkInfo->ies);
1337                 kfree(pstrNetworkInfo);
1338         }
1339
1340         return result;
1341 }
1342
1343 static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
1344                                        u8 *pu8AssocRespInfo,
1345                                        u32 u32MaxAssocRespInfoLen,
1346                                        u32 *pu32RcvdAssocRespInfoLen);
1347
1348 static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1349                                     struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
1350 {
1351         s32 result = 0;
1352         u8 u8MsgType = 0;
1353         u8 u8MsgID = 0;
1354         u16 u16MsgLen = 0;
1355         u16 u16WidID = (u16)WID_NIL;
1356         u8 u8WidLen  = 0;
1357         u8 u8MacStatus;
1358         u8 u8MacStatusReasonCode;
1359         u8 u8MacStatusAdditionalInfo;
1360         struct connect_info strConnectInfo;
1361         struct disconnect_info strDisconnectNotifInfo;
1362         s32 s32Err = 0;
1363         struct host_if_drv *hif_drv = vif->hif_drv;
1364
1365         if (!hif_drv) {
1366                 netdev_err(vif->ndev, "Driver handler is NULL\n");
1367                 return -ENODEV;
1368         }
1369
1370         if ((hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) ||
1371             (hif_drv->hif_state == HOST_IF_CONNECTED) ||
1372             hif_drv->usr_scan_req.scan_result) {
1373                 if (!pstrRcvdGnrlAsyncInfo->buffer ||
1374                     !hif_drv->usr_conn_req.conn_result) {
1375                         netdev_err(vif->ndev, "driver is null\n");
1376                         return -EINVAL;
1377                 }
1378
1379                 u8MsgType = pstrRcvdGnrlAsyncInfo->buffer[0];
1380
1381                 if ('I' != u8MsgType) {
1382                         netdev_err(vif->ndev, "Received Message incorrect.\n");
1383                         return -EFAULT;
1384                 }
1385
1386                 u8MsgID = pstrRcvdGnrlAsyncInfo->buffer[1];
1387                 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[2], pstrRcvdGnrlAsyncInfo->buffer[3]);
1388                 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[4], pstrRcvdGnrlAsyncInfo->buffer[5]);
1389                 u8WidLen = pstrRcvdGnrlAsyncInfo->buffer[6];
1390                 u8MacStatus  = pstrRcvdGnrlAsyncInfo->buffer[7];
1391                 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->buffer[8];
1392                 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->buffer[9];
1393                 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
1394                         u32 u32RcvdAssocRespInfoLen = 0;
1395                         struct connect_resp_info *pstrConnectRespInfo = NULL;
1396
1397                         memset(&strConnectInfo, 0, sizeof(struct connect_info));
1398
1399                         if (u8MacStatus == MAC_CONNECTED) {
1400                                 memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1401
1402                                 host_int_get_assoc_res_info(vif,
1403                                                             rcv_assoc_resp,
1404                                                             MAX_ASSOC_RESP_FRAME_SIZE,
1405                                                             &u32RcvdAssocRespInfoLen);
1406
1407                                 if (u32RcvdAssocRespInfoLen != 0) {
1408                                         s32Err = wilc_parse_assoc_resp_info(rcv_assoc_resp, u32RcvdAssocRespInfoLen,
1409                                                                     &pstrConnectRespInfo);
1410                                         if (s32Err) {
1411                                                 netdev_err(vif->ndev, "wilc_parse_assoc_resp_info() returned error %d\n", s32Err);
1412                                         } else {
1413                                                 strConnectInfo.status = pstrConnectRespInfo->status;
1414
1415                                                 if (strConnectInfo.status == SUCCESSFUL_STATUSCODE) {
1416                                                         if (pstrConnectRespInfo->ies) {
1417                                                                 strConnectInfo.resp_ies_len = pstrConnectRespInfo->ies_len;
1418                                                                 strConnectInfo.resp_ies = kmalloc(pstrConnectRespInfo->ies_len, GFP_KERNEL);
1419                                                                 memcpy(strConnectInfo.resp_ies, pstrConnectRespInfo->ies,
1420                                                                        pstrConnectRespInfo->ies_len);
1421                                                         }
1422                                                 }
1423
1424                                                 if (pstrConnectRespInfo) {
1425                                                         kfree(pstrConnectRespInfo->ies);
1426                                                         kfree(pstrConnectRespInfo);
1427                                                 }
1428                                         }
1429                                 }
1430                         }
1431
1432                         if ((u8MacStatus == MAC_CONNECTED) &&
1433                             (strConnectInfo.status != SUCCESSFUL_STATUSCODE))   {
1434                                 netdev_err(vif->ndev, "Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1435                                 eth_zero_addr(wilc_connected_ssid);
1436                         } else if (u8MacStatus == MAC_DISCONNECTED)    {
1437                                 netdev_err(vif->ndev, "Received MAC status is MAC_DISCONNECTED\n");
1438                                 eth_zero_addr(wilc_connected_ssid);
1439                         }
1440
1441                         if (hif_drv->usr_conn_req.bssid) {
1442                                 memcpy(strConnectInfo.bssid, hif_drv->usr_conn_req.bssid, 6);
1443
1444                                 if ((u8MacStatus == MAC_CONNECTED) &&
1445                                     (strConnectInfo.status == SUCCESSFUL_STATUSCODE))   {
1446                                         memcpy(hif_drv->assoc_bssid,
1447                                                hif_drv->usr_conn_req.bssid, ETH_ALEN);
1448                                 }
1449                         }
1450
1451                         if (hif_drv->usr_conn_req.ies) {
1452                                 strConnectInfo.req_ies_len = hif_drv->usr_conn_req.ies_len;
1453                                 strConnectInfo.req_ies = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL);
1454                                 memcpy(strConnectInfo.req_ies,
1455                                        hif_drv->usr_conn_req.ies,
1456                                        hif_drv->usr_conn_req.ies_len);
1457                         }
1458
1459                         del_timer(&hif_drv->connect_timer);
1460                         hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
1461                                                           &strConnectInfo,
1462                                                           u8MacStatus,
1463                                                           NULL,
1464                                                           hif_drv->usr_conn_req.arg);
1465
1466                         if ((u8MacStatus == MAC_CONNECTED) &&
1467                             (strConnectInfo.status == SUCCESSFUL_STATUSCODE))   {
1468                                 wilc_set_power_mgmt(vif, 0, 0);
1469
1470                                 hif_drv->hif_state = HOST_IF_CONNECTED;
1471
1472                                 wilc_optaining_ip = true;
1473                                 mod_timer(&wilc_during_ip_timer,
1474                                           jiffies + msecs_to_jiffies(10000));
1475                         } else {
1476                                 hif_drv->hif_state = HOST_IF_IDLE;
1477                                 scan_while_connected = false;
1478                         }
1479
1480                         kfree(strConnectInfo.resp_ies);
1481                         strConnectInfo.resp_ies = NULL;
1482
1483                         kfree(strConnectInfo.req_ies);
1484                         strConnectInfo.req_ies = NULL;
1485                         hif_drv->usr_conn_req.ssid_len = 0;
1486                         kfree(hif_drv->usr_conn_req.ssid);
1487                         hif_drv->usr_conn_req.ssid = NULL;
1488                         kfree(hif_drv->usr_conn_req.bssid);
1489                         hif_drv->usr_conn_req.bssid = NULL;
1490                         hif_drv->usr_conn_req.ies_len = 0;
1491                         kfree(hif_drv->usr_conn_req.ies);
1492                         hif_drv->usr_conn_req.ies = NULL;
1493                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1494                            (hif_drv->hif_state == HOST_IF_CONNECTED)) {
1495                         memset(&strDisconnectNotifInfo, 0, sizeof(struct disconnect_info));
1496
1497                         if (hif_drv->usr_scan_req.scan_result) {
1498                                 del_timer(&hif_drv->scan_timer);
1499                                 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
1500                         }
1501
1502                         strDisconnectNotifInfo.reason = 0;
1503                         strDisconnectNotifInfo.ie = NULL;
1504                         strDisconnectNotifInfo.ie_len = 0;
1505
1506                         if (hif_drv->usr_conn_req.conn_result) {
1507                                 wilc_optaining_ip = false;
1508                                 wilc_set_power_mgmt(vif, 0, 0);
1509
1510                                 hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1511                                                                   NULL,
1512                                                                   0,
1513                                                                   &strDisconnectNotifInfo,
1514                                                                   hif_drv->usr_conn_req.arg);
1515                         } else {
1516                                 netdev_err(vif->ndev, "Connect result NULL\n");
1517                         }
1518
1519                         eth_zero_addr(hif_drv->assoc_bssid);
1520
1521                         hif_drv->usr_conn_req.ssid_len = 0;
1522                         kfree(hif_drv->usr_conn_req.ssid);
1523                         hif_drv->usr_conn_req.ssid = NULL;
1524                         kfree(hif_drv->usr_conn_req.bssid);
1525                         hif_drv->usr_conn_req.bssid = NULL;
1526                         hif_drv->usr_conn_req.ies_len = 0;
1527                         kfree(hif_drv->usr_conn_req.ies);
1528                         hif_drv->usr_conn_req.ies = NULL;
1529
1530                         if (join_req && join_req_vif == vif) {
1531                                 kfree(join_req);
1532                                 join_req = NULL;
1533                         }
1534
1535                         if (info_element && join_req_vif == vif) {
1536                                 kfree(info_element);
1537                                 info_element = NULL;
1538                         }
1539
1540                         hif_drv->hif_state = HOST_IF_IDLE;
1541                         scan_while_connected = false;
1542
1543                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1544                            (hif_drv->usr_scan_req.scan_result)) {
1545                         del_timer(&hif_drv->scan_timer);
1546                         if (hif_drv->usr_scan_req.scan_result)
1547                                 Handle_ScanDone(vif, SCAN_EVENT_ABORTED);
1548                 }
1549         }
1550
1551         kfree(pstrRcvdGnrlAsyncInfo->buffer);
1552         pstrRcvdGnrlAsyncInfo->buffer = NULL;
1553
1554         return result;
1555 }
1556
1557 static int Handle_Key(struct wilc_vif *vif,
1558                       struct key_attr *pstrHostIFkeyAttr)
1559 {
1560         s32 result = 0;
1561         struct wid wid;
1562         struct wid strWIDList[5];
1563         u8 i;
1564         u8 *pu8keybuf;
1565         s8 s8idxarray[1];
1566         s8 ret = 0;
1567         struct host_if_drv *hif_drv = vif->hif_drv;
1568
1569         switch (pstrHostIFkeyAttr->type) {
1570         case WEP:
1571
1572                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1573                         strWIDList[0].id = (u16)WID_11I_MODE;
1574                         strWIDList[0].type = WID_CHAR;
1575                         strWIDList[0].size = sizeof(char);
1576                         strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.mode;
1577
1578                         strWIDList[1].id = WID_AUTH_TYPE;
1579                         strWIDList[1].type = WID_CHAR;
1580                         strWIDList[1].size = sizeof(char);
1581                         strWIDList[1].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.auth_type;
1582
1583                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2,
1584                                             GFP_KERNEL);
1585                         if (!pu8keybuf)
1586                                 return -ENOMEM;
1587
1588                         pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1589                         pu8keybuf[1] = pstrHostIFkeyAttr->attr.wep.key_len;
1590
1591                         memcpy(&pu8keybuf[2], pstrHostIFkeyAttr->attr.wep.key,
1592                                pstrHostIFkeyAttr->attr.wep.key_len);
1593
1594                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1595
1596                         strWIDList[2].id = (u16)WID_WEP_KEY_VALUE;
1597                         strWIDList[2].type = WID_STR;
1598                         strWIDList[2].size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1599                         strWIDList[2].val = (s8 *)pu8keybuf;
1600
1601                         result = wilc_send_config_pkt(vif, SET_CFG,
1602                                                       strWIDList, 3,
1603                                                       wilc_get_vif_idx(vif));
1604                         kfree(pu8keybuf);
1605                 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1606                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
1607                         if (!pu8keybuf)
1608                                 return -ENOMEM;
1609                         pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1610                         memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
1611                         memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
1612                                pstrHostIFkeyAttr->attr.wep.key_len);
1613                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1614
1615                         wid.id = (u16)WID_ADD_WEP_KEY;
1616                         wid.type = WID_STR;
1617                         wid.val = (s8 *)pu8keybuf;
1618                         wid.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1619
1620                         result = wilc_send_config_pkt(vif, SET_CFG,
1621                                                       &wid, 1,
1622                                                       wilc_get_vif_idx(vif));
1623                         kfree(pu8keybuf);
1624                 } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
1625                         wid.id = (u16)WID_REMOVE_WEP_KEY;
1626                         wid.type = WID_STR;
1627
1628                         s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
1629                         wid.val = s8idxarray;
1630                         wid.size = 1;
1631
1632                         result = wilc_send_config_pkt(vif, SET_CFG,
1633                                                       &wid, 1,
1634                                                       wilc_get_vif_idx(vif));
1635                 } else if (pstrHostIFkeyAttr->action & DEFAULTKEY) {
1636                         wid.id = (u16)WID_KEY_ID;
1637                         wid.type = WID_CHAR;
1638                         wid.val = (s8 *)&pstrHostIFkeyAttr->attr.wep.index;
1639                         wid.size = sizeof(char);
1640
1641                         result = wilc_send_config_pkt(vif, SET_CFG,
1642                                                       &wid, 1,
1643                                                       wilc_get_vif_idx(vif));
1644                 }
1645                 up(&hif_drv->sem_test_key_block);
1646                 break;
1647
1648         case WPA_RX_GTK:
1649                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1650                         pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1651                         if (!pu8keybuf) {
1652                                 ret = -ENOMEM;
1653                                 goto _WPARxGtk_end_case_;
1654                         }
1655
1656                         if (pstrHostIFkeyAttr->attr.wpa.seq)
1657                                 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1658
1659                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1660                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1661                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1662                                pstrHostIFkeyAttr->attr.wpa.key_len);
1663
1664                         strWIDList[0].id = (u16)WID_11I_MODE;
1665                         strWIDList[0].type = WID_CHAR;
1666                         strWIDList[0].size = sizeof(char);
1667                         strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
1668
1669                         strWIDList[1].id = (u16)WID_ADD_RX_GTK;
1670                         strWIDList[1].type = WID_STR;
1671                         strWIDList[1].val = (s8 *)pu8keybuf;
1672                         strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
1673
1674                         result = wilc_send_config_pkt(vif, SET_CFG,
1675                                                       strWIDList, 2,
1676                                                       wilc_get_vif_idx(vif));
1677
1678                         kfree(pu8keybuf);
1679                         up(&hif_drv->sem_test_key_block);
1680                 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1681                         pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1682                         if (pu8keybuf == NULL) {
1683                                 ret = -ENOMEM;
1684                                 goto _WPARxGtk_end_case_;
1685                         }
1686
1687                         if (hif_drv->hif_state == HOST_IF_CONNECTED)
1688                                 memcpy(pu8keybuf, hif_drv->assoc_bssid, ETH_ALEN);
1689                         else
1690                                 netdev_err(vif->ndev, "Couldn't handle\n");
1691
1692                         memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1693                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1694                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1695                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1696                                pstrHostIFkeyAttr->attr.wpa.key_len);
1697
1698                         wid.id = (u16)WID_ADD_RX_GTK;
1699                         wid.type = WID_STR;
1700                         wid.val = (s8 *)pu8keybuf;
1701                         wid.size = RX_MIC_KEY_MSG_LEN;
1702
1703                         result = wilc_send_config_pkt(vif, SET_CFG,
1704                                                       &wid, 1,
1705                                                       wilc_get_vif_idx(vif));
1706
1707                         kfree(pu8keybuf);
1708                         up(&hif_drv->sem_test_key_block);
1709                 }
1710 _WPARxGtk_end_case_:
1711                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1712                 kfree(pstrHostIFkeyAttr->attr.wpa.seq);
1713                 if (ret)
1714                         return ret;
1715
1716                 break;
1717
1718         case WPA_PTK:
1719                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1720                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1721                         if (!pu8keybuf) {
1722                                 ret = -ENOMEM;
1723                                 goto _WPAPtk_end_case_;
1724                         }
1725
1726                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1727                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1728                         memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1729                         memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
1730                                pstrHostIFkeyAttr->attr.wpa.key_len);
1731
1732                         strWIDList[0].id = (u16)WID_11I_MODE;
1733                         strWIDList[0].type = WID_CHAR;
1734                         strWIDList[0].size = sizeof(char);
1735                         strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
1736
1737                         strWIDList[1].id = (u16)WID_ADD_PTK;
1738                         strWIDList[1].type = WID_STR;
1739                         strWIDList[1].val = (s8 *)pu8keybuf;
1740                         strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
1741
1742                         result = wilc_send_config_pkt(vif, SET_CFG,
1743                                                       strWIDList, 2,
1744                                                       wilc_get_vif_idx(vif));
1745                         kfree(pu8keybuf);
1746                         up(&hif_drv->sem_test_key_block);
1747                 } else if (pstrHostIFkeyAttr->action & ADDKEY) {
1748                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1749                         if (!pu8keybuf) {
1750                                 netdev_err(vif->ndev, "No buffer send PTK\n");
1751                                 ret = -ENOMEM;
1752                                 goto _WPAPtk_end_case_;
1753                         }
1754
1755                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1756                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1757                         memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
1758                                pstrHostIFkeyAttr->attr.wpa.key_len);
1759
1760                         wid.id = (u16)WID_ADD_PTK;
1761                         wid.type = WID_STR;
1762                         wid.val = (s8 *)pu8keybuf;
1763                         wid.size = PTK_KEY_MSG_LEN;
1764
1765                         result = wilc_send_config_pkt(vif, SET_CFG,
1766                                                       &wid, 1,
1767                                                       wilc_get_vif_idx(vif));
1768                         kfree(pu8keybuf);
1769                         up(&hif_drv->sem_test_key_block);
1770                 }
1771
1772 _WPAPtk_end_case_:
1773                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1774                 if (ret)
1775                         return ret;
1776
1777                 break;
1778
1779         case PMKSA:
1780                 pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
1781                 if (!pu8keybuf) {
1782                         netdev_err(vif->ndev, "No buffer to send PMKSA Key\n");
1783                         return -ENOMEM;
1784                 }
1785
1786                 pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
1787
1788                 for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
1789                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
1790                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
1791                 }
1792
1793                 wid.id = (u16)WID_PMKID_INFO;
1794                 wid.type = WID_STR;
1795                 wid.val = (s8 *)pu8keybuf;
1796                 wid.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
1797
1798                 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1799                                               wilc_get_vif_idx(vif));
1800
1801                 kfree(pu8keybuf);
1802                 break;
1803         }
1804
1805         if (result)
1806                 netdev_err(vif->ndev, "Failed to send key config packet\n");
1807
1808         return result;
1809 }
1810
1811 static void Handle_Disconnect(struct wilc_vif *vif)
1812 {
1813         struct wid wid;
1814         struct host_if_drv *hif_drv = vif->hif_drv;
1815
1816         s32 result = 0;
1817         u16 u16DummyReasonCode = 0;
1818
1819         wid.id = (u16)WID_DISCONNECT;
1820         wid.type = WID_CHAR;
1821         wid.val = (s8 *)&u16DummyReasonCode;
1822         wid.size = sizeof(char);
1823
1824         wilc_optaining_ip = false;
1825         wilc_set_power_mgmt(vif, 0, 0);
1826
1827         eth_zero_addr(wilc_connected_ssid);
1828
1829         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1830                                       wilc_get_vif_idx(vif));
1831
1832         if (result) {
1833                 netdev_err(vif->ndev, "Failed to send dissconect\n");
1834         } else {
1835                 struct disconnect_info strDisconnectNotifInfo;
1836
1837                 memset(&strDisconnectNotifInfo, 0, sizeof(struct disconnect_info));
1838
1839                 strDisconnectNotifInfo.reason = 0;
1840                 strDisconnectNotifInfo.ie = NULL;
1841                 strDisconnectNotifInfo.ie_len = 0;
1842
1843                 if (hif_drv->usr_scan_req.scan_result) {
1844                         del_timer(&hif_drv->scan_timer);
1845                         hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED,
1846                                                           NULL,
1847                                                           hif_drv->usr_scan_req.arg,
1848                                                           NULL);
1849                         hif_drv->usr_scan_req.scan_result = NULL;
1850                 }
1851
1852                 if (hif_drv->usr_conn_req.conn_result) {
1853                         if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
1854                                 del_timer(&hif_drv->connect_timer);
1855
1856                         hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1857                                                           NULL,
1858                                                           0,
1859                                                           &strDisconnectNotifInfo,
1860                                                           hif_drv->usr_conn_req.arg);
1861                 } else {
1862                         netdev_err(vif->ndev, "conn_result = NULL\n");
1863                 }
1864
1865                 scan_while_connected = false;
1866
1867                 hif_drv->hif_state = HOST_IF_IDLE;
1868
1869                 eth_zero_addr(hif_drv->assoc_bssid);
1870
1871                 hif_drv->usr_conn_req.ssid_len = 0;
1872                 kfree(hif_drv->usr_conn_req.ssid);
1873                 hif_drv->usr_conn_req.ssid = NULL;
1874                 kfree(hif_drv->usr_conn_req.bssid);
1875                 hif_drv->usr_conn_req.bssid = NULL;
1876                 hif_drv->usr_conn_req.ies_len = 0;
1877                 kfree(hif_drv->usr_conn_req.ies);
1878                 hif_drv->usr_conn_req.ies = NULL;
1879
1880                 if (join_req && join_req_vif == vif) {
1881                         kfree(join_req);
1882                         join_req = NULL;
1883                 }
1884
1885                 if (info_element && join_req_vif == vif) {
1886                         kfree(info_element);
1887                         info_element = NULL;
1888                 }
1889         }
1890
1891         up(&hif_drv->sem_test_disconn_block);
1892 }
1893
1894 void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
1895 {
1896         if (!vif->hif_drv)
1897                 return;
1898         if ((vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) ||
1899             (vif->hif_drv->hif_state == HOST_IF_CONNECTING))
1900                 wilc_disconnect(vif, 1);
1901 }
1902
1903 static void Handle_GetRssi(struct wilc_vif *vif)
1904 {
1905         s32 result = 0;
1906         struct wid wid;
1907
1908         wid.id = (u16)WID_RSSI;
1909         wid.type = WID_CHAR;
1910         wid.val = &rssi;
1911         wid.size = sizeof(char);
1912
1913         result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
1914                                       wilc_get_vif_idx(vif));
1915         if (result) {
1916                 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1917                 result = -EFAULT;
1918         }
1919
1920         up(&vif->hif_drv->sem_get_rssi);
1921 }
1922
1923 static s32 Handle_GetStatistics(struct wilc_vif *vif,
1924                                 struct rf_info *pstrStatistics)
1925 {
1926         struct wid strWIDList[5];
1927         u32 u32WidsCount = 0, result = 0;
1928
1929         strWIDList[u32WidsCount].id = WID_LINKSPEED;
1930         strWIDList[u32WidsCount].type = WID_CHAR;
1931         strWIDList[u32WidsCount].size = sizeof(char);
1932         strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->link_speed;
1933         u32WidsCount++;
1934
1935         strWIDList[u32WidsCount].id = WID_RSSI;
1936         strWIDList[u32WidsCount].type = WID_CHAR;
1937         strWIDList[u32WidsCount].size = sizeof(char);
1938         strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rssi;
1939         u32WidsCount++;
1940
1941         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
1942         strWIDList[u32WidsCount].type = WID_INT;
1943         strWIDList[u32WidsCount].size = sizeof(u32);
1944         strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_cnt;
1945         u32WidsCount++;
1946
1947         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
1948         strWIDList[u32WidsCount].type = WID_INT;
1949         strWIDList[u32WidsCount].size = sizeof(u32);
1950         strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rx_cnt;
1951         u32WidsCount++;
1952
1953         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
1954         strWIDList[u32WidsCount].type = WID_INT;
1955         strWIDList[u32WidsCount].size = sizeof(u32);
1956         strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_fail_cnt;
1957         u32WidsCount++;
1958
1959         result = wilc_send_config_pkt(vif, GET_CFG, strWIDList,
1960                                       u32WidsCount,
1961                                       wilc_get_vif_idx(vif));
1962
1963         if (result)
1964                 netdev_err(vif->ndev, "Failed to send scan parameters\n");
1965
1966         if (pstrStatistics->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
1967             pstrStatistics->link_speed != DEFAULT_LINK_SPEED)
1968                 wilc_enable_tcp_ack_filter(true);
1969         else if (pstrStatistics->link_speed != DEFAULT_LINK_SPEED)
1970                 wilc_enable_tcp_ack_filter(false);
1971
1972         if (pstrStatistics != &vif->wilc->dummy_statistics)
1973                 up(&hif_sema_wait_response);
1974         return 0;
1975 }
1976
1977 static s32 Handle_Get_InActiveTime(struct wilc_vif *vif,
1978                                    struct sta_inactive_t *strHostIfStaInactiveT)
1979 {
1980         s32 result = 0;
1981         u8 *stamac;
1982         struct wid wid;
1983         struct host_if_drv *hif_drv = vif->hif_drv;
1984
1985         wid.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
1986         wid.type = WID_STR;
1987         wid.size = ETH_ALEN;
1988         wid.val = kmalloc(wid.size, GFP_KERNEL);
1989
1990         stamac = wid.val;
1991         memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
1992
1993         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1994                                       wilc_get_vif_idx(vif));
1995
1996         if (result) {
1997                 netdev_err(vif->ndev, "Failed to SET incative time\n");
1998                 return -EFAULT;
1999         }
2000
2001         wid.id = (u16)WID_GET_INACTIVE_TIME;
2002         wid.type = WID_INT;
2003         wid.val = (s8 *)&inactive_time;
2004         wid.size = sizeof(u32);
2005
2006         result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2007                                       wilc_get_vif_idx(vif));
2008
2009         if (result) {
2010                 netdev_err(vif->ndev, "Failed to get incative time\n");
2011                 return -EFAULT;
2012         }
2013
2014         up(&hif_drv->sem_inactive_time);
2015
2016         return result;
2017 }
2018
2019 static void Handle_AddBeacon(struct wilc_vif *vif,
2020                              struct beacon_attr *pstrSetBeaconParam)
2021 {
2022         s32 result = 0;
2023         struct wid wid;
2024         u8 *pu8CurrByte;
2025
2026         wid.id = (u16)WID_ADD_BEACON;
2027         wid.type = WID_BIN;
2028         wid.size = pstrSetBeaconParam->head_len + pstrSetBeaconParam->tail_len + 16;
2029         wid.val = kmalloc(wid.size, GFP_KERNEL);
2030         if (!wid.val)
2031                 goto ERRORHANDLER;
2032
2033         pu8CurrByte = wid.val;
2034         *pu8CurrByte++ = (pstrSetBeaconParam->interval & 0xFF);
2035         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 8) & 0xFF);
2036         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 16) & 0xFF);
2037         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 24) & 0xFF);
2038
2039         *pu8CurrByte++ = (pstrSetBeaconParam->dtim_period & 0xFF);
2040         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 8) & 0xFF);
2041         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 16) & 0xFF);
2042         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 24) & 0xFF);
2043
2044         *pu8CurrByte++ = (pstrSetBeaconParam->head_len & 0xFF);
2045         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 8) & 0xFF);
2046         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 16) & 0xFF);
2047         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 24) & 0xFF);
2048
2049         memcpy(pu8CurrByte, pstrSetBeaconParam->head, pstrSetBeaconParam->head_len);
2050         pu8CurrByte += pstrSetBeaconParam->head_len;
2051
2052         *pu8CurrByte++ = (pstrSetBeaconParam->tail_len & 0xFF);
2053         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 8) & 0xFF);
2054         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 16) & 0xFF);
2055         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 24) & 0xFF);
2056
2057         if (pstrSetBeaconParam->tail)
2058                 memcpy(pu8CurrByte, pstrSetBeaconParam->tail, pstrSetBeaconParam->tail_len);
2059         pu8CurrByte += pstrSetBeaconParam->tail_len;
2060
2061         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2062                                       wilc_get_vif_idx(vif));
2063         if (result)
2064                 netdev_err(vif->ndev, "Failed to send add beacon\n");
2065
2066 ERRORHANDLER:
2067         kfree(wid.val);
2068         kfree(pstrSetBeaconParam->head);
2069         kfree(pstrSetBeaconParam->tail);
2070 }
2071
2072 static void Handle_DelBeacon(struct wilc_vif *vif)
2073 {
2074         s32 result = 0;
2075         struct wid wid;
2076         u8 *pu8CurrByte;
2077
2078         wid.id = (u16)WID_DEL_BEACON;
2079         wid.type = WID_CHAR;
2080         wid.size = sizeof(char);
2081         wid.val = &del_beacon;
2082
2083         if (!wid.val)
2084                 return;
2085
2086         pu8CurrByte = wid.val;
2087
2088         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2089                                       wilc_get_vif_idx(vif));
2090         if (result)
2091                 netdev_err(vif->ndev, "Failed to send delete beacon\n");
2092 }
2093
2094 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
2095                                     struct add_sta_param *pstrStationParam)
2096 {
2097         u8 *pu8CurrByte;
2098
2099         pu8CurrByte = pu8Buffer;
2100
2101         memcpy(pu8CurrByte, pstrStationParam->bssid, ETH_ALEN);
2102         pu8CurrByte +=  ETH_ALEN;
2103
2104         *pu8CurrByte++ = pstrStationParam->aid & 0xFF;
2105         *pu8CurrByte++ = (pstrStationParam->aid >> 8) & 0xFF;
2106
2107         *pu8CurrByte++ = pstrStationParam->rates_len;
2108         if (pstrStationParam->rates_len > 0)
2109                 memcpy(pu8CurrByte, pstrStationParam->rates,
2110                        pstrStationParam->rates_len);
2111         pu8CurrByte += pstrStationParam->rates_len;
2112
2113         *pu8CurrByte++ = pstrStationParam->ht_supported;
2114         *pu8CurrByte++ = pstrStationParam->ht_capa_info & 0xFF;
2115         *pu8CurrByte++ = (pstrStationParam->ht_capa_info >> 8) & 0xFF;
2116
2117         *pu8CurrByte++ = pstrStationParam->ht_ampdu_params;
2118         memcpy(pu8CurrByte, pstrStationParam->ht_supp_mcs_set,
2119                WILC_SUPP_MCS_SET_SIZE);
2120         pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
2121
2122         *pu8CurrByte++ = pstrStationParam->ht_ext_params & 0xFF;
2123         *pu8CurrByte++ = (pstrStationParam->ht_ext_params >> 8) & 0xFF;
2124
2125         *pu8CurrByte++ = pstrStationParam->ht_tx_bf_cap & 0xFF;
2126         *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 8) & 0xFF;
2127         *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 16) & 0xFF;
2128         *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 24) & 0xFF;
2129
2130         *pu8CurrByte++ = pstrStationParam->ht_ante_sel;
2131
2132         *pu8CurrByte++ = pstrStationParam->flags_mask & 0xFF;
2133         *pu8CurrByte++ = (pstrStationParam->flags_mask >> 8) & 0xFF;
2134
2135         *pu8CurrByte++ = pstrStationParam->flags_set & 0xFF;
2136         *pu8CurrByte++ = (pstrStationParam->flags_set >> 8) & 0xFF;
2137
2138         return pu8CurrByte - pu8Buffer;
2139 }
2140
2141 static void Handle_AddStation(struct wilc_vif *vif,
2142                               struct add_sta_param *pstrStationParam)
2143 {
2144         s32 result = 0;
2145         struct wid wid;
2146         u8 *pu8CurrByte;
2147
2148         wid.id = (u16)WID_ADD_STA;
2149         wid.type = WID_BIN;
2150         wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len;
2151
2152         wid.val = kmalloc(wid.size, GFP_KERNEL);
2153         if (!wid.val)
2154                 goto ERRORHANDLER;
2155
2156         pu8CurrByte = wid.val;
2157         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2158
2159         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2160                                       wilc_get_vif_idx(vif));
2161         if (result != 0)
2162                 netdev_err(vif->ndev, "Failed to send add station\n");
2163
2164 ERRORHANDLER:
2165         kfree(pstrStationParam->rates);
2166         kfree(wid.val);
2167 }
2168
2169 static void Handle_DelAllSta(struct wilc_vif *vif,
2170                              struct del_all_sta *pstrDelAllStaParam)
2171 {
2172         s32 result = 0;
2173         struct wid wid;
2174         u8 *pu8CurrByte;
2175         u8 i;
2176         u8 au8Zero_Buff[6] = {0};
2177
2178         wid.id = (u16)WID_DEL_ALL_STA;
2179         wid.type = WID_STR;
2180         wid.size = (pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1;
2181
2182         wid.val = kmalloc((pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1, GFP_KERNEL);
2183         if (!wid.val)
2184                 goto ERRORHANDLER;
2185
2186         pu8CurrByte = wid.val;
2187
2188         *(pu8CurrByte++) = pstrDelAllStaParam->assoc_sta;
2189
2190         for (i = 0; i < MAX_NUM_STA; i++) {
2191                 if (memcmp(pstrDelAllStaParam->del_all_sta[i], au8Zero_Buff, ETH_ALEN))
2192                         memcpy(pu8CurrByte, pstrDelAllStaParam->del_all_sta[i], ETH_ALEN);
2193                 else
2194                         continue;
2195
2196                 pu8CurrByte += ETH_ALEN;
2197         }
2198
2199         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2200                                       wilc_get_vif_idx(vif));
2201         if (result)
2202                 netdev_err(vif->ndev, "Failed to send add station\n");
2203
2204 ERRORHANDLER:
2205         kfree(wid.val);
2206
2207         up(&hif_sema_wait_response);
2208 }
2209
2210 static void Handle_DelStation(struct wilc_vif *vif,
2211                               struct del_sta *pstrDelStaParam)
2212 {
2213         s32 result = 0;
2214         struct wid wid;
2215         u8 *pu8CurrByte;
2216
2217         wid.id = (u16)WID_REMOVE_STA;
2218         wid.type = WID_BIN;
2219         wid.size = ETH_ALEN;
2220
2221         wid.val = kmalloc(wid.size, GFP_KERNEL);
2222         if (!wid.val)
2223                 goto ERRORHANDLER;
2224
2225         pu8CurrByte = wid.val;
2226
2227         memcpy(pu8CurrByte, pstrDelStaParam->mac_addr, ETH_ALEN);
2228
2229         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2230                                       wilc_get_vif_idx(vif));
2231         if (result)
2232                 netdev_err(vif->ndev, "Failed to send add station\n");
2233
2234 ERRORHANDLER:
2235         kfree(wid.val);
2236 }
2237
2238 static void Handle_EditStation(struct wilc_vif *vif,
2239                                struct add_sta_param *pstrStationParam)
2240 {
2241         s32 result = 0;
2242         struct wid wid;
2243         u8 *pu8CurrByte;
2244
2245         wid.id = (u16)WID_EDIT_STA;
2246         wid.type = WID_BIN;
2247         wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len;
2248
2249         wid.val = kmalloc(wid.size, GFP_KERNEL);
2250         if (!wid.val)
2251                 goto ERRORHANDLER;
2252
2253         pu8CurrByte = wid.val;
2254         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2255
2256         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2257                                       wilc_get_vif_idx(vif));
2258         if (result)
2259                 netdev_err(vif->ndev, "Failed to send edit station\n");
2260
2261 ERRORHANDLER:
2262         kfree(pstrStationParam->rates);
2263         kfree(wid.val);
2264 }
2265
2266 static int Handle_RemainOnChan(struct wilc_vif *vif,
2267                                struct remain_ch *pstrHostIfRemainOnChan)
2268 {
2269         s32 result = 0;
2270         u8 u8remain_on_chan_flag;
2271         struct wid wid;
2272         struct host_if_drv *hif_drv = vif->hif_drv;
2273
2274         if (!hif_drv->remain_on_ch_pending) {
2275                 hif_drv->remain_on_ch.arg = pstrHostIfRemainOnChan->arg;
2276                 hif_drv->remain_on_ch.expired = pstrHostIfRemainOnChan->expired;
2277                 hif_drv->remain_on_ch.ready = pstrHostIfRemainOnChan->ready;
2278                 hif_drv->remain_on_ch.ch = pstrHostIfRemainOnChan->ch;
2279                 hif_drv->remain_on_ch.id = pstrHostIfRemainOnChan->id;
2280         } else {
2281                 pstrHostIfRemainOnChan->ch = hif_drv->remain_on_ch.ch;
2282         }
2283
2284         if (hif_drv->usr_scan_req.scan_result) {
2285                 hif_drv->remain_on_ch_pending = 1;
2286                 result = -EBUSY;
2287                 goto ERRORHANDLER;
2288         }
2289         if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
2290                 result = -EBUSY;
2291                 goto ERRORHANDLER;
2292         }
2293
2294         if (wilc_optaining_ip || wilc_connecting) {
2295                 result = -EBUSY;
2296                 goto ERRORHANDLER;
2297         }
2298
2299         u8remain_on_chan_flag = true;
2300         wid.id = (u16)WID_REMAIN_ON_CHAN;
2301         wid.type = WID_STR;
2302         wid.size = 2;
2303         wid.val = kmalloc(wid.size, GFP_KERNEL);
2304         if (!wid.val) {
2305                 result = -ENOMEM;
2306                 goto ERRORHANDLER;
2307         }
2308
2309         wid.val[0] = u8remain_on_chan_flag;
2310         wid.val[1] = (s8)pstrHostIfRemainOnChan->ch;
2311
2312         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2313                                       wilc_get_vif_idx(vif));
2314         if (result != 0)
2315                 netdev_err(vif->ndev, "Failed to set remain on channel\n");
2316
2317 ERRORHANDLER:
2318         {
2319                 P2P_LISTEN_STATE = 1;
2320                 hif_drv->remain_on_ch_timer.data = (unsigned long)vif;
2321                 mod_timer(&hif_drv->remain_on_ch_timer,
2322                           jiffies +
2323                           msecs_to_jiffies(pstrHostIfRemainOnChan->duration));
2324
2325                 if (hif_drv->remain_on_ch.ready)
2326                         hif_drv->remain_on_ch.ready(hif_drv->remain_on_ch.arg);
2327
2328                 if (hif_drv->remain_on_ch_pending)
2329                         hif_drv->remain_on_ch_pending = 0;
2330         }
2331
2332         return result;
2333 }
2334
2335 static int Handle_RegisterFrame(struct wilc_vif *vif,
2336                                 struct reg_frame *pstrHostIfRegisterFrame)
2337 {
2338         s32 result = 0;
2339         struct wid wid;
2340         u8 *pu8CurrByte;
2341
2342         wid.id = (u16)WID_REGISTER_FRAME;
2343         wid.type = WID_STR;
2344         wid.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2345         if (!wid.val)
2346                 return -ENOMEM;
2347
2348         pu8CurrByte = wid.val;
2349
2350         *pu8CurrByte++ = pstrHostIfRegisterFrame->reg;
2351         *pu8CurrByte++ = pstrHostIfRegisterFrame->reg_id;
2352         memcpy(pu8CurrByte, &pstrHostIfRegisterFrame->frame_type, sizeof(u16));
2353
2354         wid.size = sizeof(u16) + 2;
2355
2356         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2357                                       wilc_get_vif_idx(vif));
2358         if (result) {
2359                 netdev_err(vif->ndev, "Failed to frame register\n");
2360                 result = -EINVAL;
2361         }
2362
2363         return result;
2364 }
2365
2366 static u32 Handle_ListenStateExpired(struct wilc_vif *vif,
2367                                      struct remain_ch *pstrHostIfRemainOnChan)
2368 {
2369         u8 u8remain_on_chan_flag;
2370         struct wid wid;
2371         s32 result = 0;
2372         struct host_if_drv *hif_drv = vif->hif_drv;
2373
2374         if (P2P_LISTEN_STATE) {
2375                 u8remain_on_chan_flag = false;
2376                 wid.id = (u16)WID_REMAIN_ON_CHAN;
2377                 wid.type = WID_STR;
2378                 wid.size = 2;
2379                 wid.val = kmalloc(wid.size, GFP_KERNEL);
2380
2381                 if (!wid.val) {
2382                         netdev_err(vif->ndev, "Failed to allocate memory\n");
2383                         return -ENOMEM;
2384                 }
2385
2386                 wid.val[0] = u8remain_on_chan_flag;
2387                 wid.val[1] = FALSE_FRMWR_CHANNEL;
2388
2389                 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2390                                               wilc_get_vif_idx(vif));
2391                 if (result != 0) {
2392                         netdev_err(vif->ndev, "Failed to set remain channel\n");
2393                         goto _done_;
2394                 }
2395
2396                 if (hif_drv->remain_on_ch.expired) {
2397                         hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
2398                                                       pstrHostIfRemainOnChan->id);
2399                 }
2400                 P2P_LISTEN_STATE = 0;
2401         } else {
2402                 netdev_dbg(vif->ndev, "Not in listen state\n");
2403                 result = -EFAULT;
2404         }
2405
2406 _done_:
2407         return result;
2408 }
2409
2410 static void ListenTimerCB(unsigned long arg)
2411 {
2412         s32 result = 0;
2413         struct host_if_msg msg;
2414         struct wilc_vif *vif = (struct wilc_vif *)arg;
2415
2416         del_timer(&vif->hif_drv->remain_on_ch_timer);
2417
2418         memset(&msg, 0, sizeof(struct host_if_msg));
2419         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
2420         msg.vif = vif;
2421         msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
2422
2423         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2424         if (result)
2425                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
2426 }
2427
2428 static void Handle_PowerManagement(struct wilc_vif *vif,
2429                                    struct power_mgmt_param *strPowerMgmtParam)
2430 {
2431         s32 result = 0;
2432         struct wid wid;
2433         s8 s8PowerMode;
2434
2435         wid.id = (u16)WID_POWER_MANAGEMENT;
2436
2437         if (strPowerMgmtParam->enabled)
2438                 s8PowerMode = MIN_FAST_PS;
2439         else
2440                 s8PowerMode = NO_POWERSAVE;
2441
2442         wid.val = &s8PowerMode;
2443         wid.size = sizeof(char);
2444
2445         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2446                                       wilc_get_vif_idx(vif));
2447         if (result)
2448                 netdev_err(vif->ndev, "Failed to send power management\n");
2449 }
2450
2451 static void Handle_SetMulticastFilter(struct wilc_vif *vif,
2452                                       struct set_multicast *strHostIfSetMulti)
2453 {
2454         s32 result = 0;
2455         struct wid wid;
2456         u8 *pu8CurrByte;
2457
2458         wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
2459         wid.type = WID_BIN;
2460         wid.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN);
2461         wid.val = kmalloc(wid.size, GFP_KERNEL);
2462         if (!wid.val)
2463                 goto ERRORHANDLER;
2464
2465         pu8CurrByte = wid.val;
2466         *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
2467         *pu8CurrByte++ = 0;
2468         *pu8CurrByte++ = 0;
2469         *pu8CurrByte++ = 0;
2470
2471         *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
2472         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
2473         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);
2474         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 24) & 0xFF);
2475
2476         if ((strHostIfSetMulti->cnt) > 0)
2477                 memcpy(pu8CurrByte, wilc_multicast_mac_addr_list,
2478                        ((strHostIfSetMulti->cnt) * ETH_ALEN));
2479
2480         result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2481                                       wilc_get_vif_idx(vif));
2482         if (result)
2483                 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2484
2485 ERRORHANDLER:
2486         kfree(wid.val);
2487 }
2488
2489 static void handle_set_tx_pwr(struct wilc_vif *vif, u8 tx_pwr)
2490 {
2491         int ret;
2492         struct wid wid;
2493
2494         wid.id = (u16)WID_TX_POWER;
2495         wid.type = WID_CHAR;
2496         wid.val = &tx_pwr;
2497         wid.size = sizeof(char);
2498
2499         ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
2500                                    wilc_get_vif_idx(vif));
2501         if (ret)
2502                 netdev_err(vif->ndev, "Failed to set TX PWR\n");
2503 }
2504
2505 static void handle_get_tx_pwr(struct wilc_vif *vif, u8 *tx_pwr)
2506 {
2507         s32 ret = 0;
2508         struct wid wid;
2509
2510         wid.id = (u16)WID_TX_POWER;
2511         wid.type = WID_CHAR;
2512         wid.val = (s8 *)tx_pwr;
2513         wid.size = sizeof(char);
2514
2515         ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
2516                                    wilc_get_vif_idx(vif));
2517         if (ret)
2518                 netdev_err(vif->ndev, "Failed to get TX PWR\n");
2519
2520         up(&hif_sema_wait_response);
2521 }
2522
2523 static int hostIFthread(void *pvArg)
2524 {
2525         u32 u32Ret;
2526         struct host_if_msg msg;
2527         struct wilc *wilc = pvArg;
2528         struct wilc_vif *vif;
2529
2530         memset(&msg, 0, sizeof(struct host_if_msg));
2531
2532         while (1) {
2533                 wilc_mq_recv(&hif_msg_q, &msg, sizeof(struct host_if_msg), &u32Ret);
2534                 vif = msg.vif;
2535                 if (msg.id == HOST_IF_MSG_EXIT)
2536                         break;
2537
2538                 if ((!wilc_initialized)) {
2539                         usleep_range(200 * 1000, 200 * 1000);
2540                         wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2541                         continue;
2542                 }
2543
2544                 if (msg.id == HOST_IF_MSG_CONNECT &&
2545                     vif->hif_drv->usr_scan_req.scan_result) {
2546                         wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2547                         usleep_range(2 * 1000, 2 * 1000);
2548                         continue;
2549                 }
2550
2551                 switch (msg.id) {
2552                 case HOST_IF_MSG_Q_IDLE:
2553                         Handle_wait_msg_q_empty();
2554                         break;
2555
2556                 case HOST_IF_MSG_SCAN:
2557                         Handle_Scan(msg.vif, &msg.body.scan_info);
2558                         break;
2559
2560                 case HOST_IF_MSG_CONNECT:
2561                         Handle_Connect(msg.vif, &msg.body.con_info);
2562                         break;
2563
2564                 case HOST_IF_MSG_RCVD_NTWRK_INFO:
2565                         Handle_RcvdNtwrkInfo(msg.vif, &msg.body.net_info);
2566                         break;
2567
2568                 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
2569                         Handle_RcvdGnrlAsyncInfo(vif,
2570                                                  &msg.body.async_info);
2571                         break;
2572
2573                 case HOST_IF_MSG_KEY:
2574                         Handle_Key(msg.vif, &msg.body.key_info);
2575                         break;
2576
2577                 case HOST_IF_MSG_CFG_PARAMS:
2578                         handle_cfg_param(msg.vif, &msg.body.cfg_info);
2579                         break;
2580
2581                 case HOST_IF_MSG_SET_CHANNEL:
2582                         handle_set_channel(msg.vif, &msg.body.channel_info);
2583                         break;
2584
2585                 case HOST_IF_MSG_DISCONNECT:
2586                         Handle_Disconnect(msg.vif);
2587                         break;
2588
2589                 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
2590                         del_timer(&vif->hif_drv->scan_timer);
2591
2592                         if (!wilc_wlan_get_num_conn_ifcs(wilc))
2593                                 wilc_chip_sleep_manually(wilc);
2594
2595                         Handle_ScanDone(msg.vif, SCAN_EVENT_DONE);
2596
2597                         if (vif->hif_drv->remain_on_ch_pending)
2598                                 Handle_RemainOnChan(msg.vif,
2599                                                     &msg.body.remain_on_ch);
2600
2601                         break;
2602
2603                 case HOST_IF_MSG_GET_RSSI:
2604                         Handle_GetRssi(msg.vif);
2605                         break;
2606
2607                 case HOST_IF_MSG_GET_STATISTICS:
2608                         Handle_GetStatistics(msg.vif,
2609                                              (struct rf_info *)msg.body.data);
2610                         break;
2611
2612                 case HOST_IF_MSG_ADD_BEACON:
2613                         Handle_AddBeacon(msg.vif, &msg.body.beacon_info);
2614                         break;
2615
2616                 case HOST_IF_MSG_DEL_BEACON:
2617                         Handle_DelBeacon(msg.vif);
2618                         break;
2619
2620                 case HOST_IF_MSG_ADD_STATION:
2621                         Handle_AddStation(msg.vif, &msg.body.add_sta_info);
2622                         break;
2623
2624                 case HOST_IF_MSG_DEL_STATION:
2625                         Handle_DelStation(msg.vif, &msg.body.del_sta_info);
2626                         break;
2627
2628                 case HOST_IF_MSG_EDIT_STATION:
2629                         Handle_EditStation(msg.vif, &msg.body.edit_sta_info);
2630                         break;
2631
2632                 case HOST_IF_MSG_GET_INACTIVETIME:
2633                         Handle_Get_InActiveTime(msg.vif, &msg.body.mac_info);
2634                         break;
2635
2636                 case HOST_IF_MSG_SCAN_TIMER_FIRED:
2637
2638                         Handle_ScanDone(msg.vif, SCAN_EVENT_ABORTED);
2639                         break;
2640
2641                 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
2642                         Handle_ConnectTimeout(msg.vif);
2643                         break;
2644
2645                 case HOST_IF_MSG_POWER_MGMT:
2646                         Handle_PowerManagement(msg.vif,
2647                                                &msg.body.pwr_mgmt_info);
2648                         break;
2649
2650                 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
2651                         handle_set_wfi_drv_handler(msg.vif, &msg.body.drv);
2652                         break;
2653
2654                 case HOST_IF_MSG_SET_OPERATION_MODE:
2655                         handle_set_operation_mode(msg.vif, &msg.body.mode);
2656                         break;
2657
2658                 case HOST_IF_MSG_SET_IPADDRESS:
2659                         handle_set_ip_address(vif,
2660                                               msg.body.ip_info.ip_addr,
2661                                               msg.body.ip_info.idx);
2662                         break;
2663
2664                 case HOST_IF_MSG_GET_IPADDRESS:
2665                         handle_get_ip_address(vif, msg.body.ip_info.idx);
2666                         break;
2667
2668                 case HOST_IF_MSG_SET_MAC_ADDRESS:
2669                         handle_set_mac_address(msg.vif,
2670                                                &msg.body.set_mac_info);
2671                         break;
2672
2673                 case HOST_IF_MSG_GET_MAC_ADDRESS:
2674                         handle_get_mac_address(msg.vif,
2675                                                &msg.body.get_mac_info);
2676                         break;
2677
2678                 case HOST_IF_MSG_REMAIN_ON_CHAN:
2679                         Handle_RemainOnChan(msg.vif, &msg.body.remain_on_ch);
2680                         break;
2681
2682                 case HOST_IF_MSG_REGISTER_FRAME:
2683                         Handle_RegisterFrame(msg.vif, &msg.body.reg_frame);
2684                         break;
2685
2686                 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
2687                         Handle_ListenStateExpired(msg.vif, &msg.body.remain_on_ch);
2688                         break;
2689
2690                 case HOST_IF_MSG_SET_MULTICAST_FILTER:
2691                         Handle_SetMulticastFilter(msg.vif, &msg.body.multicast_info);
2692                         break;
2693
2694                 case HOST_IF_MSG_DEL_ALL_STA:
2695                         Handle_DelAllSta(msg.vif, &msg.body.del_all_sta_info);
2696                         break;
2697
2698                 case HOST_IF_MSG_SET_TX_POWER:
2699                         handle_set_tx_pwr(msg.vif, msg.body.tx_power.tx_pwr);
2700                         break;
2701
2702                 case HOST_IF_MSG_GET_TX_POWER:
2703                         handle_get_tx_pwr(msg.vif, &msg.body.tx_power.tx_pwr);
2704                         break;
2705                 default:
2706                         netdev_err(vif->ndev, "[Host Interface] undefined\n");
2707                         break;
2708                 }
2709         }
2710
2711         up(&hif_sema_thread);
2712         return 0;
2713 }
2714
2715 static void TimerCB_Scan(unsigned long arg)
2716 {
2717         struct wilc_vif *vif = (struct wilc_vif *)arg;
2718         struct host_if_msg msg;
2719
2720         memset(&msg, 0, sizeof(struct host_if_msg));
2721         msg.vif = vif;
2722         msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
2723
2724         wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2725 }
2726
2727 static void TimerCB_Connect(unsigned long arg)
2728 {
2729         struct wilc_vif *vif = (struct wilc_vif *)arg;
2730         struct host_if_msg msg;
2731
2732         memset(&msg, 0, sizeof(struct host_if_msg));
2733         msg.vif = vif;
2734         msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
2735
2736         wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2737 }
2738
2739 s32 wilc_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
2740 {
2741         struct wid wid;
2742
2743         wid.id = (u16)WID_REMOVE_KEY;
2744         wid.type = WID_STR;
2745         wid.val = (s8 *)pu8StaAddress;
2746         wid.size = 6;
2747
2748         return 0;
2749 }
2750
2751 int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
2752 {
2753         int result = 0;
2754         struct host_if_msg msg;
2755         struct host_if_drv *hif_drv = vif->hif_drv;
2756
2757         if (!hif_drv) {
2758                 result = -EFAULT;
2759                 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2760                 return result;
2761         }
2762
2763         memset(&msg, 0, sizeof(struct host_if_msg));
2764
2765         msg.id = HOST_IF_MSG_KEY;
2766         msg.body.key_info.type = WEP;
2767         msg.body.key_info.action = REMOVEKEY;
2768         msg.vif = vif;
2769         msg.body.key_info.attr.wep.index = index;
2770
2771         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2772         if (result)
2773                 netdev_err(vif->ndev, "Request to remove WEP key\n");
2774         down(&hif_drv->sem_test_key_block);
2775
2776         return result;
2777 }
2778
2779 int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
2780 {
2781         int result = 0;
2782         struct host_if_msg msg;
2783         struct host_if_drv *hif_drv = vif->hif_drv;
2784
2785         if (!hif_drv) {
2786                 result = -EFAULT;
2787                 netdev_err(vif->ndev, "driver is null\n");
2788                 return result;
2789         }
2790
2791         memset(&msg, 0, sizeof(struct host_if_msg));
2792
2793         msg.id = HOST_IF_MSG_KEY;
2794         msg.body.key_info.type = WEP;
2795         msg.body.key_info.action = DEFAULTKEY;
2796         msg.vif = vif;
2797         msg.body.key_info.attr.wep.index = index;
2798
2799         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2800         if (result)
2801                 netdev_err(vif->ndev, "Default key index\n");
2802         down(&hif_drv->sem_test_key_block);
2803
2804         return result;
2805 }
2806
2807 int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
2808                              u8 index)
2809 {
2810         int result = 0;
2811         struct host_if_msg msg;
2812         struct host_if_drv *hif_drv = vif->hif_drv;
2813
2814         if (!hif_drv) {
2815                 netdev_err(vif->ndev, "driver is null\n");
2816                 return -EFAULT;
2817         }
2818
2819         memset(&msg, 0, sizeof(struct host_if_msg));
2820
2821         msg.id = HOST_IF_MSG_KEY;
2822         msg.body.key_info.type = WEP;
2823         msg.body.key_info.action = ADDKEY;
2824         msg.vif = vif;
2825         msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2826         if (!msg.body.key_info.attr.wep.key)
2827                 return -ENOMEM;
2828
2829         msg.body.key_info.attr.wep.key_len = len;
2830         msg.body.key_info.attr.wep.index = index;
2831
2832         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2833         if (result)
2834                 netdev_err(vif->ndev, "STA - WEP Key\n");
2835         down(&hif_drv->sem_test_key_block);
2836
2837         return result;
2838 }
2839
2840 int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
2841                             u8 index, u8 mode, enum AUTHTYPE auth_type)
2842 {
2843         int result = 0;
2844         struct host_if_msg msg;
2845         struct host_if_drv *hif_drv = vif->hif_drv;
2846
2847         if (!hif_drv) {
2848                 netdev_err(vif->ndev, "driver is null\n");
2849                 return -EFAULT;
2850         }
2851
2852         memset(&msg, 0, sizeof(struct host_if_msg));
2853
2854         msg.id = HOST_IF_MSG_KEY;
2855         msg.body.key_info.type = WEP;
2856         msg.body.key_info.action = ADDKEY_AP;
2857         msg.vif = vif;
2858         msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
2859         if (!msg.body.key_info.attr.wep.key)
2860                 return -ENOMEM;
2861
2862         msg.body.key_info.attr.wep.key_len = len;
2863         msg.body.key_info.attr.wep.index = index;
2864         msg.body.key_info.attr.wep.mode = mode;
2865         msg.body.key_info.attr.wep.auth_type = auth_type;
2866
2867         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2868
2869         if (result)
2870                 netdev_err(vif->ndev, "AP - WEP Key\n");
2871         down(&hif_drv->sem_test_key_block);
2872
2873         return result;
2874 }
2875
2876 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
2877                  const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
2878                  u8 mode, u8 cipher_mode, u8 index)
2879 {
2880         int result = 0;
2881         struct host_if_msg msg;
2882         struct host_if_drv *hif_drv = vif->hif_drv;
2883         u8 key_len = ptk_key_len;
2884
2885         if (!hif_drv) {
2886                 netdev_err(vif->ndev, "driver is null\n");
2887                 return -EFAULT;
2888         }
2889
2890         if (rx_mic)
2891                 key_len += RX_MIC_KEY_LEN;
2892
2893         if (tx_mic)
2894                 key_len += TX_MIC_KEY_LEN;
2895
2896         memset(&msg, 0, sizeof(struct host_if_msg));
2897
2898         msg.id = HOST_IF_MSG_KEY;
2899         msg.body.key_info.type = WPA_PTK;
2900         if (mode == AP_MODE) {
2901                 msg.body.key_info.action = ADDKEY_AP;
2902                 msg.body.key_info.attr.wpa.index = index;
2903         }
2904         if (mode == STATION_MODE)
2905                 msg.body.key_info.action = ADDKEY;
2906
2907         msg.body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
2908         if (!msg.body.key_info.attr.wpa.key)
2909                 return -ENOMEM;
2910
2911         if (rx_mic)
2912                 memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic, RX_MIC_KEY_LEN);
2913
2914         if (tx_mic)
2915                 memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic, TX_MIC_KEY_LEN);
2916
2917         msg.body.key_info.attr.wpa.key_len = key_len;
2918         msg.body.key_info.attr.wpa.mac_addr = mac_addr;
2919         msg.body.key_info.attr.wpa.mode = cipher_mode;
2920         msg.vif = vif;
2921
2922         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2923
2924         if (result)
2925                 netdev_err(vif->ndev, "PTK Key\n");
2926
2927         down(&hif_drv->sem_test_key_block);
2928
2929         return result;
2930 }
2931
2932 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
2933                     u8 index, u32 key_rsc_len, const u8 *key_rsc,
2934                     const u8 *rx_mic, const u8 *tx_mic, u8 mode,
2935                     u8 cipher_mode)
2936 {
2937         int result = 0;
2938         struct host_if_msg msg;
2939         struct host_if_drv *hif_drv = vif->hif_drv;
2940         u8 key_len = gtk_key_len;
2941
2942         if (!hif_drv) {
2943                 netdev_err(vif->ndev, "driver is null\n");
2944                 return -EFAULT;
2945         }
2946         memset(&msg, 0, sizeof(struct host_if_msg));
2947
2948         if (rx_mic)
2949                 key_len += RX_MIC_KEY_LEN;
2950
2951         if (tx_mic)
2952                 key_len += TX_MIC_KEY_LEN;
2953
2954         if (key_rsc) {
2955                 msg.body.key_info.attr.wpa.seq = kmemdup(key_rsc,
2956                                                          key_rsc_len,
2957                                                          GFP_KERNEL);
2958                 if (!msg.body.key_info.attr.wpa.seq)
2959                         return -ENOMEM;
2960         }
2961
2962         msg.id = HOST_IF_MSG_KEY;
2963         msg.body.key_info.type = WPA_RX_GTK;
2964         msg.vif = vif;
2965
2966         if (mode == AP_MODE) {
2967                 msg.body.key_info.action = ADDKEY_AP;
2968                 msg.body.key_info.attr.wpa.mode = cipher_mode;
2969         }
2970         if (mode == STATION_MODE)
2971                 msg.body.key_info.action = ADDKEY;
2972
2973         msg.body.key_info.attr.wpa.key = kmemdup(rx_gtk,
2974                                                  key_len,
2975                                                  GFP_KERNEL);
2976         if (!msg.body.key_info.attr.wpa.key)
2977                 return -ENOMEM;
2978
2979         if (rx_mic)
2980                 memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic,
2981                        RX_MIC_KEY_LEN);
2982
2983         if (tx_mic)
2984                 memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic,
2985                        TX_MIC_KEY_LEN);
2986
2987         msg.body.key_info.attr.wpa.index = index;
2988         msg.body.key_info.attr.wpa.key_len = key_len;
2989         msg.body.key_info.attr.wpa.seq_len = key_rsc_len;
2990
2991         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
2992         if (result)
2993                 netdev_err(vif->ndev, "RX GTK\n");
2994
2995         down(&hif_drv->sem_test_key_block);
2996
2997         return result;
2998 }
2999
3000 int wilc_set_pmkid_info(struct wilc_vif *vif,
3001                         struct host_if_pmkid_attr *pmkid)
3002 {
3003         int result = 0;
3004         struct host_if_msg msg;
3005         struct host_if_drv *hif_drv = vif->hif_drv;
3006         int i;
3007
3008         if (!hif_drv) {
3009                 netdev_err(vif->ndev, "driver is null\n");
3010                 return -EFAULT;
3011         }
3012
3013         memset(&msg, 0, sizeof(struct host_if_msg));
3014
3015         msg.id = HOST_IF_MSG_KEY;
3016         msg.body.key_info.type = PMKSA;
3017         msg.body.key_info.action = ADDKEY;
3018         msg.vif = vif;
3019
3020         for (i = 0; i < pmkid->numpmkid; i++) {
3021                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid,
3022                        &pmkid->pmkidlist[i].bssid, ETH_ALEN);
3023                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid,
3024                        &pmkid->pmkidlist[i].pmkid, PMKID_LEN);
3025         }
3026
3027         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3028         if (result)
3029                 netdev_err(vif->ndev, "PMKID Info\n");
3030
3031         return result;
3032 }
3033
3034 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
3035 {
3036         int result = 0;
3037         struct host_if_msg msg;
3038
3039         memset(&msg, 0, sizeof(struct host_if_msg));
3040
3041         msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
3042         msg.body.get_mac_info.mac_addr = mac_addr;
3043         msg.vif = vif;
3044
3045         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3046         if (result) {
3047                 netdev_err(vif->ndev, "Failed to send get mac address\n");
3048                 return -EFAULT;
3049         }
3050
3051         down(&hif_sema_wait_response);
3052         return result;
3053 }
3054
3055 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
3056                       size_t ssid_len, const u8 *ies, size_t ies_len,
3057                       wilc_connect_result connect_result, void *user_arg,
3058                       u8 security, enum AUTHTYPE auth_type,
3059                       u8 channel, void *join_params)
3060 {
3061         int result = 0;
3062         struct host_if_msg msg;
3063         struct host_if_drv *hif_drv = vif->hif_drv;
3064
3065         if (!hif_drv || !connect_result) {
3066                 netdev_err(vif->ndev, "Driver is null\n");
3067                 return -EFAULT;
3068         }
3069
3070         if (!join_params) {
3071                 netdev_err(vif->ndev, "Unable to Join - JoinParams is NULL\n");
3072                 return -EFAULT;
3073         }
3074
3075         memset(&msg, 0, sizeof(struct host_if_msg));
3076
3077         msg.id = HOST_IF_MSG_CONNECT;
3078
3079         msg.body.con_info.security = security;
3080         msg.body.con_info.auth_type = auth_type;
3081         msg.body.con_info.ch = channel;
3082         msg.body.con_info.result = connect_result;
3083         msg.body.con_info.arg = user_arg;
3084         msg.body.con_info.params = join_params;
3085         msg.vif = vif;
3086
3087         if (bssid) {
3088                 msg.body.con_info.bssid = kmemdup(bssid, 6, GFP_KERNEL);
3089                 if (!msg.body.con_info.bssid)
3090                         return -ENOMEM;
3091         }
3092
3093         if (ssid) {
3094                 msg.body.con_info.ssid_len = ssid_len;
3095                 msg.body.con_info.ssid = kmemdup(ssid, ssid_len, GFP_KERNEL);
3096                 if (!msg.body.con_info.ssid)
3097                         return -ENOMEM;
3098         }
3099
3100         if (ies) {
3101                 msg.body.con_info.ies_len = ies_len;
3102                 msg.body.con_info.ies = kmemdup(ies, ies_len, GFP_KERNEL);
3103                 if (!msg.body.con_info.ies)
3104                         return -ENOMEM;
3105         }
3106         if (hif_drv->hif_state < HOST_IF_CONNECTING)
3107                 hif_drv->hif_state = HOST_IF_CONNECTING;
3108
3109         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3110         if (result) {
3111                 netdev_err(vif->ndev, "send message: Set join request\n");
3112                 return -EFAULT;
3113         }
3114
3115         hif_drv->connect_timer.data = (unsigned long)vif;
3116         mod_timer(&hif_drv->connect_timer,
3117                   jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3118
3119         return result;
3120 }
3121
3122 int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
3123 {
3124         int result = 0;
3125         struct host_if_msg msg;
3126         struct host_if_drv *hif_drv = vif->hif_drv;
3127
3128         if (!hif_drv) {
3129                 netdev_err(vif->ndev, "Driver is null\n");
3130                 return -EFAULT;
3131         }
3132
3133         memset(&msg, 0, sizeof(struct host_if_msg));
3134
3135         msg.id = HOST_IF_MSG_DISCONNECT;
3136         msg.vif = vif;
3137
3138         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3139         if (result)
3140                 netdev_err(vif->ndev, "Failed to send message: disconnect\n");
3141
3142         down(&hif_drv->sem_test_disconn_block);
3143
3144         return result;
3145 }
3146
3147 static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
3148                                        u8 *pu8AssocRespInfo,
3149                                        u32 u32MaxAssocRespInfoLen,
3150                                        u32 *pu32RcvdAssocRespInfoLen)
3151 {
3152         s32 result = 0;
3153         struct wid wid;
3154         struct host_if_drv *hif_drv = vif->hif_drv;
3155
3156         if (!hif_drv) {
3157                 netdev_err(vif->ndev, "Driver is null\n");
3158                 return -EFAULT;
3159         }
3160
3161         wid.id = (u16)WID_ASSOC_RES_INFO;
3162         wid.type = WID_STR;
3163         wid.val = pu8AssocRespInfo;
3164         wid.size = u32MaxAssocRespInfoLen;
3165
3166         result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
3167                                       wilc_get_vif_idx(vif));
3168         if (result) {
3169                 *pu32RcvdAssocRespInfoLen = 0;
3170                 netdev_err(vif->ndev, "Failed to send association response\n");
3171                 return -EINVAL;
3172         }
3173
3174         *pu32RcvdAssocRespInfoLen = wid.size;
3175         return result;
3176 }
3177
3178 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
3179 {
3180         int result;
3181         struct host_if_msg msg;
3182         struct host_if_drv *hif_drv = vif->hif_drv;
3183
3184         if (!hif_drv) {
3185                 netdev_err(vif->ndev, "driver is null\n");
3186                 return -EFAULT;
3187         }
3188
3189         memset(&msg, 0, sizeof(struct host_if_msg));
3190         msg.id = HOST_IF_MSG_SET_CHANNEL;
3191         msg.body.channel_info.set_ch = channel;
3192         msg.vif = vif;
3193
3194         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3195         if (result) {
3196                 netdev_err(vif->ndev, "wilc mq send fail\n");
3197                 return -EINVAL;
3198         }
3199
3200         return 0;
3201 }
3202
3203 int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mac_idx)
3204 {
3205         int result = 0;
3206         struct host_if_msg msg;
3207
3208         memset(&msg, 0, sizeof(struct host_if_msg));
3209         msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3210         msg.body.drv.handler = index;
3211         msg.body.drv.mac_idx = mac_idx;
3212         msg.vif = vif;
3213
3214         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3215         if (result) {
3216                 netdev_err(vif->ndev, "wilc mq send fail\n");
3217                 result = -EINVAL;
3218         }
3219
3220         return result;
3221 }
3222
3223 int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
3224 {
3225         int result = 0;
3226         struct host_if_msg msg;
3227
3228         memset(&msg, 0, sizeof(struct host_if_msg));
3229         msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3230         msg.body.mode.mode = mode;
3231         msg.vif = vif;
3232
3233         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3234         if (result) {
3235                 netdev_err(vif->ndev, "wilc mq send fail\n");
3236                 result = -EINVAL;
3237         }
3238
3239         return result;
3240 }
3241
3242 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
3243                            u32 *pu32InactiveTime)
3244 {
3245         s32 result = 0;
3246         struct host_if_msg msg;
3247         struct host_if_drv *hif_drv = vif->hif_drv;
3248
3249         if (!hif_drv) {
3250                 netdev_err(vif->ndev, "driver is null\n");
3251                 return -EFAULT;
3252         }
3253
3254         memset(&msg, 0, sizeof(struct host_if_msg));
3255         memcpy(msg.body.mac_info.mac, mac, ETH_ALEN);
3256
3257         msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3258         msg.vif = vif;
3259
3260         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3261         if (result)
3262                 netdev_err(vif->ndev, "Failed to send get host ch param\n");
3263
3264         down(&hif_drv->sem_inactive_time);
3265
3266         *pu32InactiveTime = inactive_time;
3267
3268         return result;
3269 }
3270
3271 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
3272 {
3273         int result = 0;
3274         struct host_if_msg msg;
3275         struct host_if_drv *hif_drv = vif->hif_drv;
3276
3277         memset(&msg, 0, sizeof(struct host_if_msg));
3278         msg.id = HOST_IF_MSG_GET_RSSI;
3279         msg.vif = vif;
3280
3281         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3282         if (result) {
3283                 netdev_err(vif->ndev, "Failed to send get host ch param\n");
3284                 return -EFAULT;
3285         }
3286
3287         down(&hif_drv->sem_get_rssi);
3288
3289         if (!rssi_level) {
3290                 netdev_err(vif->ndev, "RSS pointer value is null\n");
3291                 return -EFAULT;
3292         }
3293
3294         *rssi_level = rssi;
3295
3296         return result;
3297 }
3298
3299 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
3300 {
3301         int result = 0;
3302         struct host_if_msg msg;
3303
3304         memset(&msg, 0, sizeof(struct host_if_msg));
3305         msg.id = HOST_IF_MSG_GET_STATISTICS;
3306         msg.body.data = (char *)stats;
3307         msg.vif = vif;
3308
3309         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3310         if (result) {
3311                 netdev_err(vif->ndev, "Failed to send get host channel\n");
3312                 return -EFAULT;
3313         }
3314
3315         if (stats != &vif->wilc->dummy_statistics)
3316                 down(&hif_sema_wait_response);
3317         return result;
3318 }
3319
3320 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
3321               u8 *ch_freq_list, u8 ch_list_len, const u8 *ies,
3322               size_t ies_len, wilc_scan_result scan_result, void *user_arg,
3323               struct hidden_network *hidden_network)
3324 {
3325         int result = 0;
3326         struct host_if_msg msg;
3327         struct scan_attr *scan_info = &msg.body.scan_info;
3328         struct host_if_drv *hif_drv = vif->hif_drv;
3329
3330         if (!hif_drv || !scan_result) {
3331                 netdev_err(vif->ndev, "hif_drv or scan_result = NULL\n");
3332                 return -EFAULT;
3333         }
3334
3335         memset(&msg, 0, sizeof(struct host_if_msg));
3336
3337         msg.id = HOST_IF_MSG_SCAN;
3338
3339         if (hidden_network) {
3340                 scan_info->hidden_network.net_info = hidden_network->net_info;
3341                 scan_info->hidden_network.n_ssids = hidden_network->n_ssids;
3342         }
3343
3344         msg.vif = vif;
3345         scan_info->src = scan_source;
3346         scan_info->type = scan_type;
3347         scan_info->result = scan_result;
3348         scan_info->arg = user_arg;
3349
3350         scan_info->ch_list_len = ch_list_len;
3351         scan_info->ch_freq_list = kmemdup(ch_freq_list,
3352                                           ch_list_len,
3353                                           GFP_KERNEL);
3354         if (!scan_info->ch_freq_list)
3355                 return -ENOMEM;
3356
3357         scan_info->ies_len = ies_len;
3358         scan_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
3359         if (!scan_info->ies)
3360                 return -ENOMEM;
3361
3362         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3363         if (result) {
3364                 netdev_err(vif->ndev, "Error in sending message queue\n");
3365                 return -EINVAL;
3366         }
3367
3368         hif_drv->scan_timer.data = (unsigned long)vif;
3369         mod_timer(&hif_drv->scan_timer,
3370                   jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
3371
3372         return result;
3373 }
3374
3375 int wilc_hif_set_cfg(struct wilc_vif *vif,
3376                      struct cfg_param_attr *cfg_param)
3377 {
3378         int result = 0;
3379         struct host_if_msg msg;
3380         struct host_if_drv *hif_drv = vif->hif_drv;
3381
3382         if (!hif_drv) {
3383                 netdev_err(vif->ndev, "hif_drv NULL\n");
3384                 return -EFAULT;
3385         }
3386
3387         memset(&msg, 0, sizeof(struct host_if_msg));
3388         msg.id = HOST_IF_MSG_CFG_PARAMS;
3389         msg.body.cfg_info = *cfg_param;
3390         msg.vif = vif;
3391
3392         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3393
3394         return result;
3395 }
3396
3397 static void GetPeriodicRSSI(unsigned long arg)
3398 {
3399         struct wilc_vif *vif = (struct wilc_vif *)arg;
3400
3401         if (!vif->hif_drv) {
3402                 netdev_err(vif->ndev, "Driver handler is NULL\n");
3403                 return;
3404         }
3405
3406         if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
3407                 wilc_get_statistics(vif, &vif->wilc->dummy_statistics);
3408
3409         periodic_rssi.data = (unsigned long)vif;
3410         mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3411 }
3412
3413 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3414 {
3415         int result = 0;
3416         struct host_if_drv *hif_drv;
3417         struct wilc_vif *vif;
3418         struct wilc *wilc;
3419         int i;
3420
3421         vif = netdev_priv(dev);
3422         wilc = vif->wilc;
3423
3424         scan_while_connected = false;
3425
3426         sema_init(&hif_sema_wait_response, 0);
3427
3428         hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
3429         if (!hif_drv) {
3430                 result = -ENOMEM;
3431                 goto _fail_;
3432         }
3433         *hif_drv_handler = hif_drv;
3434         for (i = 0; i < wilc->vif_num; i++)
3435                 if (dev == wilc->vif[i]->ndev) {
3436                         wilc->vif[i]->hif_drv = hif_drv;
3437                         break;
3438                 }
3439
3440         wilc_optaining_ip = false;
3441
3442         if (clients_count == 0) {
3443                 sema_init(&hif_sema_thread, 0);
3444                 sema_init(&hif_sema_driver, 0);
3445                 sema_init(&hif_sema_deinit, 1);
3446         }
3447
3448         sema_init(&hif_drv->sem_test_key_block, 0);
3449         sema_init(&hif_drv->sem_test_disconn_block, 0);
3450         sema_init(&hif_drv->sem_get_rssi, 0);
3451         sema_init(&hif_drv->sem_inactive_time, 0);
3452
3453         if (clients_count == 0) {
3454                 result = wilc_mq_create(&hif_msg_q);
3455
3456                 if (result < 0) {
3457                         netdev_err(vif->ndev, "Failed to creat MQ\n");
3458                         goto _fail_;
3459                 }
3460
3461                 hif_thread_handler = kthread_run(hostIFthread, wilc,
3462                                                  "WILC_kthread");
3463
3464                 if (IS_ERR(hif_thread_handler)) {
3465                         netdev_err(vif->ndev, "Failed to creat Thread\n");
3466                         result = -EFAULT;
3467                         goto _fail_mq_;
3468                 }
3469                 setup_timer(&periodic_rssi, GetPeriodicRSSI,
3470                             (unsigned long)vif);
3471                 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3472         }
3473
3474         setup_timer(&hif_drv->scan_timer, TimerCB_Scan, 0);
3475         setup_timer(&hif_drv->connect_timer, TimerCB_Connect, 0);
3476         setup_timer(&hif_drv->remain_on_ch_timer, ListenTimerCB, 0);
3477
3478         sema_init(&hif_drv->sem_cfg_values, 1);
3479         down(&hif_drv->sem_cfg_values);
3480
3481         hif_drv->hif_state = HOST_IF_IDLE;
3482         hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF;
3483         hif_drv->cfg_values.scan_source = DEFAULT_SCAN;
3484         hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME;
3485         hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME;
3486         hif_drv->cfg_values.curr_tx_rate = AUTORATE;
3487
3488         hif_drv->p2p_timeout = 0;
3489
3490         up(&hif_drv->sem_cfg_values);
3491
3492         clients_count++;
3493
3494         return result;
3495
3496 _fail_mq_:
3497         wilc_mq_destroy(&hif_msg_q);
3498 _fail_:
3499         return result;
3500 }
3501
3502 int wilc_deinit(struct wilc_vif *vif)
3503 {
3504         int result = 0;
3505         struct host_if_msg msg;
3506         struct host_if_drv *hif_drv = vif->hif_drv;
3507
3508         if (!hif_drv)   {
3509                 netdev_err(vif->ndev, "hif_drv = NULL\n");
3510                 return -EFAULT;
3511         }
3512
3513         down(&hif_sema_deinit);
3514
3515         terminated_handle = hif_drv;
3516
3517         del_timer_sync(&hif_drv->scan_timer);
3518         del_timer_sync(&hif_drv->connect_timer);
3519         del_timer_sync(&periodic_rssi);
3520         del_timer_sync(&hif_drv->remain_on_ch_timer);
3521
3522         wilc_set_wfi_drv_handler(vif, 0, 0);
3523         down(&hif_sema_driver);
3524
3525         if (hif_drv->usr_scan_req.scan_result) {
3526                 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
3527                                                   hif_drv->usr_scan_req.arg, NULL);
3528                 hif_drv->usr_scan_req.scan_result = NULL;
3529         }
3530
3531         hif_drv->hif_state = HOST_IF_IDLE;
3532
3533         scan_while_connected = false;
3534
3535         memset(&msg, 0, sizeof(struct host_if_msg));
3536
3537         if (clients_count == 1) {
3538                 del_timer_sync(&periodic_rssi);
3539                 msg.id = HOST_IF_MSG_EXIT;
3540                 msg.vif = vif;
3541
3542                 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3543                 if (result != 0)
3544                         netdev_err(vif->ndev, "deinit : Error(%d)\n", result);
3545
3546                 down(&hif_sema_thread);
3547
3548                 wilc_mq_destroy(&hif_msg_q);
3549         }
3550
3551         kfree(hif_drv);
3552
3553         clients_count--;
3554         terminated_handle = NULL;
3555         up(&hif_sema_deinit);
3556         return result;
3557 }
3558
3559 void wilc_network_info_received(struct wilc *wilc, u8 *pu8Buffer,
3560                                 u32 u32Length)
3561 {
3562         s32 result = 0;
3563         struct host_if_msg msg;
3564         int id;
3565         struct host_if_drv *hif_drv = NULL;
3566         struct wilc_vif *vif;
3567
3568         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3569         vif = wilc_get_vif_from_idx(wilc, id);
3570         if (!vif)
3571                 return;
3572         hif_drv = vif->hif_drv;
3573
3574         if (!hif_drv || hif_drv == terminated_handle)   {
3575                 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
3576                 return;
3577         }
3578
3579         memset(&msg, 0, sizeof(struct host_if_msg));
3580
3581         msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
3582         msg.vif = vif;
3583
3584         msg.body.net_info.len = u32Length;
3585         msg.body.net_info.buffer = kmalloc(u32Length, GFP_KERNEL);
3586         memcpy(msg.body.net_info.buffer, pu8Buffer, u32Length);
3587
3588         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3589         if (result)
3590                 netdev_err(vif->ndev, "message parameters (%d)\n", result);
3591 }
3592
3593 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *pu8Buffer,
3594                                    u32 u32Length)
3595 {
3596         s32 result = 0;
3597         struct host_if_msg msg;
3598         int id;
3599         struct host_if_drv *hif_drv = NULL;
3600         struct wilc_vif *vif;
3601
3602         down(&hif_sema_deinit);
3603
3604         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3605         vif = wilc_get_vif_from_idx(wilc, id);
3606         if (!vif) {
3607                 up(&hif_sema_deinit);
3608                 return;
3609         }
3610
3611         hif_drv = vif->hif_drv;
3612
3613         if (!hif_drv || hif_drv == terminated_handle) {
3614                 up(&hif_sema_deinit);
3615                 return;
3616         }
3617
3618         if (!hif_drv->usr_conn_req.conn_result) {
3619                 netdev_err(vif->ndev, "there is no current Connect Request\n");
3620                 up(&hif_sema_deinit);
3621                 return;
3622         }
3623
3624         memset(&msg, 0, sizeof(struct host_if_msg));
3625
3626         msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
3627         msg.vif = vif;
3628
3629         msg.body.async_info.len = u32Length;
3630         msg.body.async_info.buffer = kmalloc(u32Length, GFP_KERNEL);
3631         memcpy(msg.body.async_info.buffer, pu8Buffer, u32Length);
3632
3633         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3634         if (result)
3635                 netdev_err(vif->ndev, "synchronous info (%d)\n", result);
3636
3637         up(&hif_sema_deinit);
3638 }
3639
3640 void wilc_scan_complete_received(struct wilc *wilc, u8 *pu8Buffer,
3641                                  u32 u32Length)
3642 {
3643         s32 result = 0;
3644         struct host_if_msg msg;
3645         int id;
3646         struct host_if_drv *hif_drv = NULL;
3647         struct wilc_vif *vif;
3648
3649         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
3650         vif = wilc_get_vif_from_idx(wilc, id);
3651         if (!vif)
3652                 return;
3653         hif_drv = vif->hif_drv;
3654
3655         if (!hif_drv || hif_drv == terminated_handle)
3656                 return;
3657
3658         if (hif_drv->usr_scan_req.scan_result) {
3659                 memset(&msg, 0, sizeof(struct host_if_msg));
3660
3661                 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
3662                 msg.vif = vif;
3663
3664                 result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3665                 if (result)
3666                         netdev_err(vif->ndev, "complete param (%d)\n", result);
3667         }
3668 }
3669
3670 int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
3671                            u32 duration, u16 chan,
3672                            wilc_remain_on_chan_expired expired,
3673                            wilc_remain_on_chan_ready ready,
3674                            void *user_arg)
3675 {
3676         int result = 0;
3677         struct host_if_msg msg;
3678         struct host_if_drv *hif_drv = vif->hif_drv;
3679
3680         if (!hif_drv) {
3681                 netdev_err(vif->ndev, "driver is null\n");
3682                 return -EFAULT;
3683         }
3684
3685         memset(&msg, 0, sizeof(struct host_if_msg));
3686
3687         msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
3688         msg.body.remain_on_ch.ch = chan;
3689         msg.body.remain_on_ch.expired = expired;
3690         msg.body.remain_on_ch.ready = ready;
3691         msg.body.remain_on_ch.arg = user_arg;
3692         msg.body.remain_on_ch.duration = duration;
3693         msg.body.remain_on_ch.id = session_id;
3694         msg.vif = vif;
3695
3696         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3697         if (result)
3698                 netdev_err(vif->ndev, "wilc mq send fail\n");
3699
3700         return result;
3701 }
3702
3703 int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
3704 {
3705         int result = 0;
3706         struct host_if_msg msg;
3707         struct host_if_drv *hif_drv = vif->hif_drv;
3708
3709         if (!hif_drv) {
3710                 netdev_err(vif->ndev, "driver is null\n");
3711                 return -EFAULT;
3712         }
3713
3714         del_timer(&hif_drv->remain_on_ch_timer);
3715
3716         memset(&msg, 0, sizeof(struct host_if_msg));
3717         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
3718         msg.vif = vif;
3719         msg.body.remain_on_ch.id = session_id;
3720
3721         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3722         if (result)
3723                 netdev_err(vif->ndev, "wilc mq send fail\n");
3724
3725         return result;
3726 }
3727
3728 int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
3729 {
3730         int result = 0;
3731         struct host_if_msg msg;
3732         struct host_if_drv *hif_drv = vif->hif_drv;
3733
3734         if (!hif_drv) {
3735                 netdev_err(vif->ndev, "driver is null\n");
3736                 return -EFAULT;
3737         }
3738
3739         memset(&msg, 0, sizeof(struct host_if_msg));
3740
3741         msg.id = HOST_IF_MSG_REGISTER_FRAME;
3742         switch (frame_type) {
3743         case ACTION:
3744                 msg.body.reg_frame.reg_id = ACTION_FRM_IDX;
3745                 break;
3746
3747         case PROBE_REQ:
3748                 msg.body.reg_frame.reg_id = PROBE_REQ_IDX;
3749                 break;
3750
3751         default:
3752                 break;
3753         }
3754         msg.body.reg_frame.frame_type = frame_type;
3755         msg.body.reg_frame.reg = reg;
3756         msg.vif = vif;
3757
3758         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3759         if (result)
3760                 netdev_err(vif->ndev, "wilc mq send fail\n");
3761
3762         return result;
3763 }
3764
3765 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
3766                     u32 head_len, u8 *head, u32 tail_len, u8 *tail)
3767 {
3768         int result = 0;
3769         struct host_if_msg msg;
3770         struct beacon_attr *beacon_info = &msg.body.beacon_info;
3771         struct host_if_drv *hif_drv = vif->hif_drv;
3772
3773         if (!hif_drv) {
3774                 netdev_err(vif->ndev, "driver is null\n");
3775                 return -EFAULT;
3776         }
3777
3778         memset(&msg, 0, sizeof(struct host_if_msg));
3779
3780         msg.id = HOST_IF_MSG_ADD_BEACON;
3781         msg.vif = vif;
3782         beacon_info->interval = interval;
3783         beacon_info->dtim_period = dtim_period;
3784         beacon_info->head_len = head_len;
3785         beacon_info->head = kmemdup(head, head_len, GFP_KERNEL);
3786         if (!beacon_info->head) {
3787                 result = -ENOMEM;
3788                 goto ERRORHANDLER;
3789         }
3790         beacon_info->tail_len = tail_len;
3791
3792         if (tail_len > 0) {
3793                 beacon_info->tail = kmemdup(tail, tail_len, GFP_KERNEL);
3794                 if (!beacon_info->tail) {
3795                         result = -ENOMEM;
3796                         goto ERRORHANDLER;
3797                 }
3798         } else {
3799                 beacon_info->tail = NULL;
3800         }
3801
3802         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3803         if (result)
3804                 netdev_err(vif->ndev, "wilc mq send fail\n");
3805
3806 ERRORHANDLER:
3807         if (result) {
3808                 kfree(beacon_info->head);
3809
3810                 kfree(beacon_info->tail);
3811         }
3812
3813         return result;
3814 }
3815
3816 int wilc_del_beacon(struct wilc_vif *vif)
3817 {
3818         int result = 0;
3819         struct host_if_msg msg;
3820         struct host_if_drv *hif_drv = vif->hif_drv;
3821
3822         if (!hif_drv) {
3823                 netdev_err(vif->ndev, "driver is null\n");
3824                 return -EFAULT;
3825         }
3826
3827         msg.id = HOST_IF_MSG_DEL_BEACON;
3828         msg.vif = vif;
3829
3830         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3831         if (result)
3832                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3833
3834         return result;
3835 }
3836
3837 int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
3838 {
3839         int result = 0;
3840         struct host_if_msg msg;
3841         struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
3842         struct host_if_drv *hif_drv = vif->hif_drv;
3843
3844         if (!hif_drv) {
3845                 netdev_err(vif->ndev, "driver is null\n");
3846                 return -EFAULT;
3847         }
3848
3849         memset(&msg, 0, sizeof(struct host_if_msg));
3850
3851         msg.id = HOST_IF_MSG_ADD_STATION;
3852         msg.vif = vif;
3853
3854         memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3855         if (add_sta_info->rates_len > 0) {
3856                 add_sta_info->rates = kmemdup(sta_param->rates,
3857                                       add_sta_info->rates_len,
3858                                       GFP_KERNEL);
3859                 if (!add_sta_info->rates)
3860                         return -ENOMEM;
3861         }
3862
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;
3867 }
3868
3869 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
3870 {
3871         int result = 0;
3872         struct host_if_msg msg;
3873         struct del_sta *del_sta_info = &msg.body.del_sta_info;
3874         struct host_if_drv *hif_drv = vif->hif_drv;
3875
3876         if (!hif_drv) {
3877                 netdev_err(vif->ndev, "driver is null\n");
3878                 return -EFAULT;
3879         }
3880
3881         memset(&msg, 0, sizeof(struct host_if_msg));
3882
3883         msg.id = HOST_IF_MSG_DEL_STATION;
3884         msg.vif = vif;
3885
3886         if (!mac_addr)
3887                 eth_broadcast_addr(del_sta_info->mac_addr);
3888         else
3889                 memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN);
3890
3891         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3892         if (result)
3893                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3894         return result;
3895 }
3896
3897 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
3898 {
3899         int result = 0;
3900         struct host_if_msg msg;
3901         struct del_all_sta *del_all_sta_info = &msg.body.del_all_sta_info;
3902         struct host_if_drv *hif_drv = vif->hif_drv;
3903         u8 zero_addr[ETH_ALEN] = {0};
3904         int i;
3905         u8 assoc_sta = 0;
3906
3907         if (!hif_drv) {
3908                 netdev_err(vif->ndev, "driver is null\n");
3909                 return -EFAULT;
3910         }
3911
3912         memset(&msg, 0, sizeof(struct host_if_msg));
3913
3914         msg.id = HOST_IF_MSG_DEL_ALL_STA;
3915         msg.vif = vif;
3916
3917         for (i = 0; i < MAX_NUM_STA; i++) {
3918                 if (memcmp(mac_addr[i], zero_addr, ETH_ALEN)) {
3919                         memcpy(del_all_sta_info->del_all_sta[i], mac_addr[i], ETH_ALEN);
3920                         assoc_sta++;
3921                 }
3922         }
3923         if (!assoc_sta)
3924                 return result;
3925
3926         del_all_sta_info->assoc_sta = assoc_sta;
3927         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3928
3929         if (result)
3930                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3931
3932         down(&hif_sema_wait_response);
3933
3934         return result;
3935 }
3936
3937 int wilc_edit_station(struct wilc_vif *vif,
3938                       struct add_sta_param *sta_param)
3939 {
3940         int result = 0;
3941         struct host_if_msg msg;
3942         struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
3943         struct host_if_drv *hif_drv = vif->hif_drv;
3944
3945         if (!hif_drv) {
3946                 netdev_err(vif->ndev, "driver is null\n");
3947                 return -EFAULT;
3948         }
3949
3950         memset(&msg, 0, sizeof(struct host_if_msg));
3951
3952         msg.id = HOST_IF_MSG_EDIT_STATION;
3953         msg.vif = vif;
3954
3955         memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3956         if (add_sta_info->rates_len > 0) {
3957                 add_sta_info->rates = kmemdup(sta_param->rates,
3958                                               add_sta_info->rates_len,
3959                                               GFP_KERNEL);
3960                 if (!add_sta_info->rates)
3961                         return -ENOMEM;
3962         }
3963
3964         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3965         if (result)
3966                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3967
3968         return result;
3969 }
3970
3971 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
3972 {
3973         int result = 0;
3974         struct host_if_msg msg;
3975         struct power_mgmt_param *pwr_mgmt_info = &msg.body.pwr_mgmt_info;
3976         struct host_if_drv *hif_drv = vif->hif_drv;
3977
3978         if (!hif_drv) {
3979                 netdev_err(vif->ndev, "driver is null\n");
3980                 return -EFAULT;
3981         }
3982
3983         if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
3984                 return 0;
3985
3986         memset(&msg, 0, sizeof(struct host_if_msg));
3987
3988         msg.id = HOST_IF_MSG_POWER_MGMT;
3989         msg.vif = vif;
3990
3991         pwr_mgmt_info->enabled = enabled;
3992         pwr_mgmt_info->timeout = timeout;
3993
3994         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
3995         if (result)
3996                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
3997         return result;
3998 }
3999
4000 int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
4001                                 u32 count)
4002 {
4003         int result = 0;
4004         struct host_if_msg msg;
4005         struct set_multicast *multicast_filter_param = &msg.body.multicast_info;
4006         struct host_if_drv *hif_drv = vif->hif_drv;
4007
4008         if (!hif_drv) {
4009                 netdev_err(vif->ndev, "driver is null\n");
4010                 return -EFAULT;
4011         }
4012
4013         memset(&msg, 0, sizeof(struct host_if_msg));
4014
4015         msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
4016         msg.vif = vif;
4017
4018         multicast_filter_param->enabled = enabled;
4019         multicast_filter_param->cnt = count;
4020
4021         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4022         if (result)
4023                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4024         return result;
4025 }
4026
4027 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo)
4028 {
4029         struct join_bss_param *pNewJoinBssParam = NULL;
4030         u8 *pu8IEs;
4031         u16 u16IEsLen;
4032         u16 index = 0;
4033         u8 suppRatesNo = 0;
4034         u8 extSuppRatesNo;
4035         u16 jumpOffset;
4036         u8 pcipherCount;
4037         u8 authCount;
4038         u8 pcipherTotalCount = 0;
4039         u8 authTotalCount = 0;
4040         u8 i, j;
4041
4042         pu8IEs = ptstrNetworkInfo->ies;
4043         u16IEsLen = ptstrNetworkInfo->ies_len;
4044
4045         pNewJoinBssParam = kzalloc(sizeof(struct join_bss_param), GFP_KERNEL);
4046         if (pNewJoinBssParam) {
4047                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->dtim_period;
4048                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->beacon_period;
4049                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->cap_info;
4050                 memcpy(pNewJoinBssParam->bssid, ptstrNetworkInfo->bssid, 6);
4051                 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->ssid,
4052                        ptstrNetworkInfo->ssid_len + 1);
4053                 pNewJoinBssParam->ssid_len = ptstrNetworkInfo->ssid_len;
4054                 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
4055                 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
4056
4057                 while (index < u16IEsLen) {
4058                         if (pu8IEs[index] == SUPP_RATES_IE) {
4059                                 suppRatesNo = pu8IEs[index + 1];
4060                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
4061                                 index += 2;
4062
4063                                 for (i = 0; i < suppRatesNo; i++)
4064                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
4065
4066                                 index += suppRatesNo;
4067                                 continue;
4068                         } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
4069                                 extSuppRatesNo = pu8IEs[index + 1];
4070                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
4071                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
4072                                 else
4073                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
4074                                 index += 2;
4075                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++)
4076                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
4077
4078                                 index += extSuppRatesNo;
4079                                 continue;
4080                         } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
4081                                 pNewJoinBssParam->ht_capable = true;
4082                                 index += pu8IEs[index + 1] + 2;
4083                                 continue;
4084                         } else if ((pu8IEs[index] == WMM_IE) &&
4085                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
4086                                    (pu8IEs[index + 4] == 0xF2) &&
4087                                    (pu8IEs[index + 5] == 0x02) &&
4088                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
4089                                    (pu8IEs[index + 7] == 0x01)) {
4090                                 pNewJoinBssParam->wmm_cap = true;
4091
4092                                 if (pu8IEs[index + 8] & BIT(7))
4093                                         pNewJoinBssParam->uapsd_cap = true;
4094                                 index += pu8IEs[index + 1] + 2;
4095                                 continue;
4096                         } else if ((pu8IEs[index] == P2P_IE) &&
4097                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
4098                                  (pu8IEs[index + 4] == 0x9a) &&
4099                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
4100                                 u16 u16P2P_count;
4101
4102                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->tsf_lo;
4103                                 pNewJoinBssParam->noa_enabled = 1;
4104                                 pNewJoinBssParam->idx = pu8IEs[index + 9];
4105
4106                                 if (pu8IEs[index + 10] & BIT(7)) {
4107                                         pNewJoinBssParam->opp_enabled = 1;
4108                                         pNewJoinBssParam->ct_window = pu8IEs[index + 10];
4109                                 } else {
4110                                         pNewJoinBssParam->opp_enabled = 0;
4111                                 }
4112
4113                                 pNewJoinBssParam->cnt = pu8IEs[index + 11];
4114                                 u16P2P_count = index + 12;
4115
4116                                 memcpy(pNewJoinBssParam->duration, pu8IEs + u16P2P_count, 4);
4117                                 u16P2P_count += 4;
4118
4119                                 memcpy(pNewJoinBssParam->interval, pu8IEs + u16P2P_count, 4);
4120                                 u16P2P_count += 4;
4121
4122                                 memcpy(pNewJoinBssParam->start_time, pu8IEs + u16P2P_count, 4);
4123
4124                                 index += pu8IEs[index + 1] + 2;
4125                                 continue;
4126
4127                         } else if ((pu8IEs[index] == RSN_IE) ||
4128                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
4129                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
4130                                   (pu8IEs[index + 5] == 0x01))) {
4131                                 u16 rsnIndex = index;
4132
4133                                 if (pu8IEs[rsnIndex] == RSN_IE) {
4134                                         pNewJoinBssParam->mode_802_11i = 2;
4135                                 } else {
4136                                         if (pNewJoinBssParam->mode_802_11i == 0)
4137                                                 pNewJoinBssParam->mode_802_11i = 1;
4138                                         rsnIndex += 4;
4139                                 }
4140
4141                                 rsnIndex += 7;
4142                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
4143                                 rsnIndex++;
4144                                 jumpOffset = pu8IEs[rsnIndex] * 4;
4145                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
4146                                 rsnIndex += 2;
4147
4148                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++)
4149                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
4150
4151                                 pcipherTotalCount += pcipherCount;
4152                                 rsnIndex += jumpOffset;
4153
4154                                 jumpOffset = pu8IEs[rsnIndex] * 4;
4155
4156                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
4157                                 rsnIndex += 2;
4158
4159                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++)
4160                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
4161
4162                                 authTotalCount += authCount;
4163                                 rsnIndex += jumpOffset;
4164
4165                                 if (pu8IEs[index] == RSN_IE) {
4166                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
4167                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
4168                                         rsnIndex += 2;
4169                                 }
4170                                 pNewJoinBssParam->rsn_found = true;
4171                                 index += pu8IEs[index + 1] + 2;
4172                                 continue;
4173                         } else
4174                                 index += pu8IEs[index + 1] + 2;
4175                 }
4176         }
4177
4178         return (void *)pNewJoinBssParam;
4179 }
4180
4181 int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4182 {
4183         int result = 0;
4184         struct host_if_msg msg;
4185         struct host_if_drv *hif_drv = vif->hif_drv;
4186
4187         if (!hif_drv) {
4188                 netdev_err(vif->ndev, "driver is null\n");
4189                 return -EFAULT;
4190         }
4191
4192         memset(&msg, 0, sizeof(struct host_if_msg));
4193
4194         msg.id = HOST_IF_MSG_SET_IPADDRESS;
4195
4196         msg.body.ip_info.ip_addr = ip_addr;
4197         msg.vif = vif;
4198         msg.body.ip_info.idx = idx;
4199
4200         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4201         if (result)
4202                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4203
4204         return result;
4205 }
4206
4207 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4208 {
4209         int result = 0;
4210         struct host_if_msg msg;
4211         struct host_if_drv *hif_drv = vif->hif_drv;
4212
4213         if (!hif_drv) {
4214                 netdev_err(vif->ndev, "driver is null\n");
4215                 return -EFAULT;
4216         }
4217
4218         memset(&msg, 0, sizeof(struct host_if_msg));
4219
4220         msg.id = HOST_IF_MSG_GET_IPADDRESS;
4221
4222         msg.body.ip_info.ip_addr = ip_addr;
4223         msg.vif = vif;
4224         msg.body.ip_info.idx = idx;
4225
4226         result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4227         if (result)
4228                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4229
4230         return result;
4231 }
4232
4233 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
4234 {
4235         int ret = 0;
4236         struct host_if_msg msg;
4237
4238         memset(&msg, 0, sizeof(struct host_if_msg));
4239
4240         msg.id = HOST_IF_MSG_SET_TX_POWER;
4241         msg.body.tx_power.tx_pwr = tx_power;
4242         msg.vif = vif;
4243
4244         ret = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4245         if (ret)
4246                 netdev_err(vif->ndev, "wilc_mq_send fail\n");
4247
4248         return ret;
4249 }
4250
4251 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
4252 {
4253         int ret = 0;
4254         struct host_if_msg msg;
4255
4256         memset(&msg, 0, sizeof(struct host_if_msg));
4257
4258         msg.id = HOST_IF_MSG_GET_TX_POWER;
4259         msg.vif = vif;
4260
4261         ret = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
4262         if (ret)
4263                 netdev_err(vif->ndev, "Failed to get TX PWR\n");
4264
4265         down(&hif_sema_wait_response);
4266         *tx_power = msg.body.tx_power.tx_pwr;
4267
4268         return ret;
4269 }