Staging: wilc1000: host_interface: Remove extra NULL test
[firefly-linux-kernel-4.4.55.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_if.h"
8 #include "wilc_msgqueue.h"
9 #include <linux/etherdevice.h>
10
11 extern u8 connecting;
12
13 extern struct timer_list hDuringIpTimer;
14
15 extern u8 g_wilc_initialized;
16
17 #define HOST_IF_MSG_SCAN                        0
18 #define HOST_IF_MSG_CONNECT                     1
19 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO        2
20 #define HOST_IF_MSG_KEY                         3
21 #define HOST_IF_MSG_RCVD_NTWRK_INFO             4
22 #define HOST_IF_MSG_RCVD_SCAN_COMPLETE          5
23 #define HOST_IF_MSG_CFG_PARAMS                  6
24 #define HOST_IF_MSG_SET_CHANNEL                 7
25 #define HOST_IF_MSG_DISCONNECT                  8
26 #define HOST_IF_MSG_GET_RSSI                    9
27 #define HOST_IF_MSG_GET_CHNL                    10
28 #define HOST_IF_MSG_ADD_BEACON                  11
29 #define HOST_IF_MSG_DEL_BEACON                  12
30 #define HOST_IF_MSG_ADD_STATION                 13
31 #define HOST_IF_MSG_DEL_STATION                 14
32 #define HOST_IF_MSG_EDIT_STATION                15
33 #define HOST_IF_MSG_SCAN_TIMER_FIRED            16
34 #define HOST_IF_MSG_CONNECT_TIMER_FIRED         17
35 #define HOST_IF_MSG_POWER_MGMT                  18
36 #define HOST_IF_MSG_GET_INACTIVETIME            19
37 #define HOST_IF_MSG_REMAIN_ON_CHAN              20
38 #define HOST_IF_MSG_REGISTER_FRAME              21
39 #define HOST_IF_MSG_LISTEN_TIMER_FIRED          22
40 #define HOST_IF_MSG_GET_LINKSPEED               23
41 #define HOST_IF_MSG_SET_WFIDRV_HANDLER          24
42 #define HOST_IF_MSG_SET_MAC_ADDRESS             25
43 #define HOST_IF_MSG_GET_MAC_ADDRESS             26
44 #define HOST_IF_MSG_SET_OPERATION_MODE          27
45 #define HOST_IF_MSG_SET_IPADDRESS               28
46 #define HOST_IF_MSG_GET_IPADDRESS               29
47 #define HOST_IF_MSG_FLUSH_CONNECT               30
48 #define HOST_IF_MSG_GET_STATISTICS              31
49 #define HOST_IF_MSG_SET_MULTICAST_FILTER        32
50 #define HOST_IF_MSG_ADD_BA_SESSION              33
51 #define HOST_IF_MSG_DEL_BA_SESSION              34
52 #define HOST_IF_MSG_Q_IDLE                      35
53 #define HOST_IF_MSG_DEL_ALL_STA                 36
54 #define HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS      34
55 #define HOST_IF_MSG_EXIT                        100
56
57 #define HOST_IF_SCAN_TIMEOUT                    4000
58 #define HOST_IF_CONNECT_TIMEOUT                 9500
59
60 #define BA_SESSION_DEFAULT_BUFFER_SIZE          16
61 #define BA_SESSION_DEFAULT_TIMEOUT              1000
62 #define BLOCK_ACK_REQ_SIZE                      0x14
63
64 struct cfg_param_attr {
65         struct cfg_param_val cfg_attr_info;
66 };
67
68 struct host_if_wpa_attr {
69         u8 *key;
70         const u8 *mac_addr;
71         u8 *seq;
72         u8 seq_len;
73         u8 index;
74         u8 key_len;
75         u8 mode;
76 };
77
78 struct host_if_wep_attr {
79         u8 *key;
80         u8 key_len;
81         u8 index;
82         u8 mode;
83         enum AUTHTYPE auth_type;
84 };
85
86 union host_if_key_attr {
87         struct host_if_wep_attr wep;
88         struct host_if_wpa_attr wpa;
89         struct host_if_pmkid_attr pmkid;
90 };
91
92 struct key_attr {
93         enum KEY_TYPE type;
94         u8 action;
95         union host_if_key_attr attr;
96 };
97
98 struct scan_attr {
99         u8 src;
100         u8 type;
101         u8 *ch_freq_list;
102         u8 ch_list_len;
103         u8 *ies;
104         size_t ies_len;
105         wilc_scan_result result;
106         void *arg;
107         struct hidden_network hidden_network;
108 };
109
110 struct connect_attr {
111         u8 *bssid;
112         u8 *ssid;
113         size_t ssid_len;
114         u8 *ies;
115         size_t ies_len;
116         u8 security;
117         wilc_connect_result result;
118         void *arg;
119         enum AUTHTYPE auth_type;
120         u8 ch;
121         void *params;
122 };
123
124 struct rcvd_async_info {
125         u8 *buffer;
126         u32 len;
127 };
128
129 struct channel_attr {
130         u8 set_ch;
131 };
132
133 struct beacon_attr {
134         u32 interval;
135         u32 dtim_period;
136         u32 head_len;
137         u8 *head;
138         u32 tail_len;
139         u8 *tail;
140 };
141
142 struct set_multicast {
143         bool enabled;
144         u32 cnt;
145 };
146
147 struct del_all_sta {
148         u8 del_all_sta[MAX_NUM_STA][ETH_ALEN];
149         u8 assoc_sta;
150 };
151
152 struct del_sta {
153         u8 mac_addr[ETH_ALEN];
154 };
155
156 struct power_mgmt_param {
157         bool enabled;
158         u32 timeout;
159 };
160
161 struct set_ip_addr {
162         u8 *ip_addr;
163         u8 idx;
164 };
165
166 struct sta_inactive_t {
167         u8 mac[6];
168 };
169
170 union message_body {
171         struct scan_attr scan_info;
172         struct connect_attr con_info;
173         struct rcvd_net_info net_info;
174         struct rcvd_async_info async_info;
175         struct key_attr key_info;
176         struct cfg_param_attr cfg_info;
177         struct channel_attr channel_info;
178         struct beacon_attr beacon_info;
179         struct add_sta_param add_sta_info;
180         struct del_sta del_sta_info;
181         struct add_sta_param edit_sta_info;
182         struct power_mgmt_param pwr_mgmt_info;
183         struct sta_inactive_t mac_info;
184         struct set_ip_addr ip_info;
185         struct drv_handler drv;
186         struct set_multicast multicast_info;
187         struct op_mode mode;
188         struct set_mac_addr set_mac_info;
189         struct get_mac_addr get_mac_info;
190         struct ba_session_info session_info;
191         struct remain_ch remain_on_ch;
192         struct reg_frame reg_frame;
193         char *data;
194         struct del_all_sta del_all_sta_info;
195 };
196
197 struct host_if_msg {
198         u16 id;
199         union message_body body;
200         struct host_if_drv *drv;
201 };
202
203 struct join_bss_param {
204         BSSTYPE_T bss_type;
205         u8 dtim_period;
206         u16 beacon_period;
207         u16 cap_info;
208         u8 au8bssid[6];
209         char ssid[MAX_SSID_LEN];
210         u8 ssidLen;
211         u8 supp_rates[MAX_RATES_SUPPORTED + 1];
212         u8 ht_capable;
213         u8 wmm_cap;
214         u8 uapsd_cap;
215         bool rsn_found;
216         u8 rsn_grp_policy;
217         u8 mode_802_11i;
218         u8 rsn_pcip_policy[3];
219         u8 rsn_auth_policy[3];
220         u8 rsn_cap[2];
221         u32 tsf;
222         u8 u8NoaEnbaled;
223         u8 u8OppEnable;
224         u8 u8CtWindow;
225         u8 u8Count;
226         u8 u8Index;
227         u8 au8Duration[4];
228         u8 au8Interval[4];
229         u8 au8StartTime[4];
230 };
231
232 enum scan_conn_timer {
233         SCAN_TIMER = 0,
234         CONNECT_TIMER   = 1,
235         SCAN_CONNECT_TIMER_FORCE_32BIT = 0xFFFFFFFF
236 };
237
238 static struct host_if_drv *wfidrv_list[NUM_CONCURRENT_IFC + 1];
239 struct host_if_drv *terminated_handle;
240 struct host_if_drv *gWFiDrvHandle;
241 bool g_obtainingIP;
242 u8 P2P_LISTEN_STATE;
243 static struct task_struct *HostIFthreadHandler;
244 static WILC_MsgQueueHandle gMsgQHostIF;
245 static struct semaphore hSemHostIFthrdEnd;
246
247 struct semaphore hSemDeinitDrvHandle;
248 static struct semaphore hWaitResponse;
249 struct semaphore hSemHostIntDeinit;
250 struct timer_list g_hPeriodicRSSI;
251
252
253
254 u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
255
256 static u8 gapu8RcvdAssocResp[MAX_ASSOC_RESP_FRAME_SIZE];
257
258 bool gbScanWhileConnected;
259
260 static s8 gs8Rssi;
261 static s8 gs8lnkspd;
262 static u8 gu8Chnl;
263 static u8 gs8SetIP[2][4];
264 static u8 gs8GetIP[2][4];
265 static u32 gu32InactiveTime;
266 static u8 gu8DelBcn;
267 static u32 gu32WidConnRstHack;
268
269 u8 *gu8FlushedJoinReq;
270 u8 *gu8FlushedInfoElemAsoc;
271 u8 gu8Flushed11iMode;
272 u8 gu8FlushedAuthType;
273 u32 gu32FlushedJoinReqSize;
274 u32 gu32FlushedInfoElemAsocSize;
275 struct host_if_drv *gu8FlushedJoinReqDrvHandler;
276 #define REAL_JOIN_REQ 0
277 #define FLUSHED_JOIN_REQ 1
278 #define FLUSHED_BYTE_POS 79
279
280 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo);
281
282 extern void chip_sleep_manually(u32 u32SleepTime);
283 extern int linux_wlan_get_num_conn_ifcs(void);
284
285 static int add_handler_in_list(struct host_if_drv *handler)
286 {
287         int i;
288
289         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
290                 if (!wfidrv_list[i]) {
291                         wfidrv_list[i] = handler;
292                         return 0;
293                 }
294         }
295
296         return -ENOBUFS;
297 }
298
299 static int remove_handler_in_list(struct host_if_drv *handler)
300 {
301         int i;
302
303         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
304                 if (wfidrv_list[i] == handler) {
305                         wfidrv_list[i] = NULL;
306                         return 0;
307                 }
308         }
309
310         return -EINVAL;
311 }
312
313 static int get_id_from_handler(struct host_if_drv *handler)
314 {
315         int i;
316
317         if (!handler)
318                 return 0;
319
320         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
321                 if (wfidrv_list[i] == handler)
322                         return i;
323         }
324
325         return 0;
326 }
327
328 static struct host_if_drv *get_handler_from_id(int id)
329 {
330         if (id <= 0 || id >= ARRAY_SIZE(wfidrv_list))
331                 return NULL;
332         return wfidrv_list[id];
333 }
334
335 static s32 Handle_SetChannel(struct host_if_drv *hif_drv,
336                              struct channel_attr *pstrHostIFSetChan)
337 {
338
339         s32 s32Error = 0;
340         struct wid strWID;
341
342         strWID.id = (u16)WID_CURRENT_CHANNEL;
343         strWID.type = WID_CHAR;
344         strWID.val = (char *)&(pstrHostIFSetChan->set_ch);
345         strWID.size = sizeof(char);
346
347         PRINT_D(HOSTINF_DBG, "Setting channel\n");
348
349         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
350                                    get_id_from_handler(hif_drv));
351         if (s32Error) {
352                 PRINT_ER("Failed to set channel\n");
353                 return -EINVAL;
354         }
355
356         return s32Error;
357 }
358
359 static s32 Handle_SetWfiDrvHandler(struct host_if_drv *hif_drv,
360                                    struct drv_handler *pstrHostIfSetDrvHandler)
361 {
362
363         s32 s32Error = 0;
364         struct wid strWID;
365
366         strWID.id = (u16)WID_SET_DRV_HANDLER;
367         strWID.type = WID_INT;
368         strWID.val = (s8 *)&(pstrHostIfSetDrvHandler->u32Address);
369         strWID.size = sizeof(u32);
370
371         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
372                                    pstrHostIfSetDrvHandler->u32Address);
373
374         if (!hif_drv)
375                 up(&hSemDeinitDrvHandle);
376
377
378         if (s32Error) {
379                 PRINT_ER("Failed to set driver handler\n");
380                 return -EINVAL;
381         }
382
383         return s32Error;
384 }
385
386 static s32 Handle_SetOperationMode(struct host_if_drv *hif_drv,
387                                    struct op_mode *pstrHostIfSetOperationMode)
388 {
389
390         s32 s32Error = 0;
391         struct wid strWID;
392
393         strWID.id = (u16)WID_SET_OPERATION_MODE;
394         strWID.type = WID_INT;
395         strWID.val = (s8 *)&(pstrHostIfSetOperationMode->u32Mode);
396         strWID.size = sizeof(u32);
397
398         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
399                                    get_id_from_handler(hif_drv));
400
401
402         if ((pstrHostIfSetOperationMode->u32Mode) == IDLE_MODE)
403                 up(&hSemDeinitDrvHandle);
404
405
406         if (s32Error) {
407                 PRINT_ER("Failed to set driver handler\n");
408                 return -EINVAL;
409         }
410
411         return s32Error;
412 }
413
414 s32 Handle_set_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
415 {
416
417         s32 s32Error = 0;
418         struct wid strWID;
419         char firmwareIPAddress[4] = {0};
420
421         if (pu8IPAddr[0] < 192)
422                 pu8IPAddr[0] = 0;
423
424         PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set  IP = %pI4\n", idx, pu8IPAddr);
425
426         memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN);
427
428         strWID.id = (u16)WID_IP_ADDRESS;
429         strWID.type = WID_STR;
430         strWID.val = (u8 *)pu8IPAddr;
431         strWID.size = IP_ALEN;
432
433         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
434                                    get_id_from_handler(hif_drv));
435
436
437         host_int_get_ipaddress(hif_drv, firmwareIPAddress, idx);
438
439         if (s32Error) {
440                 PRINT_ER("Failed to set IP address\n");
441                 return -EINVAL;
442         }
443
444         PRINT_INFO(HOSTINF_DBG, "IP address set\n");
445
446         return s32Error;
447 }
448
449 s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
450 {
451
452         s32 s32Error = 0;
453         struct wid strWID;
454
455         strWID.id = (u16)WID_IP_ADDRESS;
456         strWID.type = WID_STR;
457         strWID.val = kmalloc(IP_ALEN, GFP_KERNEL);
458         strWID.size = IP_ALEN;
459
460         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
461                                    get_id_from_handler(hif_drv));
462
463         PRINT_INFO(HOSTINF_DBG, "%pI4\n", strWID.val);
464
465         memcpy(gs8GetIP[idx], strWID.val, IP_ALEN);
466
467         kfree(strWID.val);
468
469         if (memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0)
470                 host_int_setup_ipaddress(hif_drv, gs8SetIP[idx], idx);
471
472         if (s32Error != 0) {
473                 PRINT_ER("Failed to get IP address\n");
474                 return -EINVAL;
475         }
476
477         PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d\n", idx);
478         PRINT_INFO(HOSTINF_DBG, "%pI4\n", gs8GetIP[idx]);
479         PRINT_INFO(HOSTINF_DBG, "\n");
480
481         return s32Error;
482 }
483
484 static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv,
485                                 struct set_mac_addr *pstrHostIfSetMacAddress)
486 {
487
488         s32 s32Error = 0;
489         struct wid strWID;
490         u8 *mac_buf = kmalloc(ETH_ALEN, GFP_KERNEL);
491
492         if (mac_buf == NULL) {
493                 PRINT_ER("No buffer to send mac address\n");
494                 return -EFAULT;
495         }
496         memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN);
497
498         strWID.id = (u16)WID_MAC_ADDR;
499         strWID.type = WID_STR;
500         strWID.val = mac_buf;
501         strWID.size = ETH_ALEN;
502         PRINT_D(GENERIC_DBG, "mac addr = :%pM\n", strWID.val);
503
504         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
505                                    get_id_from_handler(hif_drv));
506         if (s32Error) {
507                 PRINT_ER("Failed to set mac address\n");
508                 s32Error = -EFAULT;
509         }
510
511         kfree(mac_buf);
512         return s32Error;
513 }
514
515 static s32 Handle_GetMacAddress(struct host_if_drv *hif_drv,
516                                 struct get_mac_addr *pstrHostIfGetMacAddress)
517 {
518
519         s32 s32Error = 0;
520         struct wid strWID;
521
522         strWID.id = (u16)WID_MAC_ADDR;
523         strWID.type = WID_STR;
524         strWID.val = pstrHostIfGetMacAddress->u8MacAddress;
525         strWID.size = ETH_ALEN;
526
527         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
528                                    get_id_from_handler(hif_drv));
529         if (s32Error) {
530                 PRINT_ER("Failed to get mac address\n");
531                 s32Error = -EFAULT;
532         }
533         up(&hWaitResponse);
534
535         return s32Error;
536 }
537
538 static s32 Handle_CfgParam(struct host_if_drv *hif_drv,
539                            struct cfg_param_attr *strHostIFCfgParamAttr)
540 {
541         s32 s32Error = 0;
542         struct wid strWIDList[32];
543         u8 u8WidCnt = 0;
544
545         down(&hif_drv->gtOsCfgValuesSem);
546
547
548         PRINT_D(HOSTINF_DBG, "Setting CFG params\n");
549
550         if (strHostIFCfgParamAttr->cfg_attr_info.flag & BSS_TYPE) {
551                 if (strHostIFCfgParamAttr->cfg_attr_info.bss_type < 6) {
552                         strWIDList[u8WidCnt].id = WID_BSS_TYPE;
553                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.bss_type;
554                         strWIDList[u8WidCnt].type = WID_CHAR;
555                         strWIDList[u8WidCnt].size = sizeof(char);
556                         hif_drv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.bss_type;
557                 } else {
558                         PRINT_ER("check value 6 over\n");
559                         s32Error = -EINVAL;
560                         goto ERRORHANDLER;
561                 }
562                 u8WidCnt++;
563         }
564         if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTH_TYPE) {
565                 if ((strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 1 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 2 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 5) {
566                         strWIDList[u8WidCnt].id = WID_AUTH_TYPE;
567                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_type;
568                         strWIDList[u8WidCnt].type = WID_CHAR;
569                         strWIDList[u8WidCnt].size = sizeof(char);
570                         hif_drv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.auth_type;
571                 } else {
572                         PRINT_ER("Impossible value \n");
573                         s32Error = -EINVAL;
574                         goto ERRORHANDLER;
575                 }
576                 u8WidCnt++;
577         }
578         if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTHEN_TIMEOUT) {
579                 if (strHostIFCfgParamAttr->cfg_attr_info.auth_timeout > 0 && strHostIFCfgParamAttr->cfg_attr_info.auth_timeout < 65536) {
580                         strWIDList[u8WidCnt].id = WID_AUTH_TIMEOUT;
581                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
582                         strWIDList[u8WidCnt].type = WID_SHORT;
583                         strWIDList[u8WidCnt].size = sizeof(u16);
584                         hif_drv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
585                 } else {
586                         PRINT_ER("Range(1 ~ 65535) over\n");
587                         s32Error = -EINVAL;
588                         goto ERRORHANDLER;
589                 }
590                 u8WidCnt++;
591         }
592         if (strHostIFCfgParamAttr->cfg_attr_info.flag & POWER_MANAGEMENT) {
593                 if (strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode < 5) {
594                         strWIDList[u8WidCnt].id = WID_POWER_MANAGEMENT;
595                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
596                         strWIDList[u8WidCnt].type = WID_CHAR;
597                         strWIDList[u8WidCnt].size = sizeof(char);
598                         hif_drv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
599                 } else {
600                         PRINT_ER("Invalide power mode\n");
601                         s32Error = -EINVAL;
602                         goto ERRORHANDLER;
603                 }
604                 u8WidCnt++;
605         }
606         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_SHORT) {
607                 if ((strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit < 256))     {
608                         strWIDList[u8WidCnt].id = WID_SHORT_RETRY_LIMIT;
609                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
610                         strWIDList[u8WidCnt].type = WID_SHORT;
611                         strWIDList[u8WidCnt].size = sizeof(u16);
612                         hif_drv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
613                 } else {
614                         PRINT_ER("Range(1~256) over\n");
615                         s32Error = -EINVAL;
616                         goto ERRORHANDLER;
617                 }
618                 u8WidCnt++;
619         }
620         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_LONG) {
621                 if ((strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit < 256)) {
622                         strWIDList[u8WidCnt].id = WID_LONG_RETRY_LIMIT;
623                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
624
625                         strWIDList[u8WidCnt].type = WID_SHORT;
626                         strWIDList[u8WidCnt].size = sizeof(u16);
627                         hif_drv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
628                 } else {
629                         PRINT_ER("Range(1~256) over\n");
630                         s32Error = -EINVAL;
631                         goto ERRORHANDLER;
632                 }
633                 u8WidCnt++;
634         }
635         if (strHostIFCfgParamAttr->cfg_attr_info.flag & FRAG_THRESHOLD) {
636
637                 if (strHostIFCfgParamAttr->cfg_attr_info.frag_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.frag_threshold < 7937) {
638                         strWIDList[u8WidCnt].id = WID_FRAG_THRESHOLD;
639                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
640                         strWIDList[u8WidCnt].type = WID_SHORT;
641                         strWIDList[u8WidCnt].size = sizeof(u16);
642                         hif_drv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
643                 } else {
644                         PRINT_ER("Threshold Range fail\n");
645                         s32Error = -EINVAL;
646                         goto ERRORHANDLER;
647                 }
648                 u8WidCnt++;
649         }
650         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RTS_THRESHOLD) {
651                 if (strHostIFCfgParamAttr->cfg_attr_info.rts_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.rts_threshold < 65536)     {
652                         strWIDList[u8WidCnt].id = WID_RTS_THRESHOLD;
653                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
654                         strWIDList[u8WidCnt].type = WID_SHORT;
655                         strWIDList[u8WidCnt].size = sizeof(u16);
656                         hif_drv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
657                 } else {
658                         PRINT_ER("Threshold Range fail\n");
659                         s32Error = -EINVAL;
660                         goto ERRORHANDLER;
661                 }
662                 u8WidCnt++;
663         }
664         if (strHostIFCfgParamAttr->cfg_attr_info.flag & PREAMBLE) {
665                 if (strHostIFCfgParamAttr->cfg_attr_info.preamble_type < 3) {
666                         strWIDList[u8WidCnt].id = WID_PREAMBLE;
667                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
668                         strWIDList[u8WidCnt].type = WID_CHAR;
669                         strWIDList[u8WidCnt].size = sizeof(char);
670                         hif_drv->strCfgValues.preamble_type = strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
671                 } else {
672                         PRINT_ER("Preamle Range(0~2) over\n");
673                         s32Error = -EINVAL;
674                         goto ERRORHANDLER;
675                 }
676                 u8WidCnt++;
677         }
678         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SHORT_SLOT_ALLOWED) {
679                 if (strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed < 2) {
680                         strWIDList[u8WidCnt].id = WID_SHORT_SLOT_ALLOWED;
681                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
682                         strWIDList[u8WidCnt].type = WID_CHAR;
683                         strWIDList[u8WidCnt].size = sizeof(char);
684                         hif_drv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
685                 } else {
686                         PRINT_ER("Short slot(2) over\n");
687                         s32Error = -EINVAL;
688                         goto ERRORHANDLER;
689                 }
690                 u8WidCnt++;
691         }
692         if (strHostIFCfgParamAttr->cfg_attr_info.flag & TXOP_PROT_DISABLE) {
693                 if (strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled < 2) {
694                         strWIDList[u8WidCnt].id = WID_11N_TXOP_PROT_DISABLE;
695                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
696                         strWIDList[u8WidCnt].type = WID_CHAR;
697                         strWIDList[u8WidCnt].size = sizeof(char);
698                         hif_drv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
699                 } else {
700                         PRINT_ER("TXOP prot disable\n");
701                         s32Error = -EINVAL;
702                         goto ERRORHANDLER;
703                 }
704                 u8WidCnt++;
705         }
706         if (strHostIFCfgParamAttr->cfg_attr_info.flag & BEACON_INTERVAL) {
707                 if (strHostIFCfgParamAttr->cfg_attr_info.beacon_interval > 0 && strHostIFCfgParamAttr->cfg_attr_info.beacon_interval < 65536) {
708                         strWIDList[u8WidCnt].id = WID_BEACON_INTERVAL;
709                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
710                         strWIDList[u8WidCnt].type = WID_SHORT;
711                         strWIDList[u8WidCnt].size = sizeof(u16);
712                         hif_drv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
713                 } else {
714                         PRINT_ER("Beacon interval(1~65535) fail\n");
715                         s32Error = -EINVAL;
716                         goto ERRORHANDLER;
717                 }
718                 u8WidCnt++;
719         }
720         if (strHostIFCfgParamAttr->cfg_attr_info.flag & DTIM_PERIOD) {
721                 if (strHostIFCfgParamAttr->cfg_attr_info.dtim_period > 0 && strHostIFCfgParamAttr->cfg_attr_info.dtim_period < 256) {
722                         strWIDList[u8WidCnt].id = WID_DTIM_PERIOD;
723                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
724                         strWIDList[u8WidCnt].type = WID_CHAR;
725                         strWIDList[u8WidCnt].size = sizeof(char);
726                         hif_drv->strCfgValues.dtim_period = strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
727                 } else {
728                         PRINT_ER("DTIM range(1~255) fail\n");
729                         s32Error = -EINVAL;
730                         goto ERRORHANDLER;
731                 }
732                 u8WidCnt++;
733         }
734         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY) {
735                 if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled < 3) {
736                         strWIDList[u8WidCnt].id = WID_SITE_SURVEY;
737                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
738                         strWIDList[u8WidCnt].type = WID_CHAR;
739                         strWIDList[u8WidCnt].size = sizeof(char);
740                         hif_drv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
741                 } else {
742                         PRINT_ER("Site survey disable\n");
743                         s32Error = -EINVAL;
744                         goto ERRORHANDLER;
745                 }
746                 u8WidCnt++;
747         }
748         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY_SCAN_TIME) {
749                 if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time < 65536) {
750                         strWIDList[u8WidCnt].id = WID_SITE_SURVEY_SCAN_TIME;
751                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
752                         strWIDList[u8WidCnt].type = WID_SHORT;
753                         strWIDList[u8WidCnt].size = sizeof(u16);
754                         hif_drv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
755                 } else {
756                         PRINT_ER("Site survey scan time(1~65535) over\n");
757                         s32Error = -EINVAL;
758                         goto ERRORHANDLER;
759                 }
760                 u8WidCnt++;
761         }
762         if (strHostIFCfgParamAttr->cfg_attr_info.flag & ACTIVE_SCANTIME) {
763                 if (strHostIFCfgParamAttr->cfg_attr_info.active_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.active_scan_time < 65536) {
764                         strWIDList[u8WidCnt].id = WID_ACTIVE_SCAN_TIME;
765                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
766                         strWIDList[u8WidCnt].type = WID_SHORT;
767                         strWIDList[u8WidCnt].size = sizeof(u16);
768                         hif_drv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
769                 } else {
770                         PRINT_ER("Active scan time(1~65535) over\n");
771                         s32Error = -EINVAL;
772                         goto ERRORHANDLER;
773                 }
774                 u8WidCnt++;
775         }
776         if (strHostIFCfgParamAttr->cfg_attr_info.flag & PASSIVE_SCANTIME) {
777                 if (strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time < 65536) {
778                         strWIDList[u8WidCnt].id = WID_PASSIVE_SCAN_TIME;
779                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
780                         strWIDList[u8WidCnt].type = WID_SHORT;
781                         strWIDList[u8WidCnt].size = sizeof(u16);
782                         hif_drv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
783                 } else {
784                         PRINT_ER("Passive scan time(1~65535) over\n");
785                         s32Error = -EINVAL;
786                         goto ERRORHANDLER;
787                 }
788                 u8WidCnt++;
789         }
790         if (strHostIFCfgParamAttr->cfg_attr_info.flag & CURRENT_TX_RATE) {
791                 enum CURRENT_TXRATE curr_tx_rate = strHostIFCfgParamAttr->cfg_attr_info.curr_tx_rate;
792                 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1
793                     || curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5
794                     || curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6
795                     || curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12
796                     || curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24
797                     || curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 || curr_tx_rate == MBPS_54) {
798                         strWIDList[u8WidCnt].id = WID_CURRENT_TX_RATE;
799                         strWIDList[u8WidCnt].val = (s8 *)&curr_tx_rate;
800                         strWIDList[u8WidCnt].type = WID_SHORT;
801                         strWIDList[u8WidCnt].size = sizeof(u16);
802                         hif_drv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate;
803                 } else {
804                         PRINT_ER("out of TX rate\n");
805                         s32Error = -EINVAL;
806                         goto ERRORHANDLER;
807                 }
808                 u8WidCnt++;
809         }
810         s32Error = send_config_pkt(SET_CFG, strWIDList, u8WidCnt,
811                                    get_id_from_handler(hif_drv));
812
813         if (s32Error)
814                 PRINT_ER("Error in setting CFG params\n");
815
816 ERRORHANDLER:
817         up(&hif_drv->gtOsCfgValuesSem);
818         return s32Error;
819 }
820
821 static s32 Handle_wait_msg_q_empty(void)
822 {
823         g_wilc_initialized = 0;
824         up(&hWaitResponse);
825         return 0;
826 }
827
828 static s32 Handle_Scan(struct host_if_drv *hif_drv,
829                        struct scan_attr *pstrHostIFscanAttr)
830 {
831         s32 s32Error = 0;
832         struct wid strWIDList[5];
833         u32 u32WidsCount = 0;
834         u32 i;
835         u8 *pu8Buffer;
836         u8 valuesize = 0;
837         u8 *pu8HdnNtwrksWidVal = NULL;
838
839         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
840         PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", hif_drv->enuHostIFstate);
841
842         hif_drv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->result;
843         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->arg;
844
845         if ((hif_drv->enuHostIFstate >= HOST_IF_SCANNING) && (hif_drv->enuHostIFstate < HOST_IF_CONNECTED)) {
846                 PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", hif_drv->enuHostIFstate);
847                 PRINT_ER("Already scan\n");
848                 s32Error = -EBUSY;
849                 goto ERRORHANDLER;
850         }
851
852         if (g_obtainingIP || connecting) {
853                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
854                 PRINT_ER("Don't do obss scan\n");
855                 s32Error = -EBUSY;
856                 goto ERRORHANDLER;
857         }
858
859         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
860
861
862         hif_drv->strWILC_UsrScanReq.u32RcvdChCount = 0;
863
864         strWIDList[u32WidsCount].id = (u16)WID_SSID_PROBE_REQ;
865         strWIDList[u32WidsCount].type = WID_STR;
866
867         for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++)
868                 valuesize += ((pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
869         pu8HdnNtwrksWidVal = kmalloc(valuesize + 1, GFP_KERNEL);
870         strWIDList[u32WidsCount].val = pu8HdnNtwrksWidVal;
871         if (strWIDList[u32WidsCount].val != NULL) {
872                 pu8Buffer = strWIDList[u32WidsCount].val;
873
874                 *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.u8ssidnum;
875
876                 PRINT_D(HOSTINF_DBG, "In Handle_ProbeRequest number of ssid %d\n", pstrHostIFscanAttr->hidden_network.u8ssidnum);
877
878                 for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++) {
879                         *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
880                         memcpy(pu8Buffer, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen);
881                         pu8Buffer += pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
882                 }
883
884
885
886                 strWIDList[u32WidsCount].size = (s32)(valuesize + 1);
887                 u32WidsCount++;
888         }
889
890         {
891                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_PROBE;
892                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
893                 strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ies;
894                 strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ies_len;
895                 u32WidsCount++;
896         }
897
898         strWIDList[u32WidsCount].id = WID_SCAN_TYPE;
899         strWIDList[u32WidsCount].type = WID_CHAR;
900         strWIDList[u32WidsCount].size = sizeof(char);
901         strWIDList[u32WidsCount].val = (s8 *)(&(pstrHostIFscanAttr->type));
902         u32WidsCount++;
903
904         strWIDList[u32WidsCount].id = WID_SCAN_CHANNEL_LIST;
905         strWIDList[u32WidsCount].type = WID_BIN_DATA;
906
907         if (pstrHostIFscanAttr->ch_freq_list != NULL && pstrHostIFscanAttr->ch_list_len > 0) {
908                 int i;
909
910                 for (i = 0; i < pstrHostIFscanAttr->ch_list_len; i++)   {
911                         if (pstrHostIFscanAttr->ch_freq_list[i] > 0)
912                                 pstrHostIFscanAttr->ch_freq_list[i] = pstrHostIFscanAttr->ch_freq_list[i] - 1;
913                 }
914         }
915
916         strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ch_freq_list;
917         strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ch_list_len;
918         u32WidsCount++;
919
920         strWIDList[u32WidsCount].id = WID_START_SCAN_REQ;
921         strWIDList[u32WidsCount].type = WID_CHAR;
922         strWIDList[u32WidsCount].size = sizeof(char);
923         strWIDList[u32WidsCount].val = (s8 *)(&(pstrHostIFscanAttr->src));
924         u32WidsCount++;
925
926         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
927                 gbScanWhileConnected = true;
928         else if (hif_drv->enuHostIFstate == HOST_IF_IDLE)
929                 gbScanWhileConnected = false;
930
931         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
932                                    get_id_from_handler(hif_drv));
933
934         if (s32Error)
935                 PRINT_ER("Failed to send scan paramters config packet\n");
936         else
937                 PRINT_D(HOSTINF_DBG, "Successfully sent SCAN params config packet\n");
938
939 ERRORHANDLER:
940         if (s32Error) {
941                 del_timer(&hif_drv->hScanTimer);
942                 Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
943         }
944
945         if (pstrHostIFscanAttr->ch_freq_list != NULL) {
946                 kfree(pstrHostIFscanAttr->ch_freq_list);
947                 pstrHostIFscanAttr->ch_freq_list = NULL;
948         }
949
950         if (pstrHostIFscanAttr->ies != NULL) {
951                 kfree(pstrHostIFscanAttr->ies);
952                 pstrHostIFscanAttr->ies = NULL;
953         }
954         if (pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo != NULL)   {
955                 kfree(pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo);
956                 pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo = NULL;
957         }
958
959         if (pu8HdnNtwrksWidVal != NULL)
960                 kfree(pu8HdnNtwrksWidVal);
961
962         return s32Error;
963 }
964
965 static s32 Handle_ScanDone(struct host_if_drv *hif_drv,
966                            enum scan_event enuEvent)
967 {
968         s32 s32Error = 0;
969         u8 u8abort_running_scan;
970         struct wid strWID;
971
972
973         PRINT_D(HOSTINF_DBG, "in Handle_ScanDone()\n");
974
975         if (enuEvent == SCAN_EVENT_ABORTED) {
976                 PRINT_D(GENERIC_DBG, "Abort running scan\n");
977                 u8abort_running_scan = 1;
978                 strWID.id = (u16)WID_ABORT_RUNNING_SCAN;
979                 strWID.type = WID_CHAR;
980                 strWID.val = (s8 *)&u8abort_running_scan;
981                 strWID.size = sizeof(char);
982
983                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
984                                            get_id_from_handler(hif_drv));
985                 if (s32Error) {
986                         PRINT_ER("Failed to set abort running scan\n");
987                         s32Error = -EFAULT;
988                 }
989         }
990
991         if (!hif_drv) {
992                 PRINT_ER("Driver handler is NULL\n");
993                 return s32Error;
994         }
995
996         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
997                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(enuEvent, NULL,
998                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
999                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
1000         }
1001
1002         return s32Error;
1003 }
1004
1005 u8 u8ConnectedSSID[6] = {0};
1006 static s32 Handle_Connect(struct host_if_drv *hif_drv,
1007                           struct connect_attr *pstrHostIFconnectAttr)
1008 {
1009         s32 s32Error = 0;
1010         struct wid strWIDList[8];
1011         u32 u32WidsCount = 0, dummyval = 0;
1012         u8 *pu8CurrByte = NULL;
1013         struct join_bss_param *ptstrJoinBssParam;
1014
1015         PRINT_D(GENERIC_DBG, "Handling connect request\n");
1016
1017         if (memcmp(pstrHostIFconnectAttr->bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
1018
1019                 s32Error = 0;
1020                 PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n");
1021                 return s32Error;
1022         }
1023
1024         PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
1025
1026         ptstrJoinBssParam = (struct join_bss_param *)pstrHostIFconnectAttr->params;
1027         if (ptstrJoinBssParam == NULL) {
1028                 PRINT_ER("Required BSSID not found\n");
1029                 s32Error = -ENOENT;
1030                 goto ERRORHANDLER;
1031         }
1032
1033         if (pstrHostIFconnectAttr->bssid != NULL) {
1034                 hif_drv->strWILC_UsrConnReq.pu8bssid = kmalloc(6, GFP_KERNEL);
1035                 memcpy(hif_drv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->bssid, 6);
1036         }
1037
1038         hif_drv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssid_len;
1039         if (pstrHostIFconnectAttr->ssid != NULL) {
1040                 hif_drv->strWILC_UsrConnReq.pu8ssid = kmalloc(pstrHostIFconnectAttr->ssid_len + 1, GFP_KERNEL);
1041                 memcpy(hif_drv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->ssid,
1042                             pstrHostIFconnectAttr->ssid_len);
1043                 hif_drv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssid_len] = '\0';
1044         }
1045
1046         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->ies_len;
1047         if (pstrHostIFconnectAttr->ies != NULL) {
1048                 hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
1049                 memcpy(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->ies,
1050                             pstrHostIFconnectAttr->ies_len);
1051         }
1052
1053         hif_drv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->security;
1054         hif_drv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->auth_type;
1055         hif_drv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->result;
1056         hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->arg;
1057
1058         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
1059         strWIDList[u32WidsCount].type = WID_INT;
1060         strWIDList[u32WidsCount].size = sizeof(u32);
1061         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1062         u32WidsCount++;
1063
1064         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
1065         strWIDList[u32WidsCount].type = WID_INT;
1066         strWIDList[u32WidsCount].size = sizeof(u32);
1067         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1068         u32WidsCount++;
1069
1070         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
1071         strWIDList[u32WidsCount].type = WID_INT;
1072         strWIDList[u32WidsCount].size = sizeof(u32);
1073         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1074         u32WidsCount++;
1075
1076         {
1077                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
1078                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
1079                 strWIDList[u32WidsCount].val = hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs;
1080                 strWIDList[u32WidsCount].size = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1081                 u32WidsCount++;
1082
1083                 if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1084
1085                         gu32FlushedInfoElemAsocSize = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1086                         gu8FlushedInfoElemAsoc =  kmalloc(gu32FlushedInfoElemAsocSize, GFP_KERNEL);
1087                         memcpy(gu8FlushedInfoElemAsoc, hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1088                                gu32FlushedInfoElemAsocSize);
1089                 }
1090         }
1091         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1092         strWIDList[u32WidsCount].type = WID_CHAR;
1093         strWIDList[u32WidsCount].size = sizeof(char);
1094         strWIDList[u32WidsCount].val = (s8 *)(&(hif_drv->strWILC_UsrConnReq.u8security));
1095         u32WidsCount++;
1096
1097         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
1098                 gu8Flushed11iMode = hif_drv->strWILC_UsrConnReq.u8security;
1099
1100         PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", hif_drv->strWILC_UsrConnReq.u8security);
1101
1102
1103         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1104         strWIDList[u32WidsCount].type = WID_CHAR;
1105         strWIDList[u32WidsCount].size = sizeof(char);
1106         strWIDList[u32WidsCount].val = (s8 *)(&hif_drv->strWILC_UsrConnReq.tenuAuth_type);
1107         u32WidsCount++;
1108
1109         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
1110                 gu8FlushedAuthType = (u8)hif_drv->strWILC_UsrConnReq.tenuAuth_type;
1111
1112         PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", hif_drv->strWILC_UsrConnReq.tenuAuth_type);
1113         PRINT_D(HOSTINF_DBG, "Connecting to network of SSID %s on channel %d\n",
1114                 hif_drv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->ch);
1115
1116         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1117         strWIDList[u32WidsCount].type = WID_STR;
1118         strWIDList[u32WidsCount].size = 112;
1119         strWIDList[u32WidsCount].val = kmalloc(strWIDList[u32WidsCount].size, GFP_KERNEL);
1120
1121         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1122                 gu32FlushedJoinReqSize = strWIDList[u32WidsCount].size;
1123                 gu8FlushedJoinReq = kmalloc(gu32FlushedJoinReqSize, GFP_KERNEL);
1124         }
1125         if (strWIDList[u32WidsCount].val == NULL) {
1126                 s32Error = -EFAULT;
1127                 goto ERRORHANDLER;
1128         }
1129
1130         pu8CurrByte = strWIDList[u32WidsCount].val;
1131
1132
1133         if (pstrHostIFconnectAttr->ssid != NULL) {
1134                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->ssid, pstrHostIFconnectAttr->ssid_len);
1135                 pu8CurrByte[pstrHostIFconnectAttr->ssid_len] = '\0';
1136         }
1137         pu8CurrByte += MAX_SSID_LEN;
1138         *(pu8CurrByte++) = INFRASTRUCTURE;
1139
1140         if ((pstrHostIFconnectAttr->ch >= 1) && (pstrHostIFconnectAttr->ch <= 14)) {
1141                 *(pu8CurrByte++) = pstrHostIFconnectAttr->ch;
1142         } else {
1143                 PRINT_ER("Channel out of range\n");
1144                 *(pu8CurrByte++) = 0xFF;
1145         }
1146         *(pu8CurrByte++)  = (ptstrJoinBssParam->cap_info) & 0xFF;
1147         *(pu8CurrByte++)  = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
1148         PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1149
1150         if (pstrHostIFconnectAttr->bssid != NULL)
1151                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1152         pu8CurrByte += 6;
1153
1154         *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
1155         *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1156         PRINT_D(HOSTINF_DBG, "* Beacon Period %d*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1157         *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
1158         PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
1159
1160         memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1161         pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1162
1163         *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
1164         PRINT_D(HOSTINF_DBG, "* wmm cap%d*\n", (*(pu8CurrByte - 1)));
1165         *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
1166
1167         *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
1168         hif_drv->strWILC_UsrConnReq.IsHTCapable = ptstrJoinBssParam->ht_capable;
1169
1170         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
1171         PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1));
1172         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
1173         PRINT_D(HOSTINF_DBG, "* rsn group policy %0x*\n", (*(pu8CurrByte - 1)));
1174         *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
1175         PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
1176
1177         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1178         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1179
1180         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1181         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1182
1183         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1184         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1185
1186         *(pu8CurrByte++) = REAL_JOIN_REQ;
1187
1188         *(pu8CurrByte++) = ptstrJoinBssParam->u8NoaEnbaled;
1189         if (ptstrJoinBssParam->u8NoaEnbaled) {
1190                 PRINT_D(HOSTINF_DBG, "NOA present\n");
1191
1192                 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1193                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1194                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1195                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1196
1197                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Index;
1198
1199                 *(pu8CurrByte++) = ptstrJoinBssParam->u8OppEnable;
1200
1201                 if (ptstrJoinBssParam->u8OppEnable)
1202                         *(pu8CurrByte++) = ptstrJoinBssParam->u8CtWindow;
1203
1204                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
1205
1206                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
1207
1208                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
1209
1210                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
1211
1212                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
1213
1214                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
1215
1216                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
1217
1218         } else
1219                 PRINT_D(HOSTINF_DBG, "NOA not present\n");
1220
1221         pu8CurrByte = strWIDList[u32WidsCount].val;
1222         u32WidsCount++;
1223         gu32WidConnRstHack = 0;
1224
1225         if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
1226                 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
1227                 gu8FlushedJoinReqDrvHandler = hif_drv;
1228         }
1229
1230         PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
1231
1232         if (pstrHostIFconnectAttr->bssid != NULL) {
1233                 memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->bssid, ETH_ALEN);
1234
1235                 PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", pstrHostIFconnectAttr->bssid);
1236                 PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID);
1237         }
1238
1239         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1240                                    get_id_from_handler(hif_drv));
1241         if (s32Error) {
1242                 PRINT_ER("failed to send config packet\n");
1243                 s32Error = -EFAULT;
1244                 goto ERRORHANDLER;
1245         } else {
1246                 PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n");
1247                 hif_drv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
1248         }
1249
1250 ERRORHANDLER:
1251         if (s32Error) {
1252                 tstrConnectInfo strConnectInfo;
1253
1254                 del_timer(&hif_drv->hConnectTimer);
1255
1256                 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
1257
1258                 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1259
1260                 if (pstrHostIFconnectAttr->result != NULL) {
1261                         if (pstrHostIFconnectAttr->bssid != NULL)
1262                                 memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->bssid, 6);
1263
1264                         if (pstrHostIFconnectAttr->ies != NULL) {
1265                                 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->ies_len;
1266                                 strConnectInfo.pu8ReqIEs = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
1267                                 memcpy(strConnectInfo.pu8ReqIEs,
1268                                             pstrHostIFconnectAttr->ies,
1269                                             pstrHostIFconnectAttr->ies_len);
1270                         }
1271
1272                         pstrHostIFconnectAttr->result(CONN_DISCONN_EVENT_CONN_RESP,
1273                                                                &strConnectInfo,
1274                                                                MAC_DISCONNECTED,
1275                                                                NULL,
1276                                                                pstrHostIFconnectAttr->arg);
1277                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1278                         if (strConnectInfo.pu8ReqIEs != NULL) {
1279                                 kfree(strConnectInfo.pu8ReqIEs);
1280                                 strConnectInfo.pu8ReqIEs = NULL;
1281                         }
1282
1283                 } else {
1284                         PRINT_ER("Connect callback function pointer is NULL\n");
1285                 }
1286         }
1287
1288         PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
1289         if (pstrHostIFconnectAttr->bssid != NULL) {
1290                 kfree(pstrHostIFconnectAttr->bssid);
1291                 pstrHostIFconnectAttr->bssid = NULL;
1292         }
1293
1294         if (pstrHostIFconnectAttr->ssid != NULL) {
1295                 kfree(pstrHostIFconnectAttr->ssid);
1296                 pstrHostIFconnectAttr->ssid = NULL;
1297         }
1298
1299         if (pstrHostIFconnectAttr->ies != NULL) {
1300                 kfree(pstrHostIFconnectAttr->ies);
1301                 pstrHostIFconnectAttr->ies = NULL;
1302         }
1303
1304         if (pu8CurrByte != NULL)
1305                 kfree(pu8CurrByte);
1306         return s32Error;
1307 }
1308
1309 static s32 Handle_FlushConnect(struct host_if_drv *hif_drv)
1310 {
1311         s32 s32Error = 0;
1312         struct wid strWIDList[5];
1313         u32 u32WidsCount = 0;
1314         u8 *pu8CurrByte = NULL;
1315
1316         strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
1317         strWIDList[u32WidsCount].type = WID_BIN_DATA;
1318         strWIDList[u32WidsCount].val = gu8FlushedInfoElemAsoc;
1319         strWIDList[u32WidsCount].size = gu32FlushedInfoElemAsocSize;
1320         u32WidsCount++;
1321
1322         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1323         strWIDList[u32WidsCount].type = WID_CHAR;
1324         strWIDList[u32WidsCount].size = sizeof(char);
1325         strWIDList[u32WidsCount].val = (s8 *)(&(gu8Flushed11iMode));
1326         u32WidsCount++;
1327
1328
1329
1330         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1331         strWIDList[u32WidsCount].type = WID_CHAR;
1332         strWIDList[u32WidsCount].size = sizeof(char);
1333         strWIDList[u32WidsCount].val = (s8 *)(&gu8FlushedAuthType);
1334         u32WidsCount++;
1335
1336         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1337         strWIDList[u32WidsCount].type = WID_STR;
1338         strWIDList[u32WidsCount].size = gu32FlushedJoinReqSize;
1339         strWIDList[u32WidsCount].val = (s8 *)gu8FlushedJoinReq;
1340         pu8CurrByte = strWIDList[u32WidsCount].val;
1341
1342         pu8CurrByte += FLUSHED_BYTE_POS;
1343         *(pu8CurrByte) = FLUSHED_JOIN_REQ;
1344
1345         u32WidsCount++;
1346
1347         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1348                                    get_id_from_handler(gu8FlushedJoinReqDrvHandler));
1349         if (s32Error) {
1350                 PRINT_ER("failed to send config packet\n");
1351                 s32Error = -EINVAL;
1352         }
1353
1354         return s32Error;
1355 }
1356
1357 static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv)
1358 {
1359         s32 s32Error = 0;
1360         tstrConnectInfo strConnectInfo;
1361         struct wid strWID;
1362         u16 u16DummyReasonCode = 0;
1363
1364         if (!hif_drv) {
1365                 PRINT_ER("Driver handler is NULL\n");
1366                 return s32Error;
1367         }
1368
1369         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1370
1371         gbScanWhileConnected = false;
1372
1373
1374         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1375
1376         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1377                 if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1378                         memcpy(strConnectInfo.au8bssid,
1379                                     hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1380                 }
1381
1382                 if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1383                         strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1384                         strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1385                         memcpy(strConnectInfo.pu8ReqIEs,
1386                                     hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1387                                     hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1388                 }
1389
1390                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1391                                                                    &strConnectInfo,
1392                                                                    MAC_DISCONNECTED,
1393                                                                    NULL,
1394                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1395
1396                 if (strConnectInfo.pu8ReqIEs != NULL) {
1397                         kfree(strConnectInfo.pu8ReqIEs);
1398                         strConnectInfo.pu8ReqIEs = NULL;
1399                 }
1400         } else {
1401                 PRINT_ER("Connect callback function pointer is NULL\n");
1402         }
1403
1404         strWID.id = (u16)WID_DISCONNECT;
1405         strWID.type = WID_CHAR;
1406         strWID.val = (s8 *)&u16DummyReasonCode;
1407         strWID.size = sizeof(char);
1408
1409         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
1410
1411         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1412                                    get_id_from_handler(hif_drv));
1413         if (s32Error)
1414                 PRINT_ER("Failed to send dissconect config packet\n");
1415
1416         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1417         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1418         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1419         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1420         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1421
1422         eth_zero_addr(u8ConnectedSSID);
1423
1424         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1425                 kfree(gu8FlushedJoinReq);
1426                 gu8FlushedJoinReq = NULL;
1427         }
1428         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1429                 kfree(gu8FlushedInfoElemAsoc);
1430                 gu8FlushedInfoElemAsoc = NULL;
1431         }
1432
1433         return s32Error;
1434 }
1435
1436 static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv,
1437                                 struct rcvd_net_info *pstrRcvdNetworkInfo)
1438 {
1439         u32 i;
1440         bool bNewNtwrkFound;
1441
1442
1443
1444         s32 s32Error = 0;
1445         tstrNetworkInfo *pstrNetworkInfo = NULL;
1446         void *pJoinParams = NULL;
1447
1448         bNewNtwrkFound = true;
1449         PRINT_INFO(HOSTINF_DBG, "Handling received network info\n");
1450
1451         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1452                 PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n");
1453                 parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo);
1454                 if ((pstrNetworkInfo == NULL)
1455                     || (hif_drv->strWILC_UsrScanReq.pfUserScanResult == NULL)) {
1456                         PRINT_ER("driver is null\n");
1457                         s32Error = -EINVAL;
1458                         goto done;
1459                 }
1460
1461                 for (i = 0; i < hif_drv->strWILC_UsrScanReq.u32RcvdChCount; i++) {
1462
1463                         if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
1464                             (pstrNetworkInfo->au8bssid != NULL)) {
1465                                 if (memcmp(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
1466                                                 pstrNetworkInfo->au8bssid, 6) == 0) {
1467                                         if (pstrNetworkInfo->s8rssi <= hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
1468                                                 PRINT_D(HOSTINF_DBG, "Network previously discovered\n");
1469                                                 goto done;
1470                                         } else {
1471                                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
1472                                                 bNewNtwrkFound = false;
1473                                                 break;
1474                                         }
1475                                 }
1476                         }
1477                 }
1478
1479                 if (bNewNtwrkFound == true) {
1480                         PRINT_D(HOSTINF_DBG, "New network found\n");
1481
1482                         if (hif_drv->strWILC_UsrScanReq.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
1483                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
1484
1485                                 if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
1486                                     && (pstrNetworkInfo->au8bssid != NULL)) {
1487                                         memcpy(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
1488                                                     pstrNetworkInfo->au8bssid, 6);
1489
1490                                         hif_drv->strWILC_UsrScanReq.u32RcvdChCount++;
1491
1492                                         pstrNetworkInfo->bNewNetwork = true;
1493                                         pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
1494
1495                                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1496                                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid,
1497                                                                                         pJoinParams);
1498
1499
1500                                 }
1501                         } else {
1502                                 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n");
1503                         }
1504                 } else {
1505                         pstrNetworkInfo->bNewNetwork = false;
1506                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1507                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
1508                 }
1509         }
1510
1511 done:
1512         if (pstrRcvdNetworkInfo->buffer != NULL) {
1513                 kfree(pstrRcvdNetworkInfo->buffer);
1514                 pstrRcvdNetworkInfo->buffer = NULL;
1515         }
1516
1517         if (pstrNetworkInfo != NULL) {
1518                 DeallocateNetworkInfo(pstrNetworkInfo);
1519                 pstrNetworkInfo = NULL;
1520         }
1521
1522         return s32Error;
1523 }
1524
1525 static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv,
1526                                     struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
1527 {
1528         s32 s32Error = 0;
1529         u8 u8MsgType = 0;
1530         u8 u8MsgID = 0;
1531         u16 u16MsgLen = 0;
1532         u16 u16WidID = (u16)WID_NIL;
1533         u8 u8WidLen  = 0;
1534         u8 u8MacStatus;
1535         u8 u8MacStatusReasonCode;
1536         u8 u8MacStatusAdditionalInfo;
1537         tstrConnectInfo strConnectInfo;
1538         tstrDisconnectNotifInfo strDisconnectNotifInfo;
1539         s32 s32Err = 0;
1540
1541         if (!hif_drv) {
1542                 PRINT_ER("Driver handler is NULL\n");
1543                 return -ENODEV;
1544         }
1545         PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", hif_drv->enuHostIFstate,
1546                 pstrRcvdGnrlAsyncInfo->buffer[7]);
1547
1548         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
1549             (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) ||
1550             hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1551                 if ((pstrRcvdGnrlAsyncInfo->buffer == NULL) ||
1552                     (hif_drv->strWILC_UsrConnReq.pfUserConnectResult == NULL)) {
1553                         PRINT_ER("driver is null\n");
1554                         return -EINVAL;
1555                 }
1556
1557                 u8MsgType = pstrRcvdGnrlAsyncInfo->buffer[0];
1558
1559                 if ('I' != u8MsgType) {
1560                         PRINT_ER("Received Message format incorrect.\n");
1561                         return -EFAULT;
1562                 }
1563
1564                 u8MsgID = pstrRcvdGnrlAsyncInfo->buffer[1];
1565                 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[2], pstrRcvdGnrlAsyncInfo->buffer[3]);
1566                 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[4], pstrRcvdGnrlAsyncInfo->buffer[5]);
1567                 u8WidLen = pstrRcvdGnrlAsyncInfo->buffer[6];
1568                 u8MacStatus  = pstrRcvdGnrlAsyncInfo->buffer[7];
1569                 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->buffer[8];
1570                 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->buffer[9];
1571                 PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1572                 if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
1573                         u32 u32RcvdAssocRespInfoLen;
1574                         tstrConnectRespInfo *pstrConnectRespInfo = NULL;
1575
1576                         PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1577
1578                         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1579
1580                         if (u8MacStatus == MAC_CONNECTED) {
1581                                 memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1582
1583                                 host_int_get_assoc_res_info(hif_drv,
1584                                                             gapu8RcvdAssocResp,
1585                                                             MAX_ASSOC_RESP_FRAME_SIZE,
1586                                                             &u32RcvdAssocRespInfoLen);
1587
1588                                 PRINT_INFO(HOSTINF_DBG, "Received association response with length = %d\n", u32RcvdAssocRespInfoLen);
1589
1590                                 if (u32RcvdAssocRespInfoLen != 0) {
1591
1592                                         PRINT_D(HOSTINF_DBG, "Parsing association response\n");
1593                                         s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
1594                                                                     &pstrConnectRespInfo);
1595                                         if (s32Err) {
1596                                                 PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err);
1597                                         } else {
1598                                                 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
1599
1600                                                 if (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
1601                                                         PRINT_INFO(HOSTINF_DBG, "Association response received : Successful connection status\n");
1602                                                         if (pstrConnectRespInfo->pu8RespIEs != NULL) {
1603                                                                 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
1604
1605
1606                                                                 strConnectInfo.pu8RespIEs = kmalloc(pstrConnectRespInfo->u16RespIEsLen, GFP_KERNEL);
1607                                                                 memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
1608                                                                             pstrConnectRespInfo->u16RespIEsLen);
1609                                                         }
1610                                                 }
1611
1612                                                 if (pstrConnectRespInfo != NULL) {
1613                                                         DeallocateAssocRespInfo(pstrConnectRespInfo);
1614                                                         pstrConnectRespInfo = NULL;
1615                                                 }
1616                                         }
1617                                 }
1618                         }
1619
1620                         if ((u8MacStatus == MAC_CONNECTED) &&
1621                             (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
1622                                 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1623                                 eth_zero_addr(u8ConnectedSSID);
1624
1625                         } else if (u8MacStatus == MAC_DISCONNECTED)    {
1626                                 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
1627                                 eth_zero_addr(u8ConnectedSSID);
1628                         }
1629
1630                         if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1631                                 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
1632                                 memcpy(strConnectInfo.au8bssid, hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1633
1634                                 if ((u8MacStatus == MAC_CONNECTED) &&
1635                                     (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1636                                         memcpy(hif_drv->au8AssociatedBSSID,
1637                                                     hif_drv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
1638                                 }
1639                         }
1640
1641
1642                         if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1643                                 strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1644                                 strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1645                                 memcpy(strConnectInfo.pu8ReqIEs,
1646                                             hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1647                                             hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1648                         }
1649
1650
1651                         del_timer(&hif_drv->hConnectTimer);
1652                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1653                                                                            &strConnectInfo,
1654                                                                            u8MacStatus,
1655                                                                            NULL,
1656                                                                            hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1657
1658                         if ((u8MacStatus == MAC_CONNECTED) &&
1659                             (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1660                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1661
1662                                 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
1663                                 hif_drv->enuHostIFstate = HOST_IF_CONNECTED;
1664
1665                                 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
1666                                 g_obtainingIP = true;
1667                                 mod_timer(&hDuringIpTimer,
1668                                           jiffies + msecs_to_jiffies(10000));
1669                         } else {
1670                                 PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus);
1671                                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
1672                                 gbScanWhileConnected = false;
1673                         }
1674
1675                         if (strConnectInfo.pu8RespIEs != NULL) {
1676                                 kfree(strConnectInfo.pu8RespIEs);
1677                                 strConnectInfo.pu8RespIEs = NULL;
1678                         }
1679
1680                         if (strConnectInfo.pu8ReqIEs != NULL) {
1681                                 kfree(strConnectInfo.pu8ReqIEs);
1682                                 strConnectInfo.pu8ReqIEs = NULL;
1683                         }
1684                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1685                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1686                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1687                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1688                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1689                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1690                            (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)) {
1691                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
1692
1693                         memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
1694
1695                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1696                                 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n");
1697                                 del_timer(&hif_drv->hScanTimer);
1698                                 Handle_ScanDone((void *)hif_drv, SCAN_EVENT_ABORTED);
1699                         }
1700
1701                         strDisconnectNotifInfo.u16reason = 0;
1702                         strDisconnectNotifInfo.ie = NULL;
1703                         strDisconnectNotifInfo.ie_len = 0;
1704
1705                         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1706                                 g_obtainingIP = false;
1707                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1708
1709                                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1710                                                                                    NULL,
1711                                                                                    0,
1712                                                                                    &strDisconnectNotifInfo,
1713                                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1714
1715                         } else {
1716                                 PRINT_ER("Connect result callback function is NULL\n");
1717                         }
1718
1719                         eth_zero_addr(hif_drv->au8AssociatedBSSID);
1720
1721                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1722                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1723                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1724                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1725                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1726
1727                         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1728                                 kfree(gu8FlushedJoinReq);
1729                                 gu8FlushedJoinReq = NULL;
1730                         }
1731                         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1732                                 kfree(gu8FlushedInfoElemAsoc);
1733                                 gu8FlushedInfoElemAsoc = NULL;
1734                         }
1735
1736                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1737                         gbScanWhileConnected = false;
1738
1739                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1740                            (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
1741                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
1742                         PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n");
1743
1744                         del_timer(&hif_drv->hScanTimer);
1745                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult)
1746                                 Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
1747
1748                 }
1749
1750         }
1751
1752         if (pstrRcvdGnrlAsyncInfo->buffer != NULL) {
1753                 kfree(pstrRcvdGnrlAsyncInfo->buffer);
1754                 pstrRcvdGnrlAsyncInfo->buffer = NULL;
1755         }
1756
1757         return s32Error;
1758 }
1759
1760 static int Handle_Key(struct host_if_drv *hif_drv,
1761                       struct key_attr *pstrHostIFkeyAttr)
1762 {
1763         s32 s32Error = 0;
1764         struct wid strWID;
1765         struct wid strWIDList[5];
1766         u8 i;
1767         u8 *pu8keybuf;
1768         s8 s8idxarray[1];
1769         s8 ret = 0;
1770
1771         switch (pstrHostIFkeyAttr->type) {
1772
1773
1774         case WEP:
1775
1776                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1777
1778                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1779                         PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", (pstrHostIFkeyAttr->attr.wep.index));
1780                         strWIDList[0].id = (u16)WID_11I_MODE;
1781                         strWIDList[0].type = WID_CHAR;
1782                         strWIDList[0].size = sizeof(char);
1783                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.mode));
1784
1785                         strWIDList[1].id = WID_AUTH_TYPE;
1786                         strWIDList[1].type = WID_CHAR;
1787                         strWIDList[1].size = sizeof(char);
1788                         strWIDList[1].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.auth_type));
1789
1790                         strWIDList[2].id = (u16)WID_KEY_ID;
1791                         strWIDList[2].type = WID_CHAR;
1792
1793                         strWIDList[2].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1794                         strWIDList[2].size = sizeof(char);
1795
1796                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len, GFP_KERNEL);
1797
1798                         if (pu8keybuf == NULL) {
1799                                 PRINT_ER("No buffer to send Key\n");
1800                                 return -1;
1801                         }
1802
1803                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wep.key,
1804                                     pstrHostIFkeyAttr->attr.wep.key_len);
1805
1806                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1807
1808                         strWIDList[3].id = (u16)WID_WEP_KEY_VALUE;
1809                         strWIDList[3].type = WID_STR;
1810                         strWIDList[3].size = pstrHostIFkeyAttr->attr.wep.key_len;
1811                         strWIDList[3].val = (s8 *)pu8keybuf;
1812
1813
1814                         s32Error = send_config_pkt(SET_CFG, strWIDList, 4,
1815                                                    get_id_from_handler(hif_drv));
1816                         kfree(pu8keybuf);
1817
1818
1819                 }
1820
1821                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1822                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1823                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
1824                         if (pu8keybuf == NULL) {
1825                                 PRINT_ER("No buffer to send Key\n");
1826                                 return -1;
1827                         }
1828                         pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1829                         memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
1830                         memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
1831                                     pstrHostIFkeyAttr->attr.wep.key_len);
1832                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1833
1834                         strWID.id = (u16)WID_ADD_WEP_KEY;
1835                         strWID.type = WID_STR;
1836                         strWID.val = (s8 *)pu8keybuf;
1837                         strWID.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1838
1839                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1840                                                    get_id_from_handler(hif_drv));
1841                         kfree(pu8keybuf);
1842                 } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
1843
1844                         PRINT_D(HOSTINF_DBG, "Removing key\n");
1845                         strWID.id = (u16)WID_REMOVE_WEP_KEY;
1846                         strWID.type = WID_STR;
1847
1848                         s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
1849                         strWID.val = s8idxarray;
1850                         strWID.size = 1;
1851
1852                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1853                                                    get_id_from_handler(hif_drv));
1854                 } else {
1855                         strWID.id = (u16)WID_KEY_ID;
1856                         strWID.type = WID_CHAR;
1857                         strWID.val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1858                         strWID.size = sizeof(char);
1859
1860                         PRINT_D(HOSTINF_DBG, "Setting default key index\n");
1861
1862                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1863                                                    get_id_from_handler(hif_drv));
1864                 }
1865                 up(&hif_drv->hSemTestKeyBlock);
1866                 break;
1867
1868         case WPARxGtk:
1869                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1870                         pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1871                         if (pu8keybuf == NULL) {
1872                                 PRINT_ER("No buffer to send RxGTK Key\n");
1873                                 ret = -1;
1874                                 goto _WPARxGtk_end_case_;
1875                         }
1876
1877                         if (pstrHostIFkeyAttr->attr.wpa.seq != NULL)
1878                                 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1879
1880                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1881                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1882                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1883                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1884
1885                         strWIDList[0].id = (u16)WID_11I_MODE;
1886                         strWIDList[0].type = WID_CHAR;
1887                         strWIDList[0].size = sizeof(char);
1888                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1889
1890                         strWIDList[1].id = (u16)WID_ADD_RX_GTK;
1891                         strWIDList[1].type = WID_STR;
1892                         strWIDList[1].val = (s8 *)pu8keybuf;
1893                         strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
1894
1895                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1896                                                    get_id_from_handler(hif_drv));
1897
1898                         kfree(pu8keybuf);
1899                         up(&hif_drv->hSemTestKeyBlock);
1900                 }
1901
1902                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1903                         PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
1904
1905                         pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1906                         if (pu8keybuf == NULL) {
1907                                 PRINT_ER("No buffer to send RxGTK Key\n");
1908                                 ret = -1;
1909                                 goto _WPARxGtk_end_case_;
1910                         }
1911
1912                         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
1913                                 memcpy(pu8keybuf, hif_drv->au8AssociatedBSSID, ETH_ALEN);
1914                         else
1915                                 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n");
1916
1917                         memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1918                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1919                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1920                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1921                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1922
1923                         strWID.id = (u16)WID_ADD_RX_GTK;
1924                         strWID.type = WID_STR;
1925                         strWID.val = (s8 *)pu8keybuf;
1926                         strWID.size = RX_MIC_KEY_MSG_LEN;
1927
1928                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1929                                                    get_id_from_handler(hif_drv));
1930
1931                         kfree(pu8keybuf);
1932                         up(&hif_drv->hSemTestKeyBlock);
1933                 }
1934 _WPARxGtk_end_case_:
1935                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1936                 kfree(pstrHostIFkeyAttr->attr.wpa.seq);
1937                 if (ret == -1)
1938                         return ret;
1939
1940                 break;
1941
1942         case WPAPtk:
1943                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1944
1945
1946                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1947
1948
1949
1950                         if (pu8keybuf == NULL) {
1951                                 PRINT_ER("No buffer to send PTK Key\n");
1952                                 ret = -1;
1953                                 goto _WPAPtk_end_case_;
1954
1955                         }
1956
1957                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1958                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1959                         memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1960                         memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
1961                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1962
1963                         strWIDList[0].id = (u16)WID_11I_MODE;
1964                         strWIDList[0].type = WID_CHAR;
1965                         strWIDList[0].size = sizeof(char);
1966                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1967
1968                         strWIDList[1].id = (u16)WID_ADD_PTK;
1969                         strWIDList[1].type = WID_STR;
1970                         strWIDList[1].val = (s8 *)pu8keybuf;
1971                         strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
1972
1973                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1974                                                    get_id_from_handler(hif_drv));
1975                         kfree(pu8keybuf);
1976                         up(&hif_drv->hSemTestKeyBlock);
1977                 }
1978                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1979
1980
1981                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1982
1983
1984
1985                         if (pu8keybuf == NULL) {
1986                                 PRINT_ER("No buffer to send PTK Key\n");
1987                                 ret = -1;
1988                                 goto _WPAPtk_end_case_;
1989
1990                         }
1991
1992                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1993                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1994                         memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
1995                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1996
1997                         strWID.id = (u16)WID_ADD_PTK;
1998                         strWID.type = WID_STR;
1999                         strWID.val = (s8 *)pu8keybuf;
2000                         strWID.size = PTK_KEY_MSG_LEN;
2001
2002                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2003                                                    get_id_from_handler(hif_drv));
2004                         kfree(pu8keybuf);
2005                         up(&hif_drv->hSemTestKeyBlock);
2006                 }
2007
2008 _WPAPtk_end_case_:
2009                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
2010                 if (ret == -1)
2011                         return ret;
2012
2013                 break;
2014
2015
2016         case PMKSA:
2017
2018                 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
2019
2020                 pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
2021                 if (pu8keybuf == NULL) {
2022                         PRINT_ER("No buffer to send PMKSA Key\n");
2023                         return -1;
2024                 }
2025
2026                 pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
2027
2028                 for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
2029                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
2030                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
2031                 }
2032
2033                 strWID.id = (u16)WID_PMKID_INFO;
2034                 strWID.type = WID_STR;
2035                 strWID.val = (s8 *)pu8keybuf;
2036                 strWID.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
2037
2038                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2039                                            get_id_from_handler(hif_drv));
2040
2041                 kfree(pu8keybuf);
2042                 break;
2043         }
2044
2045         if (s32Error)
2046                 PRINT_ER("Failed to send key config packet\n");
2047
2048
2049         return s32Error;
2050 }
2051
2052 static void Handle_Disconnect(struct host_if_drv *hif_drv)
2053 {
2054         struct wid strWID;
2055
2056         s32 s32Error = 0;
2057         u16 u16DummyReasonCode = 0;
2058
2059         strWID.id = (u16)WID_DISCONNECT;
2060         strWID.type = WID_CHAR;
2061         strWID.val = (s8 *)&u16DummyReasonCode;
2062         strWID.size = sizeof(char);
2063
2064
2065
2066         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
2067
2068         g_obtainingIP = false;
2069         host_int_set_power_mgmt(hif_drv, 0, 0);
2070
2071         eth_zero_addr(u8ConnectedSSID);
2072
2073         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2074                                    get_id_from_handler(hif_drv));
2075
2076         if (s32Error) {
2077                 PRINT_ER("Failed to send dissconect config packet\n");
2078         } else {
2079                 tstrDisconnectNotifInfo strDisconnectNotifInfo;
2080
2081                 memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
2082
2083                 strDisconnectNotifInfo.u16reason = 0;
2084                 strDisconnectNotifInfo.ie = NULL;
2085                 strDisconnectNotifInfo.ie_len = 0;
2086
2087                 if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
2088                         del_timer(&hif_drv->hScanTimer);
2089                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
2090                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
2091
2092                         hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
2093                 }
2094
2095                 if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
2096                         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2097                                 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
2098                                 del_timer(&hif_drv->hConnectTimer);
2099                         }
2100
2101                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
2102                                                                            0, &strDisconnectNotifInfo, hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
2103                 } else {
2104                         PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL\n");
2105                 }
2106
2107                 gbScanWhileConnected = false;
2108
2109                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
2110
2111                 eth_zero_addr(hif_drv->au8AssociatedBSSID);
2112
2113                 hif_drv->strWILC_UsrConnReq.ssidLen = 0;
2114                 kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
2115                 kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
2116                 hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2117                 kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
2118
2119                 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2120                         kfree(gu8FlushedJoinReq);
2121                         gu8FlushedJoinReq = NULL;
2122                 }
2123                 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2124                         kfree(gu8FlushedInfoElemAsoc);
2125                         gu8FlushedInfoElemAsoc = NULL;
2126                 }
2127
2128         }
2129
2130         up(&hif_drv->hSemTestDisconnectBlock);
2131 }
2132
2133
2134 void resolve_disconnect_aberration(struct host_if_drv *hif_drv)
2135 {
2136         if (!hif_drv)
2137                 return;
2138         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (hif_drv->enuHostIFstate == HOST_IF_CONNECTING)) {
2139                 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
2140                 host_int_disconnect(hif_drv, 1);
2141         }
2142 }
2143
2144 static s32 Handle_GetChnl(struct host_if_drv *hif_drv)
2145 {
2146
2147         s32 s32Error = 0;
2148         struct wid strWID;
2149
2150         strWID.id = (u16)WID_CURRENT_CHANNEL;
2151         strWID.type = WID_CHAR;
2152         strWID.val = (s8 *)&gu8Chnl;
2153         strWID.size = sizeof(char);
2154
2155         PRINT_D(HOSTINF_DBG, "Getting channel value\n");
2156
2157         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2158                                    get_id_from_handler(hif_drv));
2159
2160         if (s32Error) {
2161                 PRINT_ER("Failed to get channel number\n");
2162                 s32Error = -EFAULT;
2163         }
2164
2165         up(&hif_drv->hSemGetCHNL);
2166
2167         return s32Error;
2168
2169
2170
2171 }
2172
2173 static void Handle_GetRssi(struct host_if_drv *hif_drv)
2174 {
2175         s32 s32Error = 0;
2176         struct wid strWID;
2177
2178         strWID.id = (u16)WID_RSSI;
2179         strWID.type = WID_CHAR;
2180         strWID.val = &gs8Rssi;
2181         strWID.size = sizeof(char);
2182
2183         PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
2184
2185         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2186                                    get_id_from_handler(hif_drv));
2187         if (s32Error) {
2188                 PRINT_ER("Failed to get RSSI value\n");
2189                 s32Error = -EFAULT;
2190         }
2191
2192         up(&hif_drv->hSemGetRSSI);
2193
2194
2195 }
2196
2197
2198 static void Handle_GetLinkspeed(struct host_if_drv *hif_drv)
2199 {
2200         s32 s32Error = 0;
2201         struct wid strWID;
2202
2203         gs8lnkspd = 0;
2204
2205         strWID.id = (u16)WID_LINKSPEED;
2206         strWID.type = WID_CHAR;
2207         strWID.val = &gs8lnkspd;
2208         strWID.size = sizeof(char);
2209
2210         PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
2211
2212         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2213                                    get_id_from_handler(hif_drv));
2214         if (s32Error) {
2215                 PRINT_ER("Failed to get LINKSPEED value\n");
2216                 s32Error = -EFAULT;
2217         }
2218
2219         up(&(hif_drv->hSemGetLINKSPEED));
2220
2221
2222 }
2223
2224 s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
2225 {
2226         struct wid strWIDList[5];
2227         u32 u32WidsCount = 0, s32Error = 0;
2228
2229         strWIDList[u32WidsCount].id = WID_LINKSPEED;
2230         strWIDList[u32WidsCount].type = WID_CHAR;
2231         strWIDList[u32WidsCount].size = sizeof(char);
2232         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u8LinkSpeed));
2233         u32WidsCount++;
2234
2235         strWIDList[u32WidsCount].id = WID_RSSI;
2236         strWIDList[u32WidsCount].type = WID_CHAR;
2237         strWIDList[u32WidsCount].size = sizeof(char);
2238         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->s8RSSI));
2239         u32WidsCount++;
2240
2241         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
2242         strWIDList[u32WidsCount].type = WID_INT;
2243         strWIDList[u32WidsCount].size = sizeof(u32);
2244         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxCount));
2245         u32WidsCount++;
2246
2247         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
2248         strWIDList[u32WidsCount].type = WID_INT;
2249         strWIDList[u32WidsCount].size = sizeof(u32);
2250         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32RxCount));
2251         u32WidsCount++;
2252
2253         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
2254         strWIDList[u32WidsCount].type = WID_INT;
2255         strWIDList[u32WidsCount].size = sizeof(u32);
2256         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxFailureCount));
2257         u32WidsCount++;
2258
2259         s32Error = send_config_pkt(GET_CFG, strWIDList, u32WidsCount,
2260                                    get_id_from_handler(hif_drv));
2261
2262         if (s32Error)
2263                 PRINT_ER("Failed to send scan paramters config packet\n");
2264
2265         up(&hWaitResponse);
2266         return 0;
2267
2268 }
2269
2270 static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv,
2271                                    struct sta_inactive_t *strHostIfStaInactiveT)
2272 {
2273
2274         s32 s32Error = 0;
2275         u8 *stamac;
2276         struct wid strWID;
2277
2278         strWID.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
2279         strWID.type = WID_STR;
2280         strWID.size = ETH_ALEN;
2281         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2282
2283
2284         stamac = strWID.val;
2285         memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
2286
2287
2288         PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
2289
2290
2291         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2292                                    get_id_from_handler(hif_drv));
2293
2294         if (s32Error) {
2295                 PRINT_ER("Failed to SET incative time\n");
2296                 return -EFAULT;
2297         }
2298
2299
2300         strWID.id = (u16)WID_GET_INACTIVE_TIME;
2301         strWID.type = WID_INT;
2302         strWID.val = (s8 *)&gu32InactiveTime;
2303         strWID.size = sizeof(u32);
2304
2305
2306         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2307                                    get_id_from_handler(hif_drv));
2308
2309         if (s32Error) {
2310                 PRINT_ER("Failed to get incative time\n");
2311                 return -EFAULT;
2312         }
2313
2314
2315         PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", gu32InactiveTime);
2316
2317         up(&hif_drv->hSemInactiveTime);
2318
2319         return s32Error;
2320
2321
2322
2323 }
2324
2325 static void Handle_AddBeacon(struct host_if_drv *hif_drv,
2326                              struct beacon_attr *pstrSetBeaconParam)
2327 {
2328         s32 s32Error = 0;
2329         struct wid strWID;
2330         u8 *pu8CurrByte;
2331
2332         PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
2333
2334         strWID.id = (u16)WID_ADD_BEACON;
2335         strWID.type = WID_BIN;
2336         strWID.size = pstrSetBeaconParam->head_len + pstrSetBeaconParam->tail_len + 16;
2337         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2338         if (strWID.val == NULL)
2339                 goto ERRORHANDLER;
2340
2341         pu8CurrByte = strWID.val;
2342         *pu8CurrByte++ = (pstrSetBeaconParam->interval & 0xFF);
2343         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 8) & 0xFF);
2344         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 16) & 0xFF);
2345         *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 24) & 0xFF);
2346
2347         *pu8CurrByte++ = (pstrSetBeaconParam->dtim_period & 0xFF);
2348         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 8) & 0xFF);
2349         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 16) & 0xFF);
2350         *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 24) & 0xFF);
2351
2352         *pu8CurrByte++ = (pstrSetBeaconParam->head_len & 0xFF);
2353         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 8) & 0xFF);
2354         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 16) & 0xFF);
2355         *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 24) & 0xFF);
2356
2357         memcpy(pu8CurrByte, pstrSetBeaconParam->head, pstrSetBeaconParam->head_len);
2358         pu8CurrByte += pstrSetBeaconParam->head_len;
2359
2360         *pu8CurrByte++ = (pstrSetBeaconParam->tail_len & 0xFF);
2361         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 8) & 0xFF);
2362         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 16) & 0xFF);
2363         *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 24) & 0xFF);
2364
2365         if (pstrSetBeaconParam->tail > 0)
2366                 memcpy(pu8CurrByte, pstrSetBeaconParam->tail, pstrSetBeaconParam->tail_len);
2367         pu8CurrByte += pstrSetBeaconParam->tail_len;
2368
2369         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2370                                    get_id_from_handler(hif_drv));
2371         if (s32Error)
2372                 PRINT_ER("Failed to send add beacon config packet\n");
2373
2374 ERRORHANDLER:
2375         kfree(strWID.val);
2376         kfree(pstrSetBeaconParam->head);
2377         kfree(pstrSetBeaconParam->tail);
2378 }
2379
2380 static void Handle_DelBeacon(struct host_if_drv *hif_drv)
2381 {
2382         s32 s32Error = 0;
2383         struct wid strWID;
2384         u8 *pu8CurrByte;
2385
2386         strWID.id = (u16)WID_DEL_BEACON;
2387         strWID.type = WID_CHAR;
2388         strWID.size = sizeof(char);
2389         strWID.val = &gu8DelBcn;
2390
2391         if (strWID.val == NULL)
2392                 return;
2393
2394         pu8CurrByte = strWID.val;
2395
2396         PRINT_D(HOSTINF_DBG, "Deleting BEACON\n");
2397
2398         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2399                                    get_id_from_handler(hif_drv));
2400         if (s32Error)
2401                 PRINT_ER("Failed to send delete beacon config packet\n");
2402 }
2403
2404 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
2405                                     struct add_sta_param *pstrStationParam)
2406 {
2407         u8 *pu8CurrByte;
2408
2409         pu8CurrByte = pu8Buffer;
2410
2411         PRINT_D(HOSTINF_DBG, "Packing STA params\n");
2412         memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN);
2413         pu8CurrByte +=  ETH_ALEN;
2414
2415         *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF;
2416         *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF;
2417
2418         *pu8CurrByte++ = pstrStationParam->u8NumRates;
2419         if (pstrStationParam->u8NumRates > 0)
2420                 memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates);
2421         pu8CurrByte += pstrStationParam->u8NumRates;
2422
2423         *pu8CurrByte++ = pstrStationParam->bIsHTSupported;
2424         *pu8CurrByte++ = pstrStationParam->u16HTCapInfo & 0xFF;
2425         *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF;
2426
2427         *pu8CurrByte++ = pstrStationParam->u8AmpduParams;
2428         memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE);
2429         pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
2430
2431         *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF;
2432         *pu8CurrByte++ = (pstrStationParam->u16HTExtParams >> 8) & 0xFF;
2433
2434         *pu8CurrByte++ = pstrStationParam->u32TxBeamformingCap & 0xFF;
2435         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 8) & 0xFF;
2436         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 16) & 0xFF;
2437         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 24) & 0xFF;
2438
2439         *pu8CurrByte++ = pstrStationParam->u8ASELCap;
2440
2441         *pu8CurrByte++ = pstrStationParam->u16FlagsMask & 0xFF;
2442         *pu8CurrByte++ = (pstrStationParam->u16FlagsMask >> 8) & 0xFF;
2443
2444         *pu8CurrByte++ = pstrStationParam->u16FlagsSet & 0xFF;
2445         *pu8CurrByte++ = (pstrStationParam->u16FlagsSet >> 8) & 0xFF;
2446
2447         return pu8CurrByte - pu8Buffer;
2448 }
2449
2450 static void Handle_AddStation(struct host_if_drv *hif_drv,
2451                               struct add_sta_param *pstrStationParam)
2452 {
2453         s32 s32Error = 0;
2454         struct wid strWID;
2455         u8 *pu8CurrByte;
2456
2457         PRINT_D(HOSTINF_DBG, "Handling add station\n");
2458         strWID.id = (u16)WID_ADD_STA;
2459         strWID.type = WID_BIN;
2460         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2461
2462         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2463         if (strWID.val == NULL)
2464                 goto ERRORHANDLER;
2465
2466         pu8CurrByte = strWID.val;
2467         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2468
2469         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2470                                    get_id_from_handler(hif_drv));
2471         if (s32Error != 0)
2472                 PRINT_ER("Failed to send add station config packet\n");
2473
2474 ERRORHANDLER:
2475         kfree(pstrStationParam->pu8Rates);
2476         kfree(strWID.val);
2477 }
2478
2479 static void Handle_DelAllSta(struct host_if_drv *hif_drv,
2480                              struct del_all_sta *pstrDelAllStaParam)
2481 {
2482         s32 s32Error = 0;
2483
2484         struct wid strWID;
2485         u8 *pu8CurrByte;
2486         u8 i;
2487         u8 au8Zero_Buff[6] = {0};
2488
2489         strWID.id = (u16)WID_DEL_ALL_STA;
2490         strWID.type = WID_STR;
2491         strWID.size = (pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1;
2492
2493         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2494
2495         strWID.val = kmalloc((pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1, GFP_KERNEL);
2496         if (strWID.val == NULL)
2497                 goto ERRORHANDLER;
2498
2499         pu8CurrByte = strWID.val;
2500
2501         *(pu8CurrByte++) = pstrDelAllStaParam->assoc_sta;
2502
2503         for (i = 0; i < MAX_NUM_STA; i++) {
2504                 if (memcmp(pstrDelAllStaParam->del_all_sta[i], au8Zero_Buff, ETH_ALEN))
2505                         memcpy(pu8CurrByte, pstrDelAllStaParam->del_all_sta[i], ETH_ALEN);
2506                 else
2507                         continue;
2508
2509                 pu8CurrByte += ETH_ALEN;
2510         }
2511
2512         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2513                                    get_id_from_handler(hif_drv));
2514         if (s32Error)
2515                 PRINT_ER("Failed to send add station config packet\n");
2516
2517 ERRORHANDLER:
2518         kfree(strWID.val);
2519
2520         up(&hWaitResponse);
2521 }
2522
2523 static void Handle_DelStation(struct host_if_drv *hif_drv,
2524                               struct del_sta *pstrDelStaParam)
2525 {
2526         s32 s32Error = 0;
2527         struct wid strWID;
2528         u8 *pu8CurrByte;
2529
2530         strWID.id = (u16)WID_REMOVE_STA;
2531         strWID.type = WID_BIN;
2532         strWID.size = ETH_ALEN;
2533
2534         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2535
2536         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2537         if (strWID.val == NULL)
2538                 goto ERRORHANDLER;
2539
2540         pu8CurrByte = strWID.val;
2541
2542         memcpy(pu8CurrByte, pstrDelStaParam->mac_addr, ETH_ALEN);
2543
2544         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2545                                    get_id_from_handler(hif_drv));
2546         if (s32Error)
2547                 PRINT_ER("Failed to send add station config packet\n");
2548
2549 ERRORHANDLER:
2550         kfree(strWID.val);
2551 }
2552
2553 static void Handle_EditStation(struct host_if_drv *hif_drv,
2554                                struct add_sta_param *pstrStationParam)
2555 {
2556         s32 s32Error = 0;
2557         struct wid strWID;
2558         u8 *pu8CurrByte;
2559
2560         strWID.id = (u16)WID_EDIT_STA;
2561         strWID.type = WID_BIN;
2562         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2563
2564         PRINT_D(HOSTINF_DBG, "Handling edit station\n");
2565         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2566         if (strWID.val == NULL)
2567                 goto ERRORHANDLER;
2568
2569         pu8CurrByte = strWID.val;
2570         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2571
2572         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2573                                    get_id_from_handler(hif_drv));
2574         if (s32Error)
2575                 PRINT_ER("Failed to send edit station config packet\n");
2576
2577 ERRORHANDLER:
2578         kfree(pstrStationParam->pu8Rates);
2579         kfree(strWID.val);
2580 }
2581
2582 static int Handle_RemainOnChan(struct host_if_drv *hif_drv,
2583                                struct remain_ch *pstrHostIfRemainOnChan)
2584 {
2585         s32 s32Error = 0;
2586         u8 u8remain_on_chan_flag;
2587         struct wid strWID;
2588
2589         if (!hif_drv->u8RemainOnChan_pendingreq) {
2590                 hif_drv->strHostIfRemainOnChan.pVoid = pstrHostIfRemainOnChan->pVoid;
2591                 hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
2592                 hif_drv->strHostIfRemainOnChan.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
2593                 hif_drv->strHostIfRemainOnChan.u16Channel = pstrHostIfRemainOnChan->u16Channel;
2594                 hif_drv->strHostIfRemainOnChan.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
2595         } else {
2596                 pstrHostIfRemainOnChan->u16Channel = hif_drv->strHostIfRemainOnChan.u16Channel;
2597         }
2598
2599         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2600                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n");
2601                 hif_drv->u8RemainOnChan_pendingreq = 1;
2602                 s32Error = -EBUSY;
2603                 goto ERRORHANDLER;
2604         }
2605         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2606                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n");
2607                 s32Error = -EBUSY;
2608                 goto ERRORHANDLER;
2609         }
2610
2611         if (g_obtainingIP || connecting) {
2612                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
2613                 s32Error = -EBUSY;
2614                 goto ERRORHANDLER;
2615         }
2616
2617         PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel);
2618
2619         u8remain_on_chan_flag = true;
2620         strWID.id = (u16)WID_REMAIN_ON_CHAN;
2621         strWID.type = WID_STR;
2622         strWID.size = 2;
2623         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2624
2625         if (strWID.val == NULL) {
2626                 s32Error = -ENOMEM;
2627                 goto ERRORHANDLER;
2628         }
2629
2630         strWID.val[0] = u8remain_on_chan_flag;
2631         strWID.val[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
2632
2633         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2634                                    get_id_from_handler(hif_drv));
2635         if (s32Error != 0)
2636                 PRINT_ER("Failed to set remain on channel\n");
2637
2638 ERRORHANDLER:
2639         {
2640                 P2P_LISTEN_STATE = 1;
2641                 hif_drv->hRemainOnChannel.data = (unsigned long)hif_drv;
2642                 mod_timer(&hif_drv->hRemainOnChannel,
2643                           jiffies +
2644                           msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration));
2645
2646                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanReady)
2647                         hif_drv->strHostIfRemainOnChan.pRemainOnChanReady(hif_drv->strHostIfRemainOnChan.pVoid);
2648
2649                 if (hif_drv->u8RemainOnChan_pendingreq)
2650                         hif_drv->u8RemainOnChan_pendingreq = 0;
2651         }
2652         return s32Error;
2653 }
2654
2655 static int Handle_RegisterFrame(struct host_if_drv *hif_drv,
2656                                 struct reg_frame *pstrHostIfRegisterFrame)
2657 {
2658         s32 s32Error = 0;
2659         struct wid strWID;
2660         u8 *pu8CurrByte;
2661
2662         PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType);
2663
2664         strWID.id = (u16)WID_REGISTER_FRAME;
2665         strWID.type = WID_STR;
2666         strWID.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2667         if (strWID.val == NULL)
2668                 return -ENOMEM;
2669
2670         pu8CurrByte = strWID.val;
2671
2672         *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
2673         *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
2674         memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
2675
2676
2677         strWID.size = sizeof(u16) + 2;
2678
2679         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2680                                    get_id_from_handler(hif_drv));
2681         if (s32Error) {
2682                 PRINT_ER("Failed to frame register config packet\n");
2683                 s32Error = -EINVAL;
2684         }
2685
2686         return s32Error;
2687
2688 }
2689
2690 #define FALSE_FRMWR_CHANNEL 100
2691 static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv,
2692                                      struct remain_ch *pstrHostIfRemainOnChan)
2693 {
2694         u8 u8remain_on_chan_flag;
2695         struct wid strWID;
2696         s32 s32Error = 0;
2697
2698         PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n");
2699
2700         if (P2P_LISTEN_STATE) {
2701                 u8remain_on_chan_flag = false;
2702                 strWID.id = (u16)WID_REMAIN_ON_CHAN;
2703                 strWID.type = WID_STR;
2704                 strWID.size = 2;
2705                 strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2706
2707                 if (strWID.val == NULL)
2708                         PRINT_ER("Failed to allocate memory\n");
2709
2710                 strWID.val[0] = u8remain_on_chan_flag;
2711                 strWID.val[1] = FALSE_FRMWR_CHANNEL;
2712
2713                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2714                                            get_id_from_handler(hif_drv));
2715                 if (s32Error != 0) {
2716                         PRINT_ER("Failed to set remain on channel\n");
2717                         goto _done_;
2718                 }
2719
2720                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired) {
2721                         hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired(hif_drv->strHostIfRemainOnChan.pVoid
2722                                                                                , pstrHostIfRemainOnChan->u32ListenSessionID);
2723                 }
2724                 P2P_LISTEN_STATE = 0;
2725         } else {
2726                 PRINT_D(GENERIC_DBG, "Not in listen state\n");
2727                 s32Error = -EFAULT;
2728         }
2729
2730 _done_:
2731         return s32Error;
2732 }
2733
2734 static void ListenTimerCB(unsigned long arg)
2735 {
2736         s32 s32Error = 0;
2737         struct host_if_msg msg;
2738         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
2739
2740         del_timer(&hif_drv->hRemainOnChannel);
2741
2742         memset(&msg, 0, sizeof(struct host_if_msg));
2743         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
2744         msg.drv = hif_drv;
2745         msg.body.remain_on_ch.u32ListenSessionID = hif_drv->strHostIfRemainOnChan.u32ListenSessionID;
2746
2747         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2748         if (s32Error)
2749                 PRINT_ER("wilc_mq_send fail\n");
2750 }
2751
2752 static void Handle_PowerManagement(struct host_if_drv *hif_drv,
2753                                    struct power_mgmt_param *strPowerMgmtParam)
2754 {
2755         s32 s32Error = 0;
2756         struct wid strWID;
2757         s8 s8PowerMode;
2758
2759         strWID.id = (u16)WID_POWER_MANAGEMENT;
2760
2761         if (strPowerMgmtParam->enabled == true)
2762                 s8PowerMode = MIN_FAST_PS;
2763         else
2764                 s8PowerMode = NO_POWERSAVE;
2765         PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
2766         strWID.val = &s8PowerMode;
2767         strWID.size = sizeof(char);
2768
2769         PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
2770
2771         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2772                                    get_id_from_handler(hif_drv));
2773         if (s32Error)
2774                 PRINT_ER("Failed to send power management config packet\n");
2775 }
2776
2777 static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv,
2778                                       struct set_multicast *strHostIfSetMulti)
2779 {
2780         s32 s32Error = 0;
2781         struct wid strWID;
2782         u8 *pu8CurrByte;
2783
2784         PRINT_D(HOSTINF_DBG, "Setup Multicast Filter\n");
2785
2786         strWID.id = (u16)WID_SETUP_MULTICAST_FILTER;
2787         strWID.type = WID_BIN;
2788         strWID.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN);
2789         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2790         if (strWID.val == NULL)
2791                 goto ERRORHANDLER;
2792
2793         pu8CurrByte = strWID.val;
2794         *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
2795         *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF);
2796         *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF);
2797         *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF);
2798
2799         *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
2800         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
2801         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);
2802         *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 24) & 0xFF);
2803
2804         if ((strHostIfSetMulti->cnt) > 0)
2805                 memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->cnt) * ETH_ALEN));
2806
2807         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2808                                    get_id_from_handler(hif_drv));
2809         if (s32Error)
2810                 PRINT_ER("Failed to send setup multicast config packet\n");
2811
2812 ERRORHANDLER:
2813         kfree(strWID.val);
2814
2815 }
2816
2817 static s32 Handle_AddBASession(struct host_if_drv *hif_drv,
2818                                struct ba_session_info *strHostIfBASessionInfo)
2819 {
2820         s32 s32Error = 0;
2821         struct wid strWID;
2822         int AddbaTimeout = 100;
2823         char *ptr = NULL;
2824
2825         PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n",
2826                 strHostIfBASessionInfo->au8Bssid[0],
2827                 strHostIfBASessionInfo->au8Bssid[1],
2828                 strHostIfBASessionInfo->au8Bssid[2],
2829                 strHostIfBASessionInfo->u16BufferSize,
2830                 strHostIfBASessionInfo->u16SessionTimeout,
2831                 strHostIfBASessionInfo->u8Ted);
2832
2833         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2834         strWID.type = WID_STR;
2835         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2836         strWID.size = BLOCK_ACK_REQ_SIZE;
2837         ptr = strWID.val;
2838         *ptr++ = 0x14;
2839         *ptr++ = 0x3;
2840         *ptr++ = 0x0;
2841         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2842         ptr += ETH_ALEN;
2843         *ptr++ = strHostIfBASessionInfo->u8Ted;
2844         *ptr++ = 1;
2845         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2846         *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF);
2847         *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF);
2848         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2849         *ptr++ = (AddbaTimeout & 0xFF);
2850         *ptr++ = ((AddbaTimeout >> 16) & 0xFF);
2851         *ptr++ = 8;
2852         *ptr++ = 0;
2853
2854         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2855                                    get_id_from_handler(hif_drv));
2856         if (s32Error)
2857                 PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
2858
2859
2860         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2861         strWID.type = WID_STR;
2862         strWID.size = 15;
2863         ptr = strWID.val;
2864         *ptr++ = 15;
2865         *ptr++ = 7;
2866         *ptr++ = 0x2;
2867         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2868         ptr += ETH_ALEN;
2869         *ptr++ = strHostIfBASessionInfo->u8Ted;
2870         *ptr++ = 8;
2871         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2872         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2873         *ptr++ = 3;
2874         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2875                                    get_id_from_handler(hif_drv));
2876
2877         if (strWID.val != NULL)
2878                 kfree(strWID.val);
2879
2880         return s32Error;
2881
2882 }
2883
2884 static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv,
2885                                      struct ba_session_info *strHostIfBASessionInfo)
2886 {
2887         s32 s32Error = 0;
2888         struct wid strWID;
2889         char *ptr = NULL;
2890
2891         PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
2892                 strHostIfBASessionInfo->au8Bssid[0],
2893                 strHostIfBASessionInfo->au8Bssid[1],
2894                 strHostIfBASessionInfo->au8Bssid[2],
2895                 strHostIfBASessionInfo->u8Ted);
2896
2897         strWID.id = (u16)WID_DEL_ALL_RX_BA;
2898         strWID.type = WID_STR;
2899         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2900         strWID.size = BLOCK_ACK_REQ_SIZE;
2901         ptr = strWID.val;
2902         *ptr++ = 0x14;
2903         *ptr++ = 0x3;
2904         *ptr++ = 0x2;
2905         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2906         ptr += ETH_ALEN;
2907         *ptr++ = strHostIfBASessionInfo->u8Ted;
2908         *ptr++ = 0;
2909         *ptr++ = 32;
2910
2911         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2912                                    get_id_from_handler(hif_drv));
2913         if (s32Error)
2914                 PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
2915
2916
2917         if (strWID.val != NULL)
2918                 kfree(strWID.val);
2919
2920         up(&hWaitResponse);
2921
2922         return s32Error;
2923
2924 }
2925
2926 static int hostIFthread(void *pvArg)
2927 {
2928         u32 u32Ret;
2929         struct host_if_msg msg;
2930         struct host_if_drv *hif_drv;
2931
2932         memset(&msg, 0, sizeof(struct host_if_msg));
2933
2934         while (1) {
2935                 wilc_mq_recv(&gMsgQHostIF, &msg, sizeof(struct host_if_msg), &u32Ret);
2936                 hif_drv = (struct host_if_drv *)msg.drv;
2937                 if (msg.id == HOST_IF_MSG_EXIT) {
2938                         PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
2939                         break;
2940                 }
2941
2942                 if ((!g_wilc_initialized)) {
2943                         PRINT_D(GENERIC_DBG, "--WAIT--");
2944                         usleep_range(200 * 1000, 200 * 1000);
2945                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2946                         continue;
2947                 }
2948
2949                 if (msg.id == HOST_IF_MSG_CONNECT && hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2950                         PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
2951                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2952                         usleep_range(2 * 1000, 2 * 1000);
2953                         continue;
2954                 }
2955
2956                 switch (msg.id) {
2957                 case HOST_IF_MSG_Q_IDLE:
2958                         Handle_wait_msg_q_empty();
2959                         break;
2960
2961                 case HOST_IF_MSG_SCAN:
2962                         Handle_Scan(msg.drv, &msg.body.scan_info);
2963                         break;
2964
2965                 case HOST_IF_MSG_CONNECT:
2966                         Handle_Connect(msg.drv, &msg.body.con_info);
2967                         break;
2968
2969                 case HOST_IF_MSG_FLUSH_CONNECT:
2970                         Handle_FlushConnect(msg.drv);
2971                         break;
2972
2973                 case HOST_IF_MSG_RCVD_NTWRK_INFO:
2974                         Handle_RcvdNtwrkInfo(msg.drv, &msg.body.net_info);
2975                         break;
2976
2977                 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
2978                         Handle_RcvdGnrlAsyncInfo(msg.drv, &msg.body.async_info);
2979                         break;
2980
2981                 case HOST_IF_MSG_KEY:
2982                         Handle_Key(msg.drv, &msg.body.key_info);
2983                         break;
2984
2985                 case HOST_IF_MSG_CFG_PARAMS:
2986
2987                         Handle_CfgParam(msg.drv, &msg.body.cfg_info);
2988                         break;
2989
2990                 case HOST_IF_MSG_SET_CHANNEL:
2991                         Handle_SetChannel(msg.drv, &msg.body.channel_info);
2992                         break;
2993
2994                 case HOST_IF_MSG_DISCONNECT:
2995                         Handle_Disconnect(msg.drv);
2996                         break;
2997
2998                 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
2999                         del_timer(&hif_drv->hScanTimer);
3000                         PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
3001
3002                         if (!linux_wlan_get_num_conn_ifcs())
3003                                 chip_sleep_manually(INFINITE_SLEEP_TIME);
3004
3005                         Handle_ScanDone(msg.drv, SCAN_EVENT_DONE);
3006
3007                         if (hif_drv->u8RemainOnChan_pendingreq)
3008                                 Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3009
3010                         break;
3011
3012                 case HOST_IF_MSG_GET_RSSI:
3013                         Handle_GetRssi(msg.drv);
3014                         break;
3015
3016                 case HOST_IF_MSG_GET_LINKSPEED:
3017                         Handle_GetLinkspeed(msg.drv);
3018                         break;
3019
3020                 case HOST_IF_MSG_GET_STATISTICS:
3021                         Handle_GetStatistics(msg.drv, (struct rf_info *)msg.body.data);
3022                         break;
3023
3024                 case HOST_IF_MSG_GET_CHNL:
3025                         Handle_GetChnl(msg.drv);
3026                         break;
3027
3028                 case HOST_IF_MSG_ADD_BEACON:
3029                         Handle_AddBeacon(msg.drv, &msg.body.beacon_info);
3030                         break;
3031
3032                 case HOST_IF_MSG_DEL_BEACON:
3033                         Handle_DelBeacon(msg.drv);
3034                         break;
3035
3036                 case HOST_IF_MSG_ADD_STATION:
3037                         Handle_AddStation(msg.drv, &msg.body.add_sta_info);
3038                         break;
3039
3040                 case HOST_IF_MSG_DEL_STATION:
3041                         Handle_DelStation(msg.drv, &msg.body.del_sta_info);
3042                         break;
3043
3044                 case HOST_IF_MSG_EDIT_STATION:
3045                         Handle_EditStation(msg.drv, &msg.body.edit_sta_info);
3046                         break;
3047
3048                 case HOST_IF_MSG_GET_INACTIVETIME:
3049                         Handle_Get_InActiveTime(msg.drv, &msg.body.mac_info);
3050                         break;
3051
3052                 case HOST_IF_MSG_SCAN_TIMER_FIRED:
3053                         PRINT_D(HOSTINF_DBG, "Scan Timeout\n");
3054
3055                         Handle_ScanDone(msg.drv, SCAN_EVENT_ABORTED);
3056                         break;
3057
3058                 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
3059                         PRINT_D(HOSTINF_DBG, "Connect Timeout\n");
3060                         Handle_ConnectTimeout(msg.drv);
3061                         break;
3062
3063                 case HOST_IF_MSG_POWER_MGMT:
3064                         Handle_PowerManagement(msg.drv, &msg.body.pwr_mgmt_info);
3065                         break;
3066
3067                 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
3068                         Handle_SetWfiDrvHandler(msg.drv,
3069                                                 &msg.body.drv);
3070                         break;
3071
3072                 case HOST_IF_MSG_SET_OPERATION_MODE:
3073                         Handle_SetOperationMode(msg.drv, &msg.body.mode);
3074                         break;
3075
3076                 case HOST_IF_MSG_SET_IPADDRESS:
3077                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3078                         Handle_set_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx);
3079                         break;
3080
3081                 case HOST_IF_MSG_GET_IPADDRESS:
3082                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3083                         Handle_get_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx);
3084                         break;
3085
3086                 case HOST_IF_MSG_SET_MAC_ADDRESS:
3087                         Handle_SetMacAddress(msg.drv, &msg.body.set_mac_info);
3088                         break;
3089
3090                 case HOST_IF_MSG_GET_MAC_ADDRESS:
3091                         Handle_GetMacAddress(msg.drv, &msg.body.get_mac_info);
3092                         break;
3093
3094                 case HOST_IF_MSG_REMAIN_ON_CHAN:
3095                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n");
3096                         Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3097                         break;
3098
3099                 case HOST_IF_MSG_REGISTER_FRAME:
3100                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n");
3101                         Handle_RegisterFrame(msg.drv, &msg.body.reg_frame);
3102                         break;
3103
3104                 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
3105                         Handle_ListenStateExpired(msg.drv, &msg.body.remain_on_ch);
3106                         break;
3107
3108                 case HOST_IF_MSG_SET_MULTICAST_FILTER:
3109                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n");
3110                         Handle_SetMulticastFilter(msg.drv, &msg.body.multicast_info);
3111                         break;
3112
3113                 case HOST_IF_MSG_ADD_BA_SESSION:
3114                         Handle_AddBASession(msg.drv, &msg.body.session_info);
3115                         break;
3116
3117                 case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS:
3118                         Handle_DelAllRxBASessions(msg.drv, &msg.body.session_info);
3119                         break;
3120
3121                 case HOST_IF_MSG_DEL_ALL_STA:
3122                         Handle_DelAllSta(msg.drv, &msg.body.del_all_sta_info);
3123                         break;
3124
3125                 default:
3126                         PRINT_ER("[Host Interface] undefined Received Msg ID\n");
3127                         break;
3128                 }
3129         }
3130
3131         PRINT_D(HOSTINF_DBG, "Releasing thread exit semaphore\n");
3132         up(&hSemHostIFthrdEnd);
3133         return 0;
3134 }
3135
3136 static void TimerCB_Scan(unsigned long arg)
3137 {
3138         void *pvArg = (void *)arg;
3139         struct host_if_msg msg;
3140
3141         memset(&msg, 0, sizeof(struct host_if_msg));
3142         msg.drv = pvArg;
3143         msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
3144
3145         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3146 }
3147
3148 static void TimerCB_Connect(unsigned long arg)
3149 {
3150         void *pvArg = (void *)arg;
3151         struct host_if_msg msg;
3152
3153         memset(&msg, 0, sizeof(struct host_if_msg));
3154         msg.drv = pvArg;
3155         msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
3156
3157         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3158 }
3159
3160 s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
3161 {
3162         struct wid strWID;
3163
3164         strWID.id = (u16)WID_REMOVE_KEY;
3165         strWID.type = WID_STR;
3166         strWID.val = (s8 *)pu8StaAddress;
3167         strWID.size = 6;
3168
3169         return 0;
3170 }
3171
3172 int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index)
3173 {
3174         int result = 0;
3175         struct host_if_msg msg;
3176
3177         if (!hif_drv) {
3178                 result = -EFAULT;
3179                 PRINT_ER("Failed to send setup multicast config packet\n");
3180                 return result;
3181         }
3182
3183         memset(&msg, 0, sizeof(struct host_if_msg));
3184
3185         msg.id = HOST_IF_MSG_KEY;
3186         msg.body.key_info.type = WEP;
3187         msg.body.key_info.action = REMOVEKEY;
3188         msg.drv = hif_drv;
3189         msg.body.key_info.attr.wep.index = index;
3190
3191         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3192         if (result)
3193                 PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
3194         down(&hif_drv->hSemTestKeyBlock);
3195
3196         return result;
3197 }
3198
3199 s32 host_int_set_WEPDefaultKeyID(struct host_if_drv *hif_drv, u8 u8Index)
3200 {
3201         s32 s32Error = 0;
3202         struct host_if_msg msg;
3203
3204
3205         if (!hif_drv) {
3206                 s32Error = -EFAULT;
3207                 PRINT_ER("driver is null\n");
3208                 return s32Error;
3209         }
3210
3211         memset(&msg, 0, sizeof(struct host_if_msg));
3212
3213
3214         msg.id = HOST_IF_MSG_KEY;
3215         msg.body.key_info.type = WEP;
3216         msg.body.key_info.action = DEFAULTKEY;
3217         msg.drv = hif_drv;
3218         msg.body.key_info.attr.wep.index = u8Index;
3219
3220         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3221         if (s32Error)
3222                 PRINT_ER("Error in sending message queue : Default key index\n");
3223         down(&hif_drv->hSemTestKeyBlock);
3224
3225         return s32Error;
3226 }
3227
3228 s32 host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv,
3229                                  const u8 *pu8WepKey,
3230                                  u8 u8WepKeylen,
3231                                  u8 u8Keyidx)
3232 {
3233
3234         s32 s32Error = 0;
3235         struct host_if_msg msg;
3236
3237         if (!hif_drv) {
3238                 s32Error = -EFAULT;
3239                 PRINT_ER("driver is null\n");
3240                 return s32Error;
3241         }
3242
3243         memset(&msg, 0, sizeof(struct host_if_msg));
3244
3245
3246         msg.id = HOST_IF_MSG_KEY;
3247         msg.body.key_info.type = WEP;
3248         msg.body.key_info.action = ADDKEY;
3249         msg.drv = hif_drv;
3250         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3251         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, u8WepKeylen);
3252         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3253         msg.body.key_info.attr.wep.index = u8Keyidx;
3254
3255         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3256         if (s32Error)
3257                 PRINT_ER("Error in sending message queue :WEP Key\n");
3258         down(&hif_drv->hSemTestKeyBlock);
3259
3260         return s32Error;
3261
3262 }
3263
3264 s32 host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv,
3265                                 const u8 *pu8WepKey,
3266                                 u8 u8WepKeylen,
3267                                 u8 u8Keyidx,
3268                                 u8 u8mode,
3269                                 enum AUTHTYPE tenuAuth_type)
3270 {
3271
3272         s32 s32Error = 0;
3273         struct host_if_msg msg;
3274         u8 i;
3275
3276         if (!hif_drv) {
3277                 s32Error = -EFAULT;
3278                 PRINT_ER("driver is null\n");
3279                 return s32Error;
3280         }
3281
3282         memset(&msg, 0, sizeof(struct host_if_msg));
3283
3284         if (INFO) {
3285                 for (i = 0; i < u8WepKeylen; i++)
3286                         PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", pu8WepKey[i]);
3287         }
3288         msg.id = HOST_IF_MSG_KEY;
3289         msg.body.key_info.type = WEP;
3290         msg.body.key_info.action = ADDKEY_AP;
3291         msg.drv = hif_drv;
3292         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3293         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, (u8WepKeylen));
3294         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3295         msg.body.key_info.attr.wep.index = u8Keyidx;
3296         msg.body.key_info.attr.wep.mode = u8mode;
3297         msg.body.key_info.attr.wep.auth_type = tenuAuth_type;
3298
3299         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3300
3301         if (s32Error)
3302                 PRINT_ER("Error in sending message queue :WEP Key\n");
3303         down(&hif_drv->hSemTestKeyBlock);
3304
3305         return s32Error;
3306
3307 }
3308
3309 s32 host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *pu8Ptk,
3310                      u8 u8PtkKeylen, const u8 *mac_addr,
3311                      const u8 *pu8RxMic, const u8 *pu8TxMic,
3312                      u8 mode, u8 u8Ciphermode, u8 u8Idx)
3313 {
3314         s32 s32Error = 0;
3315         struct host_if_msg msg;
3316         u8 u8KeyLen = u8PtkKeylen;
3317         u32 i;
3318
3319         if (!hif_drv) {
3320                 s32Error = -EFAULT;
3321                 PRINT_ER("driver is null\n");
3322                 return s32Error;
3323         }
3324         if (pu8RxMic != NULL)
3325                 u8KeyLen += RX_MIC_KEY_LEN;
3326         if (pu8TxMic != NULL)
3327                 u8KeyLen += TX_MIC_KEY_LEN;
3328
3329         memset(&msg, 0, sizeof(struct host_if_msg));
3330
3331
3332         msg.id = HOST_IF_MSG_KEY;
3333         msg.body.key_info.type = WPAPtk;
3334         if (mode == AP_MODE) {
3335                 msg.body.key_info.action = ADDKEY_AP;
3336                 msg.body.key_info.attr.wpa.index = u8Idx;
3337         }
3338         if (mode == STATION_MODE)
3339                 msg.body.key_info.action = ADDKEY;
3340
3341         msg.body.key_info.attr.wpa.key = kmalloc(u8PtkKeylen, GFP_KERNEL);
3342         memcpy(msg.body.key_info.attr.wpa.key, pu8Ptk, u8PtkKeylen);
3343
3344         if (pu8RxMic != NULL) {
3345                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3346                 if (INFO) {
3347                         for (i = 0; i < RX_MIC_KEY_LEN; i++)
3348                                 PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]);
3349                 }
3350         }
3351         if (pu8TxMic != NULL) {
3352                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3353                 if (INFO) {
3354                         for (i = 0; i < TX_MIC_KEY_LEN; i++)
3355                                 PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]);
3356                 }
3357         }
3358
3359         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3360         msg.body.key_info.attr.wpa.mac_addr = mac_addr;
3361         msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3362         msg.drv = hif_drv;
3363
3364         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3365
3366         if (s32Error)
3367                 PRINT_ER("Error in sending message queue:  PTK Key\n");
3368
3369         down(&hif_drv->hSemTestKeyBlock);
3370
3371         return s32Error;
3372 }
3373
3374 s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk,
3375                         u8 u8GtkKeylen, u8 u8KeyIdx,
3376                         u32 u32KeyRSClen, const u8 *KeyRSC,
3377                         const u8 *pu8RxMic, const u8 *pu8TxMic,
3378                         u8 mode, u8 u8Ciphermode)
3379 {
3380         s32 s32Error = 0;
3381         struct host_if_msg msg;
3382         u8 u8KeyLen = u8GtkKeylen;
3383
3384         if (!hif_drv) {
3385                 s32Error = -EFAULT;
3386                 PRINT_ER("driver is null\n");
3387                 return s32Error;
3388         }
3389         memset(&msg, 0, sizeof(struct host_if_msg));
3390
3391
3392         if (pu8RxMic != NULL)
3393                 u8KeyLen += RX_MIC_KEY_LEN;
3394         if (pu8TxMic != NULL)
3395                 u8KeyLen += TX_MIC_KEY_LEN;
3396         if (KeyRSC != NULL) {
3397                 msg.body.key_info.attr.wpa.seq = kmalloc(u32KeyRSClen, GFP_KERNEL);
3398                 memcpy(msg.body.key_info.attr.wpa.seq, KeyRSC, u32KeyRSClen);
3399         }
3400
3401
3402         msg.id = HOST_IF_MSG_KEY;
3403         msg.body.key_info.type = WPARxGtk;
3404         msg.drv = hif_drv;
3405
3406         if (mode == AP_MODE) {
3407                 msg.body.key_info.action = ADDKEY_AP;
3408                 msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3409         }
3410         if (mode == STATION_MODE)
3411                 msg.body.key_info.action = ADDKEY;
3412
3413         msg.body.key_info.attr.wpa.key = kmalloc(u8KeyLen, GFP_KERNEL);
3414         memcpy(msg.body.key_info.attr.wpa.key, pu8RxGtk, u8GtkKeylen);
3415
3416         if (pu8RxMic != NULL) {
3417                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3418         }
3419         if (pu8TxMic != NULL) {
3420                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3421         }
3422
3423         msg.body.key_info.attr.wpa.index = u8KeyIdx;
3424         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3425         msg.body.key_info.attr.wpa.seq_len = u32KeyRSClen;
3426
3427         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3428         if (s32Error)
3429                 PRINT_ER("Error in sending message queue:  RX GTK\n");
3430
3431         down(&hif_drv->hSemTestKeyBlock);
3432
3433         return s32Error;
3434 }
3435
3436 s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_attr *pu8PmkidInfoArray)
3437 {
3438         s32 s32Error = 0;
3439         struct host_if_msg msg;
3440         u32 i;
3441
3442
3443         if (!hif_drv) {
3444                 s32Error = -EFAULT;
3445                 PRINT_ER("driver is null\n");
3446                 return s32Error;
3447         }
3448
3449         memset(&msg, 0, sizeof(struct host_if_msg));
3450
3451         msg.id = HOST_IF_MSG_KEY;
3452         msg.body.key_info.type = PMKSA;
3453         msg.body.key_info.action = ADDKEY;
3454         msg.drv = hif_drv;
3455
3456         for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
3457                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
3458                             ETH_ALEN);
3459                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
3460                             PMKID_LEN);
3461         }
3462
3463         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3464         if (s32Error)
3465                 PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
3466
3467         return s32Error;
3468 }
3469
3470 s32 host_int_get_pmkid_info(struct host_if_drv *hif_drv,
3471                             u8 *pu8PmkidInfoArray,
3472                             u32 u32PmkidInfoLen)
3473 {
3474         struct wid strWID;
3475
3476         strWID.id = (u16)WID_PMKID_INFO;
3477         strWID.type = WID_STR;
3478         strWID.size = u32PmkidInfoLen;
3479         strWID.val = pu8PmkidInfoArray;
3480
3481         return 0;
3482 }
3483
3484 s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3485                                          u8 *pu8PassPhrase,
3486                                          u8 u8Psklength)
3487 {
3488         struct wid strWID;
3489
3490         if ((u8Psklength > 7) && (u8Psklength < 65)) {
3491                 strWID.id = (u16)WID_11I_PSK;
3492                 strWID.type = WID_STR;
3493                 strWID.val = pu8PassPhrase;
3494                 strWID.size = u8Psklength;
3495         }
3496
3497         return 0;
3498 }
3499
3500 s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3501 {
3502         s32 s32Error = 0;
3503         struct host_if_msg msg;
3504
3505         memset(&msg, 0, sizeof(struct host_if_msg));
3506
3507         msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
3508         msg.body.get_mac_info.u8MacAddress = pu8MacAddress;
3509         msg.drv = hif_drv;
3510
3511         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3512         if (s32Error) {
3513                 PRINT_ER("Failed to send get mac address\n");
3514                 return -EFAULT;
3515         }
3516
3517         down(&hWaitResponse);
3518         return s32Error;
3519 }
3520
3521 s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3522 {
3523         s32 s32Error = 0;
3524         struct host_if_msg msg;
3525
3526         PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
3527
3528         memset(&msg, 0, sizeof(struct host_if_msg));
3529         msg.id = HOST_IF_MSG_SET_MAC_ADDRESS;
3530         memcpy(msg.body.set_mac_info.u8MacAddress, pu8MacAddress, ETH_ALEN);
3531         msg.drv = hif_drv;
3532
3533         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3534         if (s32Error)
3535                 PRINT_ER("Failed to send message queue: Set mac address\n");
3536
3537         return s32Error;
3538
3539 }
3540
3541 s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3542                                          u8 *pu8PassPhrase, u8 u8Psklength)
3543 {
3544         struct wid strWID;
3545
3546         strWID.id = (u16)WID_11I_PSK;
3547         strWID.type = WID_STR;
3548         strWID.size = u8Psklength;
3549         strWID.val = pu8PassPhrase;
3550
3551         return 0;
3552 }
3553
3554 s32 host_int_set_start_scan_req(struct host_if_drv *hif_drv, u8 scanSource)
3555 {
3556         struct wid strWID;
3557
3558         strWID.id = (u16)WID_START_SCAN_REQ;
3559         strWID.type = WID_CHAR;
3560         strWID.val = (s8 *)&scanSource;
3561         strWID.size = sizeof(char);
3562
3563         return 0;
3564 }
3565
3566 s32 host_int_get_start_scan_req(struct host_if_drv *hif_drv, u8 *pu8ScanSource)
3567 {
3568         struct wid strWID;
3569
3570         strWID.id = (u16)WID_START_SCAN_REQ;
3571         strWID.type = WID_CHAR;
3572         strWID.val = (s8 *)pu8ScanSource;
3573         strWID.size = sizeof(char);
3574
3575         return 0;
3576 }
3577
3578 s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid,
3579                           const u8 *pu8ssid, size_t ssidLen,
3580                           const u8 *pu8IEs, size_t IEsLen,
3581                           wilc_connect_result pfConnectResult, void *pvUserArg,
3582                           u8 u8security, enum AUTHTYPE tenuAuth_type,
3583                           u8 u8channel, void *pJoinParams)
3584 {
3585         s32 s32Error = 0;
3586         struct host_if_msg msg;
3587         enum scan_conn_timer enuScanConnTimer;
3588
3589         if (!hif_drv || pfConnectResult == NULL) {
3590                 s32Error = -EFAULT;
3591                 PRINT_ER("Driver is null\n");
3592                 return s32Error;
3593         }
3594
3595         if (pJoinParams == NULL) {
3596                 PRINT_ER("Unable to Join - JoinParams is NULL\n");
3597                 return -EFAULT;
3598         }
3599
3600         memset(&msg, 0, sizeof(struct host_if_msg));
3601
3602         msg.id = HOST_IF_MSG_CONNECT;
3603
3604         msg.body.con_info.security = u8security;
3605         msg.body.con_info.auth_type = tenuAuth_type;
3606         msg.body.con_info.ch = u8channel;
3607         msg.body.con_info.result = pfConnectResult;
3608         msg.body.con_info.arg = pvUserArg;
3609         msg.body.con_info.params = pJoinParams;
3610         msg.drv = hif_drv ;
3611
3612         if (pu8bssid != NULL) {
3613                 msg.body.con_info.bssid = kmalloc(6, GFP_KERNEL);
3614                 memcpy(msg.body.con_info.bssid, pu8bssid, 6);
3615         }
3616
3617         if (pu8ssid != NULL) {
3618                 msg.body.con_info.ssid_len = ssidLen;
3619                 msg.body.con_info.ssid = kmalloc(ssidLen, GFP_KERNEL);
3620                 memcpy(msg.body.con_info.ssid, pu8ssid, ssidLen);
3621         }
3622
3623         if (pu8IEs != NULL) {
3624                 msg.body.con_info.ies_len = IEsLen;
3625                 msg.body.con_info.ies = kmalloc(IEsLen, GFP_KERNEL);
3626                 memcpy(msg.body.con_info.ies, pu8IEs, IEsLen);
3627         }
3628         if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING)
3629                 hif_drv->enuHostIFstate = HOST_IF_CONNECTING;
3630         else
3631                 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate);
3632
3633         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3634         if (s32Error) {
3635                 PRINT_ER("Failed to send message queue: Set join request\n");
3636                 return -EFAULT;
3637         }
3638
3639         enuScanConnTimer = CONNECT_TIMER;
3640         hif_drv->hConnectTimer.data = (unsigned long)hif_drv;
3641         mod_timer(&hif_drv->hConnectTimer,
3642                   jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3643
3644         return s32Error;
3645 }
3646
3647 s32 host_int_flush_join_req(struct host_if_drv *hif_drv)
3648 {
3649         s32 s32Error = 0;
3650         struct host_if_msg msg;
3651
3652         if (!gu8FlushedJoinReq) {
3653                 s32Error = -EFAULT;
3654                 return s32Error;
3655         }
3656
3657
3658         if (!hif_drv) {
3659                 s32Error = -EFAULT;
3660                 PRINT_ER("Driver is null\n");
3661                 return s32Error;
3662         }
3663
3664         msg.id = HOST_IF_MSG_FLUSH_CONNECT;
3665         msg.drv = hif_drv;
3666
3667         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3668         if (s32Error) {
3669                 PRINT_ER("Failed to send message queue: Flush join request\n");
3670                 return -EFAULT;
3671         }
3672
3673         return s32Error;
3674 }
3675
3676 s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode)
3677 {
3678         s32 s32Error = 0;
3679         struct host_if_msg msg;
3680
3681         if (!hif_drv) {
3682                 PRINT_ER("Driver is null\n");
3683                 return -EFAULT;
3684         }
3685
3686         memset(&msg, 0, sizeof(struct host_if_msg));
3687
3688         msg.id = HOST_IF_MSG_DISCONNECT;
3689         msg.drv = hif_drv;
3690
3691         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3692         if (s32Error)
3693                 PRINT_ER("Failed to send message queue: disconnect\n");
3694
3695         down(&hif_drv->hSemTestDisconnectBlock);
3696
3697         return s32Error;
3698 }
3699
3700 s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id)
3701 {
3702         struct wid strWID;
3703
3704         strWID.id = (u16)WID_DISCONNECT;
3705         strWID.type = WID_CHAR;
3706         strWID.val = (s8 *)&assoc_id;
3707         strWID.size = sizeof(char);
3708
3709         return 0;
3710 }
3711
3712 s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv, u8 *pu8AssocReqInfo,
3713                                         u32 u32AssocReqInfoLen)
3714 {
3715         struct wid strWID;
3716
3717         strWID.id = (u16)WID_ASSOC_REQ_INFO;
3718         strWID.type = WID_STR;
3719         strWID.val = pu8AssocReqInfo;
3720         strWID.size = u32AssocReqInfoLen;
3721
3722         return 0;
3723 }
3724
3725 s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, u8 *pu8AssocRespInfo,
3726                                         u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
3727 {
3728         s32 s32Error = 0;
3729         struct wid strWID;
3730
3731         if (!hif_drv) {
3732                 PRINT_ER("Driver is null\n");
3733                 return -EFAULT;
3734         }
3735
3736         strWID.id = (u16)WID_ASSOC_RES_INFO;
3737         strWID.type = WID_STR;
3738         strWID.val = pu8AssocRespInfo;
3739         strWID.size = u32MaxAssocRespInfoLen;
3740
3741         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3742                                    get_id_from_handler(hif_drv));
3743         if (s32Error) {
3744                 *pu32RcvdAssocRespInfoLen = 0;
3745                 PRINT_ER("Failed to send association response config packet\n");
3746                 return -EINVAL;
3747         } else {
3748                 *pu32RcvdAssocRespInfoLen = strWID.size;
3749         }
3750
3751         return s32Error;
3752 }
3753
3754 s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv, u8 *pu8RxPowerLevel,
3755                                         u32 u32RxPowerLevelLen)
3756 {
3757         struct wid strWID;
3758
3759         strWID.id = (u16)WID_RX_POWER_LEVEL;
3760         strWID.type = WID_STR;
3761         strWID.val = pu8RxPowerLevel;
3762         strWID.size = u32RxPowerLevelLen;
3763
3764         return 0;
3765 }
3766
3767 int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel)
3768 {
3769         int result;
3770         struct host_if_msg msg;
3771
3772         if (!hif_drv) {
3773                 PRINT_ER("driver is null\n");
3774                 return -EFAULT;
3775         }
3776
3777         memset(&msg, 0, sizeof(struct host_if_msg));
3778         msg.id = HOST_IF_MSG_SET_CHANNEL;
3779         msg.body.channel_info.set_ch = channel;
3780         msg.drv = hif_drv;
3781
3782         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3783         if (result) {
3784                 PRINT_ER("wilc mq send fail\n");
3785                 return -EINVAL;
3786         }
3787
3788         return 0;
3789 }
3790
3791 int host_int_wait_msg_queue_idle(void)
3792 {
3793         int result = 0;
3794
3795         struct host_if_msg msg;
3796         memset(&msg, 0, sizeof(struct host_if_msg));
3797         msg.id = HOST_IF_MSG_Q_IDLE;
3798         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3799         if (result) {
3800                 PRINT_ER("wilc mq send fail\n");
3801                 result = -EINVAL;
3802         }
3803
3804         down(&hWaitResponse);
3805
3806         return result;
3807 }
3808
3809 int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv)
3810 {
3811         int result = 0;
3812
3813         struct host_if_msg msg;
3814         memset(&msg, 0, sizeof(struct host_if_msg));
3815         msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3816         msg.body.drv.u32Address = get_id_from_handler(hif_drv);
3817         msg.drv = hif_drv;
3818
3819         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3820         if (result) {
3821                 PRINT_ER("wilc mq send fail\n");
3822                 result = -EINVAL;
3823         }
3824
3825         return result;
3826 }
3827
3828 int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode)
3829 {
3830         int result = 0;
3831
3832         struct host_if_msg msg;
3833         memset(&msg, 0, sizeof(struct host_if_msg));
3834         msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3835         msg.body.mode.u32Mode = mode;
3836         msg.drv = hif_drv;
3837
3838         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3839         if (result) {
3840                 PRINT_ER("wilc mq send fail\n");
3841                 result = -EINVAL;
3842         }
3843
3844         return result;
3845 }
3846
3847 s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo)
3848 {
3849         s32 s32Error = 0;
3850         struct host_if_msg msg;
3851
3852         if (!hif_drv) {
3853                 PRINT_ER("driver is null\n");
3854                 return -EFAULT;
3855         }
3856
3857         memset(&msg, 0, sizeof(struct host_if_msg));
3858
3859         msg.id = HOST_IF_MSG_GET_CHNL;
3860         msg.drv = hif_drv;
3861
3862         s32Error =      wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3863         if (s32Error)
3864                 PRINT_ER("wilc mq send fail\n");
3865         down(&hif_drv->hSemGetCHNL);
3866
3867         *pu8ChNo = gu8Chnl;
3868
3869         return s32Error;
3870
3871
3872 }
3873
3874 s32 host_int_get_inactive_time(struct host_if_drv *hif_drv,
3875                                const u8 *mac, u32 *pu32InactiveTime)
3876 {
3877         s32 s32Error = 0;
3878         struct host_if_msg msg;
3879
3880         if (!hif_drv) {
3881                 PRINT_ER("driver is null\n");
3882                 return -EFAULT;
3883         }
3884
3885         memset(&msg, 0, sizeof(struct host_if_msg));
3886
3887
3888         memcpy(msg.body.mac_info.mac,
3889                     mac, ETH_ALEN);
3890
3891         msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3892         msg.drv = hif_drv;
3893
3894         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3895         if (s32Error)
3896                 PRINT_ER("Failed to send get host channel param's message queue ");
3897
3898         down(&hif_drv->hSemInactiveTime);
3899
3900         *pu32InactiveTime = gu32InactiveTime;
3901
3902         return s32Error;
3903 }
3904
3905 s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr)
3906 {
3907
3908         s32 s32Error = 0;
3909         struct wid strWID;
3910
3911         if (!hif_drv) {
3912                 PRINT_ER("driver is null\n");
3913                 return -EFAULT;
3914         }
3915
3916         strWID.id = (u16)WID_MEMORY_ADDRESS;
3917         strWID.type = WID_INT;
3918         strWID.val = (s8 *)pu32TestMemAddr;
3919         strWID.size = sizeof(u32);
3920
3921         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3922                                    get_id_from_handler(hif_drv));
3923
3924         if (s32Error) {
3925                 PRINT_ER("Failed to get wid value\n");
3926                 return -EINVAL;
3927         } else {
3928                 PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
3929
3930         }
3931
3932         return s32Error;
3933 }
3934
3935 s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi)
3936 {
3937         s32 s32Error = 0;
3938         struct host_if_msg msg;
3939         memset(&msg, 0, sizeof(struct host_if_msg));
3940
3941         msg.id = HOST_IF_MSG_GET_RSSI;
3942         msg.drv = hif_drv;
3943
3944         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3945         if (s32Error) {
3946                 PRINT_ER("Failed to send get host channel param's message queue ");
3947                 return -EFAULT;
3948         }
3949
3950         down(&hif_drv->hSemGetRSSI);
3951
3952
3953         if (ps8Rssi == NULL) {
3954                 PRINT_ER("RSS pointer value is null");
3955                 return -EFAULT;
3956         }
3957
3958
3959         *ps8Rssi = gs8Rssi;
3960
3961
3962         return s32Error;
3963 }
3964
3965 s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd)
3966 {
3967         struct host_if_msg msg;
3968         s32 s32Error = 0;
3969         memset(&msg, 0, sizeof(struct host_if_msg));
3970
3971         msg.id = HOST_IF_MSG_GET_LINKSPEED;
3972         msg.drv = hif_drv;
3973
3974         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3975         if (s32Error) {
3976                 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
3977                 return -EFAULT;
3978         }
3979
3980         down(&hif_drv->hSemGetLINKSPEED);
3981
3982
3983         if (ps8lnkspd == NULL) {
3984                 PRINT_ER("LINKSPEED pointer value is null");
3985                 return -EFAULT;
3986         }
3987
3988
3989         *ps8lnkspd = gs8lnkspd;
3990
3991
3992         return s32Error;
3993 }
3994
3995 s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
3996 {
3997         s32 s32Error = 0;
3998         struct host_if_msg msg;
3999         memset(&msg, 0, sizeof(struct host_if_msg));
4000
4001         msg.id = HOST_IF_MSG_GET_STATISTICS;
4002         msg.body.data = (char *)pstrStatistics;
4003         msg.drv = hif_drv;
4004
4005         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4006         if (s32Error) {
4007                 PRINT_ER("Failed to send get host channel param's message queue ");
4008                 return -EFAULT;
4009         }
4010
4011         down(&hWaitResponse);
4012         return s32Error;
4013 }
4014
4015 s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource,
4016                   u8 u8ScanType, u8 *pu8ChnlFreqList,
4017                   u8 u8ChnlListLen, const u8 *pu8IEs,
4018                   size_t IEsLen, wilc_scan_result ScanResult,
4019                   void *pvUserArg, struct hidden_network *pstrHiddenNetwork)
4020 {
4021         s32 s32Error = 0;
4022         struct host_if_msg msg;
4023         enum scan_conn_timer enuScanConnTimer;
4024
4025         if (!hif_drv || ScanResult == NULL) {
4026                 PRINT_ER("hif_drv or ScanResult = NULL\n");
4027                 return -EFAULT;
4028         }
4029
4030         memset(&msg, 0, sizeof(struct host_if_msg));
4031
4032         msg.id = HOST_IF_MSG_SCAN;
4033
4034         if (pstrHiddenNetwork != NULL) {
4035                 msg.body.scan_info.hidden_network.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
4036                 msg.body.scan_info.hidden_network.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
4037
4038         } else
4039                 PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
4040
4041         msg.drv = hif_drv;
4042         msg.body.scan_info.src = u8ScanSource;
4043         msg.body.scan_info.type = u8ScanType;
4044         msg.body.scan_info.result = ScanResult;
4045         msg.body.scan_info.arg = pvUserArg;
4046
4047         msg.body.scan_info.ch_list_len = u8ChnlListLen;
4048         msg.body.scan_info.ch_freq_list = kmalloc(u8ChnlListLen, GFP_KERNEL);
4049         memcpy(msg.body.scan_info.ch_freq_list, pu8ChnlFreqList, u8ChnlListLen);
4050
4051         msg.body.scan_info.ies_len = IEsLen;
4052         msg.body.scan_info.ies = kmalloc(IEsLen, GFP_KERNEL);
4053         memcpy(msg.body.scan_info.ies, pu8IEs, IEsLen);
4054
4055         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4056         if (s32Error) {
4057                 PRINT_ER("Error in sending message queue\n");
4058                 return -EINVAL;
4059         }
4060
4061         enuScanConnTimer = SCAN_TIMER;
4062         PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
4063         hif_drv->hScanTimer.data = (unsigned long)hif_drv;
4064         mod_timer(&hif_drv->hScanTimer,
4065                   jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
4066
4067         return s32Error;
4068
4069 }
4070
4071 s32 hif_set_cfg(struct host_if_drv *hif_drv,
4072                 struct cfg_param_val *pstrCfgParamVal)
4073 {
4074
4075         s32 s32Error = 0;
4076         struct host_if_msg msg;
4077
4078
4079         if (!hif_drv) {
4080                 PRINT_ER("hif_drv NULL\n");
4081                 return -EFAULT;
4082         }
4083
4084         memset(&msg, 0, sizeof(struct host_if_msg));
4085         msg.id = HOST_IF_MSG_CFG_PARAMS;
4086         msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal;
4087         msg.drv = hif_drv;
4088
4089         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4090
4091         return s32Error;
4092
4093 }
4094
4095 s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value)
4096 {
4097         s32 s32Error = 0;
4098
4099         down(&hif_drv->gtOsCfgValuesSem);
4100
4101         if (!hif_drv) {
4102                 PRINT_ER("hif_drv NULL\n");
4103                 return -EFAULT;
4104         }
4105         PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
4106         switch (u16WID) {
4107
4108         case WID_BSS_TYPE:
4109                 *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type;
4110                 break;
4111
4112         case WID_AUTH_TYPE:
4113                 *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type;
4114                 break;
4115
4116         case WID_AUTH_TIMEOUT:
4117                 *pu16WID_Value = hif_drv->strCfgValues.auth_timeout;
4118                 break;
4119
4120         case WID_POWER_MANAGEMENT:
4121                 *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode;
4122                 break;
4123
4124         case WID_SHORT_RETRY_LIMIT:
4125                 *pu16WID_Value =       hif_drv->strCfgValues.short_retry_limit;
4126                 break;
4127
4128         case WID_LONG_RETRY_LIMIT:
4129                 *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit;
4130                 break;
4131
4132         case WID_FRAG_THRESHOLD:
4133                 *pu16WID_Value = hif_drv->strCfgValues.frag_threshold;
4134                 break;
4135
4136         case WID_RTS_THRESHOLD:
4137                 *pu16WID_Value = hif_drv->strCfgValues.rts_threshold;
4138                 break;
4139
4140         case WID_PREAMBLE:
4141                 *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type;
4142                 break;
4143
4144         case WID_SHORT_SLOT_ALLOWED:
4145                 *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed;
4146                 break;
4147
4148         case WID_11N_TXOP_PROT_DISABLE:
4149                 *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled;
4150                 break;
4151
4152         case WID_BEACON_INTERVAL:
4153                 *pu16WID_Value = hif_drv->strCfgValues.beacon_interval;
4154                 break;
4155
4156         case WID_DTIM_PERIOD:
4157                 *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period;
4158                 break;
4159
4160         case WID_SITE_SURVEY:
4161                 *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled;
4162                 break;
4163
4164         case WID_SITE_SURVEY_SCAN_TIME:
4165                 *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time;
4166                 break;
4167
4168         case WID_ACTIVE_SCAN_TIME:
4169                 *pu16WID_Value = hif_drv->strCfgValues.active_scan_time;
4170                 break;
4171
4172         case WID_PASSIVE_SCAN_TIME:
4173                 *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time;
4174                 break;
4175
4176         case WID_CURRENT_TX_RATE:
4177                 *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate;
4178                 break;
4179
4180         default:
4181                 break;
4182         }
4183
4184         up(&hif_drv->gtOsCfgValuesSem);
4185
4186         return s32Error;
4187
4188 }
4189
4190 void host_int_send_join_leave_info_to_host
4191         (u16 assocId, u8 *stationAddr, bool joining)
4192 {
4193 }
4194
4195 static void GetPeriodicRSSI(unsigned long arg)
4196 {
4197         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
4198
4199         if (!hif_drv)   {
4200                 PRINT_ER("Driver handler is NULL\n");
4201                 return;
4202         }
4203
4204         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) {
4205                 s32 s32Error = 0;
4206                 struct host_if_msg msg;
4207
4208                 memset(&msg, 0, sizeof(struct host_if_msg));
4209
4210                 msg.id = HOST_IF_MSG_GET_RSSI;
4211                 msg.drv = hif_drv;
4212
4213                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4214                 if (s32Error) {
4215                         PRINT_ER("Failed to send get host channel param's message queue ");
4216                         return;
4217                 }
4218         }
4219         g_hPeriodicRSSI.data = (unsigned long)hif_drv;
4220         mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4221 }
4222
4223
4224 void host_int_send_network_info_to_host
4225         (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
4226 {
4227 }
4228
4229 static u32 clients_count;
4230
4231 s32 host_int_init(struct host_if_drv **hif_drv_handler)
4232 {
4233         s32 result = 0;
4234         struct host_if_drv *hif_drv;
4235         int err;
4236
4237         PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
4238
4239         gbScanWhileConnected = false;
4240
4241         sema_init(&hWaitResponse, 0);
4242
4243         hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
4244         if (!hif_drv) {
4245                 result = -ENOMEM;
4246                 goto _fail_;
4247         }
4248         *hif_drv_handler = hif_drv;
4249         err = add_handler_in_list(hif_drv);
4250         if (err) {
4251                 result = -EFAULT;
4252                 goto _fail_timer_2;
4253         }
4254
4255         g_obtainingIP = false;
4256
4257         PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv);
4258         if (clients_count == 0) {
4259                 sema_init(&hSemHostIFthrdEnd, 0);
4260                 sema_init(&hSemDeinitDrvHandle, 0);
4261                 sema_init(&hSemHostIntDeinit, 1);
4262         }
4263
4264         sema_init(&hif_drv->hSemTestKeyBlock, 0);
4265         sema_init(&hif_drv->hSemTestDisconnectBlock, 0);
4266         sema_init(&hif_drv->hSemGetRSSI, 0);
4267         sema_init(&hif_drv->hSemGetLINKSPEED, 0);
4268         sema_init(&hif_drv->hSemGetCHNL, 0);
4269         sema_init(&hif_drv->hSemInactiveTime, 0);
4270
4271         PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
4272
4273         if (clients_count == 0) {
4274                 result = wilc_mq_create(&gMsgQHostIF);
4275
4276                 if (result < 0) {
4277                         PRINT_ER("Failed to creat MQ\n");
4278                         goto _fail_;
4279                 }
4280                 HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
4281                 if (IS_ERR(HostIFthreadHandler)) {
4282                         PRINT_ER("Failed to creat Thread\n");
4283                         result = -EFAULT;
4284                         goto _fail_mq_;
4285                 }
4286                 setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
4287                             (unsigned long)hif_drv);
4288                 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4289         }
4290
4291         setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0);
4292
4293         setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0);
4294
4295         setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0);
4296
4297         sema_init(&(hif_drv->gtOsCfgValuesSem), 1);
4298         down(&hif_drv->gtOsCfgValuesSem);
4299
4300         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4301         hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
4302         hif_drv->strCfgValues.scan_source = DEFAULT_SCAN;
4303         hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
4304         hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
4305         hif_drv->strCfgValues.curr_tx_rate = AUTORATE;
4306
4307         hif_drv->u64P2p_MgmtTimeout = 0;
4308
4309         PRINT_INFO(HOSTINF_DBG, "Initialization values, Site survey value: %d\n Scan source: %d\n Active scan time: %d\n Passive scan time: %d\nCurrent tx Rate = %d\n",
4310
4311                    hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source,
4312                    hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time,
4313                    hif_drv->strCfgValues.curr_tx_rate);
4314
4315         up(&hif_drv->gtOsCfgValuesSem);
4316
4317         clients_count++;
4318
4319         return result;
4320
4321 _fail_timer_2:
4322         up(&hif_drv->gtOsCfgValuesSem);
4323         del_timer_sync(&hif_drv->hConnectTimer);
4324         del_timer_sync(&hif_drv->hScanTimer);
4325         kthread_stop(HostIFthreadHandler);
4326 _fail_mq_:
4327         wilc_mq_destroy(&gMsgQHostIF);
4328 _fail_:
4329         return result;
4330 }
4331
4332 s32 host_int_deinit(struct host_if_drv *hif_drv)
4333 {
4334         s32 s32Error = 0;
4335         struct host_if_msg msg;
4336         int ret;
4337
4338         if (!hif_drv)   {
4339                 PRINT_ER("hif_drv = NULL\n");
4340                 return 0;
4341         }
4342
4343         down(&hSemHostIntDeinit);
4344
4345         terminated_handle = hif_drv;
4346         PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
4347
4348         if (del_timer_sync(&hif_drv->hScanTimer)) {
4349                 PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
4350         }
4351
4352         if (del_timer_sync(&hif_drv->hConnectTimer)) {
4353                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4354         }
4355
4356
4357         if (del_timer_sync(&g_hPeriodicRSSI)) {
4358                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4359         }
4360
4361         del_timer_sync(&hif_drv->hRemainOnChannel);
4362
4363         host_int_set_wfi_drv_handler(NULL);
4364         down(&hSemDeinitDrvHandle);
4365
4366         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4367                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
4368                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
4369
4370                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
4371         }
4372
4373         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4374
4375         gbScanWhileConnected = false;
4376
4377         memset(&msg, 0, sizeof(struct host_if_msg));
4378
4379         if (clients_count == 1) {
4380                 if (del_timer_sync(&g_hPeriodicRSSI)) {
4381                         PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4382                 }
4383                 msg.id = HOST_IF_MSG_EXIT;
4384                 msg.drv = hif_drv;
4385
4386
4387                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4388                 if (s32Error != 0)
4389                         PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
4390
4391                 down(&hSemHostIFthrdEnd);
4392
4393                 wilc_mq_destroy(&gMsgQHostIF);
4394         }
4395
4396         down(&(hif_drv->gtOsCfgValuesSem));
4397
4398         ret = remove_handler_in_list(hif_drv);
4399         if (ret)
4400                 s32Error = -ENOENT;
4401
4402         kfree(hif_drv);
4403
4404         clients_count--;
4405         terminated_handle = NULL;
4406         up(&hSemHostIntDeinit);
4407         return s32Error;
4408 }
4409
4410 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
4411 {
4412         s32 s32Error = 0;
4413         struct host_if_msg msg;
4414         int id;
4415         struct host_if_drv *hif_drv = NULL;
4416
4417         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4418         hif_drv = get_handler_from_id(id);
4419
4420
4421
4422
4423         if (!hif_drv || hif_drv == terminated_handle)   {
4424                 PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv);
4425                 return;
4426         }
4427
4428         memset(&msg, 0, sizeof(struct host_if_msg));
4429
4430         msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
4431         msg.drv = hif_drv;
4432
4433         msg.body.net_info.len = u32Length;
4434         msg.body.net_info.buffer = kmalloc(u32Length, GFP_KERNEL);
4435         memcpy(msg.body.net_info.buffer, pu8Buffer, u32Length);
4436
4437         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4438         if (s32Error)
4439                 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
4440 }
4441
4442 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
4443 {
4444         s32 s32Error = 0;
4445         struct host_if_msg msg;
4446         int id;
4447         struct host_if_drv *hif_drv = NULL;
4448
4449         down(&hSemHostIntDeinit);
4450
4451         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4452         hif_drv = get_handler_from_id(id);
4453         PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
4454
4455
4456         if (!hif_drv || hif_drv == terminated_handle) {
4457                 PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
4458                 up(&hSemHostIntDeinit);
4459                 return;
4460         }
4461
4462         if (!hif_drv->strWILC_UsrConnReq.pfUserConnectResult) {
4463                 PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
4464                 up(&hSemHostIntDeinit);
4465                 return;
4466         }
4467
4468         memset(&msg, 0, sizeof(struct host_if_msg));
4469
4470
4471         msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
4472         msg.drv = hif_drv;
4473
4474         msg.body.async_info.len = u32Length;
4475         msg.body.async_info.buffer = kmalloc(u32Length, GFP_KERNEL);
4476         memcpy(msg.body.async_info.buffer, pu8Buffer, u32Length);
4477
4478         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4479         if (s32Error)
4480                 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
4481
4482         up(&hSemHostIntDeinit);
4483 }
4484
4485 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
4486 {
4487         s32 s32Error = 0;
4488         struct host_if_msg msg;
4489         int id;
4490         struct host_if_drv *hif_drv = NULL;
4491
4492         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4493         hif_drv = get_handler_from_id(id);
4494
4495
4496         PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv);
4497
4498         if (!hif_drv || hif_drv == terminated_handle)
4499                 return;
4500
4501         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4502                 memset(&msg, 0, sizeof(struct host_if_msg));
4503
4504                 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
4505                 msg.drv = hif_drv;
4506
4507                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4508                 if (s32Error)
4509                         PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
4510         }
4511
4512
4513         return;
4514
4515 }
4516
4517 s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID,
4518                                u32 u32duration, u16 chan,
4519                                wilc_remain_on_chan_expired RemainOnChanExpired,
4520                                wilc_remain_on_chan_ready RemainOnChanReady,
4521                                void *pvUserArg)
4522 {
4523         s32 s32Error = 0;
4524         struct host_if_msg msg;
4525
4526         if (!hif_drv) {
4527                 PRINT_ER("driver is null\n");
4528                 return -EFAULT;
4529         }
4530
4531         memset(&msg, 0, sizeof(struct host_if_msg));
4532
4533         msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
4534         msg.body.remain_on_ch.u16Channel = chan;
4535         msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired;
4536         msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady;
4537         msg.body.remain_on_ch.pVoid = pvUserArg;
4538         msg.body.remain_on_ch.u32duration = u32duration;
4539         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4540         msg.drv = hif_drv;
4541
4542         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4543         if (s32Error)
4544                 PRINT_ER("wilc mq send fail\n");
4545
4546         return s32Error;
4547 }
4548
4549 s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID)
4550 {
4551         s32 s32Error = 0;
4552         struct host_if_msg msg;
4553
4554         if (!hif_drv) {
4555                 PRINT_ER("driver is null\n");
4556                 return -EFAULT;
4557         }
4558
4559         del_timer(&hif_drv->hRemainOnChannel);
4560
4561         memset(&msg, 0, sizeof(struct host_if_msg));
4562         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4563         msg.drv = hif_drv;
4564         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4565
4566         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4567         if (s32Error)
4568                 PRINT_ER("wilc mq send fail\n");
4569
4570         return s32Error;
4571 }
4572
4573 s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg)
4574 {
4575         s32 s32Error = 0;
4576         struct host_if_msg msg;
4577
4578         if (!hif_drv) {
4579                 PRINT_ER("driver is null\n");
4580                 return -EFAULT;
4581         }
4582
4583         memset(&msg, 0, sizeof(struct host_if_msg));
4584
4585         msg.id = HOST_IF_MSG_REGISTER_FRAME;
4586         switch (u16FrameType) {
4587         case ACTION:
4588                 PRINT_D(HOSTINF_DBG, "ACTION\n");
4589                 msg.body.reg_frame.u8Regid = ACTION_FRM_IDX;
4590                 break;
4591
4592         case PROBE_REQ:
4593                 PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
4594                 msg.body.reg_frame.u8Regid = PROBE_REQ_IDX;
4595                 break;
4596
4597         default:
4598                 PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
4599                 break;
4600         }
4601         msg.body.reg_frame.u16FrameType = u16FrameType;
4602         msg.body.reg_frame.bReg = bReg;
4603         msg.drv = hif_drv;
4604
4605         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4606         if (s32Error)
4607                 PRINT_ER("wilc mq send fail\n");
4608
4609         return s32Error;
4610
4611
4612 }
4613
4614 s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
4615                         u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head,
4616                         u32 u32TailLen, u8 *pu8Tail)
4617 {
4618         s32 s32Error = 0;
4619         struct host_if_msg msg;
4620         struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info;
4621
4622         if (!hif_drv) {
4623                 PRINT_ER("driver is null\n");
4624                 return -EFAULT;
4625         }
4626
4627         memset(&msg, 0, sizeof(struct host_if_msg));
4628
4629         PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
4630
4631         msg.id = HOST_IF_MSG_ADD_BEACON;
4632         msg.drv = hif_drv;
4633         pstrSetBeaconParam->interval = u32Interval;
4634         pstrSetBeaconParam->dtim_period = u32DTIMPeriod;
4635         pstrSetBeaconParam->head_len = u32HeadLen;
4636         pstrSetBeaconParam->head = kmalloc(u32HeadLen, GFP_KERNEL);
4637         if (pstrSetBeaconParam->head == NULL) {
4638                 s32Error = -ENOMEM;
4639                 goto ERRORHANDLER;
4640         }
4641         memcpy(pstrSetBeaconParam->head, pu8Head, u32HeadLen);
4642         pstrSetBeaconParam->tail_len = u32TailLen;
4643
4644         if (u32TailLen > 0) {
4645                 pstrSetBeaconParam->tail = kmalloc(u32TailLen, GFP_KERNEL);
4646                 if (pstrSetBeaconParam->tail == NULL) {
4647                         s32Error = -ENOMEM;
4648                         goto ERRORHANDLER;
4649                 }
4650                 memcpy(pstrSetBeaconParam->tail, pu8Tail, u32TailLen);
4651         } else {
4652                 pstrSetBeaconParam->tail = NULL;
4653         }
4654
4655         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4656         if (s32Error)
4657                 PRINT_ER("wilc mq send fail\n");
4658
4659 ERRORHANDLER:
4660         if (s32Error) {
4661                 if (pstrSetBeaconParam->head != NULL)
4662                         kfree(pstrSetBeaconParam->head);
4663
4664                 if (pstrSetBeaconParam->tail != NULL)
4665                         kfree(pstrSetBeaconParam->tail);
4666         }
4667
4668         return s32Error;
4669
4670 }
4671
4672 s32 host_int_del_beacon(struct host_if_drv *hif_drv)
4673 {
4674         s32 s32Error = 0;
4675         struct host_if_msg msg;
4676
4677         if (!hif_drv) {
4678                 PRINT_ER("driver is null\n");
4679                 return -EFAULT;
4680         }
4681
4682         msg.id = HOST_IF_MSG_DEL_BEACON;
4683         msg.drv = hif_drv;
4684         PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
4685
4686         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4687         if (s32Error)
4688                 PRINT_ER("wilc_mq_send fail\n");
4689
4690         return s32Error;
4691 }
4692
4693 s32 host_int_add_station(struct host_if_drv *hif_drv,
4694                          struct add_sta_param *pstrStaParams)
4695 {
4696         s32 s32Error = 0;
4697         struct host_if_msg msg;
4698         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4699
4700
4701         if (!hif_drv) {
4702                 PRINT_ER("driver is null\n");
4703                 return -EFAULT;
4704         }
4705
4706         memset(&msg, 0, sizeof(struct host_if_msg));
4707
4708         PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
4709
4710         msg.id = HOST_IF_MSG_ADD_STATION;
4711         msg.drv = hif_drv;
4712
4713         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4714         if (pstrAddStationMsg->u8NumRates > 0) {
4715                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4716
4717                 if (!rates)
4718                         return -ENOMEM;
4719
4720                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4721                 pstrAddStationMsg->pu8Rates = rates;
4722         }
4723
4724
4725         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4726         if (s32Error)
4727                 PRINT_ER("wilc_mq_send fail\n");
4728         return s32Error;
4729 }
4730
4731 s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr)
4732 {
4733         s32 s32Error = 0;
4734         struct host_if_msg msg;
4735         struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info;
4736
4737         if (!hif_drv) {
4738                 PRINT_ER("driver is null\n");
4739                 return -EFAULT;
4740         }
4741
4742         memset(&msg, 0, sizeof(struct host_if_msg));
4743
4744         PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
4745
4746         msg.id = HOST_IF_MSG_DEL_STATION;
4747         msg.drv = hif_drv;
4748
4749         if (pu8MacAddr == NULL)
4750                 memset(pstrDelStationMsg->mac_addr, 255, ETH_ALEN);
4751         else
4752                 memcpy(pstrDelStationMsg->mac_addr, pu8MacAddr, ETH_ALEN);
4753
4754         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4755         if (s32Error)
4756                 PRINT_ER("wilc_mq_send fail\n");
4757         return s32Error;
4758 }
4759
4760 s32 host_int_del_allstation(struct host_if_drv *hif_drv,
4761                             u8 pu8MacAddr[][ETH_ALEN])
4762 {
4763         s32 s32Error = 0;
4764         struct host_if_msg msg;
4765         struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info;
4766         u8 au8Zero_Buff[ETH_ALEN] = {0};
4767         u32 i;
4768         u8 u8AssocNumb = 0;
4769
4770
4771         if (!hif_drv) {
4772                 PRINT_ER("driver is null\n");
4773                 return -EFAULT;
4774         }
4775
4776         memset(&msg, 0, sizeof(struct host_if_msg));
4777
4778         PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
4779
4780         msg.id = HOST_IF_MSG_DEL_ALL_STA;
4781         msg.drv = hif_drv;
4782
4783         for (i = 0; i < MAX_NUM_STA; i++) {
4784                 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
4785                         memcpy(pstrDelAllStationMsg->del_all_sta[i], pu8MacAddr[i], ETH_ALEN);
4786                         PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n",
4787                                 pstrDelAllStationMsg->del_all_sta[i][0],
4788                                 pstrDelAllStationMsg->del_all_sta[i][1],
4789                                 pstrDelAllStationMsg->del_all_sta[i][2],
4790                                 pstrDelAllStationMsg->del_all_sta[i][3],
4791                                 pstrDelAllStationMsg->del_all_sta[i][4],
4792                                 pstrDelAllStationMsg->del_all_sta[i][5]);
4793                         u8AssocNumb++;
4794                 }
4795         }
4796         if (!u8AssocNumb) {
4797                 PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
4798                 return s32Error;
4799         }
4800
4801         pstrDelAllStationMsg->assoc_sta = u8AssocNumb;
4802         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4803
4804
4805         if (s32Error)
4806                 PRINT_ER("wilc_mq_send fail\n");
4807
4808         down(&hWaitResponse);
4809
4810         return s32Error;
4811
4812 }
4813
4814 s32 host_int_edit_station(struct host_if_drv *hif_drv,
4815                           struct add_sta_param *pstrStaParams)
4816 {
4817         s32 s32Error = 0;
4818         struct host_if_msg msg;
4819         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4820
4821         if (!hif_drv) {
4822                 PRINT_ER("driver is null\n");
4823                 return -EFAULT;
4824         }
4825
4826         PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
4827
4828         memset(&msg, 0, sizeof(struct host_if_msg));
4829
4830         msg.id = HOST_IF_MSG_EDIT_STATION;
4831         msg.drv = hif_drv;
4832
4833         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4834         if (pstrAddStationMsg->u8NumRates > 0) {
4835                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4836
4837                 if (!rates)
4838                         return -ENOMEM;
4839
4840                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4841                 pstrAddStationMsg->pu8Rates = rates;
4842         }
4843
4844         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4845         if (s32Error)
4846                 PRINT_ER("wilc_mq_send fail\n");
4847
4848         return s32Error;
4849 }
4850
4851 s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv,
4852                             bool bIsEnabled,
4853                             u32 u32Timeout)
4854 {
4855         s32 s32Error = 0;
4856         struct host_if_msg msg;
4857         struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info;
4858
4859         PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
4860
4861         if (!hif_drv) {
4862                 PRINT_ER("driver is null\n");
4863                 return -EFAULT;
4864         }
4865
4866         PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
4867
4868         memset(&msg, 0, sizeof(struct host_if_msg));
4869
4870         msg.id = HOST_IF_MSG_POWER_MGMT;
4871         msg.drv = hif_drv;
4872
4873         pstrPowerMgmtParam->enabled = bIsEnabled;
4874         pstrPowerMgmtParam->timeout = u32Timeout;
4875
4876         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4877         if (s32Error)
4878                 PRINT_ER("wilc_mq_send fail\n");
4879         return s32Error;
4880 }
4881
4882 s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv,
4883                                     bool bIsEnabled,
4884                                     u32 u32count)
4885 {
4886         s32 s32Error = 0;
4887         struct host_if_msg msg;
4888         struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info;
4889
4890
4891         if (!hif_drv) {
4892                 PRINT_ER("driver is null\n");
4893                 return -EFAULT;
4894         }
4895
4896         PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
4897
4898         memset(&msg, 0, sizeof(struct host_if_msg));
4899
4900         msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
4901         msg.drv = hif_drv;
4902
4903         pstrMulticastFilterParam->enabled = bIsEnabled;
4904         pstrMulticastFilterParam->cnt = u32count;
4905
4906         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4907         if (s32Error)
4908                 PRINT_ER("wilc_mq_send fail\n");
4909         return s32Error;
4910 }
4911
4912 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
4913 {
4914         struct join_bss_param *pNewJoinBssParam = NULL;
4915         u8 *pu8IEs;
4916         u16 u16IEsLen;
4917         u16 index = 0;
4918         u8 suppRatesNo = 0;
4919         u8 extSuppRatesNo;
4920         u16 jumpOffset;
4921         u8 pcipherCount;
4922         u8 authCount;
4923         u8 pcipherTotalCount = 0;
4924         u8 authTotalCount = 0;
4925         u8 i, j;
4926
4927         pu8IEs = ptstrNetworkInfo->pu8IEs;
4928         u16IEsLen = ptstrNetworkInfo->u16IEsLen;
4929
4930         pNewJoinBssParam = kzalloc(sizeof(struct join_bss_param), GFP_KERNEL);
4931         if (pNewJoinBssParam != NULL) {
4932                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
4933                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
4934                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
4935                 memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
4936                 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
4937                 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
4938                 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
4939                 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
4940
4941                 while (index < u16IEsLen) {
4942                         if (pu8IEs[index] == SUPP_RATES_IE) {
4943                                 suppRatesNo = pu8IEs[index + 1];
4944                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
4945                                 index += 2;
4946
4947                                 for (i = 0; i < suppRatesNo; i++) {
4948                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
4949                                 }
4950                                 index += suppRatesNo;
4951                                 continue;
4952                         } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
4953                                 extSuppRatesNo = pu8IEs[index + 1];
4954                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
4955                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
4956                                 else
4957                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
4958                                 index += 2;
4959                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
4960                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
4961                                 }
4962                                 index += extSuppRatesNo;
4963                                 continue;
4964                         } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
4965                                 pNewJoinBssParam->ht_capable = true;
4966                                 index += pu8IEs[index + 1] + 2;
4967                                 continue;
4968                         } else if ((pu8IEs[index] == WMM_IE) &&
4969                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
4970                                    (pu8IEs[index + 4] == 0xF2) &&
4971                                    (pu8IEs[index + 5] == 0x02) &&
4972                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
4973                                    (pu8IEs[index + 7] == 0x01)) {
4974                                 pNewJoinBssParam->wmm_cap = true;
4975
4976                                 if (pu8IEs[index + 8] & BIT(7))
4977                                         pNewJoinBssParam->uapsd_cap = true;
4978                                 index += pu8IEs[index + 1] + 2;
4979                                 continue;
4980                         } else if ((pu8IEs[index] == P2P_IE) &&
4981                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
4982                                  (pu8IEs[index + 4] == 0x9a) &&
4983                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
4984                                 u16 u16P2P_count;
4985
4986                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
4987                                 pNewJoinBssParam->u8NoaEnbaled = 1;
4988                                 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
4989
4990                                 if (pu8IEs[index + 10] & BIT(7)) {
4991                                         pNewJoinBssParam->u8OppEnable = 1;
4992                                         pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
4993                                 } else
4994                                         pNewJoinBssParam->u8OppEnable = 0;
4995
4996                                 PRINT_D(GENERIC_DBG, "P2P Dump\n");
4997                                 for (i = 0; i < pu8IEs[index + 7]; i++)
4998                                         PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
4999
5000                                 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
5001                                 u16P2P_count = index + 12;
5002
5003                                 memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
5004                                 u16P2P_count += 4;
5005
5006                                 memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
5007                                 u16P2P_count += 4;
5008
5009                                 memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
5010
5011                                 index += pu8IEs[index + 1] + 2;
5012                                 continue;
5013
5014                         } else if ((pu8IEs[index] == RSN_IE) ||
5015                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
5016                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
5017                                   (pu8IEs[index + 5] == 0x01))) {
5018                                 u16 rsnIndex = index;
5019
5020                                 if (pu8IEs[rsnIndex] == RSN_IE) {
5021                                         pNewJoinBssParam->mode_802_11i = 2;
5022                                 } else {
5023                                         if (pNewJoinBssParam->mode_802_11i == 0)
5024                                                 pNewJoinBssParam->mode_802_11i = 1;
5025                                         rsnIndex += 4;
5026                                 }
5027
5028                                 rsnIndex += 7;
5029                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
5030                                 rsnIndex++;
5031                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5032                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5033                                 rsnIndex += 2;
5034
5035                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
5036                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5037                                 }
5038                                 pcipherTotalCount += pcipherCount;
5039                                 rsnIndex += jumpOffset;
5040
5041                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5042
5043                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5044                                 rsnIndex += 2;
5045
5046                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
5047                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5048                                 }
5049                                 authTotalCount += authCount;
5050                                 rsnIndex += jumpOffset;
5051
5052                                 if (pu8IEs[index] == RSN_IE) {
5053                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
5054                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
5055                                         rsnIndex += 2;
5056                                 }
5057                                 pNewJoinBssParam->rsn_found = true;
5058                                 index += pu8IEs[index + 1] + 2;
5059                                 continue;
5060                         } else
5061                                 index += pu8IEs[index + 1] + 2;
5062
5063                 }
5064
5065
5066         }
5067
5068         return (void *)pNewJoinBssParam;
5069
5070 }
5071
5072 void host_int_freeJoinParams(void *pJoinParams)
5073 {
5074         if ((struct bss_param *)pJoinParams != NULL)
5075                 kfree((struct bss_param *)pJoinParams);
5076         else
5077                 PRINT_ER("Unable to FREE null pointer\n");
5078 }
5079
5080 s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID)
5081 {
5082         s32 s32Error = 0;
5083         struct host_if_msg msg;
5084         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5085
5086         if (!hif_drv) {
5087                 PRINT_ER("driver is null\n");
5088                 return -EFAULT;
5089         }
5090
5091         memset(&msg, 0, sizeof(struct host_if_msg));
5092
5093         msg.id = HOST_IF_MSG_DEL_BA_SESSION;
5094
5095         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5096         pBASessionInfo->u8Ted = TID;
5097         msg.drv = hif_drv;
5098
5099         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5100         if (s32Error)
5101                 PRINT_ER("wilc_mq_send fail\n");
5102
5103         down(&hWaitResponse);
5104
5105         return s32Error;
5106 }
5107
5108 s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv,
5109                                   char *pBSSID,
5110                                   char TID)
5111 {
5112         s32 s32Error = 0;
5113         struct host_if_msg msg;
5114         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5115
5116         if (!hif_drv) {
5117                 PRINT_ER("driver is null\n");
5118                 return -EFAULT;
5119         }
5120
5121         memset(&msg, 0, sizeof(struct host_if_msg));
5122
5123         msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
5124
5125         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5126         pBASessionInfo->u8Ted = TID;
5127         msg.drv = hif_drv;
5128
5129         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5130         if (s32Error)
5131                 PRINT_ER("wilc_mq_send fail\n");
5132
5133         down(&hWaitResponse);
5134
5135         return s32Error;
5136 }
5137
5138 s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5139 {
5140         s32 s32Error = 0;
5141         struct host_if_msg msg;
5142
5143         return 0;
5144
5145         if (!hif_drv) {
5146                 PRINT_ER("driver is null\n");
5147                 return -EFAULT;
5148         }
5149
5150         memset(&msg, 0, sizeof(struct host_if_msg));
5151
5152         msg.id = HOST_IF_MSG_SET_IPADDRESS;
5153
5154         msg.body.ip_info.ip_addr = u16ipadd;
5155         msg.drv = hif_drv;
5156         msg.body.ip_info.idx = idx;
5157
5158         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5159         if (s32Error)
5160                 PRINT_ER("wilc_mq_send fail\n");
5161
5162         return s32Error;
5163
5164
5165 }
5166
5167 s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5168 {
5169         s32 s32Error = 0;
5170         struct host_if_msg msg;
5171
5172         if (!hif_drv) {
5173                 PRINT_ER("driver is null\n");
5174                 return -EFAULT;
5175         }
5176
5177         memset(&msg, 0, sizeof(struct host_if_msg));
5178
5179         msg.id = HOST_IF_MSG_GET_IPADDRESS;
5180
5181         msg.body.ip_info.ip_addr = u16ipadd;
5182         msg.drv = hif_drv;
5183         msg.body.ip_info.idx = idx;
5184
5185         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5186         if (s32Error)
5187                 PRINT_ER("wilc_mq_send fail\n");
5188
5189         return s32Error;
5190
5191
5192 }