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