]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
staging: wilc1000: remove unused variable g_flushing_in_progress
[karo-tx-linux.git] / drivers / staging / wilc1000 / wilc_wfi_cfgoperations.c
1 /*!
2  *  @file       wilc_wfi_cfgopertaions.c
3  *  @brief      CFG80211 Function Implementation functionality
4  *  @author     aabouzaeid
5  *                      mabubakr
6  *                      mdaftedar
7  *                      zsalah
8  *  @sa         wilc_wfi_cfgopertaions.h top level OS wrapper file
9  *  @date       31 Aug 2010
10  *  @version    1.0
11  */
12
13 #include "wilc_wfi_cfgoperations.h"
14 #include "wilc_wlan.c"
15 #ifdef WILC_SDIO
16 #include "linux_wlan_sdio.h"    /* tony : for set_wiphy_dev() */
17 #endif
18
19
20 #define IS_MANAGMEMENT                          0x100
21 #define IS_MANAGMEMENT_CALLBACK                 0x080
22 #define IS_MGMT_STATUS_SUCCES                   0x040
23 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
24
25 extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
26 extern u16 Set_machw_change_vir_if(bool bValue);
27
28 extern int mac_open(struct net_device *ndev);
29 extern int mac_close(struct net_device *ndev);
30
31 tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
32 u32 u32LastScannedNtwrksCountShadow;
33 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
34 struct timer_list hDuringIpTimer;
35 #endif
36 struct timer_list hAgingTimer;
37 static u8 op_ifcs;
38 extern u8 u8ConnectedSSID[6];
39
40 /*BugID_5137*/
41 u8 g_wilc_initialized = 1;
42 extern linux_wlan_t *g_linux_wlan;
43 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
44 extern bool g_obtainingIP;
45 #endif
46
47 #define CHAN2G(_channel, _freq, _flags) {        \
48                 .band             = IEEE80211_BAND_2GHZ, \
49                 .center_freq      = (_freq),             \
50                 .hw_value         = (_channel),          \
51                 .flags            = (_flags),            \
52                 .max_antenna_gain = 0,                   \
53                 .max_power        = 30,                  \
54 }
55
56 /*Frequency range for channels*/
57 static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
58         CHAN2G(1,  2412, 0),
59         CHAN2G(2,  2417, 0),
60         CHAN2G(3,  2422, 0),
61         CHAN2G(4,  2427, 0),
62         CHAN2G(5,  2432, 0),
63         CHAN2G(6,  2437, 0),
64         CHAN2G(7,  2442, 0),
65         CHAN2G(8,  2447, 0),
66         CHAN2G(9,  2452, 0),
67         CHAN2G(10, 2457, 0),
68         CHAN2G(11, 2462, 0),
69         CHAN2G(12, 2467, 0),
70         CHAN2G(13, 2472, 0),
71         CHAN2G(14, 2484, 0),
72 };
73
74 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
75                 .bitrate  = (_rate),                    \
76                 .hw_value = (_hw_value),                \
77                 .flags    = (_flags),                   \
78 }
79
80
81 /* Table 6 in section 3.2.1.1 */
82 static struct ieee80211_rate WILC_WFI_rates[] = {
83         RATETAB_ENT(10,  0,  0),
84         RATETAB_ENT(20,  1,  0),
85         RATETAB_ENT(55,  2,  0),
86         RATETAB_ENT(110, 3,  0),
87         RATETAB_ENT(60,  9,  0),
88         RATETAB_ENT(90,  6,  0),
89         RATETAB_ENT(120, 7,  0),
90         RATETAB_ENT(180, 8,  0),
91         RATETAB_ENT(240, 9,  0),
92         RATETAB_ENT(360, 10, 0),
93         RATETAB_ENT(480, 11, 0),
94         RATETAB_ENT(540, 12, 0),
95 };
96
97 #ifdef WILC_P2P
98 struct p2p_mgmt_data {
99         int size;
100         u8 *buff;
101 };
102
103 /*Global variable used to state the current  connected STA channel*/
104 u8 u8WLANChannel = INVALID_CHANNEL;
105
106 /*BugID_5442*/
107 u8 u8CurrChannel;
108
109 u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
110 u8 u8P2Plocalrandom = 0x01;
111 u8 u8P2Precvrandom = 0x00;
112 u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
113 bool bWilc_ie;
114 #endif
115
116 static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
117         .channels = WILC_WFI_2ghz_channels,
118         .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
119         .bitrates = WILC_WFI_rates,
120         .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
121 };
122
123
124 /*BugID_5137*/
125 struct add_key_params {
126         u8 key_idx;
127         bool pairwise;
128         u8 *mac_addr;
129 };
130 struct add_key_params g_add_gtk_key_params;
131 struct wilc_wfi_key g_key_gtk_params;
132 struct add_key_params g_add_ptk_key_params;
133 struct wilc_wfi_key g_key_ptk_params;
134 struct wilc_wfi_wep_key g_key_wep_params;
135 bool g_ptk_keys_saved;
136 bool g_gtk_keys_saved;
137 bool g_wep_keys_saved;
138
139 #define AGING_TIME      (9 * 1000)
140 #define duringIP_TIME 15000
141
142 void clear_shadow_scan(void *pUserVoid)
143 {
144         int i;
145
146         if (op_ifcs == 0) {
147                 del_timer_sync(&hAgingTimer);
148                 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
149
150                 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
151                         if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
152                                 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
153                                 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
154                         }
155
156                         host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
157                         astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
158                 }
159                 u32LastScannedNtwrksCountShadow = 0;
160         }
161
162 }
163
164 u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
165 {
166         u8 i;
167         int rssi_v = 0;
168         u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
169
170         for (i = 0; i < num_rssi; i++)
171                 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
172
173         rssi_v /= num_rssi;
174         return rssi_v;
175 }
176
177 void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
178 {
179         struct wilc_priv *priv;
180         struct wiphy *wiphy;
181         struct cfg80211_bss *bss = NULL;
182         int i;
183         int rssi = 0;
184
185         priv = (struct wilc_priv *)pUserVoid;
186         wiphy = priv->dev->ieee80211_ptr->wiphy;
187
188         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
189                 tstrNetworkInfo *pstrNetworkInfo;
190
191                 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
192
193
194                 if ((!pstrNetworkInfo->u8Found) || all) {
195                         s32 s32Freq;
196                         struct ieee80211_channel *channel;
197
198                         if (pstrNetworkInfo != NULL) {
199
200                                 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
201                                 channel = ieee80211_get_channel(wiphy, s32Freq);
202
203                                 rssi = get_rssi_avg(pstrNetworkInfo);
204                                 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan)      {
205                                         bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
206                                                                   pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
207                                                                   (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
208                                         cfg80211_put_bss(wiphy, bss);
209                                 }
210                         }
211
212                 }
213         }
214
215 }
216
217 void reset_shadow_found(void *pUserVoid)
218 {
219         int i;
220
221         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
222                 astrLastScannedNtwrksShadow[i].u8Found = 0;
223
224         }
225 }
226
227 void update_scan_time(void *pUserVoid)
228 {
229         int i;
230
231         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
232                 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
233         }
234 }
235
236 static void remove_network_from_shadow(unsigned long arg)
237 {
238         unsigned long now = jiffies;
239         int i, j;
240
241
242         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
243                 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
244                         PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
245
246                         if (astrLastScannedNtwrksShadow[i].pu8IEs != NULL) {
247                                 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
248                                 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
249                         }
250
251                         host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
252
253                         for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
254                                 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
255                         }
256                         u32LastScannedNtwrksCountShadow--;
257                 }
258         }
259
260         PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
261         if (u32LastScannedNtwrksCountShadow != 0) {
262                 hAgingTimer.data = arg;
263                 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
264         } else {
265                 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
266         }
267 }
268
269 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
270 static void clear_duringIP(unsigned long arg)
271 {
272         PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
273         g_obtainingIP = false;
274 }
275 #endif
276
277 int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
278 {
279         int8_t state = -1;
280         int i;
281
282         if (u32LastScannedNtwrksCountShadow == 0) {
283                 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
284                 hAgingTimer.data = (unsigned long)pUserVoid;
285                 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
286                 state = -1;
287         } else {
288                 /* Linear search for now */
289                 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
290                         if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
291                                         pstrNetworkInfo->au8bssid, 6) == 0) {
292                                 state = i;
293                                 break;
294                         }
295                 }
296         }
297         return state;
298 }
299
300 void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
301 {
302         int8_t ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
303         u32 ap_index = 0;
304         u8 rssi_index = 0;
305
306         if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
307                 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
308                 return;
309         }
310         if (ap_found == -1) {
311                 ap_index = u32LastScannedNtwrksCountShadow;
312                 u32LastScannedNtwrksCountShadow++;
313
314         } else {
315                 ap_index = ap_found;
316         }
317         rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
318         astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
319         if (rssi_index == NUM_RSSI) {
320                 rssi_index = 0;
321                 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
322         }
323         astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
324
325         astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
326         astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
327
328         astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
329         memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
330                     pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
331
332         memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
333                     pstrNetworkInfo->au8bssid, ETH_ALEN);
334
335         astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
336         astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
337         astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
338
339         astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
340         astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
341         if (ap_found != -1)
342                 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
343         astrLastScannedNtwrksShadow[ap_index].pu8IEs =
344                 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL);        /* will be deallocated by the WILC_WFI_CfgScan() function */
345         memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
346                     pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
347
348         astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
349         astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
350         astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
351         if (ap_found != -1)
352                 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
353         astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
354
355 }
356
357
358 /**
359  *  @brief      CfgScanResult
360  *  @details  Callback function which returns the scan results found
361  *
362  *  @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is
363  *                        SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE
364  *                        tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information
365  *                        void* pUserVoid: Private structure associated with the wireless interface
366  *  @return     NONE
367  *  @author     mabubakr
368  *  @date
369  *  @version    1.0
370  */
371 static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
372 {
373         struct wilc_priv *priv;
374         struct wiphy *wiphy;
375         s32 s32Freq;
376         struct ieee80211_channel *channel;
377         s32 s32Error = WILC_SUCCESS;
378         struct cfg80211_bss *bss = NULL;
379
380         priv = (struct wilc_priv *)pUserVoid;
381         if (priv->bCfgScanning == true) {
382                 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
383                         wiphy = priv->dev->ieee80211_ptr->wiphy;
384                         WILC_NULLCHECK(s32Error, wiphy);
385                         if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
386                             &&
387                             ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
388                              ||
389                              (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
390                             ) {
391                                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
392                         }
393
394                         if (pstrNetworkInfo != NULL) {
395                                 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
396                                 channel = ieee80211_get_channel(wiphy, s32Freq);
397
398                                 WILC_NULLCHECK(s32Error, channel);
399
400                                 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
401                                            "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
402                                            pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
403
404                                 if (pstrNetworkInfo->bNewNetwork == true) {
405                                         if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
406                                                 /*               max_scan_ssids */
407                                                 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
408
409
410                                                 priv->u32RcvdChCount++;
411
412
413
414                                                 if (pJoinParams == NULL) {
415                                                         PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
416                                                 }
417                                                 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
418
419                                                 /*P2P peers are sent to WPA supplicant and added to shadow table*/
420
421                                                 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
422                                                         bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN,  pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
423                                                                                   pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
424                                                                                   (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
425                                                         cfg80211_put_bss(wiphy, bss);
426                                                 }
427
428
429                                         } else {
430                                                 PRINT_ER("Discovered networks exceeded the max limit\n");
431                                         }
432                                 } else {
433                                         u32 i;
434                                         /* So this network is discovered before, we'll just update its RSSI */
435                                         for (i = 0; i < priv->u32RcvdChCount; i++) {
436                                                 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
437                                                         PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
438
439                                                         astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
440                                                         astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
441                                                         break;
442                                                 }
443                                         }
444                                 }
445                         }
446                 } else if (enuScanEvent == SCAN_EVENT_DONE)    {
447                         PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
448                         PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
449                         refresh_scan(priv, 1, false);
450
451                         if (priv->u32RcvdChCount > 0)
452                                 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
453                         else
454                                 PRINT_D(CFG80211_DBG, "No networks found\n");
455
456                         down(&(priv->hSemScanReq));
457
458                         if (priv->pstrScanReq != NULL) {
459                                 cfg80211_scan_done(priv->pstrScanReq, false);
460                                 priv->u32RcvdChCount = 0;
461                                 priv->bCfgScanning = false;
462                                 priv->pstrScanReq = NULL;
463                         }
464                         up(&(priv->hSemScanReq));
465
466                 }
467                 /*Aborting any scan operation during mac close*/
468                 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
469                         down(&(priv->hSemScanReq));
470
471                         PRINT_D(CFG80211_DBG, "Scan Aborted\n");
472                         if (priv->pstrScanReq != NULL) {
473
474                                 update_scan_time(priv);
475                                 refresh_scan(priv, 1, false);
476
477                                 cfg80211_scan_done(priv->pstrScanReq, false);
478                                 priv->bCfgScanning = false;
479                                 priv->pstrScanReq = NULL;
480                         }
481                         up(&(priv->hSemScanReq));
482                 }
483         }
484
485
486         WILC_CATCH(s32Error)
487         {
488         }
489 }
490
491
492 /**
493  *  @brief      WILC_WFI_Set_PMKSA
494  *  @details  Check if pmksa is cached and set it.
495  *  @param[in]
496  *  @return     int : Return 0 on Success
497  *  @author     mdaftedar
498  *  @date       01 MAR 2012
499  *  @version    1.0
500  */
501 int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
502 {
503         u32 i;
504         s32 s32Error = WILC_SUCCESS;
505
506
507         for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
508
509                 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
510                                  ETH_ALEN)) {
511                         PRINT_D(CFG80211_DBG, "PMKID successful comparison");
512
513                         /*If bssid is found, set the values*/
514                         s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
515
516                         if (s32Error != WILC_SUCCESS)
517                                 PRINT_ER("Error in pmkid\n");
518
519                         break;
520                 }
521         }
522
523         return s32Error;
524
525
526 }
527 int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
528
529
530 /**
531  *  @brief      CfgConnectResult
532  *  @details
533  *  @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
534  *                        connection response or disconnection notification.
535  *                        tstrConnectInfo* pstrConnectInfo: COnnection information.
536  *                        u8 u8MacStatus: Mac Status from firmware
537  *                        tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
538  *                        void* pUserVoid: Private data associated with wireless interface
539  *  @return     NONE
540  *  @author     mabubakr
541  *  @date       01 MAR 2012
542  *  @version    1.0
543  */
544 int connecting;
545
546 static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
547                              tstrConnectInfo *pstrConnectInfo,
548                              u8 u8MacStatus,
549                              tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
550                              void *pUserVoid)
551 {
552         struct wilc_priv *priv;
553         struct net_device *dev;
554         #ifdef WILC_P2P
555         tstrWILC_WFIDrv *pstrWFIDrv;
556         #endif
557         u8 NullBssid[ETH_ALEN] = {0};
558
559         connecting = 0;
560
561         priv = (struct wilc_priv *)pUserVoid;
562         dev = priv->dev;
563         #ifdef WILC_P2P
564         pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
565         #endif
566
567         if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
568                 /*Initialization*/
569                 u16 u16ConnectStatus = WLAN_STATUS_SUCCESS;
570
571                 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
572
573                 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
574
575                 if ((u8MacStatus == MAC_DISCONNECTED) &&
576                     (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
577                         /* The case here is that our station was waiting for association response frame and has just received it containing status code
578                          *  = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
579                         u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
580                         linux_wlan_set_bssid(priv->dev, NullBssid);
581                         memset(u8ConnectedSSID, 0, ETH_ALEN);
582
583                         /*BugID_5457*/
584                         /*Invalidate u8WLANChannel value on wlan0 disconnect*/
585                         #ifdef WILC_P2P
586                         if (!pstrWFIDrv->u8P2PConnect)
587                                 u8WLANChannel = INVALID_CHANNEL;
588                         #endif
589
590                         PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
591                 }
592
593                 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
594                         bool bNeedScanRefresh = false;
595                         u32 i;
596
597                         PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
598                                    pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
599                         memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
600
601                         /* BugID_4209: if this network has expired in the scan results in the above nl80211 layer, refresh them here by calling
602                          *  cfg80211_inform_bss() with the last Scan results before calling cfg80211_connect_result() to avoid
603                          *  Linux kernel warning generated at the nl80211 layer */
604
605                         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
606                                 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
607                                                 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
608                                         unsigned long now = jiffies;
609
610                                         if (time_after(now,
611                                                        astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
612                                                 bNeedScanRefresh = true;
613                                         }
614
615                                         break;
616                                 }
617                         }
618
619                         if (bNeedScanRefresh) {
620                                 /*BugID_5418*/
621                                 /*Also, refrsh DIRECT- results if */
622                                 refresh_scan(priv, 1, true);
623
624                         }
625
626                 }
627
628
629                 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
630
631                 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
632
633                 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
634                                         pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
635                                         pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
636                                         u16ConnectStatus, GFP_KERNEL);                         /* TODO: mostafa: u16ConnectStatus to */
637                 /* be replaced by pstrConnectInfo->u16ConnectStatus */
638         } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF)    {
639                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
640                 g_obtainingIP = false;
641                 #endif
642                 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
643                          pstrDisconnectNotifInfo->u16reason, priv->dev);
644                 u8P2Plocalrandom = 0x01;
645                 u8P2Precvrandom = 0x00;
646                 bWilc_ie = false;
647                 memset(priv->au8AssociatedBss, 0, ETH_ALEN);
648                 linux_wlan_set_bssid(priv->dev, NullBssid);
649                 memset(u8ConnectedSSID, 0, ETH_ALEN);
650
651                 /*BugID_5457*/
652                 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
653                 #ifdef WILC_P2P
654                 if (!pstrWFIDrv->u8P2PConnect)
655                         u8WLANChannel = INVALID_CHANNEL;
656                 #endif
657                 /*BugID_5315*/
658                 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
659                  *      virtual interface to station*/
660                 if ((pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
661                         pstrDisconnectNotifInfo->u16reason = 3;
662                 }
663                 /*BugID_5315*/
664                 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
665                  *      to scan again and retry the connection*/
666                 else if ((!pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
667                         pstrDisconnectNotifInfo->u16reason = 1;
668                 }
669                 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
670                                       pstrDisconnectNotifInfo->ie_len, false,
671                                       GFP_KERNEL);
672
673         }
674
675 }
676
677
678 /**
679  *  @brief      set_channel
680  *  @details    Set channel for a given wireless interface. Some devices
681  *                      may support multi-channel operation (by channel hopping) so cfg80211
682  *                      doesn't verify much. Note, however, that the passed netdev may be
683  *                      %NULL as well if the user requested changing the channel for the
684  *                      device itself, or for a monitor interface.
685  *  @param[in]
686  *  @return     int : Return 0 on Success
687  *  @author     mdaftedar
688  *  @date       01 MAR 2012
689  *  @version    1.0
690  */
691 static int set_channel(struct wiphy *wiphy,
692                        struct cfg80211_chan_def *chandef)
693 {
694
695         u32 channelnum = 0;
696         struct wilc_priv *priv;
697         s32 s32Error = WILC_SUCCESS;
698
699         priv = wiphy_priv(wiphy);
700
701         channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
702         PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
703
704         u8CurrChannel = channelnum;
705         s32Error   = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
706
707         if (s32Error != WILC_SUCCESS)
708                 PRINT_ER("Error in setting channel %d\n", channelnum);
709
710         return s32Error;
711 }
712
713 /**
714  *  @brief      scan
715  *  @details    Request to do a scan. If returning zero, the scan request is given
716  *                      the driver, and will be valid until passed to cfg80211_scan_done().
717  *                      For scan results, call cfg80211_inform_bss(); you can call this outside
718  *                      the scan/scan_done bracket too.
719  *  @param[in]
720  *  @return     int : Return 0 on Success
721  *  @author     mabubakr
722  *  @date       01 MAR 2012
723  *  @version    1.0
724  */
725
726 /*
727  *      kernel version 3.8.8 supported
728  *      tony, sswd, WILC-KR, 2013-10-29
729  */
730 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
731 {
732         struct wilc_priv *priv;
733         u32 i;
734         s32 s32Error = WILC_SUCCESS;
735         u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
736         tstrHiddenNetwork strHiddenNetwork;
737
738         priv = wiphy_priv(wiphy);
739
740         priv->pstrScanReq = request;
741
742         priv->u32RcvdChCount = 0;
743
744         host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
745
746
747         reset_shadow_found(priv);
748
749         priv->bCfgScanning = true;
750         if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
751                 /*               max_scan_ssids */
752                 for (i = 0; i < request->n_channels; i++) {
753                         au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
754                         PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
755                 }
756
757                 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
758                 PRINT_D(CFG80211_DBG, "Scan Request IE len =  %zu\n", request->ie_len);
759
760                 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
761
762                 if (request->n_ssids >= 1) {
763
764
765                         strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(tstrHiddenNetwork), GFP_KERNEL);
766                         strHiddenNetwork.u8ssidnum = request->n_ssids;
767
768
769                         /*BugID_4156*/
770                         for (i = 0; i < request->n_ssids; i++) {
771
772                                 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
773                                         strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
774                                         memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
775                                         strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
776                                 } else {
777                                         PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
778                                         strHiddenNetwork.u8ssidnum -= 1;
779                                 }
780                         }
781                         PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
782                         s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
783                                                  au8ScanChanList, request->n_channels,
784                                                  (const u8 *)request->ie, request->ie_len,
785                                                  CfgScanResult, (void *)priv, &strHiddenNetwork);
786                 } else {
787                         PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
788                         s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
789                                                  au8ScanChanList, request->n_channels,
790                                                  (const u8 *)request->ie, request->ie_len,
791                                                  CfgScanResult, (void *)priv, NULL);
792                 }
793
794         } else {
795                 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
796                          " channels\n");
797         }
798
799         if (s32Error != WILC_SUCCESS) {
800                 s32Error = -EBUSY;
801                 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
802         }
803
804         return s32Error;
805 }
806
807 /**
808  *  @brief      connect
809  *  @details    Connect to the ESS with the specified parameters. When connected,
810  *                      call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
811  *                      If the connection fails for some reason, call cfg80211_connect_result()
812  *                      with the status from the AP.
813  *  @param[in]
814  *  @return     int : Return 0 on Success
815  *  @author     mabubakr
816  *  @date       01 MAR 2012
817  *  @version    1.0
818  */
819 static int connect(struct wiphy *wiphy, struct net_device *dev,
820                    struct cfg80211_connect_params *sme)
821 {
822         s32 s32Error = WILC_SUCCESS;
823         u32 i;
824         u8 u8security = NO_ENCRYPT;
825         AUTHTYPE_T tenuAuth_type = ANY;
826         char *pcgroup_encrypt_val = NULL;
827         char *pccipher_group = NULL;
828         char *pcwpa_version = NULL;
829
830         struct wilc_priv *priv;
831         tstrWILC_WFIDrv *pstrWFIDrv;
832         tstrNetworkInfo *pstrNetworkInfo = NULL;
833
834
835         connecting = 1;
836         priv = wiphy_priv(wiphy);
837         pstrWFIDrv = (tstrWILC_WFIDrv *)(priv->hWILCWFIDrv);
838
839         host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
840
841         PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
842         #ifdef WILC_P2P
843         if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
844                 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
845                 pstrWFIDrv->u8P2PConnect = 1;
846         } else
847                 pstrWFIDrv->u8P2PConnect = 0;
848         #endif
849         PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
850
851         for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
852                 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
853                     memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
854                                 sme->ssid,
855                                 sme->ssid_len) == 0) {
856                         PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
857                         if (sme->bssid == NULL) {
858                                 /* BSSID is not passed from the user, so decision of matching
859                                  * is done by SSID only */
860                                 PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n");
861                                 break;
862                         } else {
863                                 /* BSSID is also passed from the user, so decision of matching
864                                  * should consider also this passed BSSID */
865                                 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
866                                                 sme->bssid,
867                                                 ETH_ALEN) == 0) {
868                                         PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
869                                         break;
870                                 }
871                         }
872                 }
873         }
874
875         if (i < u32LastScannedNtwrksCountShadow) {
876                 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
877
878                 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
879
880                 PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n",
881                            pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1],
882                            pstrNetworkInfo->au8bssid[2], pstrNetworkInfo->au8bssid[3],
883                            pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]);
884         } else {
885                 s32Error = -ENOENT;
886                 if (u32LastScannedNtwrksCountShadow == 0)
887                         PRINT_D(CFG80211_DBG, "No Scan results yet\n");
888                 else
889                         PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
890
891                 goto done;
892         }
893
894         priv->WILC_WFI_wep_default = 0;
895         memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
896         memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
897
898         PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
899         PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
900
901         PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
902
903         if (INFO) {
904                 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
905                         PRINT_D(CORECONFIG_DBG, "sme->crypto.ciphers_pairwise[%d]=%x\n", i, sme->crypto.ciphers_pairwise[i]);
906         }
907
908         if (sme->crypto.cipher_group != NO_ENCRYPT) {
909                 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
910                  *  we will add to it the pairwise cipher suite(s) */
911                 pcwpa_version = "Default";
912                 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
913                 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
914                         u8security = ENCRYPT_ENABLED | WEP;
915                         pcgroup_encrypt_val = "WEP40";
916                         pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
917                         PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
918
919                         if (INFO) {
920                                 for (i = 0; i < sme->key_len; i++)
921                                         PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
922                         }
923                         priv->WILC_WFI_wep_default = sme->key_idx;
924                         priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
925                         memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
926
927                         /*BugID_5137*/
928                         g_key_wep_params.key_len = sme->key_len;
929                         g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
930                         memcpy(g_key_wep_params.key, sme->key, sme->key_len);
931                         g_key_wep_params.key_idx = sme->key_idx;
932                         g_wep_keys_saved = true;
933
934                         host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
935                         host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
936                 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104)   {
937                         u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
938                         pcgroup_encrypt_val = "WEP104";
939                         pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
940
941                         priv->WILC_WFI_wep_default = sme->key_idx;
942                         priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
943                         memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
944
945                         /*BugID_5137*/
946                         g_key_wep_params.key_len = sme->key_len;
947                         g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
948                         memcpy(g_key_wep_params.key, sme->key, sme->key_len);
949                         g_key_wep_params.key_idx = sme->key_idx;
950                         g_wep_keys_saved = true;
951
952                         host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
953                         host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
954                 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)   {
955                         if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
956                                 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
957                                 pcgroup_encrypt_val = "WPA2_TKIP";
958                                 pccipher_group = "TKIP";
959                         } else {     /* TODO: mostafa: here we assume that any other encryption type is AES */
960                                      /* tenuSecurity_t = WPA2_AES; */
961                                 u8security = ENCRYPT_ENABLED | WPA2 | AES;
962                                 pcgroup_encrypt_val = "WPA2_AES";
963                                 pccipher_group = "AES";
964                         }
965                         pcwpa_version = "WPA_VERSION_2";
966                 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)   {
967                         if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
968                                 u8security = ENCRYPT_ENABLED | WPA | TKIP;
969                                 pcgroup_encrypt_val = "WPA_TKIP";
970                                 pccipher_group = "TKIP";
971                         } else {     /* TODO: mostafa: here we assume that any other encryption type is AES */
972                                      /* tenuSecurity_t = WPA_AES; */
973                                 u8security = ENCRYPT_ENABLED | WPA | AES;
974                                 pcgroup_encrypt_val = "WPA_AES";
975                                 pccipher_group = "AES";
976
977                         }
978                         pcwpa_version = "WPA_VERSION_1";
979
980                 } else {
981                         s32Error = -ENOTSUPP;
982                         PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
983
984                         goto done;
985                 }
986
987         }
988
989         /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will
990          *   add to it the pairwise cipher suite(s) */
991         if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
992             || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
993                 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
994                         if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) {
995                                 u8security = u8security | TKIP;
996                         } else {     /* TODO: mostafa: here we assume that any other encryption type is AES */
997                                 u8security = u8security | AES;
998                         }
999                 }
1000         }
1001
1002         PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
1003
1004         PRINT_D(CFG80211_DBG, "Authentication Type = %d\n", sme->auth_type);
1005         switch (sme->auth_type) {
1006         case NL80211_AUTHTYPE_OPEN_SYSTEM:
1007                 PRINT_D(CFG80211_DBG, "In OPEN SYSTEM\n");
1008                 tenuAuth_type = OPEN_SYSTEM;
1009                 break;
1010
1011         case NL80211_AUTHTYPE_SHARED_KEY:
1012                 tenuAuth_type = SHARED_KEY;
1013                 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
1014                 break;
1015
1016         default:
1017                 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
1018         }
1019
1020
1021         /* ai: key_mgmt: enterprise case */
1022         if (sme->crypto.n_akm_suites) {
1023                 switch (sme->crypto.akm_suites[0]) {
1024                 case WLAN_AKM_SUITE_8021X:
1025                         tenuAuth_type = IEEE8021;
1026                         break;
1027
1028                 default:
1029                         break;
1030                 }
1031         }
1032
1033
1034         PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
1035
1036         PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
1037                    pcgroup_encrypt_val, pccipher_group, pcwpa_version);
1038
1039         /*BugID_5442*/
1040         u8CurrChannel = pstrNetworkInfo->u8channel;
1041
1042         if (!pstrWFIDrv->u8P2PConnect) {
1043                 u8WLANChannel = pstrNetworkInfo->u8channel;
1044         }
1045
1046         linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1047
1048         s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1049                                          sme->ssid_len, sme->ie, sme->ie_len,
1050                                          CfgConnectResult, (void *)priv, u8security,
1051                                          tenuAuth_type, pstrNetworkInfo->u8channel,
1052                                          pstrNetworkInfo->pJoinParams);
1053         if (s32Error != WILC_SUCCESS) {
1054                 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
1055                 s32Error = -ENOENT;
1056                 goto done;
1057         }
1058
1059 done:
1060
1061         return s32Error;
1062 }
1063
1064
1065 /**
1066  *  @brief      disconnect
1067  *  @details    Disconnect from the BSS/ESS.
1068  *  @param[in]
1069  *  @return     int : Return 0 on Success
1070  *  @author     mdaftedar
1071  *  @date       01 MAR 2012
1072  *  @version    1.0
1073  */
1074 static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
1075 {
1076         s32 s32Error = WILC_SUCCESS;
1077         struct wilc_priv *priv;
1078         #ifdef WILC_P2P
1079         tstrWILC_WFIDrv *pstrWFIDrv;
1080         #endif
1081         u8 NullBssid[ETH_ALEN] = {0};
1082
1083         connecting = 0;
1084         priv = wiphy_priv(wiphy);
1085
1086         /*BugID_5457*/
1087         /*Invalidate u8WLANChannel value on wlan0 disconnect*/
1088         #ifdef WILC_P2P
1089         pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
1090         if (!pstrWFIDrv->u8P2PConnect)
1091                 u8WLANChannel = INVALID_CHANNEL;
1092         #endif
1093         linux_wlan_set_bssid(priv->dev, NullBssid);
1094
1095         PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1096
1097         u8P2Plocalrandom = 0x01;
1098         u8P2Precvrandom = 0x00;
1099         bWilc_ie = false;
1100         #ifdef WILC_P2P
1101         pstrWFIDrv->u64P2p_MgmtTimeout = 0;
1102         #endif
1103
1104         s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
1105         if (s32Error != WILC_SUCCESS) {
1106                 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1107                 s32Error = -EINVAL;
1108         }
1109
1110         return s32Error;
1111 }
1112
1113 /**
1114  *  @brief      add_key
1115  *  @details    Add a key with the given parameters. @mac_addr will be %NULL
1116  *                      when adding a group key.
1117  *  @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1118  *  @return     int : Return 0 on Success
1119  *  @author     mdaftedar
1120  *  @date       01 MAR 2012
1121  *  @version    1.0
1122  */
1123 static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1124                    bool pairwise,
1125                    const u8 *mac_addr, struct key_params *params)
1126
1127 {
1128         s32 s32Error = WILC_SUCCESS, KeyLen = params->key_len;
1129         u32 i;
1130         struct wilc_priv *priv;
1131         const u8 *pu8RxMic = NULL;
1132         const u8 *pu8TxMic = NULL;
1133         u8 u8mode = NO_ENCRYPT;
1134         #ifdef WILC_AP_EXTERNAL_MLME
1135         u8 u8gmode = NO_ENCRYPT;
1136         u8 u8pmode = NO_ENCRYPT;
1137         AUTHTYPE_T tenuAuth_type = ANY;
1138         #endif
1139
1140         priv = wiphy_priv(wiphy);
1141
1142         PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1143
1144         /*BugID_5137*/
1145         PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
1146
1147         PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1148                 params->key[1],
1149                 params->key[2]);
1150
1151
1152         switch (params->cipher) {
1153         case WLAN_CIPHER_SUITE_WEP40:
1154         case WLAN_CIPHER_SUITE_WEP104:
1155                                 #ifdef WILC_AP_EXTERNAL_MLME
1156                 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1157
1158                         priv->WILC_WFI_wep_default = key_index;
1159                         priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1160                         memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1161
1162                         PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1163                         PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1164
1165                         for (i = 0; i < params->key_len; i++)
1166                                 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1167
1168                         tenuAuth_type = OPEN_SYSTEM;
1169
1170                         if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1171                                 u8mode = ENCRYPT_ENABLED | WEP;
1172                         else
1173                                 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1174
1175                         host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1176                         break;
1177                 }
1178                                 #endif
1179                 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
1180                         priv->WILC_WFI_wep_default = key_index;
1181                         priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1182                         memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1183
1184                         PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1185                         PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1186                         if (INFO) {
1187                                 for (i = 0; i < params->key_len; i++)
1188                                         PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1189                         }
1190                         host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1191                 }
1192
1193                 break;
1194
1195         case WLAN_CIPHER_SUITE_TKIP:
1196         case WLAN_CIPHER_SUITE_CCMP:
1197                                 #ifdef WILC_AP_EXTERNAL_MLME
1198                 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1199
1200                         if (priv->wilc_gtk[key_index] == NULL) {
1201                                 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1202                                 priv->wilc_gtk[key_index]->key = NULL;
1203                                 priv->wilc_gtk[key_index]->seq = NULL;
1204
1205                         }
1206                         if (priv->wilc_ptk[key_index] == NULL) {
1207                                 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1208                                 priv->wilc_ptk[key_index]->key = NULL;
1209                                 priv->wilc_ptk[key_index]->seq = NULL;
1210                         }
1211
1212
1213
1214                         if (!pairwise) {
1215                                 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1216                                         u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1217                                 else
1218                                         u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1219
1220                                 priv->wilc_groupkey = u8gmode;
1221
1222                                 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1223
1224                                         pu8TxMic = params->key + 24;
1225                                         pu8RxMic = params->key + 16;
1226                                         KeyLen = params->key_len - 16;
1227                                 }
1228                                 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
1229                                 if (priv->wilc_gtk[key_index]->key)
1230                                         kfree(priv->wilc_gtk[key_index]->key);
1231
1232                                 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1233                                 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
1234
1235                                 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
1236                                 if (priv->wilc_gtk[key_index]->seq)
1237                                         kfree(priv->wilc_gtk[key_index]->seq);
1238
1239                                 if ((params->seq_len) > 0) {
1240                                         priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
1241                                         memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
1242                                 }
1243
1244                                 priv->wilc_gtk[key_index]->cipher = params->cipher;
1245                                 priv->wilc_gtk[key_index]->key_len = params->key_len;
1246                                 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1247
1248                                 if (INFO) {
1249                                         for (i = 0; i < params->key_len; i++)
1250                                                 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1251                                         for (i = 0; i < params->seq_len; i++)
1252                                                 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1253                                 }
1254
1255
1256                                 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1257                                                     key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1258
1259                         } else {
1260                                 PRINT_INFO(CFG80211_DBG, "STA Address: %x%x%x%x%x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4]);
1261
1262                                 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1263                                         u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1264                                 else
1265                                         u8pmode = priv->wilc_groupkey | AES;
1266
1267
1268                                 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1269
1270                                         pu8TxMic = params->key + 24;
1271                                         pu8RxMic = params->key + 16;
1272                                         KeyLen = params->key_len - 16;
1273                                 }
1274
1275                                 if (priv->wilc_ptk[key_index]->key)
1276                                         kfree(priv->wilc_ptk[key_index]->key);
1277
1278                                 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1279
1280                                 if (priv->wilc_ptk[key_index]->seq)
1281                                         kfree(priv->wilc_ptk[key_index]->seq);
1282
1283                                 if ((params->seq_len) > 0)
1284                                         priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
1285
1286                                 if (INFO) {
1287                                         for (i = 0; i < params->key_len; i++)
1288                                                 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1289
1290                                         for (i = 0; i < params->seq_len; i++)
1291                                                 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1292                                 }
1293
1294                                 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
1295
1296                                 if ((params->seq_len) > 0)
1297                                         memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
1298
1299                                 priv->wilc_ptk[key_index]->cipher = params->cipher;
1300                                 priv->wilc_ptk[key_index]->key_len = params->key_len;
1301                                 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1302
1303                                 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1304                                                  pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1305                         }
1306                         break;
1307                 }
1308                                 #endif
1309
1310                 {
1311                         u8mode = 0;
1312                         if (!pairwise) {
1313                                 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1314                                         /* swap the tx mic by rx mic */
1315                                         pu8RxMic = params->key + 24;
1316                                         pu8TxMic = params->key + 16;
1317                                         KeyLen = params->key_len - 16;
1318                                 }
1319
1320                                 /*BugID_5137*/
1321                                 /*save keys only on interface 0 (wifi interface)*/
1322                                 if (!g_gtk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
1323                                         g_add_gtk_key_params.key_idx = key_index;
1324                                         g_add_gtk_key_params.pairwise = pairwise;
1325                                         if (!mac_addr) {
1326                                                 g_add_gtk_key_params.mac_addr = NULL;
1327                                         } else {
1328                                                 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1329                                                 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1330                                         }
1331                                         g_key_gtk_params.key_len = params->key_len;
1332                                         g_key_gtk_params.seq_len = params->seq_len;
1333                                         g_key_gtk_params.key =  kmalloc(params->key_len, GFP_KERNEL);
1334                                         memcpy(g_key_gtk_params.key, params->key, params->key_len);
1335                                         if (params->seq_len > 0) {
1336                                                 g_key_gtk_params.seq =  kmalloc(params->seq_len, GFP_KERNEL);
1337                                                 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1338                                         }
1339                                         g_key_gtk_params.cipher = params->cipher;
1340
1341                                         PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1342                                                 g_key_gtk_params.key[1],
1343                                                 g_key_gtk_params.key[2]);
1344                                         g_gtk_keys_saved = true;
1345                                 }
1346
1347                                 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1348                                                     key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
1349                         } else {
1350                                 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1351                                         /* swap the tx mic by rx mic */
1352                                         pu8RxMic = params->key + 24;
1353                                         pu8TxMic = params->key + 16;
1354                                         KeyLen = params->key_len - 16;
1355                                 }
1356
1357                                 /*BugID_5137*/
1358                                 /*save keys only on interface 0 (wifi interface)*/
1359                                 if (!g_ptk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
1360                                         g_add_ptk_key_params.key_idx = key_index;
1361                                         g_add_ptk_key_params.pairwise = pairwise;
1362                                         if (!mac_addr) {
1363                                                 g_add_ptk_key_params.mac_addr = NULL;
1364                                         } else {
1365                                                 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1366                                                 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1367                                         }
1368                                         g_key_ptk_params.key_len = params->key_len;
1369                                         g_key_ptk_params.seq_len = params->seq_len;
1370                                         g_key_ptk_params.key =  kmalloc(params->key_len, GFP_KERNEL);
1371                                         memcpy(g_key_ptk_params.key, params->key, params->key_len);
1372                                         if (params->seq_len > 0) {
1373                                                 g_key_ptk_params.seq =  kmalloc(params->seq_len, GFP_KERNEL);
1374                                                 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1375                                         }
1376                                         g_key_ptk_params.cipher = params->cipher;
1377
1378                                         PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1379                                                 g_key_ptk_params.key[1],
1380                                                 g_key_ptk_params.key[2]);
1381                                         g_ptk_keys_saved = true;
1382                                 }
1383
1384                                 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1385                                                  pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1386                                 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1387                                 if (INFO) {
1388                                         for (i = 0; i < params->key_len; i++)
1389                                                 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1390                                 }
1391                         }
1392                 }
1393                 break;
1394
1395         default:
1396                 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1397                 s32Error = -ENOTSUPP;
1398
1399         }
1400
1401         return s32Error;
1402 }
1403
1404 /**
1405  *  @brief      del_key
1406  *  @details    Remove a key given the @mac_addr (%NULL for a group key)
1407  *                      and @key_index, return -ENOENT if the key doesn't exist.
1408  *  @param[in]
1409  *  @return     int : Return 0 on Success
1410  *  @author     mdaftedar
1411  *  @date       01 MAR 2012
1412  *  @version    1.0
1413  */
1414 static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1415                    u8 key_index,
1416                    bool pairwise,
1417                    const u8 *mac_addr)
1418 {
1419         struct wilc_priv *priv;
1420         s32 s32Error = WILC_SUCCESS;
1421
1422         priv = wiphy_priv(wiphy);
1423
1424         /*BugID_5137*/
1425         /*delete saved keys, if any*/
1426         if (netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
1427                 g_ptk_keys_saved = false;
1428                 g_gtk_keys_saved = false;
1429                 g_wep_keys_saved = false;
1430
1431                 /*Delete saved WEP keys params, if any*/
1432                 if (g_key_wep_params.key != NULL) {
1433                         kfree(g_key_wep_params.key);
1434                         g_key_wep_params.key = NULL;
1435                 }
1436
1437                 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1438
1439         #ifdef WILC_AP_EXTERNAL_MLME
1440                 if ((priv->wilc_gtk[key_index]) != NULL) {
1441
1442                         if (priv->wilc_gtk[key_index]->key != NULL) {
1443
1444                                 kfree(priv->wilc_gtk[key_index]->key);
1445                                 priv->wilc_gtk[key_index]->key = NULL;
1446                         }
1447                         if (priv->wilc_gtk[key_index]->seq) {
1448
1449                                 kfree(priv->wilc_gtk[key_index]->seq);
1450                                 priv->wilc_gtk[key_index]->seq = NULL;
1451                         }
1452
1453                         kfree(priv->wilc_gtk[key_index]);
1454                         priv->wilc_gtk[key_index] = NULL;
1455
1456                 }
1457
1458                 if ((priv->wilc_ptk[key_index]) != NULL) {
1459
1460                         if (priv->wilc_ptk[key_index]->key) {
1461
1462                                 kfree(priv->wilc_ptk[key_index]->key);
1463                                 priv->wilc_ptk[key_index]->key = NULL;
1464                         }
1465                         if (priv->wilc_ptk[key_index]->seq) {
1466
1467                                 kfree(priv->wilc_ptk[key_index]->seq);
1468                                 priv->wilc_ptk[key_index]->seq = NULL;
1469                         }
1470                         kfree(priv->wilc_ptk[key_index]);
1471                         priv->wilc_ptk[key_index] = NULL;
1472                 }
1473         #endif
1474
1475                 /*Delete saved PTK and GTK keys params, if any*/
1476                 if (g_key_ptk_params.key != NULL) {
1477                         kfree(g_key_ptk_params.key);
1478                         g_key_ptk_params.key = NULL;
1479                 }
1480                 if (g_key_ptk_params.seq != NULL) {
1481                         kfree(g_key_ptk_params.seq);
1482                         g_key_ptk_params.seq = NULL;
1483                 }
1484
1485                 if (g_key_gtk_params.key != NULL) {
1486                         kfree(g_key_gtk_params.key);
1487                         g_key_gtk_params.key = NULL;
1488                 }
1489                 if (g_key_gtk_params.seq != NULL) {
1490                         kfree(g_key_gtk_params.seq);
1491                         g_key_gtk_params.seq = NULL;
1492                 }
1493
1494                 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
1495                 Set_machw_change_vir_if(false);
1496         }
1497
1498         if (key_index >= 0 && key_index <= 3) {
1499                 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
1500                 priv->WILC_WFI_wep_key_len[key_index] = 0;
1501
1502                 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1503                 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1504         } else {
1505                 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1506                 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1507         }
1508
1509         return s32Error;
1510 }
1511
1512 /**
1513  *  @brief      get_key
1514  *  @details    Get information about the key with the given parameters.
1515  *                      @mac_addr will be %NULL when requesting information for a group
1516  *                      key. All pointers given to the @callback function need not be valid
1517  *                      after it returns. This function should return an error if it is
1518  *                      not possible to retrieve the key, -ENOENT if it doesn't exist.
1519  *  @param[in]
1520  *  @return     int : Return 0 on Success
1521  *  @author     mdaftedar
1522  *  @date       01 MAR 2012
1523  *  @version    1.0
1524  */
1525 static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1526                    bool pairwise,
1527                    const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
1528 {
1529
1530         s32 s32Error = WILC_SUCCESS;
1531
1532         struct wilc_priv *priv;
1533         struct  key_params key_params;
1534         u32 i;
1535
1536         priv = wiphy_priv(wiphy);
1537
1538
1539         if (!pairwise)
1540         {
1541                 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1542
1543                 key_params.key = priv->wilc_gtk[key_index]->key;
1544                 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1545                 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1546                 key_params.seq = priv->wilc_gtk[key_index]->seq;
1547                 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1548                 if (INFO) {
1549                         for (i = 0; i < key_params.key_len; i++)
1550                                 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1551                 }
1552         } else {
1553                 PRINT_D(CFG80211_DBG, "Getting pairwise  key\n");
1554
1555                 key_params.key = priv->wilc_ptk[key_index]->key;
1556                 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1557                 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1558                 key_params.seq = priv->wilc_ptk[key_index]->seq;
1559                 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1560         }
1561
1562         callback(cookie, &key_params);
1563
1564         return s32Error;        /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
1565 }
1566
1567 /**
1568  *  @brief      set_default_key
1569  *  @details    Set the default management frame key on an interface
1570  *  @param[in]
1571  *  @return     int : Return 0 on Success.
1572  *  @author     mdaftedar
1573  *  @date       01 MAR 2012
1574  *  @version    1.0
1575  */
1576 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1577                            bool unicast, bool multicast)
1578 {
1579         s32 s32Error = WILC_SUCCESS;
1580         struct wilc_priv *priv;
1581
1582
1583         priv = wiphy_priv(wiphy);
1584
1585         PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
1586
1587         if (key_index != priv->WILC_WFI_wep_default) {
1588
1589                 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
1590         }
1591
1592         return s32Error;
1593 }
1594
1595 /**
1596  *  @brief      WILC_WFI_dump_survey
1597  *  @details    Get site survey information
1598  *  @param[in]
1599  *  @return     int : Return 0 on Success.
1600  *  @author     mdaftedar
1601  *  @date       01 MAR 2012
1602  *  @version    1.0
1603  */
1604 static int WILC_WFI_dump_survey(struct wiphy *wiphy, struct net_device *netdev,
1605                                 int idx, struct survey_info *info)
1606 {
1607         s32 s32Error = WILC_SUCCESS;
1608
1609
1610         if (idx != 0) {
1611                 s32Error = -ENOENT;
1612                 PRINT_ER("Error Idx value doesn't equal zero: Error(%d)\n", s32Error);
1613
1614         }
1615
1616         return s32Error;
1617 }
1618
1619
1620 /**
1621  *  @brief      get_station
1622  *  @details    Get station information for the station identified by @mac
1623  *  @param[in]   NONE
1624  *  @return     int : Return 0 on Success.
1625  *  @author     mdaftedar
1626  *  @date       01 MAR 2012
1627  *  @version    1.0
1628  */
1629
1630 static int get_station(struct wiphy *wiphy, struct net_device *dev,
1631                        const u8 *mac, struct station_info *sinfo)
1632 {
1633         s32 s32Error = WILC_SUCCESS;
1634         struct wilc_priv *priv;
1635         perInterface_wlan_t *nic;
1636         #ifdef WILC_AP_EXTERNAL_MLME
1637         u32 i = 0;
1638         u32 associatedsta = 0;
1639         u32 inactive_time = 0;
1640         #endif
1641         priv = wiphy_priv(wiphy);
1642         nic = netdev_priv(dev);
1643
1644         #ifdef WILC_AP_EXTERNAL_MLME
1645         if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1646                 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1647
1648                 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1649
1650                 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1651
1652                         if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1653                                 associatedsta = i;
1654                                 break;
1655                         }
1656
1657                 }
1658
1659                 if (associatedsta == -1) {
1660                         s32Error = -ENOENT;
1661                         PRINT_ER("Station required is not associated : Error(%d)\n", s32Error);
1662
1663                         return s32Error;
1664                 }
1665
1666                 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
1667
1668                 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1669                 sinfo->inactive_time = 1000 * inactive_time;
1670                 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1671
1672         }
1673         #endif
1674
1675         if (nic->iftype == STATION_MODE) {
1676                 tstrStatistics strStatistics;
1677
1678                 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1679
1680                 /*
1681                  * tony: 2013-11-13
1682                  * tx_failed introduced more than
1683                  * kernel version 3.0.0
1684                  */
1685                 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
1686                                                 BIT(NL80211_STA_INFO_RX_PACKETS) |
1687                                                 BIT(NL80211_STA_INFO_TX_PACKETS) |
1688                                                 BIT(NL80211_STA_INFO_TX_FAILED) |
1689                                                 BIT(NL80211_STA_INFO_TX_BITRATE);
1690
1691                 sinfo->signal           =  strStatistics.s8RSSI;
1692                 sinfo->rx_packets   =  strStatistics.u32RxCount;
1693                 sinfo->tx_packets   =  strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
1694                 sinfo->tx_failed        =  strStatistics.u32TxFailureCount;
1695                 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1696
1697 #ifdef TCP_ENHANCEMENTS
1698                 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
1699                         Enable_TCP_ACK_Filter(true);
1700                 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
1701                         Enable_TCP_ACK_Filter(false);
1702 #endif
1703
1704                 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1705                         sinfo->tx_failed, sinfo->txrate.legacy);
1706         }
1707         return s32Error;
1708 }
1709
1710
1711 /**
1712  *  @brief      change_bss
1713  *  @details    Modify parameters for a given BSS.
1714  *  @param[in]
1715  *   -use_cts_prot: Whether to use CTS protection
1716  *          (0 = no, 1 = yes, -1 = do not change)
1717  *  -use_short_preamble: Whether the use of short preambles is allowed
1718  *          (0 = no, 1 = yes, -1 = do not change)
1719  *  -use_short_slot_time: Whether the use of short slot time is allowed
1720  *          (0 = no, 1 = yes, -1 = do not change)
1721  *  -basic_rates: basic rates in IEEE 802.11 format
1722  *          (or NULL for no change)
1723  *  -basic_rates_len: number of basic rates
1724  *  -ap_isolate: do not forward packets between connected stations
1725  *  -ht_opmode: HT Operation mode
1726  *         (u16 = opmode, -1 = do not change)
1727  *  @return     int : Return 0 on Success.
1728  *  @author     mdaftedar
1729  *  @date       01 MAR 2012
1730  *  @version    1.0
1731  */
1732 static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1733                       struct bss_parameters *params)
1734 {
1735         PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1736         return 0;
1737 }
1738
1739 /**
1740  *  @brief      WILC_WFI_auth
1741  *  @details    Request to authenticate with the specified peer
1742  *  @param[in]
1743  *  @return     int : Return 0 on Success.
1744  *  @author     mdaftedar
1745  *  @date       01 MAR 2012
1746  *  @version    1.0
1747  */
1748 static int WILC_WFI_auth(struct wiphy *wiphy, struct net_device *dev,
1749                          struct cfg80211_auth_request *req)
1750 {
1751         PRINT_D(CFG80211_DBG, "In Authentication Function\n");
1752         return 0;
1753 }
1754
1755 /**
1756  *  @brief      WILC_WFI_assoc
1757  *  @details    Request to (re)associate with the specified peer
1758  *  @param[in]
1759  *  @return     int : Return 0 on Success.
1760  *  @author     mdaftedar
1761  *  @date       01 MAR 2012
1762  *  @version    1.0
1763  */
1764 static int WILC_WFI_assoc(struct wiphy *wiphy, struct net_device *dev,
1765                           struct cfg80211_assoc_request *req)
1766 {
1767         PRINT_D(CFG80211_DBG, "In Association Function\n");
1768         return 0;
1769 }
1770
1771 /**
1772  *  @brief      WILC_WFI_deauth
1773  *  @details    Request to deauthenticate from the specified peer
1774  *  @param[in]
1775  *  @return     int : Return 0 on Success.
1776  *  @author     mdaftedar
1777  *  @date       01 MAR 2012
1778  *  @version    1.0
1779  */
1780 static int  WILC_WFI_deauth(struct wiphy *wiphy, struct net_device *dev,
1781                             struct cfg80211_deauth_request *req, void *cookie)
1782 {
1783         PRINT_D(CFG80211_DBG, "In De-authentication Function\n");
1784         return 0;
1785 }
1786
1787 /**
1788  *  @brief      WILC_WFI_disassoc
1789  *  @details    Request to disassociate from the specified peer
1790  *  @param[in]
1791  *  @return     int : Return 0 on Success
1792  *  @author     mdaftedar
1793  *  @date       01 MAR 2012
1794  *  @version    1.0
1795  */
1796 static int  WILC_WFI_disassoc(struct wiphy *wiphy, struct net_device *dev,
1797                               struct cfg80211_disassoc_request *req, void *cookie)
1798 {
1799         PRINT_D(CFG80211_DBG, "In Disassociation Function\n");
1800         return 0;
1801 }
1802
1803 /**
1804  *  @brief      set_wiphy_params
1805  *  @details    Notify that wiphy parameters have changed;
1806  *  @param[in]   Changed bitfield (see &enum wiphy_params_flags) describes which values
1807  *                      have changed.
1808  *  @return     int : Return 0 on Success
1809  *  @author     mdaftedar
1810  *  @date       01 MAR 2012
1811  *  @version    1.0
1812  */
1813 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
1814 {
1815         s32 s32Error = WILC_SUCCESS;
1816         tstrCfgParamVal pstrCfgParamVal;
1817         struct wilc_priv *priv;
1818
1819         priv = wiphy_priv(wiphy);
1820
1821         pstrCfgParamVal.u32SetCfgFlag = 0;
1822         PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
1823
1824         if (changed & WIPHY_PARAM_RETRY_SHORT) {
1825                 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1826                         priv->dev->ieee80211_ptr->wiphy->retry_short);
1827                 pstrCfgParamVal.u32SetCfgFlag  |= RETRY_SHORT;
1828                 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1829         }
1830         if (changed & WIPHY_PARAM_RETRY_LONG) {
1831
1832                 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
1833                 pstrCfgParamVal.u32SetCfgFlag |= RETRY_LONG;
1834                 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1835
1836         }
1837         if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1838                 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
1839                 pstrCfgParamVal.u32SetCfgFlag |= FRAG_THRESHOLD;
1840                 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1841
1842         }
1843
1844         if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1845                 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1846
1847                 pstrCfgParamVal.u32SetCfgFlag |= RTS_THRESHOLD;
1848                 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1849
1850         }
1851
1852         PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1853         s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1854         if (s32Error)
1855                 PRINT_ER("Error in setting WIPHY PARAMS\n");
1856
1857
1858         return s32Error;
1859 }
1860
1861 /**
1862  *  @brief      WILC_WFI_set_bitrate_mask
1863  *  @details    set the bitrate mask configuration
1864  *  @param[in]
1865  *  @return     int : Return 0 on Success
1866  *  @author     mdaftedar
1867  *  @date       01 MAR 2012
1868  *  @version    1.0
1869  */
1870 static int WILC_WFI_set_bitrate_mask(struct wiphy *wiphy,
1871                                      struct net_device *dev, const u8 *peer,
1872                                      const struct cfg80211_bitrate_mask *mask)
1873 {
1874         s32 s32Error = WILC_SUCCESS;
1875
1876         PRINT_D(CFG80211_DBG, "Setting Bitrate mask function\n");
1877         return s32Error;
1878
1879 }
1880
1881 /**
1882  *  @brief      set_pmksa
1883  *  @details    Cache a PMKID for a BSSID. This is mostly useful for fullmac
1884  *                      devices running firmwares capable of generating the (re) association
1885  *                      RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1886  *  @param[in]
1887  *  @return     int : Return 0 on Success
1888  *  @author     mdaftedar
1889  *  @date       01 MAR 2012
1890  *  @version    1.0
1891  */
1892 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1893                      struct cfg80211_pmksa *pmksa)
1894 {
1895         u32 i;
1896         s32 s32Error = WILC_SUCCESS;
1897         u8 flag = 0;
1898
1899         struct wilc_priv *priv = wiphy_priv(wiphy);
1900
1901         PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1902
1903
1904         for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1905                 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1906                                  ETH_ALEN)) {
1907                         /*If bssid already exists and pmkid value needs to reset*/
1908                         flag = PMKID_FOUND;
1909                         PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1910                         break;
1911                 }
1912         }
1913         if (i < WILC_MAX_NUM_PMKIDS) {
1914                 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
1915                 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
1916                             ETH_ALEN);
1917                 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
1918                             PMKID_LEN);
1919                 if (!(flag == PMKID_FOUND))
1920                         priv->pmkid_list.numpmkid++;
1921         } else {
1922                 PRINT_ER("Invalid PMKID index\n");
1923                 s32Error = -EINVAL;
1924         }
1925
1926         if (!s32Error) {
1927                 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1928                 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1929         }
1930         return s32Error;
1931 }
1932
1933 /**
1934  *  @brief      del_pmksa
1935  *  @details    Delete a cached PMKID.
1936  *  @param[in]
1937  *  @return     int : Return 0 on Success
1938  *  @author     mdaftedar
1939  *  @date       01 MAR 2012
1940  *  @version    1.0
1941  */
1942 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1943                      struct cfg80211_pmksa *pmksa)
1944 {
1945
1946         u32 i;
1947         u8 flag = 0;
1948         s32 s32Error = WILC_SUCCESS;
1949
1950         struct wilc_priv *priv = wiphy_priv(wiphy);
1951
1952         PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1953
1954         for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1955                 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1956                                  ETH_ALEN)) {
1957                         /*If bssid is found, reset the values*/
1958                         PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
1959                         memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(tstrHostIFpmkid));
1960                         flag = PMKID_FOUND;
1961                         break;
1962                 }
1963         }
1964
1965         if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1966                 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
1967                         memcpy(priv->pmkid_list.pmkidlist[i].bssid,
1968                                     priv->pmkid_list.pmkidlist[i + 1].bssid,
1969                                     ETH_ALEN);
1970                         memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
1971                                     priv->pmkid_list.pmkidlist[i].pmkid,
1972                                     PMKID_LEN);
1973                 }
1974                 priv->pmkid_list.numpmkid--;
1975         } else {
1976                 s32Error = -EINVAL;
1977         }
1978
1979         return s32Error;
1980 }
1981
1982 /**
1983  *  @brief      flush_pmksa
1984  *  @details    Flush all cached PMKIDs.
1985  *  @param[in]
1986  *  @return     int : Return 0 on Success
1987  *  @author     mdaftedar
1988  *  @date       01 MAR 2012
1989  *  @version    1.0
1990  */
1991 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1992 {
1993         struct wilc_priv *priv = wiphy_priv(wiphy);
1994
1995         PRINT_D(CFG80211_DBG,  "Flushing  PMKID key values\n");
1996
1997         /*Get cashed Pmkids and set all with zeros*/
1998         memset(&priv->pmkid_list, 0, sizeof(tstrHostIFpmkidAttr));
1999
2000         return 0;
2001 }
2002
2003 #ifdef WILC_P2P
2004
2005 /**
2006  *  @brief      WILC_WFI_CfgParseRxAction
2007  *  @details Function parses the received  frames and modifies the following attributes:
2008  *                -GO Intent
2009  *                  -Channel list
2010  *                  -Operating Channel
2011  *
2012  *  @param[in] u8* Buffer, u32 length
2013  *  @return     NONE.
2014  *  @author     mdaftedar
2015  *  @date       12 DEC 2012
2016  *  @version
2017  */
2018
2019 void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
2020 {
2021         u32 index = 0;
2022         u32 i = 0, j = 0;
2023
2024         /*BugID_5460*/
2025         u8 op_channel_attr_index = 0;
2026         u8 channel_list_attr_index = 0;
2027
2028         while (index < len) {
2029                 if (buf[index] == GO_INTENT_ATTR_ID) {
2030                         buf[index + 3] = (buf[index + 3]  & 0x01) | (0x00 << 1);
2031                 }
2032
2033                 if (buf[index] ==  CHANLIST_ATTR_ID)
2034                         channel_list_attr_index = index;
2035                 else if (buf[index] ==  OPERCHAN_ATTR_ID)
2036                         op_channel_attr_index = index;
2037                 index += buf[index + 1] + 3; /* ID,Length byte */
2038         }
2039
2040         if (u8WLANChannel != INVALID_CHANNEL)
2041         {
2042                 /*Modify channel list attribute*/
2043                 if (channel_list_attr_index) {
2044                         PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
2045                         for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
2046                                 if (buf[i] == 0x51) {
2047                                         for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
2048                                                 buf[j] = u8WLANChannel;
2049                                         }
2050                                         break;
2051                                 }
2052                         }
2053                 }
2054                 /*Modify operating channel attribute*/
2055                 if (op_channel_attr_index) {
2056                         PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
2057                         buf[op_channel_attr_index + 6] = 0x51;
2058                         buf[op_channel_attr_index + 7] = u8WLANChannel;
2059                 }
2060         }
2061 }
2062
2063 /**
2064  *  @brief      WILC_WFI_CfgParseTxAction
2065  *  @details Function parses the transmitted  action frames and modifies the
2066  *               GO Intent attribute
2067  *  @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
2068  *  @return     NONE.
2069  *  @author     mdaftedar
2070  *  @date       12 DEC 2012
2071  *  @version
2072  */
2073 void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
2074 {
2075         u32 index = 0;
2076         u32 i = 0, j = 0;
2077
2078         u8 op_channel_attr_index = 0;
2079         u8 channel_list_attr_index = 0;
2080
2081         while (index < len) {
2082                 if (buf[index] == GO_INTENT_ATTR_ID) {
2083                         buf[index + 3] = (buf[index + 3]  & 0x01) | (0x0f << 1);
2084
2085                         break;
2086                 }
2087
2088                 if (buf[index] ==  CHANLIST_ATTR_ID)
2089                         channel_list_attr_index = index;
2090                 else if (buf[index] ==  OPERCHAN_ATTR_ID)
2091                         op_channel_attr_index = index;
2092                 index += buf[index + 1] + 3; /* ID,Length byte */
2093         }
2094
2095         if (u8WLANChannel != INVALID_CHANNEL && bOperChan)
2096         {
2097                 /*Modify channel list attribute*/
2098                 if (channel_list_attr_index) {
2099                         PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
2100                         for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
2101                                 if (buf[i] == 0x51) {
2102                                         for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
2103                                                 buf[j] = u8WLANChannel;
2104                                         }
2105                                         break;
2106                                 }
2107                         }
2108                 }
2109                 /*Modify operating channel attribute*/
2110                 if (op_channel_attr_index) {
2111                         PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
2112                         buf[op_channel_attr_index + 6] = 0x51;
2113                         buf[op_channel_attr_index + 7] = u8WLANChannel;
2114                 }
2115         }
2116 }
2117
2118 /*  @brief                       WILC_WFI_p2p_rx
2119  *  @details
2120  *  @param[in]
2121  *
2122  *  @return             None
2123  *  @author             Mai Daftedar
2124  *  @date                       2 JUN 2013
2125  *  @version            1.0
2126  */
2127
2128 void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
2129 {
2130
2131         struct wilc_priv *priv;
2132         u32 header, pkt_offset;
2133         tstrWILC_WFIDrv *pstrWFIDrv;
2134         u32 i = 0;
2135         s32 s32Freq;
2136
2137         priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
2138         pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2139
2140         /* Get WILC header */
2141         memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
2142
2143         /* The packet offset field conain info about what type of managment frame */
2144         /* we are dealing with and ack status */
2145         pkt_offset = GET_PKT_OFFSET(header);
2146
2147         if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
2148                 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
2149                         PRINT_D(GENERIC_DBG, "Probe response ACK\n");
2150                         cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
2151                         return;
2152                 } else {
2153                         if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
2154                                 PRINT_D(GENERIC_DBG, "Success Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
2155                                         buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
2156                                 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
2157                         } else {
2158                                 PRINT_D(GENERIC_DBG, "Fail Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
2159                                         buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
2160                                 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
2161                         }
2162                         return;
2163                 }
2164         } else {
2165
2166                 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
2167
2168                 /*BugID_5442*/
2169                 /*Upper layer is informed that the frame is received on this freq*/
2170                 s32Freq = ieee80211_channel_to_frequency(u8CurrChannel, IEEE80211_BAND_2GHZ);
2171
2172                 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
2173                         PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
2174
2175                         if (priv->bCfgScanning == true && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
2176                                 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
2177                                 return;
2178                         }
2179                         if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
2180
2181                                 switch (buff[ACTION_SUBTYPE_ID]) {
2182                                 case GAS_INTIAL_REQ:
2183                                         PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
2184                                         break;
2185
2186                                 case GAS_INTIAL_RSP:
2187                                         PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
2188                                         break;
2189
2190                                 case PUBLIC_ACT_VENDORSPEC:
2191                                         /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2192                                          * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2193                                         if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
2194                                                 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2195                                                         if (!bWilc_ie) {
2196                                                                 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
2197                                                                         if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
2198                                                                                 u8P2Precvrandom = buff[i + 6];
2199                                                                                 bWilc_ie = true;
2200                                                                                 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
2201                                                                                 break;
2202                                                                         }
2203                                                                 }
2204                                                         }
2205                                                 }
2206                                                 if (u8P2Plocalrandom > u8P2Precvrandom) {
2207                                                         if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2208                                                               || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2209                                                                 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
2210                                                                         if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
2211                                                                                 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
2212                                                                                 break;
2213                                                                         }
2214                                                                 }
2215                                                         }
2216                                                 } else
2217                                                         PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2218                                         }
2219
2220
2221                                         if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie))   {
2222                                                 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2223                                                 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
2224                                                 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2225                                                 return;
2226                                         }
2227                                         break;
2228
2229                                 default:
2230                                         PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2231                                         break;
2232                                 }
2233                         }
2234                 }
2235
2236                 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2237         }
2238 }
2239
2240 /**
2241  *  @brief                      WILC_WFI_mgmt_tx_complete
2242  *  @details            Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2243  *  @param[in]          priv
2244  *                              transmitting status
2245  *  @return             None
2246  *  @author             Amr Abdelmoghny
2247  *  @date                       20 MAY 2013
2248  *  @version            1.0
2249  */
2250 static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2251 {
2252         struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2253
2254
2255         kfree(pv_data->buff);
2256         kfree(pv_data);
2257 }
2258
2259 /**
2260  * @brief               WILC_WFI_RemainOnChannelReady
2261  *  @details    Callback function, called from handle_remain_on_channel on being ready on channel
2262  *  @param
2263  *  @return     none
2264  *  @author     Amr abdelmoghny
2265  *  @date               9 JUNE 2013
2266  *  @version
2267  */
2268
2269 static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2270 {
2271         struct wilc_priv *priv;
2272
2273         priv = (struct wilc_priv *)pUserVoid;
2274
2275         PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
2276
2277         priv->bInP2PlistenState = true;
2278
2279         cfg80211_ready_on_channel(priv->wdev,
2280                                   priv->strRemainOnChanParams.u64ListenCookie,
2281                                   priv->strRemainOnChanParams.pstrListenChan,
2282                                   priv->strRemainOnChanParams.u32ListenDuration,
2283                                   GFP_KERNEL);
2284 }
2285
2286 /**
2287  * @brief               WILC_WFI_RemainOnChannelExpired
2288  *  @details    Callback function, called on expiration of remain-on-channel duration
2289  *  @param
2290  *  @return     none
2291  *  @author     Amr abdelmoghny
2292  *  @date               15 MAY 2013
2293  *  @version
2294  */
2295
2296 static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
2297 {
2298         struct wilc_priv *priv;
2299
2300         priv = (struct wilc_priv *)pUserVoid;
2301
2302         /*BugID_5477*/
2303         if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
2304                 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
2305
2306                 priv->bInP2PlistenState = false;
2307
2308                 /*Inform wpas of remain-on-channel expiration*/
2309                 cfg80211_remain_on_channel_expired(priv->wdev,
2310                                                    priv->strRemainOnChanParams.u64ListenCookie,
2311                                                    priv->strRemainOnChanParams.pstrListenChan,
2312                                                    GFP_KERNEL);
2313         } else {
2314                 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2315                         , priv->strRemainOnChanParams.u32ListenSessionID);
2316         }
2317 }
2318
2319
2320 /**
2321  *  @brief      remain_on_channel
2322  *  @details    Request the driver to remain awake on the specified
2323  *                      channel for the specified duration to complete an off-channel
2324  *                      operation (e.g., public action frame exchange). When the driver is
2325  *                      ready on the requested channel, it must indicate this with an event
2326  *                      notification by calling cfg80211_ready_on_channel().
2327  *  @param[in]
2328  *  @return     int : Return 0 on Success
2329  *  @author     mdaftedar
2330  *  @date       01 MAR 2012
2331  *  @version    1.0
2332  */
2333 static int remain_on_channel(struct wiphy *wiphy,
2334                              struct wireless_dev *wdev,
2335                              struct ieee80211_channel *chan,
2336                              unsigned int duration, u64 *cookie)
2337 {
2338         s32 s32Error = WILC_SUCCESS;
2339         struct wilc_priv *priv;
2340
2341         priv = wiphy_priv(wiphy);
2342
2343         PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2344
2345         /*BugID_4800: if in AP mode, return.*/
2346         /*This check is to handle the situation when user*/
2347         /*requests "create group" during a running scan*/
2348
2349         if (wdev->iftype == NL80211_IFTYPE_AP) {
2350                 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2351                 return s32Error;
2352         }
2353
2354         u8CurrChannel = chan->hw_value;
2355
2356         /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2357         priv->strRemainOnChanParams.pstrListenChan = chan;
2358         priv->strRemainOnChanParams.u64ListenCookie = *cookie;
2359         priv->strRemainOnChanParams.u32ListenDuration = duration;
2360         priv->strRemainOnChanParams.u32ListenSessionID++;
2361
2362         s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2363                                               , priv->strRemainOnChanParams.u32ListenSessionID
2364                                               , duration
2365                                               , chan->hw_value
2366                                               , WILC_WFI_RemainOnChannelExpired
2367                                               , WILC_WFI_RemainOnChannelReady
2368                                               , (void *)priv);
2369
2370         return s32Error;
2371 }
2372
2373 /**
2374  *  @brief      cancel_remain_on_channel
2375  *  @details    Cancel an on-going remain-on-channel operation.
2376  *                      This allows the operation to be terminated prior to timeout based on
2377  *                      the duration value.
2378  *  @param[in]   struct wiphy *wiphy,
2379  *  @param[in]  struct net_device *dev
2380  *  @param[in]  u64 cookie,
2381  *  @return     int : Return 0 on Success
2382  *  @author     mdaftedar
2383  *  @date       01 MAR 2012
2384  *  @version    1.0
2385  */
2386 static int cancel_remain_on_channel(struct wiphy *wiphy,
2387                                     struct wireless_dev *wdev,
2388                                     u64 cookie)
2389 {
2390         s32 s32Error = WILC_SUCCESS;
2391         struct wilc_priv *priv;
2392
2393         priv = wiphy_priv(wiphy);
2394
2395         PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2396
2397         s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2398         return s32Error;
2399 }
2400 /**
2401  *  @brief       WILC_WFI_add_wilcvendorspec
2402  *  @details    Adding WILC information elemet to allow two WILC devices to
2403  *                              identify each other and connect
2404  *  @param[in]   u8 * buf
2405  *  @return     void
2406  *  @author     mdaftedar
2407  *  @date       01 JAN 2014
2408  *  @version    1.0
2409  */
2410 void WILC_WFI_add_wilcvendorspec(u8 *buff)
2411 {
2412         memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
2413 }
2414 /**
2415  *  @brief      WILC_WFI_mgmt_tx_frame
2416  *  @details
2417  *
2418  *  @param[in]
2419  *  @return     NONE.
2420  *  @author     mdaftedar
2421  *  @date       01 JUL 2012
2422  *  @version
2423  */
2424 extern linux_wlan_t *g_linux_wlan;
2425 extern bool bEnablePS;
2426 int mgmt_tx(struct wiphy *wiphy,
2427             struct wireless_dev *wdev,
2428             struct cfg80211_mgmt_tx_params *params,
2429             u64 *cookie)
2430 {
2431         struct ieee80211_channel *chan = params->chan;
2432         unsigned int wait = params->wait;
2433         const u8 *buf = params->buf;
2434         size_t len = params->len;
2435         const struct ieee80211_mgmt *mgmt;
2436         struct p2p_mgmt_data *mgmt_tx;
2437         struct wilc_priv *priv;
2438         s32 s32Error = WILC_SUCCESS;
2439         tstrWILC_WFIDrv *pstrWFIDrv;
2440         u32 i;
2441         perInterface_wlan_t *nic;
2442         u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
2443
2444         nic = netdev_priv(wdev->netdev);
2445         priv = wiphy_priv(wiphy);
2446         pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2447
2448         *cookie = (unsigned long)buf;
2449         priv->u64tx_cookie = *cookie;
2450         mgmt = (const struct ieee80211_mgmt *) buf;
2451
2452         if (ieee80211_is_mgmt(mgmt->frame_control)) {
2453
2454                 /*mgmt frame allocation*/
2455                 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
2456                 if (mgmt_tx == NULL) {
2457                         PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
2458                         return WILC_FAIL;
2459                 }
2460                 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
2461                 if (mgmt_tx->buff == NULL) {
2462                         PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
2463                         kfree(mgmt_tx);
2464                         return WILC_FAIL;
2465                 }
2466                 memcpy(mgmt_tx->buff, buf, len);
2467                 mgmt_tx->size = len;
2468
2469
2470                 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2471                         PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2472                         PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2473                         host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2474                         /*Save the current channel after we tune to it*/
2475                         u8CurrChannel = chan->hw_value;
2476                 } else if (ieee80211_is_action(mgmt->frame_control))   {
2477                         PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
2478
2479
2480                         /*BugID_4847*/
2481                         if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
2482                                 /*BugID_4847*/
2483                                 /*Only set the channel, if not a negotiation confirmation frame
2484                                  * (If Negotiation confirmation frame, force it
2485                                  * to be transmitted on the same negotiation channel)*/
2486
2487                                 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2488                                     buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2489                                         PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2490                                         host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2491                                         /*Save the current channel after we tune to it*/
2492                                         u8CurrChannel = chan->hw_value;
2493                                 }
2494                                 switch (buf[ACTION_SUBTYPE_ID]) {
2495                                 case GAS_INTIAL_REQ:
2496                                 {
2497                                         PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2498                                         break;
2499                                 }
2500
2501                                 case GAS_INTIAL_RSP:
2502                                 {
2503                                         PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2504                                         break;
2505                                 }
2506
2507                                 case PUBLIC_ACT_VENDORSPEC:
2508                                 {
2509                                         /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2510                                          * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2511                                         if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
2512                                                 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2513                                                 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2514                                                         if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2515                                                                 get_random_bytes(&u8P2Plocalrandom, 1);
2516                                                                 /*Increment the number to prevent if its 0*/
2517                                                                 u8P2Plocalrandom++;
2518                                                         }
2519                                                 }
2520
2521                                                 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2522                                                       || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2523                                                         if (u8P2Plocalrandom > u8P2Precvrandom) {
2524                                                                 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2525
2526                                                                 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2527                                                                 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
2528                                                                         if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
2529                                                                                 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
2530                                                                                         WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
2531
2532                                                                                 /*BugID_5460*/
2533                                                                                 /*If using supplicant go intent, no need at all*/
2534                                                                                 /*to parse transmitted negotiation frames*/
2535                                                                                 else
2536                                                                                         WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
2537                                                                                 break;
2538                                                                         }
2539                                                                 }
2540
2541                                                                 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
2542                                                                         WILC_WFI_add_wilcvendorspec(&mgmt_tx->buff[len]);
2543                                                                         mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2544                                                                         mgmt_tx->size = buf_len;
2545                                                                 }
2546                                                         } else
2547                                                                 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2548                                                 }
2549
2550                                         } else {
2551                                                 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2552                                         }
2553
2554                                         break;
2555                                 }
2556
2557                                 default:
2558                                 {
2559                                         PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2560                                         break;
2561                                 }
2562                                 }
2563
2564                         }
2565
2566                         PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
2567                         pstrWFIDrv->u64P2p_MgmtTimeout = (jiffies + msecs_to_jiffies(wait));
2568
2569                         PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2570
2571                 }
2572
2573                 g_linux_wlan->oup.wlan_add_mgmt_to_tx_que(mgmt_tx, mgmt_tx->buff, mgmt_tx->size, WILC_WFI_mgmt_tx_complete);
2574         } else {
2575                 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2576         }
2577         return s32Error;
2578 }
2579
2580 int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2581                         struct wireless_dev *wdev,
2582                         u64 cookie)
2583 {
2584         struct wilc_priv *priv;
2585         tstrWILC_WFIDrv *pstrWFIDrv;
2586
2587         priv = wiphy_priv(wiphy);
2588         pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2589
2590
2591         PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2592         pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2593
2594         if (priv->bInP2PlistenState == false) {
2595                 /* Bug 5504: This is just to avoid connection failure when getting stuck when the supplicant
2596                  *                      considers the driver falsely that it is in Listen state */
2597                 cfg80211_remain_on_channel_expired(priv->wdev,
2598                                                    priv->strRemainOnChanParams.u64ListenCookie,
2599                                                    priv->strRemainOnChanParams.pstrListenChan,
2600                                                    GFP_KERNEL);
2601         }
2602
2603         return 0;
2604 }
2605
2606 /**
2607  *  @brief      WILC_WFI_frame_register
2608  *  @details Notify driver that a management frame type was
2609  *              registered. Note that this callback may not sleep, and cannot run
2610  *                      concurrently with itself.
2611  *  @param[in]
2612  *  @return     NONE.
2613  *  @author     mdaftedar
2614  *  @date       01 JUL 2012
2615  *  @version
2616  */
2617 void    WILC_WFI_frame_register(struct wiphy *wiphy,
2618                                 struct wireless_dev *wdev,
2619                                 u16 frame_type, bool reg)
2620 {
2621
2622         struct wilc_priv *priv;
2623         perInterface_wlan_t *nic;
2624
2625
2626         priv = wiphy_priv(wiphy);
2627         nic = netdev_priv(priv->wdev->netdev);
2628
2629
2630
2631         /*BugID_5137*/
2632         if (!frame_type)
2633                 return;
2634
2635         PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2636         switch (frame_type) {
2637         case PROBE_REQ:
2638         {
2639                 nic->g_struct_frame_reg[0].frame_type = frame_type;
2640                 nic->g_struct_frame_reg[0].reg = reg;
2641         }
2642         break;
2643
2644         case ACTION:
2645         {
2646                 nic->g_struct_frame_reg[1].frame_type = frame_type;
2647                 nic->g_struct_frame_reg[1].reg = reg;
2648         }
2649         break;
2650
2651         default:
2652         {
2653                 break;
2654         }
2655
2656         }
2657         /*If mac is closed, then return*/
2658         if (!g_linux_wlan->wilc1000_initialized) {
2659                 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2660                 return;
2661         }
2662         host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2663
2664
2665 }
2666 #endif /*WILC_P2P*/
2667
2668 /**
2669  *  @brief      WILC_WFI_set_cqm_rssi_config
2670  *  @details    Configure connection quality monitor RSSI threshold.
2671  *  @param[in]   struct wiphy *wiphy:
2672  *  @param[in]  struct net_device *dev:
2673  *  @param[in]          s32 rssi_thold:
2674  *  @param[in]  u32 rssi_hyst:
2675  *  @return     int : Return 0 on Success
2676  *  @author     mdaftedar
2677  *  @date       01 MAR 2012
2678  *  @version    1.0
2679  */
2680 static int    WILC_WFI_set_cqm_rssi_config(struct wiphy *wiphy,
2681                                            struct net_device *dev,  s32 rssi_thold, u32 rssi_hyst)
2682 {
2683         PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2684         return 0;
2685
2686 }
2687 /**
2688  *  @brief      dump_station
2689  *  @details    Configure connection quality monitor RSSI threshold.
2690  *  @param[in]   struct wiphy *wiphy:
2691  *  @param[in]  struct net_device *dev
2692  *  @param[in]          int idx
2693  *  @param[in]  u8 *mac
2694  *  @param[in]  struct station_info *sinfo
2695  *  @return     int : Return 0 on Success
2696  *  @author     mdaftedar
2697  *  @date       01 MAR 2012
2698  *  @version    1.0
2699  */
2700 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2701                         int idx, u8 *mac, struct station_info *sinfo)
2702 {
2703         struct wilc_priv *priv;
2704
2705         PRINT_D(CFG80211_DBG, "Dumping station information\n");
2706
2707         if (idx != 0)
2708                 return -ENOENT;
2709
2710         priv = wiphy_priv(wiphy);
2711
2712         sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2713
2714         host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2715
2716         return 0;
2717
2718 }
2719
2720
2721 /**
2722  *  @brief      WILC_WFI_set_power_mgmt
2723  *  @details
2724  *  @param[in]
2725  *  @return     int : Return 0 on Success.
2726  *  @author     mdaftedar
2727  *  @date       01 JUL 2012
2728  *  @version    1.0WILC_WFI_set_cqmWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_config_rssi_config
2729  */
2730 int WILC_WFI_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2731                             bool enabled, int timeout)
2732 {
2733         struct wilc_priv *priv;
2734
2735         PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2736
2737         if (wiphy == NULL)
2738                 return -ENOENT;
2739
2740         priv = wiphy_priv(wiphy);
2741         if (priv->hWILCWFIDrv == NULL) {
2742                 PRINT_ER("Driver is NULL\n");
2743                 return -EIO;
2744         }
2745
2746         if (bEnablePS)
2747                 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2748
2749
2750         return WILC_SUCCESS;
2751
2752 }
2753 #ifdef WILC_AP_EXTERNAL_MLME
2754 /**
2755  *  @brief      change_virtual_intf
2756  *  @details    Change type/configuration of virtual interface,
2757  *                      keep the struct wireless_dev's iftype updated.
2758  *  @param[in]   NONE
2759  *  @return     int : Return 0 on Success.
2760  *  @author     mdaftedar
2761  *  @date       01 MAR 2012
2762  *  @version    1.0
2763  */
2764 void wilc1000_wlan_deinit(linux_wlan_t *nic);
2765 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2766
2767 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2768                                enum nl80211_iftype type, u32 *flags, struct vif_params *params)
2769 {
2770         s32 s32Error = WILC_SUCCESS;
2771         struct wilc_priv *priv;
2772         perInterface_wlan_t *nic;
2773         u8 interface_type;
2774         u16 TID = 0;
2775         #ifdef WILC_P2P
2776         u8 i;
2777         #endif
2778
2779         nic = netdev_priv(dev);
2780         priv = wiphy_priv(wiphy);
2781
2782         PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2783         PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2784         u8P2Plocalrandom = 0x01;
2785         u8P2Precvrandom = 0x00;
2786
2787         bWilc_ie = false;
2788
2789         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2790         g_obtainingIP = false;
2791         del_timer(&hDuringIpTimer);
2792         PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
2793         #endif
2794         /*BugID_5137*/
2795         /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2796         if (g_ptk_keys_saved && g_gtk_keys_saved) {
2797                 Set_machw_change_vir_if(true);
2798         }
2799
2800         switch (type) {
2801         case NL80211_IFTYPE_STATION:
2802                 connecting = 0;
2803                 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
2804
2805                 /* send delba over wlan interface */
2806
2807
2808                 dev->ieee80211_ptr->iftype = type;
2809                 priv->wdev->iftype = type;
2810                 nic->monitor_flag = 0;
2811                 nic->iftype = STATION_MODE;
2812
2813                 /*Remove the enteries of the previously connected clients*/
2814                 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
2815                 #ifdef WILC_P2P
2816                 interface_type = nic->iftype;
2817                 nic->iftype = STATION_MODE;
2818
2819                 if (g_linux_wlan->wilc1000_initialized) {
2820                         host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
2821                         /* ensure that the message Q is empty */
2822                         host_int_wait_msg_queue_idle();
2823
2824                         /*BugID_5213*/
2825                         /*Eliminate host interface blocking state*/
2826                         up(&g_linux_wlan->cfg_event);
2827
2828                         wilc1000_wlan_deinit(g_linux_wlan);
2829                         wilc1000_wlan_init(dev, nic);
2830                         g_wilc_initialized = 1;
2831                         nic->iftype = interface_type;
2832
2833                         /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2834                         host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
2835                         host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2836                                                 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2837                         host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2838
2839                         /*Add saved WEP keys, if any*/
2840                         if (g_wep_keys_saved) {
2841                                 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2842                                                              g_key_wep_params.key_idx);
2843                                 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2844                                                              g_key_wep_params.key,
2845                                                              g_key_wep_params.key_len,
2846                                                              g_key_wep_params.key_idx);
2847                         }
2848
2849                         /*No matter the driver handler passed here, it will be overwriiten*/
2850                         /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2851                         host_int_flush_join_req(priv->hWILCWFIDrv);
2852
2853                         /*Add saved PTK and GTK keys, if any*/
2854                         if (g_ptk_keys_saved && g_gtk_keys_saved) {
2855                                 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2856                                         g_key_ptk_params.key[1],
2857                                         g_key_ptk_params.key[2]);
2858                                 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2859                                         g_key_gtk_params.key[1],
2860                                         g_key_gtk_params.key[2]);
2861                                 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2862                                         g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2863                                         g_add_ptk_key_params.key_idx,
2864                                         g_add_ptk_key_params.pairwise,
2865                                         g_add_ptk_key_params.mac_addr,
2866                                         (struct key_params *)(&g_key_ptk_params));
2867
2868                                 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2869                                         g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2870                                         g_add_gtk_key_params.key_idx,
2871                                         g_add_gtk_key_params.pairwise,
2872                                         g_add_gtk_key_params.mac_addr,
2873                                         (struct key_params *)(&g_key_gtk_params));
2874                         }
2875
2876                         /*BugID_4847: registered frames in firmware are now*/
2877                         /*lost due to mac close. So re-register those frames*/
2878                         if (g_linux_wlan->wilc1000_initialized) {
2879                                 for (i = 0; i < num_reg_frame; i++) {
2880                                         PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2881                                                 nic->g_struct_frame_reg[i].reg);
2882                                         host_int_frame_register(priv->hWILCWFIDrv,
2883                                                                 nic->g_struct_frame_reg[i].frame_type,
2884                                                                 nic->g_struct_frame_reg[i].reg);
2885                                 }
2886                         }
2887
2888                         bEnablePS = true;
2889                         host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2890                 }
2891                 #endif
2892                 break;
2893
2894         case NL80211_IFTYPE_P2P_CLIENT:
2895                 bEnablePS = false;
2896                 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2897                 connecting = 0;
2898                 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
2899
2900                 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
2901
2902                 dev->ieee80211_ptr->iftype = type;
2903                 priv->wdev->iftype = type;
2904                 nic->monitor_flag = 0;
2905
2906                 #ifdef WILC_P2P
2907
2908                 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2909                 nic->iftype = CLIENT_MODE;
2910
2911
2912                 if (g_linux_wlan->wilc1000_initialized) {
2913                         /* ensure that the message Q is empty */
2914                         host_int_wait_msg_queue_idle();
2915
2916                         wilc1000_wlan_deinit(g_linux_wlan);
2917                         wilc1000_wlan_init(dev, nic);
2918                         g_wilc_initialized = 1;
2919
2920                         host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
2921                         host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2922                                                 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2923                         host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2924
2925                         /*Add saved WEP keys, if any*/
2926                         if (g_wep_keys_saved) {
2927                                 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2928                                                              g_key_wep_params.key_idx);
2929                                 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2930                                                              g_key_wep_params.key,
2931                                                              g_key_wep_params.key_len,
2932                                                              g_key_wep_params.key_idx);
2933                         }
2934
2935                         /*No matter the driver handler passed here, it will be overwriiten*/
2936                         /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2937                         host_int_flush_join_req(priv->hWILCWFIDrv);
2938
2939                         /*Add saved PTK and GTK keys, if any*/
2940                         if (g_ptk_keys_saved && g_gtk_keys_saved) {
2941                                 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2942                                         g_key_ptk_params.key[1],
2943                                         g_key_ptk_params.key[2]);
2944                                 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2945                                         g_key_gtk_params.key[1],
2946                                         g_key_gtk_params.key[2]);
2947                                 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2948                                         g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2949                                         g_add_ptk_key_params.key_idx,
2950                                         g_add_ptk_key_params.pairwise,
2951                                         g_add_ptk_key_params.mac_addr,
2952                                         (struct key_params *)(&g_key_ptk_params));
2953
2954                                 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2955                                         g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2956                                         g_add_gtk_key_params.key_idx,
2957                                         g_add_gtk_key_params.pairwise,
2958                                         g_add_gtk_key_params.mac_addr,
2959                                         (struct key_params *)(&g_key_gtk_params));
2960                         }
2961
2962                         /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
2963                         refresh_scan(priv, 1, true);
2964                         Set_machw_change_vir_if(false);
2965
2966                         /*BugID_4847: registered frames in firmware are now lost
2967                          *  due to mac close. So re-register those frames */
2968                         if (g_linux_wlan->wilc1000_initialized) {
2969                                 for (i = 0; i < num_reg_frame; i++) {
2970                                         PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2971                                                 nic->g_struct_frame_reg[i].reg);
2972                                         host_int_frame_register(priv->hWILCWFIDrv,
2973                                                                 nic->g_struct_frame_reg[i].frame_type,
2974                                                                 nic->g_struct_frame_reg[i].reg);
2975                                 }
2976                         }
2977                 }
2978                 #endif
2979                 break;
2980
2981         case NL80211_IFTYPE_AP:
2982                 bEnablePS = false;
2983                 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
2984                 dev->ieee80211_ptr->iftype = type;
2985                 priv->wdev->iftype = type;
2986                 nic->iftype = AP_MODE;
2987                 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
2988
2989                 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2990                 linux_wlan_get_firmware(nic);
2991                 #ifdef WILC_P2P
2992                 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
2993                 if (g_linux_wlan->wilc1000_initialized) {
2994                         nic->iftype = AP_MODE;
2995                         g_linux_wlan->wilc1000_initialized = 1;
2996                         mac_close(dev);
2997                         mac_open(dev);
2998
2999                         /*BugID_4847: registered frames in firmware are now lost
3000                          * due to mac close. So re-register those frames */
3001                         for (i = 0; i < num_reg_frame; i++) {
3002                                 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
3003                                         nic->g_struct_frame_reg[i].reg);
3004                                 host_int_frame_register(priv->hWILCWFIDrv,
3005                                                         nic->g_struct_frame_reg[i].frame_type,
3006                                                         nic->g_struct_frame_reg[i].reg);
3007                         }
3008                 }
3009                 #endif
3010                 break;
3011
3012         case NL80211_IFTYPE_P2P_GO:
3013                 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
3014
3015                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3016                 g_obtainingIP = true;
3017                 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
3018                 #endif
3019                 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
3020                 /*BugID_5222*/
3021                 /*Delete block ack has to be the latest config packet*/
3022                 /*sent before downloading new FW. This is because it blocks on*/
3023                 /*hWaitResponse semaphore, which allows previous config*/
3024                 /*packets to actually take action on old FW*/
3025                 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
3026                 bEnablePS = false;
3027                 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
3028                 dev->ieee80211_ptr->iftype = type;
3029                 priv->wdev->iftype = type;
3030
3031                 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
3032
3033                 #ifdef WILC_P2P
3034                 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
3035
3036
3037                 #if 1
3038                 nic->iftype = GO_MODE;
3039
3040                 /* ensure that the message Q is empty */
3041                 host_int_wait_msg_queue_idle();
3042                 wilc1000_wlan_deinit(g_linux_wlan);
3043                 wilc1000_wlan_init(dev, nic);
3044                 g_wilc_initialized = 1;
3045
3046
3047                 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
3048                 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
3049                 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3050                                         g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
3051                 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
3052
3053                 /*Add saved WEP keys, if any*/
3054                 if (g_wep_keys_saved) {
3055                         host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3056                                                      g_key_wep_params.key_idx);
3057                         host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3058                                                      g_key_wep_params.key,
3059                                                      g_key_wep_params.key_len,
3060                                                      g_key_wep_params.key_idx);
3061                 }
3062
3063                 /*No matter the driver handler passed here, it will be overwriiten*/
3064                 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
3065                 host_int_flush_join_req(priv->hWILCWFIDrv);
3066
3067                 /*Add saved PTK and GTK keys, if any*/
3068                 if (g_ptk_keys_saved && g_gtk_keys_saved) {
3069                         PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
3070                                 g_key_ptk_params.key[1],
3071                                 g_key_ptk_params.key[2],
3072                                 g_key_ptk_params.cipher);
3073                         PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
3074                                 g_key_gtk_params.key[1],
3075                                 g_key_gtk_params.key[2],
3076                                 g_key_gtk_params.cipher);
3077                         #if 1
3078                         add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
3079                                 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
3080                                 g_add_ptk_key_params.key_idx,
3081                                 g_add_ptk_key_params.pairwise,
3082                                 g_add_ptk_key_params.mac_addr,
3083                                 (struct key_params *)(&g_key_ptk_params));
3084
3085                         add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
3086                                 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
3087                                 g_add_gtk_key_params.key_idx,
3088                                 g_add_gtk_key_params.pairwise,
3089                                 g_add_gtk_key_params.mac_addr,
3090                                 (struct key_params *)(&g_key_gtk_params));
3091                         #endif
3092                 }
3093                 #endif
3094
3095                 /*BugID_4847: registered frames in firmware are now*/
3096                 /*lost due to mac close. So re-register those frames*/
3097                 if (g_linux_wlan->wilc1000_initialized) {
3098                         for (i = 0; i < num_reg_frame; i++) {
3099                                 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
3100                                         nic->g_struct_frame_reg[i].reg);
3101                                 host_int_frame_register(priv->hWILCWFIDrv,
3102                                                         nic->g_struct_frame_reg[i].frame_type,
3103                                                         nic->g_struct_frame_reg[i].reg);
3104                         }
3105                 }
3106                 #endif
3107                 break;
3108
3109         default:
3110                 PRINT_ER("Unknown interface type= %d\n", type);
3111                 s32Error = -EINVAL;
3112                 return s32Error;
3113                 break;
3114         }
3115
3116         return s32Error;
3117 }
3118
3119 /* (austin.2013-07-23)
3120  *
3121  *      To support revised cfg80211_ops
3122  *
3123  *              add_beacon --> start_ap
3124  *              set_beacon --> change_beacon
3125  *              del_beacon --> stop_ap
3126  *
3127  *              beacon_parameters  -->  cfg80211_ap_settings
3128  *                                                              cfg80211_beacon_data
3129  *
3130  *      applicable for linux kernel 3.4+
3131  */
3132
3133 /**
3134  *  @brief      start_ap
3135  *  @details    Add a beacon with given parameters, @head, @interval
3136  *                      and @dtim_period will be valid, @tail is optional.
3137  *  @param[in]   wiphy
3138  *  @param[in]   dev    The net device structure
3139  *  @param[in]   settings       cfg80211_ap_settings parameters for the beacon to be added
3140  *  @return     int : Return 0 on Success.
3141  *  @author     austin
3142  *  @date       23 JUL 2013
3143  *  @version    1.0
3144  */
3145 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
3146                     struct cfg80211_ap_settings *settings)
3147 {
3148         struct cfg80211_beacon_data *beacon = &(settings->beacon);
3149         struct wilc_priv *priv;
3150         s32 s32Error = WILC_SUCCESS;
3151
3152         priv = wiphy_priv(wiphy);
3153         PRINT_D(HOSTAPD_DBG, "Starting ap\n");
3154
3155         PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
3156                 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
3157
3158         s32Error = set_channel(wiphy, &settings->chandef);
3159
3160         if (s32Error != WILC_SUCCESS)
3161                 PRINT_ER("Error in setting channel\n");
3162
3163         linux_wlan_set_bssid(dev, g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
3164
3165         s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
3166                                         settings->beacon_interval,
3167                                         settings->dtim_period,
3168                                         beacon->head_len, (u8 *)beacon->head,
3169                                         beacon->tail_len, (u8 *)beacon->tail);
3170
3171         return s32Error;
3172 }
3173
3174 /**
3175  *  @brief      change_beacon
3176  *  @details    Add a beacon with given parameters, @head, @interval
3177  *                      and @dtim_period will be valid, @tail is optional.
3178  *  @param[in]   wiphy
3179  *  @param[in]   dev    The net device structure
3180  *  @param[in]   beacon cfg80211_beacon_data for the beacon to be changed
3181  *  @return     int : Return 0 on Success.
3182  *  @author     austin
3183  *  @date       23 JUL 2013
3184  *  @version    1.0
3185  */
3186 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
3187                          struct cfg80211_beacon_data *beacon)
3188 {
3189         struct wilc_priv *priv;
3190         s32 s32Error = WILC_SUCCESS;
3191
3192         priv = wiphy_priv(wiphy);
3193         PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
3194
3195
3196         s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
3197                                         0,
3198                                         0,
3199                                         beacon->head_len, (u8 *)beacon->head,
3200                                         beacon->tail_len, (u8 *)beacon->tail);
3201
3202         return s32Error;
3203 }
3204
3205 /**
3206  *  @brief      stop_ap
3207  *  @details    Remove beacon configuration and stop sending the beacon.
3208  *  @param[in]
3209  *  @return     int : Return 0 on Success.
3210  *  @author     austin
3211  *  @date       23 JUL 2013
3212  *  @version    1.0
3213  */
3214 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
3215 {
3216         s32 s32Error = WILC_SUCCESS;
3217         struct wilc_priv *priv;
3218         u8 NullBssid[ETH_ALEN] = {0};
3219
3220
3221         WILC_NULLCHECK(s32Error, wiphy);
3222
3223         priv = wiphy_priv(wiphy);
3224
3225         PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
3226
3227         /*BugID_5188*/
3228         linux_wlan_set_bssid(dev, NullBssid);
3229
3230         s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
3231
3232         WILC_ERRORCHECK(s32Error);
3233
3234         WILC_CATCH(s32Error)
3235         {
3236         }
3237         return s32Error;
3238 }
3239
3240 /**
3241  *  @brief      add_station
3242  *  @details    Add a new station.
3243  *  @param[in]
3244  *  @return     int : Return 0 on Success.
3245  *  @author     mdaftedar
3246  *  @date       01 MAR 2012
3247  *  @version    1.0
3248  */
3249 static int add_station(struct wiphy *wiphy, struct net_device *dev,
3250                        const u8 *mac, struct station_parameters *params)
3251 {
3252         s32 s32Error = WILC_SUCCESS;
3253         struct wilc_priv *priv;
3254         tstrWILC_AddStaParam strStaParams = { {0} };
3255         perInterface_wlan_t *nic;
3256
3257
3258         WILC_NULLCHECK(s32Error, wiphy);
3259
3260         priv = wiphy_priv(wiphy);
3261         nic = netdev_priv(dev);
3262
3263         if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3264                 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3265                 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
3266                 strStaParams.u16AssocID = params->aid;
3267                 strStaParams.u8NumRates = params->supported_rates_len;
3268                 strStaParams.pu8Rates = params->supported_rates;
3269
3270                 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3271
3272                 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4],
3273                         priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
3274                 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3275                 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3276
3277                 if (params->ht_capa == NULL) {
3278                         strStaParams.bIsHTSupported = false;
3279                 } else {
3280                         strStaParams.bIsHTSupported = true;
3281                         strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3282                         strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3283                         memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3284                         strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3285                         strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3286                         strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3287                 }
3288
3289                 strStaParams.u16FlagsMask = params->sta_flags_mask;
3290                 strStaParams.u16FlagsSet = params->sta_flags_set;
3291
3292                 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3293                 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3294                 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3295                 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3296                 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3297                 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3298                 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3299                 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3300
3301                 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
3302                 WILC_ERRORCHECK(s32Error);
3303         }
3304
3305         WILC_CATCH(s32Error)
3306         {
3307         }
3308         return s32Error;
3309 }
3310
3311 /**
3312  *  @brief      del_station
3313  *  @details    Remove a station; @mac may be NULL to remove all stations.
3314  *  @param[in]
3315  *  @return     int : Return 0 on Success.
3316  *  @author     mdaftedar
3317  *  @date       01 MAR 2012
3318  *  @version    1.0
3319  */
3320 static int del_station(struct wiphy *wiphy, struct net_device *dev,
3321                        struct station_del_parameters *params)
3322 {
3323         const u8 *mac = params->mac;
3324         s32 s32Error = WILC_SUCCESS;
3325         struct wilc_priv *priv;
3326         perInterface_wlan_t *nic;
3327
3328         WILC_NULLCHECK(s32Error, wiphy);
3329
3330         priv = wiphy_priv(wiphy);
3331         nic = netdev_priv(dev);
3332
3333         if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3334                 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3335
3336
3337                 if (mac == NULL) {
3338                         PRINT_D(HOSTAPD_DBG, "All associated stations\n");
3339                         s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3340                 } else {
3341                         PRINT_D(HOSTAPD_DBG, "With mac address: %x%x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
3342                 }
3343
3344                 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
3345
3346                 WILC_ERRORCHECK(s32Error);
3347         }
3348         WILC_CATCH(s32Error)
3349         {
3350         }
3351         return s32Error;
3352 }
3353
3354 /**
3355  *  @brief      change_station
3356  *  @details    Modify a given station.
3357  *  @param[in]
3358  *  @return     int : Return 0 on Success.
3359  *  @author     mdaftedar
3360  *  @date       01 MAR 2012
3361  *  @version    1.0
3362  */
3363 static int change_station(struct wiphy *wiphy, struct net_device *dev,
3364                           const u8 *mac, struct station_parameters *params)
3365 {
3366         s32 s32Error = WILC_SUCCESS;
3367         struct wilc_priv *priv;
3368         tstrWILC_AddStaParam strStaParams = { {0} };
3369         perInterface_wlan_t *nic;
3370
3371
3372         PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3373
3374         WILC_NULLCHECK(s32Error, wiphy);
3375
3376         priv = wiphy_priv(wiphy);
3377         nic = netdev_priv(dev);
3378
3379         if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3380                 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3381                 strStaParams.u16AssocID = params->aid;
3382                 strStaParams.u8NumRates = params->supported_rates_len;
3383                 strStaParams.pu8Rates = params->supported_rates;
3384
3385                 PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n", strStaParams.au8BSSID[0], strStaParams.au8BSSID[1], strStaParams.au8BSSID[2], strStaParams.au8BSSID[3], strStaParams.au8BSSID[4],
3386                         strStaParams.au8BSSID[5]);
3387                 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3388                 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3389
3390                 if (params->ht_capa == NULL) {
3391                         strStaParams.bIsHTSupported = false;
3392                 } else {
3393                         strStaParams.bIsHTSupported = true;
3394                         strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3395                         strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3396                         memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3397                         strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3398                         strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3399                         strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3400
3401                 }
3402
3403                 strStaParams.u16FlagsMask = params->sta_flags_mask;
3404                 strStaParams.u16FlagsSet = params->sta_flags_set;
3405
3406                 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3407                 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3408                 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3409                 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3410                 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3411                 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3412                 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3413                 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3414
3415                 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
3416                 WILC_ERRORCHECK(s32Error);
3417         }
3418         WILC_CATCH(s32Error)
3419         {
3420         }
3421         return s32Error;
3422 }
3423
3424
3425 /**
3426  *  @brief      add_virtual_intf
3427  *  @details
3428  *  @param[in]
3429  *  @return     int : Return 0 on Success.
3430  *  @author     mdaftedar
3431  *  @date       01 JUL 2012
3432  *  @version    1.0
3433  */
3434 struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, const char *name,
3435                                       unsigned char name_assign_type,
3436                                       enum nl80211_iftype type, u32 *flags,
3437                                       struct vif_params *params)
3438 {
3439         perInterface_wlan_t *nic;
3440         struct wilc_priv *priv;
3441         struct net_device *new_ifc = NULL;
3442
3443         priv = wiphy_priv(wiphy);
3444
3445
3446
3447         PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3448
3449         nic = netdev_priv(priv->wdev->netdev);
3450
3451
3452         if (type == NL80211_IFTYPE_MONITOR) {
3453                 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3454                 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3455                 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3456                 if (new_ifc != NULL) {
3457                         PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
3458                         nic = netdev_priv(priv->wdev->netdev);
3459                         nic->monitor_flag = 1;
3460                 } else
3461                         PRINT_ER("Error in initializing monitor interface\n ");
3462         }
3463         return priv->wdev;
3464 }
3465
3466 /**
3467  *  @brief      del_virtual_intf
3468  *  @details
3469  *  @param[in]
3470  *  @return     int : Return 0 on Success.
3471  *  @author     mdaftedar
3472  *  @date       01 JUL 2012
3473  *  @version    1.0
3474  */
3475 int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)      /* tony for v3.8 support */
3476 {
3477         PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
3478         return WILC_SUCCESS;
3479 }
3480
3481
3482
3483 #endif /*WILC_AP_EXTERNAL_MLME*/
3484 static struct cfg80211_ops wilc_cfg80211_ops = {
3485
3486         .set_monitor_channel = set_channel,
3487         .scan = scan,
3488         .connect = connect,
3489         .disconnect = disconnect,
3490         .add_key = add_key,
3491         .del_key = del_key,
3492         .get_key = get_key,
3493         .set_default_key = set_default_key,
3494         #ifdef WILC_AP_EXTERNAL_MLME
3495         .add_virtual_intf = add_virtual_intf,
3496         .del_virtual_intf = del_virtual_intf,
3497         .change_virtual_intf = change_virtual_intf,
3498
3499         .start_ap = start_ap,
3500         .change_beacon = change_beacon,
3501         .stop_ap = stop_ap,
3502         .add_station = add_station,
3503         .del_station = del_station,
3504         .change_station = change_station,
3505         #endif /* WILC_AP_EXTERNAL_MLME*/
3506         .get_station = get_station,
3507         .dump_station = dump_station,
3508         .change_bss = change_bss,
3509         .set_wiphy_params = set_wiphy_params,
3510
3511         .set_pmksa = set_pmksa,
3512         .del_pmksa = del_pmksa,
3513         .flush_pmksa = flush_pmksa,
3514 #ifdef WILC_P2P
3515         .remain_on_channel = remain_on_channel,
3516         .cancel_remain_on_channel = cancel_remain_on_channel,
3517         .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
3518         .mgmt_tx = mgmt_tx,
3519         .mgmt_frame_register = WILC_WFI_frame_register,
3520         .set_power_mgmt = WILC_WFI_set_power_mgmt,
3521         .set_cqm_rssi_config = WILC_WFI_set_cqm_rssi_config,
3522 #endif
3523
3524 };
3525
3526
3527
3528
3529
3530 /**
3531  *  @brief      WILC_WFI_update_stats
3532  *  @details    Modify parameters for a given BSS.
3533  *  @param[in]
3534  *  @return     int : Return 0 on Success.
3535  *  @author     mdaftedar
3536  *  @date       01 MAR 2012
3537  *  @version    1.0WILC_WFI_set_cqmWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_config_rssi_config
3538  */
3539 int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3540 {
3541
3542         struct wilc_priv *priv;
3543
3544         priv = wiphy_priv(wiphy);
3545 #if 1
3546         switch (changed) {
3547
3548         case WILC_WFI_RX_PKT:
3549         {
3550                 priv->netstats.rx_packets++;
3551                 priv->netstats.rx_bytes += pktlen;
3552                 priv->netstats.rx_time = get_jiffies_64();
3553         }
3554         break;
3555
3556         case WILC_WFI_TX_PKT:
3557         {
3558                 priv->netstats.tx_packets++;
3559                 priv->netstats.tx_bytes += pktlen;
3560                 priv->netstats.tx_time = get_jiffies_64();
3561
3562         }
3563         break;
3564
3565         default:
3566                 break;
3567         }
3568 #endif
3569         return 0;
3570 }
3571
3572 /**
3573  *  @brief      WILC_WFI_CfgAlloc
3574  *  @details    Allocation of the wireless device structure and assigning it
3575  *              to the cfg80211 operations structure.
3576  *  @param[in]   NONE
3577  *  @return     wireless_dev : Returns pointer to wireless_dev structure.
3578  *  @author     mdaftedar
3579  *  @date       01 MAR 2012
3580  *  @version    1.0
3581  */
3582 struct wireless_dev *WILC_WFI_CfgAlloc(void)
3583 {
3584
3585         struct wireless_dev *wdev;
3586
3587
3588         PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3589         /*Allocating the wireless device structure*/
3590         wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3591         if (!wdev) {
3592                 PRINT_ER("Cannot allocate wireless device\n");
3593                 goto _fail_;
3594         }
3595
3596         /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
3597         wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
3598         if (!wdev->wiphy) {
3599                 PRINT_ER("Cannot allocate wiphy\n");
3600                 goto _fail_mem_;
3601
3602         }
3603
3604         #ifdef WILC_AP_EXTERNAL_MLME
3605         /* enable 802.11n HT */
3606         WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3607         WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3608         WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3609         WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3610         WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
3611         #endif
3612
3613         /*wiphy bands*/
3614         wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3615
3616         return wdev;
3617
3618 _fail_mem_:
3619         kfree(wdev);
3620 _fail_:
3621         return NULL;
3622
3623 }
3624 /**
3625  *  @brief      WILC_WFI_WiphyRegister
3626  *  @details    Registering of the wiphy structure and interface modes
3627  *  @param[in]   NONE
3628  *  @return     NONE
3629  *  @author     mdaftedar
3630  *  @date       01 MAR 2012
3631  *  @version    1.0
3632  */
3633 struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net)
3634 {
3635         struct wilc_priv *priv;
3636         struct wireless_dev *wdev;
3637         s32 s32Error = WILC_SUCCESS;
3638
3639         PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3640
3641         wdev = WILC_WFI_CfgAlloc();
3642         if (wdev == NULL) {
3643                 PRINT_ER("CfgAlloc Failed\n");
3644                 return NULL;
3645         }
3646
3647
3648         /*Return hardware description structure (wiphy)'s priv*/
3649         priv = wdev_priv(wdev);
3650         sema_init(&(priv->SemHandleUpdateStats), 1);
3651
3652         /*Link the wiphy with wireless structure*/
3653         priv->wdev = wdev;
3654
3655         /*Maximum number of probed ssid to be added by user for the scan request*/
3656         wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
3657         /*Maximum number of pmkids to be cashed*/
3658         wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3659         PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
3660
3661         wdev->wiphy->max_scan_ie_len = 1000;
3662
3663         /*signal strength in mBm (100*dBm) */
3664         wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3665
3666         /*Set the availaible cipher suites*/
3667         wdev->wiphy->cipher_suites = cipher_suites;
3668         wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3669         /*Setting default managment types: for register action frame:  */
3670         wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
3671
3672 #ifdef WILC_P2P
3673         wdev->wiphy->max_remain_on_channel_duration = 500;
3674         /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3675         wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3676                 BIT(NL80211_IFTYPE_P2P_CLIENT);
3677         wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3678 #else
3679         wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR);
3680 #endif
3681         wdev->iftype = NL80211_IFTYPE_STATION;
3682
3683
3684
3685         PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3686                    wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3687                    wdev->wiphy->interface_modes, wdev->iftype);
3688
3689         #ifdef WILC_SDIO
3690         set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev); /* tony */
3691         #endif
3692
3693         /*Register wiphy structure*/
3694         s32Error = wiphy_register(wdev->wiphy);
3695         if (s32Error) {
3696                 PRINT_ER("Cannot register wiphy device\n");
3697                 /*should define what action to be taken in such failure*/
3698         } else {
3699                 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3700         }
3701
3702         priv->dev = net;
3703         return wdev;
3704
3705
3706 }
3707 /**
3708  *  @brief      WILC_WFI_WiphyFree
3709  *  @details    Freeing allocation of the wireless device structure
3710  *  @param[in]   NONE
3711  *  @return     NONE
3712  *  @author     mdaftedar
3713  *  @date       01 MAR 2012
3714  *  @version    1.0
3715  */
3716 int WILC_WFI_InitHostInt(struct net_device *net)
3717 {
3718
3719         s32 s32Error = WILC_SUCCESS;
3720
3721         struct wilc_priv *priv;
3722
3723         PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3724         priv = wdev_priv(net->ieee80211_ptr);
3725         if (op_ifcs == 0) {
3726                 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
3727                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3728                 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
3729                 #endif
3730         }
3731         op_ifcs++;
3732         if (s32Error < 0) {
3733                 PRINT_ER("Failed to creat refresh Timer\n");
3734                 return s32Error;
3735         }
3736
3737         priv->gbAutoRateAdjusted = false;
3738
3739         priv->bInP2PlistenState = false;
3740
3741         sema_init(&(priv->hSemScanReq), 1);
3742         s32Error = host_int_init(&priv->hWILCWFIDrv);
3743         if (s32Error) {
3744                 PRINT_ER("Error while initializing hostinterface\n");
3745         }
3746         return s32Error;
3747 }
3748
3749 /**
3750  *  @brief      WILC_WFI_WiphyFree
3751  *  @details    Freeing allocation of the wireless device structure
3752  *  @param[in]   NONE
3753  *  @return     NONE
3754  *  @author     mdaftedar
3755  *  @date       01 MAR 2012
3756  *  @version    1.0
3757  */
3758 int WILC_WFI_DeInitHostInt(struct net_device *net)
3759 {
3760         s32 s32Error = WILC_SUCCESS;
3761
3762         struct wilc_priv *priv;
3763
3764         priv = wdev_priv(net->ieee80211_ptr);
3765
3766         priv->gbAutoRateAdjusted = false;
3767
3768         priv->bInP2PlistenState = false;
3769
3770         op_ifcs--;
3771
3772         s32Error = host_int_deinit(priv->hWILCWFIDrv);
3773
3774         /* Clear the Shadow scan */
3775         clear_shadow_scan(priv);
3776         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3777         if (op_ifcs == 0) {
3778                 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
3779                 del_timer_sync(&hDuringIpTimer);
3780         }
3781         #endif
3782
3783         if (s32Error) {
3784                 PRINT_ER("Error while deintializing host interface\n");
3785         }
3786         return s32Error;
3787 }
3788
3789
3790 /**
3791  *  @brief      WILC_WFI_WiphyFree
3792  *  @details    Freeing allocation of the wireless device structure
3793  *  @param[in]   NONE
3794  *  @return     NONE
3795  *  @author     mdaftedar
3796  *  @date       01 MAR 2012
3797  *  @version    1.0
3798  */
3799 void WILC_WFI_WiphyFree(struct net_device *net)
3800 {
3801
3802         PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3803
3804         if (net == NULL) {
3805                 PRINT_D(INIT_DBG, "net_device is NULL\n");
3806                 return;
3807         }
3808
3809         if (net->ieee80211_ptr == NULL) {
3810                 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3811                 return;
3812         }
3813
3814         if (net->ieee80211_ptr->wiphy == NULL) {
3815                 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3816                 return;
3817         }
3818
3819         wiphy_unregister(net->ieee80211_ptr->wiphy);
3820
3821         PRINT_D(INIT_DBG, "Freeing wiphy\n");
3822         wiphy_free(net->ieee80211_ptr->wiphy);
3823         kfree(net->ieee80211_ptr);
3824
3825 }