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