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