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