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