2 * @file wilc_wfi_cfgopertaions.c
3 * @brief CFG80211 Function Implementation functionality
8 * @sa wilc_wfi_cfgopertaions.h top level OS wrapper file
13 #include "wilc_wfi_cfgoperations.h"
15 #include "linux_wlan_sdio.h"
17 #include <linux/errno.h>
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)
24 extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
25 extern u16 Set_machw_change_vir_if(bool bValue);
27 extern int mac_open(struct net_device *ndev);
28 extern int mac_close(struct net_device *ndev);
30 tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
31 u32 u32LastScannedNtwrksCountShadow;
32 struct timer_list hDuringIpTimer;
33 struct timer_list hAgingTimer;
35 extern u8 u8ConnectedSSID[6];
37 u8 g_wilc_initialized = 1;
38 extern bool g_obtainingIP;
40 #define CHAN2G(_channel, _freq, _flags) { \
41 .band = IEEE80211_BAND_2GHZ, \
42 .center_freq = (_freq), \
43 .hw_value = (_channel), \
45 .max_antenna_gain = 0, \
49 /*Frequency range for channels*/
50 static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
67 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
69 .hw_value = (_hw_value), \
74 /* Table 6 in section 3.2.1.1 */
75 static struct ieee80211_rate WILC_WFI_rates[] = {
76 RATETAB_ENT(10, 0, 0),
77 RATETAB_ENT(20, 1, 0),
78 RATETAB_ENT(55, 2, 0),
79 RATETAB_ENT(110, 3, 0),
80 RATETAB_ENT(60, 9, 0),
81 RATETAB_ENT(90, 6, 0),
82 RATETAB_ENT(120, 7, 0),
83 RATETAB_ENT(180, 8, 0),
84 RATETAB_ENT(240, 9, 0),
85 RATETAB_ENT(360, 10, 0),
86 RATETAB_ENT(480, 11, 0),
87 RATETAB_ENT(540, 12, 0),
90 struct p2p_mgmt_data {
95 /*Global variable used to state the current connected STA channel*/
96 u8 u8WLANChannel = INVALID_CHANNEL;
100 u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
101 u8 u8P2Plocalrandom = 0x01;
102 u8 u8P2Precvrandom = 0x00;
103 u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
106 static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
107 .channels = WILC_WFI_2ghz_channels,
108 .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
109 .bitrates = WILC_WFI_rates,
110 .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
114 struct add_key_params {
119 struct add_key_params g_add_gtk_key_params;
120 struct wilc_wfi_key g_key_gtk_params;
121 struct add_key_params g_add_ptk_key_params;
122 struct wilc_wfi_key g_key_ptk_params;
123 struct wilc_wfi_wep_key g_key_wep_params;
124 bool g_ptk_keys_saved;
125 bool g_gtk_keys_saved;
126 bool g_wep_keys_saved;
128 #define AGING_TIME (9 * 1000)
129 #define duringIP_TIME 15000
131 void clear_shadow_scan(void *pUserVoid)
136 del_timer_sync(&hAgingTimer);
137 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
139 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
140 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
141 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
142 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
145 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
146 astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
148 u32LastScannedNtwrksCountShadow = 0;
153 u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
157 u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
159 for (i = 0; i < num_rssi; i++)
160 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
166 void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
168 struct wilc_priv *priv;
170 struct cfg80211_bss *bss = NULL;
174 priv = (struct wilc_priv *)pUserVoid;
175 wiphy = priv->dev->ieee80211_ptr->wiphy;
177 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
178 tstrNetworkInfo *pstrNetworkInfo;
180 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
183 if ((!pstrNetworkInfo->u8Found) || all) {
185 struct ieee80211_channel *channel;
187 if (pstrNetworkInfo != NULL) {
189 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
190 channel = ieee80211_get_channel(wiphy, s32Freq);
192 rssi = get_rssi_avg(pstrNetworkInfo);
193 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
194 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
195 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
196 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
197 cfg80211_put_bss(wiphy, bss);
206 void reset_shadow_found(void *pUserVoid)
210 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
211 astrLastScannedNtwrksShadow[i].u8Found = 0;
216 void update_scan_time(void *pUserVoid)
220 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
221 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
225 static void remove_network_from_shadow(unsigned long arg)
227 unsigned long now = jiffies;
231 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
232 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
233 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
235 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
236 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
238 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
240 for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
241 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
243 u32LastScannedNtwrksCountShadow--;
247 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
248 if (u32LastScannedNtwrksCountShadow != 0) {
249 hAgingTimer.data = arg;
250 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
252 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
256 static void clear_duringIP(unsigned long arg)
258 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
259 g_obtainingIP = false;
262 int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
267 if (u32LastScannedNtwrksCountShadow == 0) {
268 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
269 hAgingTimer.data = (unsigned long)pUserVoid;
270 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
273 /* Linear search for now */
274 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
275 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
276 pstrNetworkInfo->au8bssid, 6) == 0) {
285 void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
287 int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
291 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
292 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
295 if (ap_found == -1) {
296 ap_index = u32LastScannedNtwrksCountShadow;
297 u32LastScannedNtwrksCountShadow++;
302 rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
303 astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
304 if (rssi_index == NUM_RSSI) {
306 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
308 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
310 astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
311 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
313 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
314 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
315 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
317 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
318 pstrNetworkInfo->au8bssid, ETH_ALEN);
320 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
321 astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
322 astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
324 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
325 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
327 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
328 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
329 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */
330 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
331 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
333 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
334 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
335 astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
337 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
338 astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
344 * @brief CfgScanResult
345 * @details Callback function which returns the scan results found
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
356 static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
358 struct wilc_priv *priv;
361 struct ieee80211_channel *channel;
362 struct cfg80211_bss *bss = NULL;
364 priv = (struct wilc_priv *)pUserVoid;
365 if (priv->bCfgScanning) {
366 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
367 wiphy = priv->dev->ieee80211_ptr->wiphy;
372 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
374 ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
376 (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
378 PRINT_ER("wiphy signal type fial\n");
382 if (pstrNetworkInfo != NULL) {
383 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
384 channel = ieee80211_get_channel(wiphy, s32Freq);
389 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
390 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
391 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
393 if (pstrNetworkInfo->bNewNetwork) {
394 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
396 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
399 priv->u32RcvdChCount++;
403 if (pJoinParams == NULL) {
404 PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
406 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
408 /*P2P peers are sent to WPA supplicant and added to shadow table*/
410 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
411 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
412 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
413 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
414 cfg80211_put_bss(wiphy, bss);
419 PRINT_ER("Discovered networks exceeded the max limit\n");
423 /* So this network is discovered before, we'll just update its RSSI */
424 for (i = 0; i < priv->u32RcvdChCount; i++) {
425 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
426 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
428 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
429 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
435 } else if (enuScanEvent == SCAN_EVENT_DONE) {
436 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
437 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
438 refresh_scan(priv, 1, false);
440 if (priv->u32RcvdChCount > 0)
441 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
443 PRINT_D(CFG80211_DBG, "No networks found\n");
445 down(&(priv->hSemScanReq));
447 if (priv->pstrScanReq != NULL) {
448 cfg80211_scan_done(priv->pstrScanReq, false);
449 priv->u32RcvdChCount = 0;
450 priv->bCfgScanning = false;
451 priv->pstrScanReq = NULL;
453 up(&(priv->hSemScanReq));
456 /*Aborting any scan operation during mac close*/
457 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
458 down(&(priv->hSemScanReq));
460 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
461 if (priv->pstrScanReq != NULL) {
463 update_scan_time(priv);
464 refresh_scan(priv, 1, false);
466 cfg80211_scan_done(priv->pstrScanReq, false);
467 priv->bCfgScanning = false;
468 priv->pstrScanReq = NULL;
470 up(&(priv->hSemScanReq));
477 * @brief WILC_WFI_Set_PMKSA
478 * @details Check if pmksa is cached and set it.
480 * @return int : Return 0 on Success
485 int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
491 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
493 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
495 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
497 /*If bssid is found, set the values*/
498 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
501 PRINT_ER("Error in pmkid\n");
511 int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
515 * @brief CfgConnectResult
517 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
518 * connection response or disconnection notification.
519 * tstrConnectInfo* pstrConnectInfo: COnnection information.
520 * u8 u8MacStatus: Mac Status from firmware
521 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
522 * void* pUserVoid: Private data associated with wireless interface
530 static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
531 tstrConnectInfo *pstrConnectInfo,
533 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
536 struct wilc_priv *priv;
537 struct net_device *dev;
538 struct host_if_drv *pstrWFIDrv;
539 u8 NullBssid[ETH_ALEN] = {0};
541 perInterface_wlan_t *nic;
545 priv = (struct wilc_priv *)pUserVoid;
547 nic = netdev_priv(dev);
549 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
551 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
553 u16 u16ConnectStatus;
555 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
557 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
559 if ((u8MacStatus == MAC_DISCONNECTED) &&
560 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
561 /* The case here is that our station was waiting for association response frame and has just received it containing status code
562 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
563 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
564 linux_wlan_set_bssid(priv->dev, NullBssid);
565 eth_zero_addr(u8ConnectedSSID);
567 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
568 if (!pstrWFIDrv->u8P2PConnect)
569 u8WLANChannel = INVALID_CHANNEL;
571 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
574 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
575 bool bNeedScanRefresh = false;
578 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
579 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
580 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
583 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
584 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
585 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
586 unsigned long now = jiffies;
589 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
590 bNeedScanRefresh = true;
597 if (bNeedScanRefresh) {
598 /*Also, refrsh DIRECT- results if */
599 refresh_scan(priv, 1, true);
606 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
608 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
610 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
611 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
612 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
613 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
614 /* be replaced by pstrConnectInfo->u16ConnectStatus */
615 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
616 g_obtainingIP = false;
617 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
618 pstrDisconnectNotifInfo->u16reason, priv->dev);
619 u8P2Plocalrandom = 0x01;
620 u8P2Precvrandom = 0x00;
622 eth_zero_addr(priv->au8AssociatedBss);
623 linux_wlan_set_bssid(priv->dev, NullBssid);
624 eth_zero_addr(u8ConnectedSSID);
626 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
627 if (!pstrWFIDrv->u8P2PConnect)
628 u8WLANChannel = INVALID_CHANNEL;
629 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
630 * virtual interface to station*/
631 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
632 pstrDisconnectNotifInfo->u16reason = 3;
634 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
635 * to scan again and retry the connection*/
636 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
637 pstrDisconnectNotifInfo->u16reason = 1;
639 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
640 pstrDisconnectNotifInfo->ie_len, false,
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.
656 * @return int : Return 0 on Success
661 static int set_channel(struct wiphy *wiphy,
662 struct cfg80211_chan_def *chandef)
665 struct wilc_priv *priv;
668 priv = wiphy_priv(wiphy);
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);
673 curr_channel = channelnum;
674 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
677 PRINT_ER("Error in setting channel %d\n", channelnum);
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.
689 * @return int : Return 0 on Success
695 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
697 struct wilc_priv *priv;
700 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
701 struct hidden_network strHiddenNetwork;
703 priv = wiphy_priv(wiphy);
705 priv->pstrScanReq = request;
707 priv->u32RcvdChCount = 0;
709 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
712 reset_shadow_found(priv);
714 priv->bCfgScanning = true;
715 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
717 for (i = 0; i < request->n_channels; i++) {
718 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
719 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
722 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
723 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
725 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
727 if (request->n_ssids >= 1) {
730 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
731 strHiddenNetwork.u8ssidnum = request->n_ssids;
734 for (i = 0; i < request->n_ssids; i++) {
736 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
737 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
738 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
739 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
741 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
742 strHiddenNetwork.u8ssidnum -= 1;
745 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
746 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
747 au8ScanChanList, request->n_channels,
748 (const u8 *)request->ie, request->ie_len,
749 CfgScanResult, (void *)priv, &strHiddenNetwork);
751 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
752 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
753 au8ScanChanList, request->n_channels,
754 (const u8 *)request->ie, request->ie_len,
755 CfgScanResult, (void *)priv, NULL);
759 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
765 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
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.
778 * @return int : Return 0 on Success
783 static int connect(struct wiphy *wiphy, struct net_device *dev,
784 struct cfg80211_connect_params *sme)
788 u8 u8security = NO_ENCRYPT;
789 enum AUTHTYPE tenuAuth_type = ANY;
790 char *pcgroup_encrypt_val = NULL;
791 char *pccipher_group = NULL;
792 char *pcwpa_version = NULL;
794 struct wilc_priv *priv;
795 struct host_if_drv *pstrWFIDrv;
796 tstrNetworkInfo *pstrNetworkInfo = NULL;
800 priv = wiphy_priv(wiphy);
801 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
803 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
805 PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
806 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
807 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
808 pstrWFIDrv->u8P2PConnect = 1;
810 pstrWFIDrv->u8P2PConnect = 0;
811 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
813 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
814 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
815 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
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");
825 /* BSSID is also passed from the user, so decision of matching
826 * should consider also this passed BSSID */
827 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
830 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
837 if (i < u32LastScannedNtwrksCountShadow) {
838 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
840 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
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]);
848 if (u32LastScannedNtwrksCountShadow == 0)
849 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
851 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
856 priv->WILC_WFI_wep_default = 0;
857 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
858 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
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);
863 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
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]);
870 if (sme->crypto.cipher_group != NO_ENCRYPT) {
871 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
872 * we will add to it the pairwise cipher suite(s) */
873 pcwpa_version = "Default";
874 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
875 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
876 u8security = ENCRYPT_ENABLED | WEP;
877 pcgroup_encrypt_val = "WEP40";
878 pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
879 PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
882 for (i = 0; i < sme->key_len; i++)
883 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
885 priv->WILC_WFI_wep_default = sme->key_idx;
886 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
887 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
889 g_key_wep_params.key_len = sme->key_len;
890 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
891 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
892 g_key_wep_params.key_idx = sme->key_idx;
893 g_wep_keys_saved = true;
895 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
896 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
897 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
898 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
899 pcgroup_encrypt_val = "WEP104";
900 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
902 priv->WILC_WFI_wep_default = sme->key_idx;
903 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
904 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
906 g_key_wep_params.key_len = sme->key_len;
907 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
908 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
909 g_key_wep_params.key_idx = sme->key_idx;
910 g_wep_keys_saved = true;
912 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
913 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
914 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
915 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
916 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
917 pcgroup_encrypt_val = "WPA2_TKIP";
918 pccipher_group = "TKIP";
919 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
920 /* tenuSecurity_t = WPA2_AES; */
921 u8security = ENCRYPT_ENABLED | WPA2 | AES;
922 pcgroup_encrypt_val = "WPA2_AES";
923 pccipher_group = "AES";
925 pcwpa_version = "WPA_VERSION_2";
926 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
927 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
928 u8security = ENCRYPT_ENABLED | WPA | TKIP;
929 pcgroup_encrypt_val = "WPA_TKIP";
930 pccipher_group = "TKIP";
931 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
932 /* tenuSecurity_t = WPA_AES; */
933 u8security = ENCRYPT_ENABLED | WPA | AES;
934 pcgroup_encrypt_val = "WPA_AES";
935 pccipher_group = "AES";
938 pcwpa_version = "WPA_VERSION_1";
941 s32Error = -ENOTSUPP;
942 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
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;
962 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
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;
971 case NL80211_AUTHTYPE_SHARED_KEY:
972 tenuAuth_type = SHARED_KEY;
973 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
977 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
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;
994 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
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);
999 curr_channel = pstrNetworkInfo->u8channel;
1001 if (!pstrWFIDrv->u8P2PConnect) {
1002 u8WLANChannel = pstrNetworkInfo->u8channel;
1005 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1007 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1008 sme->ssid_len, sme->ie, sme->ie_len,
1009 CfgConnectResult, (void *)priv, u8security,
1010 tenuAuth_type, pstrNetworkInfo->u8channel,
1011 pstrNetworkInfo->pJoinParams);
1012 if (s32Error != 0) {
1013 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
1026 * @details Disconnect from the BSS/ESS.
1028 * @return int : Return 0 on Success
1033 static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
1036 struct wilc_priv *priv;
1037 struct host_if_drv *pstrWFIDrv;
1038 u8 NullBssid[ETH_ALEN] = {0};
1041 priv = wiphy_priv(wiphy);
1043 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
1044 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1045 if (!pstrWFIDrv->u8P2PConnect)
1046 u8WLANChannel = INVALID_CHANNEL;
1047 linux_wlan_set_bssid(priv->dev, NullBssid);
1049 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1051 u8P2Plocalrandom = 0x01;
1052 u8P2Precvrandom = 0x00;
1054 pstrWFIDrv->u64P2p_MgmtTimeout = 0;
1056 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
1057 if (s32Error != 0) {
1058 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
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
1075 static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1077 const u8 *mac_addr, struct key_params *params)
1080 s32 s32Error = 0, KeyLen = params->key_len;
1082 struct wilc_priv *priv;
1083 const u8 *pu8RxMic = NULL;
1084 const u8 *pu8TxMic = NULL;
1085 u8 u8mode = NO_ENCRYPT;
1086 u8 u8gmode = NO_ENCRYPT;
1087 u8 u8pmode = NO_ENCRYPT;
1088 enum AUTHTYPE tenuAuth_type = ANY;
1090 perInterface_wlan_t *nic;
1092 priv = wiphy_priv(wiphy);
1093 nic = netdev_priv(netdev);
1096 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1098 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
1100 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1105 switch (params->cipher) {
1106 case WLAN_CIPHER_SUITE_WEP40:
1107 case WLAN_CIPHER_SUITE_WEP104:
1108 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1110 priv->WILC_WFI_wep_default = key_index;
1111 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1112 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
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);
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]);
1120 tenuAuth_type = OPEN_SYSTEM;
1122 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1123 u8mode = ENCRYPT_ENABLED | WEP;
1125 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1127 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1130 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
1131 priv->WILC_WFI_wep_default = key_index;
1132 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1133 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
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);
1138 for (i = 0; i < params->key_len; i++)
1139 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1141 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1146 case WLAN_CIPHER_SUITE_TKIP:
1147 case WLAN_CIPHER_SUITE_CCMP:
1148 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1150 if (priv->wilc_gtk[key_index] == NULL) {
1151 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1152 priv->wilc_gtk[key_index]->key = NULL;
1153 priv->wilc_gtk[key_index]->seq = NULL;
1156 if (priv->wilc_ptk[key_index] == NULL) {
1157 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1158 priv->wilc_ptk[key_index]->key = NULL;
1159 priv->wilc_ptk[key_index]->seq = NULL;
1165 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1166 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1168 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1170 priv->wilc_groupkey = u8gmode;
1172 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1174 pu8TxMic = params->key + 24;
1175 pu8RxMic = params->key + 16;
1176 KeyLen = params->key_len - 16;
1178 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
1179 kfree(priv->wilc_gtk[key_index]->key);
1181 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1182 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
1184 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
1185 kfree(priv->wilc_gtk[key_index]->seq);
1187 if ((params->seq_len) > 0) {
1188 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
1189 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
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;
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]);
1204 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1205 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
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]);
1210 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1211 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1213 u8pmode = priv->wilc_groupkey | AES;
1216 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1218 pu8TxMic = params->key + 24;
1219 pu8RxMic = params->key + 16;
1220 KeyLen = params->key_len - 16;
1223 kfree(priv->wilc_ptk[key_index]->key);
1225 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1227 kfree(priv->wilc_ptk[key_index]->seq);
1229 if ((params->seq_len) > 0)
1230 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
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]);
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]);
1240 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
1242 if ((params->seq_len) > 0)
1243 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
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;
1249 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1250 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
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;
1265 /*save keys only on interface 0 (wifi interface)*/
1266 if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) {
1267 g_add_gtk_key_params.key_idx = key_index;
1268 g_add_gtk_key_params.pairwise = pairwise;
1270 g_add_gtk_key_params.mac_addr = NULL;
1272 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1273 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1275 g_key_gtk_params.key_len = params->key_len;
1276 g_key_gtk_params.seq_len = params->seq_len;
1277 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
1278 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1279 if (params->seq_len > 0) {
1280 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
1281 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1283 g_key_gtk_params.cipher = params->cipher;
1285 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1286 g_key_gtk_params.key[1],
1287 g_key_gtk_params.key[2]);
1288 g_gtk_keys_saved = true;
1291 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1292 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
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;
1301 /*save keys only on interface 0 (wifi interface)*/
1302 if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) {
1303 g_add_ptk_key_params.key_idx = key_index;
1304 g_add_ptk_key_params.pairwise = pairwise;
1306 g_add_ptk_key_params.mac_addr = NULL;
1308 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1309 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1311 g_key_ptk_params.key_len = params->key_len;
1312 g_key_ptk_params.seq_len = params->seq_len;
1313 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
1314 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1315 if (params->seq_len > 0) {
1316 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
1317 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1319 g_key_ptk_params.cipher = params->cipher;
1321 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1322 g_key_ptk_params.key[1],
1323 g_key_ptk_params.key[2]);
1324 g_ptk_keys_saved = true;
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");
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]);
1339 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1340 s32Error = -ENOTSUPP;
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.
1352 * @return int : Return 0 on Success
1357 static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1362 struct wilc_priv *priv;
1364 perInterface_wlan_t *nic;
1366 priv = wiphy_priv(wiphy);
1367 nic = netdev_priv(netdev);
1370 /*delete saved keys, if any*/
1371 if (netdev == wl->vif[0].ndev) {
1372 g_ptk_keys_saved = false;
1373 g_gtk_keys_saved = false;
1374 g_wep_keys_saved = false;
1376 /*Delete saved WEP keys params, if any*/
1377 kfree(g_key_wep_params.key);
1378 g_key_wep_params.key = NULL;
1380 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1382 if ((priv->wilc_gtk[key_index]) != NULL) {
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;
1389 kfree(priv->wilc_gtk[key_index]);
1390 priv->wilc_gtk[key_index] = NULL;
1394 if ((priv->wilc_ptk[key_index]) != NULL) {
1396 kfree(priv->wilc_ptk[key_index]->key);
1397 priv->wilc_ptk[key_index]->key = NULL;
1398 kfree(priv->wilc_ptk[key_index]->seq);
1399 priv->wilc_ptk[key_index]->seq = NULL;
1400 kfree(priv->wilc_ptk[key_index]);
1401 priv->wilc_ptk[key_index] = NULL;
1404 /*Delete saved PTK and GTK keys params, if any*/
1405 kfree(g_key_ptk_params.key);
1406 g_key_ptk_params.key = NULL;
1407 kfree(g_key_ptk_params.seq);
1408 g_key_ptk_params.seq = NULL;
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;
1415 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
1416 Set_machw_change_vir_if(false);
1419 if (key_index >= 0 && key_index <= 3) {
1420 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
1421 priv->WILC_WFI_wep_key_len[key_index] = 0;
1423 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1424 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1426 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1427 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
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.
1441 * @return int : Return 0 on Success
1446 static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1448 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
1450 struct wilc_priv *priv;
1451 struct key_params key_params;
1454 priv = wiphy_priv(wiphy);
1458 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
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;
1466 for (i = 0; i < key_params.key_len; i++)
1467 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1470 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
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;
1479 callback(cookie, &key_params);
1481 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
1485 * @brief set_default_key
1486 * @details Set the default management frame key on an interface
1488 * @return int : Return 0 on Success.
1493 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1494 bool unicast, bool multicast)
1496 struct wilc_priv *priv;
1499 priv = wiphy_priv(wiphy);
1501 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
1503 if (key_index != priv->WILC_WFI_wep_default) {
1505 host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index);
1512 * @brief get_station
1513 * @details Get station information for the station identified by @mac
1515 * @return int : Return 0 on Success.
1521 static int get_station(struct wiphy *wiphy, struct net_device *dev,
1522 const u8 *mac, struct station_info *sinfo)
1524 struct wilc_priv *priv;
1525 perInterface_wlan_t *nic;
1527 u32 associatedsta = 0;
1528 u32 inactive_time = 0;
1529 priv = wiphy_priv(wiphy);
1530 nic = netdev_priv(dev);
1532 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1533 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1535 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1537 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1539 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1546 if (associatedsta == -1) {
1547 PRINT_ER("Station required is not associated\n");
1551 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
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);
1559 if (nic->iftype == STATION_MODE) {
1560 struct rf_info strStatistics;
1562 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1564 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
1565 BIT(NL80211_STA_INFO_RX_PACKETS) |
1566 BIT(NL80211_STA_INFO_TX_PACKETS) |
1567 BIT(NL80211_STA_INFO_TX_FAILED) |
1568 BIT(NL80211_STA_INFO_TX_BITRATE);
1570 sinfo->signal = strStatistics.s8RSSI;
1571 sinfo->rx_packets = strStatistics.u32RxCount;
1572 sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
1573 sinfo->tx_failed = strStatistics.u32TxFailureCount;
1574 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1576 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
1577 Enable_TCP_ACK_Filter(true);
1578 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
1579 Enable_TCP_ACK_Filter(false);
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);
1590 * @details Modify parameters for a given BSS.
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.
1609 static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1610 struct bss_parameters *params)
1612 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1617 * @brief set_wiphy_params
1618 * @details Notify that wiphy parameters have changed;
1619 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1621 * @return int : Return 0 on Success
1626 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
1629 struct cfg_param_val pstrCfgParamVal;
1630 struct wilc_priv *priv;
1632 priv = wiphy_priv(wiphy);
1634 pstrCfgParamVal.flag = 0;
1635 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
1637 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1638 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1639 priv->dev->ieee80211_ptr->wiphy->retry_short);
1640 pstrCfgParamVal.flag |= RETRY_SHORT;
1641 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1643 if (changed & WIPHY_PARAM_RETRY_LONG) {
1645 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
1646 pstrCfgParamVal.flag |= RETRY_LONG;
1647 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1650 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1651 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
1652 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
1653 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
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);
1660 pstrCfgParamVal.flag |= RTS_THRESHOLD;
1661 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1665 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1666 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1668 PRINT_ER("Error in setting WIPHY PARAMS\n");
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.
1680 * @return int : Return 0 on Success
1685 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1686 struct cfg80211_pmksa *pmksa)
1692 struct wilc_priv *priv = wiphy_priv(wiphy);
1694 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1697 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1698 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1700 /*If bssid already exists and pmkid value needs to reset*/
1702 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1706 if (i < WILC_MAX_NUM_PMKIDS) {
1707 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
1708 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
1710 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
1712 if (!(flag == PMKID_FOUND))
1713 priv->pmkid_list.numpmkid++;
1715 PRINT_ER("Invalid PMKID index\n");
1720 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1721 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1728 * @details Delete a cached PMKID.
1730 * @return int : Return 0 on Success
1735 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1736 struct cfg80211_pmksa *pmksa)
1742 struct wilc_priv *priv = wiphy_priv(wiphy);
1744 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1746 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1747 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1749 /*If bssid is found, reset the values*/
1750 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
1751 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
1756 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1757 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
1758 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
1759 priv->pmkid_list.pmkidlist[i + 1].bssid,
1761 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
1762 priv->pmkid_list.pmkidlist[i].pmkid,
1765 priv->pmkid_list.numpmkid--;
1774 * @brief flush_pmksa
1775 * @details Flush all cached PMKIDs.
1777 * @return int : Return 0 on Success
1782 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1784 struct wilc_priv *priv = wiphy_priv(wiphy);
1786 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1788 /*Get cashed Pmkids and set all with zeros*/
1789 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
1796 * @brief WILC_WFI_CfgParseRxAction
1797 * @details Function parses the received frames and modifies the following attributes:
1800 * -Operating Channel
1802 * @param[in] u8* Buffer, u32 length
1809 void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
1814 u8 op_channel_attr_index = 0;
1815 u8 channel_list_attr_index = 0;
1817 while (index < len) {
1818 if (buf[index] == GO_INTENT_ATTR_ID) {
1819 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
1822 if (buf[index] == CHANLIST_ATTR_ID)
1823 channel_list_attr_index = index;
1824 else if (buf[index] == OPERCHAN_ATTR_ID)
1825 op_channel_attr_index = index;
1826 index += buf[index + 1] + 3; /* ID,Length byte */
1828 if (u8WLANChannel != INVALID_CHANNEL) {
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;
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;
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
1861 void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
1866 u8 op_channel_attr_index = 0;
1867 u8 channel_list_attr_index = 0;
1869 while (index < len) {
1870 if (buf[index] == GO_INTENT_ATTR_ID) {
1871 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
1876 if (buf[index] == CHANLIST_ATTR_ID)
1877 channel_list_attr_index = index;
1878 else if (buf[index] == OPERCHAN_ATTR_ID)
1879 op_channel_attr_index = index;
1880 index += buf[index + 1] + 3; /* ID,Length byte */
1882 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
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;
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;
1905 /* @brief WILC_WFI_p2p_rx
1910 * @author Mai Daftedar
1915 void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
1918 struct wilc_priv *priv;
1919 u32 header, pkt_offset;
1920 struct host_if_drv *pstrWFIDrv;
1924 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1925 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1927 /* Get WILC header */
1928 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
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);
1934 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1935 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1936 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
1937 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
1940 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1941 PRINT_D(GENERIC_DBG, "Success Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1942 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
1943 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
1945 PRINT_D(GENERIC_DBG, "Fail Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1946 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
1947 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
1953 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1955 /*Upper layer is informed that the frame is received on this freq*/
1956 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
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]);
1961 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
1962 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1965 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
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]);
1972 case GAS_INTIAL_RSP:
1973 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1976 case PUBLIC_ACT_VENDORSPEC:
1977 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1978 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
1979 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
1980 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1982 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
1983 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
1984 u8P2Precvrandom = buff[i + 6];
1986 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1992 if (u8P2Plocalrandom > u8P2Precvrandom) {
1993 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1994 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1995 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
1996 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
1997 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
2003 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2007 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2008 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2009 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
2010 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2016 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2022 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2027 * @brief WILC_WFI_mgmt_tx_complete
2028 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2030 * transmitting status
2032 * @author Amr Abdelmoghny
2036 static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2038 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2041 kfree(pv_data->buff);
2046 * @brief WILC_WFI_RemainOnChannelReady
2047 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2050 * @author Amr abdelmoghny
2055 static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2057 struct wilc_priv *priv;
2059 priv = (struct wilc_priv *)pUserVoid;
2061 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
2063 priv->bInP2PlistenState = true;
2065 cfg80211_ready_on_channel(priv->wdev,
2066 priv->strRemainOnChanParams.u64ListenCookie,
2067 priv->strRemainOnChanParams.pstrListenChan,
2068 priv->strRemainOnChanParams.u32ListenDuration,
2073 * @brief WILC_WFI_RemainOnChannelExpired
2074 * @details Callback function, called on expiration of remain-on-channel duration
2077 * @author Amr abdelmoghny
2082 static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
2084 struct wilc_priv *priv;
2086 priv = (struct wilc_priv *)pUserVoid;
2088 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
2089 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
2091 priv->bInP2PlistenState = false;
2093 /*Inform wpas of remain-on-channel expiration*/
2094 cfg80211_remain_on_channel_expired(priv->wdev,
2095 priv->strRemainOnChanParams.u64ListenCookie,
2096 priv->strRemainOnChanParams.pstrListenChan,
2099 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2100 , priv->strRemainOnChanParams.u32ListenSessionID);
2106 * @brief remain_on_channel
2107 * @details Request the driver to remain awake on the specified
2108 * channel for the specified duration to complete an off-channel
2109 * operation (e.g., public action frame exchange). When the driver is
2110 * ready on the requested channel, it must indicate this with an event
2111 * notification by calling cfg80211_ready_on_channel().
2113 * @return int : Return 0 on Success
2118 static int remain_on_channel(struct wiphy *wiphy,
2119 struct wireless_dev *wdev,
2120 struct ieee80211_channel *chan,
2121 unsigned int duration, u64 *cookie)
2124 struct wilc_priv *priv;
2126 priv = wiphy_priv(wiphy);
2128 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2131 if (wdev->iftype == NL80211_IFTYPE_AP) {
2132 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2136 curr_channel = chan->hw_value;
2138 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2139 priv->strRemainOnChanParams.pstrListenChan = chan;
2140 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
2141 priv->strRemainOnChanParams.u32ListenDuration = duration;
2142 priv->strRemainOnChanParams.u32ListenSessionID++;
2144 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2145 , priv->strRemainOnChanParams.u32ListenSessionID
2148 , WILC_WFI_RemainOnChannelExpired
2149 , WILC_WFI_RemainOnChannelReady
2156 * @brief cancel_remain_on_channel
2157 * @details Cancel an on-going remain-on-channel operation.
2158 * This allows the operation to be terminated prior to timeout based on
2159 * the duration value.
2160 * @param[in] struct wiphy *wiphy,
2161 * @param[in] struct net_device *dev
2162 * @param[in] u64 cookie,
2163 * @return int : Return 0 on Success
2168 static int cancel_remain_on_channel(struct wiphy *wiphy,
2169 struct wireless_dev *wdev,
2173 struct wilc_priv *priv;
2175 priv = wiphy_priv(wiphy);
2177 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2179 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2183 * @brief WILC_WFI_add_wilcvendorspec
2184 * @details Adding WILC information elemet to allow two WILC devices to
2185 * identify each other and connect
2186 * @param[in] u8 * buf
2192 void WILC_WFI_add_wilcvendorspec(u8 *buff)
2194 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
2197 * @brief WILC_WFI_mgmt_tx_frame
2206 extern bool bEnablePS;
2207 static int mgmt_tx(struct wiphy *wiphy,
2208 struct wireless_dev *wdev,
2209 struct cfg80211_mgmt_tx_params *params,
2212 struct ieee80211_channel *chan = params->chan;
2213 unsigned int wait = params->wait;
2214 const u8 *buf = params->buf;
2215 size_t len = params->len;
2216 const struct ieee80211_mgmt *mgmt;
2217 struct p2p_mgmt_data *mgmt_tx;
2218 struct wilc_priv *priv;
2219 struct host_if_drv *pstrWFIDrv;
2221 perInterface_wlan_t *nic;
2222 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
2224 nic = netdev_priv(wdev->netdev);
2225 priv = wiphy_priv(wiphy);
2226 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
2228 *cookie = (unsigned long)buf;
2229 priv->u64tx_cookie = *cookie;
2230 mgmt = (const struct ieee80211_mgmt *) buf;
2232 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2234 /*mgmt frame allocation*/
2235 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
2236 if (mgmt_tx == NULL) {
2237 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
2240 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
2241 if (mgmt_tx->buff == NULL) {
2242 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
2246 memcpy(mgmt_tx->buff, buf, len);
2247 mgmt_tx->size = len;
2250 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2251 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2252 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2253 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2254 /*Save the current channel after we tune to it*/
2255 curr_channel = chan->hw_value;
2256 } else if (ieee80211_is_action(mgmt->frame_control)) {
2257 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
2260 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
2261 /*Only set the channel, if not a negotiation confirmation frame
2262 * (If Negotiation confirmation frame, force it
2263 * to be transmitted on the same negotiation channel)*/
2265 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2266 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2267 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2268 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2269 /*Save the current channel after we tune to it*/
2270 curr_channel = chan->hw_value;
2272 switch (buf[ACTION_SUBTYPE_ID]) {
2273 case GAS_INTIAL_REQ:
2275 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2279 case GAS_INTIAL_RSP:
2281 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2285 case PUBLIC_ACT_VENDORSPEC:
2287 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2288 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2289 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
2290 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2291 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2292 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2293 get_random_bytes(&u8P2Plocalrandom, 1);
2294 /*Increment the number to prevent if its 0*/
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);
2304 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2305 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
2306 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
2307 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
2308 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
2310 /*If using supplicant go intent, no need at all*/
2311 /*to parse transmitted negotiation frames*/
2313 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
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;
2324 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2328 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2336 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
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));
2346 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2350 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2352 WILC_WFI_mgmt_tx_complete);
2354 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2359 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2360 struct wireless_dev *wdev,
2363 struct wilc_priv *priv;
2364 struct host_if_drv *pstrWFIDrv;
2366 priv = wiphy_priv(wiphy);
2367 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
2370 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2371 pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2373 if (!priv->bInP2PlistenState) {
2374 cfg80211_remain_on_channel_expired(priv->wdev,
2375 priv->strRemainOnChanParams.u64ListenCookie,
2376 priv->strRemainOnChanParams.pstrListenChan,
2384 * @brief wilc_mgmt_frame_register
2385 * @details Notify driver that a management frame type was
2386 * registered. Note that this callback may not sleep, and cannot run
2387 * concurrently with itself.
2394 void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2395 u16 frame_type, bool reg)
2398 struct wilc_priv *priv;
2399 perInterface_wlan_t *nic;
2402 priv = wiphy_priv(wiphy);
2403 nic = netdev_priv(priv->wdev->netdev);
2409 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2410 switch (frame_type) {
2413 nic->g_struct_frame_reg[0].frame_type = frame_type;
2414 nic->g_struct_frame_reg[0].reg = reg;
2420 nic->g_struct_frame_reg[1].frame_type = frame_type;
2421 nic->g_struct_frame_reg[1].reg = reg;
2431 /*If mac is closed, then return*/
2432 if (!wl->initialized) {
2433 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2436 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2442 * @brief set_cqm_rssi_config
2443 * @details Configure connection quality monitor RSSI threshold.
2444 * @param[in] struct wiphy *wiphy:
2445 * @param[in] struct net_device *dev:
2446 * @param[in] s32 rssi_thold:
2447 * @param[in] u32 rssi_hyst:
2448 * @return int : Return 0 on Success
2453 static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2454 s32 rssi_thold, u32 rssi_hyst)
2456 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2461 * @brief dump_station
2462 * @details Configure connection quality monitor RSSI threshold.
2463 * @param[in] struct wiphy *wiphy:
2464 * @param[in] struct net_device *dev
2465 * @param[in] int idx
2466 * @param[in] u8 *mac
2467 * @param[in] struct station_info *sinfo
2468 * @return int : Return 0 on Success
2473 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2474 int idx, u8 *mac, struct station_info *sinfo)
2476 struct wilc_priv *priv;
2478 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2483 priv = wiphy_priv(wiphy);
2485 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2487 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2495 * @brief set_power_mgmt
2498 * @return int : Return 0 on Success.
2503 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2504 bool enabled, int timeout)
2506 struct wilc_priv *priv;
2508 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2513 priv = wiphy_priv(wiphy);
2514 if (priv->hWILCWFIDrv == NULL) {
2515 PRINT_ER("Driver is NULL\n");
2520 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2528 * @brief change_virtual_intf
2529 * @details Change type/configuration of virtual interface,
2530 * keep the struct wireless_dev's iftype updated.
2532 * @return int : Return 0 on Success.
2537 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2539 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2540 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
2542 struct wilc_priv *priv;
2543 perInterface_wlan_t *nic;
2549 nic = netdev_priv(dev);
2550 priv = wiphy_priv(wiphy);
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;
2560 g_obtainingIP = false;
2561 del_timer(&hDuringIpTimer);
2562 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
2563 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2564 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2565 Set_machw_change_vir_if(true);
2569 case NL80211_IFTYPE_STATION:
2571 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
2573 /* send delba over wlan interface */
2576 dev->ieee80211_ptr->iftype = type;
2577 priv->wdev->iftype = type;
2578 nic->monitor_flag = 0;
2579 nic->iftype = STATION_MODE;
2581 /*Remove the enteries of the previously connected clients*/
2582 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
2583 interface_type = nic->iftype;
2584 nic->iftype = STATION_MODE;
2586 if (wl->initialized) {
2587 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2588 wl->vif[0].bssid, TID);
2589 /* ensure that the message Q is empty */
2590 host_int_wait_msg_queue_idle();
2592 /*Eliminate host interface blocking state*/
2595 wilc1000_wlan_deinit(dev);
2596 wilc1000_wlan_init(dev, nic);
2597 g_wilc_initialized = 1;
2598 nic->iftype = interface_type;
2600 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2601 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2602 host_int_set_MacAddress(wl->vif[0].hif_drv,
2603 wl->vif[0].src_addr);
2604 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2606 /*Add saved WEP keys, if any*/
2607 if (g_wep_keys_saved) {
2608 host_int_set_wep_default_key(wl->vif[0].hif_drv,
2609 g_key_wep_params.key_idx);
2610 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
2611 g_key_wep_params.key,
2612 g_key_wep_params.key_len,
2613 g_key_wep_params.key_idx);
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);
2620 /*Add saved PTK and GTK keys, if any*/
2621 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2622 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2623 g_key_ptk_params.key[1],
2624 g_key_ptk_params.key[2]);
2625 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2626 g_key_gtk_params.key[1],
2627 g_key_gtk_params.key[2]);
2628 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2635 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2643 if (wl->initialized) {
2644 for (i = 0; i < num_reg_frame; i++) {
2645 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2646 nic->g_struct_frame_reg[i].reg);
2647 host_int_frame_register(priv->hWILCWFIDrv,
2648 nic->g_struct_frame_reg[i].frame_type,
2649 nic->g_struct_frame_reg[i].reg);
2654 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2658 case NL80211_IFTYPE_P2P_CLIENT:
2660 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2662 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
2664 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2665 wl->vif[0].bssid, TID);
2667 dev->ieee80211_ptr->iftype = type;
2668 priv->wdev->iftype = type;
2669 nic->monitor_flag = 0;
2671 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2672 nic->iftype = CLIENT_MODE;
2675 if (wl->initialized) {
2676 /* ensure that the message Q is empty */
2677 host_int_wait_msg_queue_idle();
2679 wilc1000_wlan_deinit(dev);
2680 wilc1000_wlan_init(dev, nic);
2681 g_wilc_initialized = 1;
2683 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2684 host_int_set_MacAddress(wl->vif[0].hif_drv,
2685 wl->vif[0].src_addr);
2686 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2688 /*Add saved WEP keys, if any*/
2689 if (g_wep_keys_saved) {
2690 host_int_set_wep_default_key(wl->vif[0].hif_drv,
2691 g_key_wep_params.key_idx);
2692 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
2693 g_key_wep_params.key,
2694 g_key_wep_params.key_len,
2695 g_key_wep_params.key_idx);
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);
2702 /*Add saved PTK and GTK keys, if any*/
2703 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2704 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2705 g_key_ptk_params.key[1],
2706 g_key_ptk_params.key[2]);
2707 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2708 g_key_gtk_params.key[1],
2709 g_key_gtk_params.key[2]);
2710 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2717 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2725 /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
2726 refresh_scan(priv, 1, true);
2727 Set_machw_change_vir_if(false);
2729 if (wl->initialized) {
2730 for (i = 0; i < num_reg_frame; i++) {
2731 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2732 nic->g_struct_frame_reg[i].reg);
2733 host_int_frame_register(priv->hWILCWFIDrv,
2734 nic->g_struct_frame_reg[i].frame_type,
2735 nic->g_struct_frame_reg[i].reg);
2741 case NL80211_IFTYPE_AP:
2743 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
2744 dev->ieee80211_ptr->iftype = type;
2745 priv->wdev->iftype = type;
2746 nic->iftype = AP_MODE;
2747 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
2749 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2750 linux_wlan_get_firmware(nic);
2751 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
2752 if (wl->initialized) {
2753 nic->iftype = AP_MODE;
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);
2767 case NL80211_IFTYPE_P2P_GO:
2768 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2770 g_obtainingIP = true;
2771 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
2772 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2773 /*Delete block ack has to be the latest config packet*/
2774 /*sent before downloading new FW. This is because it blocks on*/
2775 /*hWaitResponse semaphore, which allows previous config*/
2776 /*packets to actually take action on old FW*/
2777 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2778 wl->vif[0].bssid, TID);
2780 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
2781 dev->ieee80211_ptr->iftype = type;
2782 priv->wdev->iftype = type;
2784 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
2786 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2789 nic->iftype = GO_MODE;
2791 /* ensure that the message Q is empty */
2792 host_int_wait_msg_queue_idle();
2793 wilc1000_wlan_deinit(dev);
2794 wilc1000_wlan_init(dev, nic);
2795 g_wilc_initialized = 1;
2798 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2799 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2800 host_int_set_MacAddress(wl->vif[0].hif_drv,
2801 wl->vif[0].src_addr);
2802 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2804 /*Add saved WEP keys, if any*/
2805 if (g_wep_keys_saved) {
2806 host_int_set_wep_default_key(wl->vif[0].hif_drv,
2807 g_key_wep_params.key_idx);
2808 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
2809 g_key_wep_params.key,
2810 g_key_wep_params.key_len,
2811 g_key_wep_params.key_idx);
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);
2818 /*Add saved PTK and GTK keys, if any*/
2819 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2820 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2821 g_key_ptk_params.key[1],
2822 g_key_ptk_params.key[2],
2823 g_key_ptk_params.cipher);
2824 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2825 g_key_gtk_params.key[1],
2826 g_key_gtk_params.key[2],
2827 g_key_gtk_params.cipher);
2828 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2835 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
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));
2843 if (wl->initialized) {
2844 for (i = 0; i < num_reg_frame; i++) {
2845 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2846 nic->g_struct_frame_reg[i].reg);
2847 host_int_frame_register(priv->hWILCWFIDrv,
2848 nic->g_struct_frame_reg[i].frame_type,
2849 nic->g_struct_frame_reg[i].reg);
2855 PRINT_ER("Unknown interface type= %d\n", type);
2862 /* (austin.2013-07-23)
2864 * To support revised cfg80211_ops
2866 * add_beacon --> start_ap
2867 * set_beacon --> change_beacon
2868 * del_beacon --> stop_ap
2870 * beacon_parameters --> cfg80211_ap_settings
2871 * cfg80211_beacon_data
2873 * applicable for linux kernel 3.4+
2878 * @details Add a beacon with given parameters, @head, @interval
2879 * and @dtim_period will be valid, @tail is optional.
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.
2888 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2889 struct cfg80211_ap_settings *settings)
2891 struct cfg80211_beacon_data *beacon = &(settings->beacon);
2892 struct wilc_priv *priv;
2895 perInterface_wlan_t *nic;
2897 priv = wiphy_priv(wiphy);
2898 nic = netdev_priv(dev);
2900 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2902 PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
2903 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2905 s32Error = set_channel(wiphy, &settings->chandef);
2908 PRINT_ER("Error in setting channel\n");
2910 linux_wlan_set_bssid(dev, wl->vif[0].src_addr);
2912 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2913 settings->beacon_interval,
2914 settings->dtim_period,
2915 beacon->head_len, (u8 *)beacon->head,
2916 beacon->tail_len, (u8 *)beacon->tail);
2922 * @brief change_beacon
2923 * @details Add a beacon with given parameters, @head, @interval
2924 * and @dtim_period will be valid, @tail is optional.
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.
2933 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2934 struct cfg80211_beacon_data *beacon)
2936 struct wilc_priv *priv;
2939 priv = wiphy_priv(wiphy);
2940 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2943 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2946 beacon->head_len, (u8 *)beacon->head,
2947 beacon->tail_len, (u8 *)beacon->tail);
2954 * @details Remove beacon configuration and stop sending the beacon.
2956 * @return int : Return 0 on Success.
2961 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
2964 struct wilc_priv *priv;
2965 u8 NullBssid[ETH_ALEN] = {0};
2970 priv = wiphy_priv(wiphy);
2972 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2974 linux_wlan_set_bssid(dev, NullBssid);
2976 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
2979 PRINT_ER("Host delete beacon fail\n");
2985 * @brief add_station
2986 * @details Add a new station.
2988 * @return int : Return 0 on Success.
2993 static int add_station(struct wiphy *wiphy, struct net_device *dev,
2994 const u8 *mac, struct station_parameters *params)
2997 struct wilc_priv *priv;
2998 struct add_sta_param strStaParams = { {0} };
2999 perInterface_wlan_t *nic;
3004 priv = wiphy_priv(wiphy);
3005 nic = netdev_priv(dev);
3007 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3008 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3009 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
3010 strStaParams.u16AssocID = params->aid;
3011 strStaParams.u8NumRates = params->supported_rates_len;
3012 strStaParams.pu8Rates = params->supported_rates;
3014 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
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);
3021 if (params->ht_capa == NULL) {
3022 strStaParams.bIsHTSupported = false;
3024 strStaParams.bIsHTSupported = true;
3025 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3026 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3027 memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3028 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3029 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3030 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3033 strStaParams.u16FlagsMask = params->sta_flags_mask;
3034 strStaParams.u16FlagsSet = params->sta_flags_set;
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);
3045 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
3047 PRINT_ER("Host add station fail\n");
3054 * @brief del_station
3055 * @details Remove a station; @mac may be NULL to remove all stations.
3057 * @return int : Return 0 on Success.
3062 static int del_station(struct wiphy *wiphy, struct net_device *dev,
3063 struct station_del_parameters *params)
3065 const u8 *mac = params->mac;
3067 struct wilc_priv *priv;
3068 perInterface_wlan_t *nic;
3073 priv = wiphy_priv(wiphy);
3074 nic = netdev_priv(dev);
3076 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3077 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3081 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
3082 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
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]);
3087 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
3090 PRINT_ER("Host delete station fail\n");
3096 * @brief change_station
3097 * @details Modify a given station.
3099 * @return int : Return 0 on Success.
3104 static int change_station(struct wiphy *wiphy, struct net_device *dev,
3105 const u8 *mac, struct station_parameters *params)
3108 struct wilc_priv *priv;
3109 struct add_sta_param strStaParams = { {0} };
3110 perInterface_wlan_t *nic;
3113 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3118 priv = wiphy_priv(wiphy);
3119 nic = netdev_priv(dev);
3121 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3122 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3123 strStaParams.u16AssocID = params->aid;
3124 strStaParams.u8NumRates = params->supported_rates_len;
3125 strStaParams.pu8Rates = params->supported_rates;
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);
3132 if (params->ht_capa == NULL) {
3133 strStaParams.bIsHTSupported = false;
3135 strStaParams.bIsHTSupported = true;
3136 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3137 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3138 memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3139 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3140 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3141 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3145 strStaParams.u16FlagsMask = params->sta_flags_mask;
3146 strStaParams.u16FlagsSet = params->sta_flags_set;
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);
3157 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
3159 PRINT_ER("Host edit station fail\n");
3166 * @brief add_virtual_intf
3169 * @return int : Return 0 on Success.
3174 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3176 unsigned char name_assign_type,
3177 enum nl80211_iftype type,
3179 struct vif_params *params)
3181 perInterface_wlan_t *nic;
3182 struct wilc_priv *priv;
3183 struct net_device *new_ifc = NULL;
3185 priv = wiphy_priv(wiphy);
3189 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3191 nic = netdev_priv(priv->wdev->netdev);
3194 if (type == NL80211_IFTYPE_MONITOR) {
3195 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3196 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3197 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3198 if (new_ifc != NULL) {
3199 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
3200 nic = netdev_priv(priv->wdev->netdev);
3201 nic->monitor_flag = 1;
3203 PRINT_ER("Error in initializing monitor interface\n ");
3209 * @brief del_virtual_intf
3212 * @return int : Return 0 on Success.
3217 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3219 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
3223 static struct cfg80211_ops wilc_cfg80211_ops = {
3225 .set_monitor_channel = set_channel,
3228 .disconnect = disconnect,
3232 .set_default_key = set_default_key,
3233 .add_virtual_intf = add_virtual_intf,
3234 .del_virtual_intf = del_virtual_intf,
3235 .change_virtual_intf = change_virtual_intf,
3237 .start_ap = start_ap,
3238 .change_beacon = change_beacon,
3240 .add_station = add_station,
3241 .del_station = del_station,
3242 .change_station = change_station,
3243 .get_station = get_station,
3244 .dump_station = dump_station,
3245 .change_bss = change_bss,
3246 .set_wiphy_params = set_wiphy_params,
3248 .set_pmksa = set_pmksa,
3249 .del_pmksa = del_pmksa,
3250 .flush_pmksa = flush_pmksa,
3251 .remain_on_channel = remain_on_channel,
3252 .cancel_remain_on_channel = cancel_remain_on_channel,
3253 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
3255 .mgmt_frame_register = wilc_mgmt_frame_register,
3256 .set_power_mgmt = set_power_mgmt,
3257 .set_cqm_rssi_config = set_cqm_rssi_config,
3266 * @brief WILC_WFI_update_stats
3267 * @details Modify parameters for a given BSS.
3269 * @return int : Return 0 on Success.
3274 int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3277 struct wilc_priv *priv;
3279 priv = wiphy_priv(wiphy);
3282 case WILC_WFI_RX_PKT:
3284 priv->netstats.rx_packets++;
3285 priv->netstats.rx_bytes += pktlen;
3286 priv->netstats.rx_time = get_jiffies_64();
3290 case WILC_WFI_TX_PKT:
3292 priv->netstats.tx_packets++;
3293 priv->netstats.tx_bytes += pktlen;
3294 priv->netstats.tx_time = get_jiffies_64();
3306 * @brief WILC_WFI_CfgAlloc
3307 * @details Allocation of the wireless device structure and assigning it
3308 * to the cfg80211 operations structure.
3310 * @return wireless_dev : Returns pointer to wireless_dev structure.
3315 struct wireless_dev *WILC_WFI_CfgAlloc(void)
3318 struct wireless_dev *wdev;
3321 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3322 /*Allocating the wireless device structure*/
3323 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3325 PRINT_ER("Cannot allocate wireless device\n");
3329 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
3330 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
3332 PRINT_ER("Cannot allocate wiphy\n");
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;
3345 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3356 * @brief wilc_create_wiphy
3357 * @details Registering of the wiphy structure and interface modes
3364 struct wireless_dev *wilc_create_wiphy(struct net_device *net)
3366 struct wilc_priv *priv;
3367 struct wireless_dev *wdev;
3370 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3372 wdev = WILC_WFI_CfgAlloc();
3374 PRINT_ER("CfgAlloc Failed\n");
3379 /*Return hardware description structure (wiphy)'s priv*/
3380 priv = wdev_priv(wdev);
3381 sema_init(&(priv->SemHandleUpdateStats), 1);
3383 /*Link the wiphy with wireless structure*/
3386 /*Maximum number of probed ssid to be added by user for the scan request*/
3387 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
3388 /*Maximum number of pmkids to be cashed*/
3389 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3390 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
3392 wdev->wiphy->max_scan_ie_len = 1000;
3394 /*signal strength in mBm (100*dBm) */
3395 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3397 /*Set the availaible cipher suites*/
3398 wdev->wiphy->cipher_suites = cipher_suites;
3399 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3400 /*Setting default managment types: for register action frame: */
3401 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
3403 wdev->wiphy->max_remain_on_channel_duration = 500;
3404 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3405 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3406 BIT(NL80211_IFTYPE_P2P_CLIENT);
3407 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3408 wdev->iftype = NL80211_IFTYPE_STATION;
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);
3417 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
3420 /*Register wiphy structure*/
3421 s32Error = wiphy_register(wdev->wiphy);
3423 PRINT_ER("Cannot register wiphy device\n");
3424 /*should define what action to be taken in such failure*/
3426 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3435 * @brief WILC_WFI_WiphyFree
3436 * @details Freeing allocation of the wireless device structure
3443 int wilc_init_host_int(struct net_device *net)
3448 struct wilc_priv *priv;
3450 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3451 priv = wdev_priv(net->ieee80211_ptr);
3453 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
3454 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
3458 PRINT_ER("Failed to creat refresh Timer\n");
3462 priv->gbAutoRateAdjusted = false;
3464 priv->bInP2PlistenState = false;
3466 sema_init(&(priv->hSemScanReq), 1);
3467 s32Error = host_int_init(net, &priv->hWILCWFIDrv);
3469 PRINT_ER("Error while initializing hostinterface\n");
3475 * @brief WILC_WFI_WiphyFree
3476 * @details Freeing allocation of the wireless device structure
3483 int wilc_deinit_host_int(struct net_device *net)
3487 struct wilc_priv *priv;
3489 priv = wdev_priv(net->ieee80211_ptr);
3491 priv->gbAutoRateAdjusted = false;
3493 priv->bInP2PlistenState = false;
3497 s32Error = host_int_deinit(priv->hWILCWFIDrv);
3499 /* Clear the Shadow scan */
3500 clear_shadow_scan(priv);
3502 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
3503 del_timer_sync(&hDuringIpTimer);
3507 PRINT_ER("Error while deintializing host interface\n");
3514 * @brief WILC_WFI_WiphyFree
3515 * @details Freeing allocation of the wireless device structure
3522 void wilc_free_wiphy(struct net_device *net)
3524 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3527 PRINT_D(INIT_DBG, "net_device is NULL\n");
3531 if (!net->ieee80211_ptr) {
3532 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3536 if (!net->ieee80211_ptr->wiphy) {
3537 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3541 wiphy_unregister(net->ieee80211_ptr->wiphy);
3543 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3544 wiphy_free(net->ieee80211_ptr->wiphy);
3545 kfree(net->ieee80211_ptr);