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