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