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