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