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};
543 priv = (struct wilc_priv *)pUserVoid;
545 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
547 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
549 u16 u16ConnectStatus;
551 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
553 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
555 if ((u8MacStatus == MAC_DISCONNECTED) &&
556 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
557 /* The case here is that our station was waiting for association response frame and has just received it containing status code
558 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
559 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
560 linux_wlan_set_bssid(priv->dev, NullBssid);
561 eth_zero_addr(u8ConnectedSSID);
563 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
564 if (!pstrWFIDrv->u8P2PConnect)
565 u8WLANChannel = INVALID_CHANNEL;
567 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
570 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
571 bool bNeedScanRefresh = false;
574 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
575 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
576 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
579 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
580 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
581 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
582 unsigned long now = jiffies;
585 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
586 bNeedScanRefresh = true;
593 if (bNeedScanRefresh) {
594 /*Also, refrsh DIRECT- results if */
595 refresh_scan(priv, 1, true);
602 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
604 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
606 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
607 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
608 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
609 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
610 /* be replaced by pstrConnectInfo->u16ConnectStatus */
611 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
612 g_obtainingIP = false;
613 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
614 pstrDisconnectNotifInfo->u16reason, priv->dev);
615 u8P2Plocalrandom = 0x01;
616 u8P2Precvrandom = 0x00;
618 eth_zero_addr(priv->au8AssociatedBss);
619 linux_wlan_set_bssid(priv->dev, NullBssid);
620 eth_zero_addr(u8ConnectedSSID);
622 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
623 if (!pstrWFIDrv->u8P2PConnect)
624 u8WLANChannel = INVALID_CHANNEL;
625 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
626 * virtual interface to station*/
627 if ((pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->vif[1].ndev)) {
628 pstrDisconnectNotifInfo->u16reason = 3;
630 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
631 * to scan again and retry the connection*/
632 else if ((!pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->vif[1].ndev)) {
633 pstrDisconnectNotifInfo->u16reason = 1;
635 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
636 pstrDisconnectNotifInfo->ie_len, false,
646 * @details Set channel for a given wireless interface. Some devices
647 * may support multi-channel operation (by channel hopping) so cfg80211
648 * doesn't verify much. Note, however, that the passed netdev may be
649 * %NULL as well if the user requested changing the channel for the
650 * device itself, or for a monitor interface.
652 * @return int : Return 0 on Success
657 static int set_channel(struct wiphy *wiphy,
658 struct cfg80211_chan_def *chandef)
661 struct wilc_priv *priv;
664 priv = wiphy_priv(wiphy);
666 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
667 PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
669 curr_channel = channelnum;
670 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
673 PRINT_ER("Error in setting channel %d\n", channelnum);
680 * @details Request to do a scan. If returning zero, the scan request is given
681 * the driver, and will be valid until passed to cfg80211_scan_done().
682 * For scan results, call cfg80211_inform_bss(); you can call this outside
683 * the scan/scan_done bracket too.
685 * @return int : Return 0 on Success
691 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
693 struct wilc_priv *priv;
696 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
697 struct hidden_network strHiddenNetwork;
699 priv = wiphy_priv(wiphy);
701 priv->pstrScanReq = request;
703 priv->u32RcvdChCount = 0;
705 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
708 reset_shadow_found(priv);
710 priv->bCfgScanning = true;
711 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
713 for (i = 0; i < request->n_channels; i++) {
714 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
715 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
718 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
719 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
721 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
723 if (request->n_ssids >= 1) {
726 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
727 strHiddenNetwork.u8ssidnum = request->n_ssids;
730 for (i = 0; i < request->n_ssids; i++) {
732 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
733 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
734 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
735 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
737 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
738 strHiddenNetwork.u8ssidnum -= 1;
741 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
742 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
743 au8ScanChanList, request->n_channels,
744 (const u8 *)request->ie, request->ie_len,
745 CfgScanResult, (void *)priv, &strHiddenNetwork);
747 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
748 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
749 au8ScanChanList, request->n_channels,
750 (const u8 *)request->ie, request->ie_len,
751 CfgScanResult, (void *)priv, NULL);
755 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
761 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
769 * @details Connect to the ESS with the specified parameters. When connected,
770 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
771 * If the connection fails for some reason, call cfg80211_connect_result()
772 * with the status from the AP.
774 * @return int : Return 0 on Success
779 static int connect(struct wiphy *wiphy, struct net_device *dev,
780 struct cfg80211_connect_params *sme)
784 u8 u8security = NO_ENCRYPT;
785 enum AUTHTYPE tenuAuth_type = ANY;
786 char *pcgroup_encrypt_val = NULL;
787 char *pccipher_group = NULL;
788 char *pcwpa_version = NULL;
790 struct wilc_priv *priv;
791 struct host_if_drv *pstrWFIDrv;
792 tstrNetworkInfo *pstrNetworkInfo = NULL;
796 priv = wiphy_priv(wiphy);
797 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
799 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
801 PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
802 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
803 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
804 pstrWFIDrv->u8P2PConnect = 1;
806 pstrWFIDrv->u8P2PConnect = 0;
807 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
809 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
810 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
811 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
813 sme->ssid_len) == 0) {
814 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
815 if (sme->bssid == NULL) {
816 /* BSSID is not passed from the user, so decision of matching
817 * is done by SSID only */
818 PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n");
821 /* BSSID is also passed from the user, so decision of matching
822 * should consider also this passed BSSID */
823 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
826 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
833 if (i < u32LastScannedNtwrksCountShadow) {
834 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
836 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
838 PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n",
839 pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1],
840 pstrNetworkInfo->au8bssid[2], pstrNetworkInfo->au8bssid[3],
841 pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]);
844 if (u32LastScannedNtwrksCountShadow == 0)
845 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
847 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
852 priv->WILC_WFI_wep_default = 0;
853 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
854 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
856 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
857 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
859 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
862 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
863 PRINT_D(CORECONFIG_DBG, "sme->crypto.ciphers_pairwise[%d]=%x\n", i, sme->crypto.ciphers_pairwise[i]);
866 if (sme->crypto.cipher_group != NO_ENCRYPT) {
867 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
868 * we will add to it the pairwise cipher suite(s) */
869 pcwpa_version = "Default";
870 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
871 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
872 u8security = ENCRYPT_ENABLED | WEP;
873 pcgroup_encrypt_val = "WEP40";
874 pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
875 PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
878 for (i = 0; i < sme->key_len; i++)
879 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
881 priv->WILC_WFI_wep_default = sme->key_idx;
882 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
883 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
885 g_key_wep_params.key_len = sme->key_len;
886 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
887 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
888 g_key_wep_params.key_idx = sme->key_idx;
889 g_wep_keys_saved = true;
891 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
892 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
893 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
894 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
895 pcgroup_encrypt_val = "WEP104";
896 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
898 priv->WILC_WFI_wep_default = sme->key_idx;
899 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
900 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
902 g_key_wep_params.key_len = sme->key_len;
903 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
904 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
905 g_key_wep_params.key_idx = sme->key_idx;
906 g_wep_keys_saved = true;
908 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
909 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
910 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
911 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
912 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
913 pcgroup_encrypt_val = "WPA2_TKIP";
914 pccipher_group = "TKIP";
915 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
916 /* tenuSecurity_t = WPA2_AES; */
917 u8security = ENCRYPT_ENABLED | WPA2 | AES;
918 pcgroup_encrypt_val = "WPA2_AES";
919 pccipher_group = "AES";
921 pcwpa_version = "WPA_VERSION_2";
922 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
923 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
924 u8security = ENCRYPT_ENABLED | WPA | TKIP;
925 pcgroup_encrypt_val = "WPA_TKIP";
926 pccipher_group = "TKIP";
927 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
928 /* tenuSecurity_t = WPA_AES; */
929 u8security = ENCRYPT_ENABLED | WPA | AES;
930 pcgroup_encrypt_val = "WPA_AES";
931 pccipher_group = "AES";
934 pcwpa_version = "WPA_VERSION_1";
937 s32Error = -ENOTSUPP;
938 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
945 /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will
946 * add to it the pairwise cipher suite(s) */
947 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
948 || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
949 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
950 if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) {
951 u8security = u8security | TKIP;
952 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
953 u8security = u8security | AES;
958 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
960 PRINT_D(CFG80211_DBG, "Authentication Type = %d\n", sme->auth_type);
961 switch (sme->auth_type) {
962 case NL80211_AUTHTYPE_OPEN_SYSTEM:
963 PRINT_D(CFG80211_DBG, "In OPEN SYSTEM\n");
964 tenuAuth_type = OPEN_SYSTEM;
967 case NL80211_AUTHTYPE_SHARED_KEY:
968 tenuAuth_type = SHARED_KEY;
969 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
973 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
977 /* ai: key_mgmt: enterprise case */
978 if (sme->crypto.n_akm_suites) {
979 switch (sme->crypto.akm_suites[0]) {
980 case WLAN_AKM_SUITE_8021X:
981 tenuAuth_type = IEEE8021;
990 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
992 PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
993 pcgroup_encrypt_val, pccipher_group, pcwpa_version);
995 curr_channel = pstrNetworkInfo->u8channel;
997 if (!pstrWFIDrv->u8P2PConnect) {
998 u8WLANChannel = pstrNetworkInfo->u8channel;
1001 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1003 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1004 sme->ssid_len, sme->ie, sme->ie_len,
1005 CfgConnectResult, (void *)priv, u8security,
1006 tenuAuth_type, pstrNetworkInfo->u8channel,
1007 pstrNetworkInfo->pJoinParams);
1008 if (s32Error != 0) {
1009 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
1022 * @details Disconnect from the BSS/ESS.
1024 * @return int : Return 0 on Success
1029 static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
1032 struct wilc_priv *priv;
1033 struct host_if_drv *pstrWFIDrv;
1034 u8 NullBssid[ETH_ALEN] = {0};
1037 priv = wiphy_priv(wiphy);
1039 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
1040 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1041 if (!pstrWFIDrv->u8P2PConnect)
1042 u8WLANChannel = INVALID_CHANNEL;
1043 linux_wlan_set_bssid(priv->dev, NullBssid);
1045 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1047 u8P2Plocalrandom = 0x01;
1048 u8P2Precvrandom = 0x00;
1050 pstrWFIDrv->u64P2p_MgmtTimeout = 0;
1052 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
1053 if (s32Error != 0) {
1054 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1063 * @details Add a key with the given parameters. @mac_addr will be %NULL
1064 * when adding a group key.
1065 * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1066 * @return int : Return 0 on Success
1071 static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1073 const u8 *mac_addr, struct key_params *params)
1076 s32 s32Error = 0, KeyLen = params->key_len;
1078 struct wilc_priv *priv;
1079 const u8 *pu8RxMic = NULL;
1080 const u8 *pu8TxMic = NULL;
1081 u8 u8mode = NO_ENCRYPT;
1082 u8 u8gmode = NO_ENCRYPT;
1083 u8 u8pmode = NO_ENCRYPT;
1084 enum AUTHTYPE tenuAuth_type = ANY;
1086 priv = wiphy_priv(wiphy);
1088 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1090 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
1092 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1097 switch (params->cipher) {
1098 case WLAN_CIPHER_SUITE_WEP40:
1099 case WLAN_CIPHER_SUITE_WEP104:
1100 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1102 priv->WILC_WFI_wep_default = key_index;
1103 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1104 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1106 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1107 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1109 for (i = 0; i < params->key_len; i++)
1110 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1112 tenuAuth_type = OPEN_SYSTEM;
1114 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1115 u8mode = ENCRYPT_ENABLED | WEP;
1117 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1119 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1122 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
1123 priv->WILC_WFI_wep_default = key_index;
1124 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1125 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1127 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1128 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1130 for (i = 0; i < params->key_len; i++)
1131 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1133 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1138 case WLAN_CIPHER_SUITE_TKIP:
1139 case WLAN_CIPHER_SUITE_CCMP:
1140 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1142 if (priv->wilc_gtk[key_index] == NULL) {
1143 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1144 priv->wilc_gtk[key_index]->key = NULL;
1145 priv->wilc_gtk[key_index]->seq = NULL;
1148 if (priv->wilc_ptk[key_index] == NULL) {
1149 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
1150 priv->wilc_ptk[key_index]->key = NULL;
1151 priv->wilc_ptk[key_index]->seq = NULL;
1157 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1158 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1160 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1162 priv->wilc_groupkey = u8gmode;
1164 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1166 pu8TxMic = params->key + 24;
1167 pu8RxMic = params->key + 16;
1168 KeyLen = params->key_len - 16;
1170 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
1171 kfree(priv->wilc_gtk[key_index]->key);
1173 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1174 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
1176 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
1177 kfree(priv->wilc_gtk[key_index]->seq);
1179 if ((params->seq_len) > 0) {
1180 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
1181 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
1184 priv->wilc_gtk[key_index]->cipher = params->cipher;
1185 priv->wilc_gtk[key_index]->key_len = params->key_len;
1186 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1189 for (i = 0; i < params->key_len; i++)
1190 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1191 for (i = 0; i < params->seq_len; i++)
1192 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1196 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1197 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1200 PRINT_INFO(CFG80211_DBG, "STA Address: %x%x%x%x%x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4]);
1202 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1203 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1205 u8pmode = priv->wilc_groupkey | AES;
1208 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1210 pu8TxMic = params->key + 24;
1211 pu8RxMic = params->key + 16;
1212 KeyLen = params->key_len - 16;
1215 kfree(priv->wilc_ptk[key_index]->key);
1217 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
1219 kfree(priv->wilc_ptk[key_index]->seq);
1221 if ((params->seq_len) > 0)
1222 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
1225 for (i = 0; i < params->key_len; i++)
1226 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1228 for (i = 0; i < params->seq_len; i++)
1229 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1232 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
1234 if ((params->seq_len) > 0)
1235 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
1237 priv->wilc_ptk[key_index]->cipher = params->cipher;
1238 priv->wilc_ptk[key_index]->key_len = params->key_len;
1239 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1241 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1242 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1250 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1251 /* swap the tx mic by rx mic */
1252 pu8RxMic = params->key + 24;
1253 pu8TxMic = params->key + 16;
1254 KeyLen = params->key_len - 16;
1257 /*save keys only on interface 0 (wifi interface)*/
1258 if (!g_gtk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
1259 g_add_gtk_key_params.key_idx = key_index;
1260 g_add_gtk_key_params.pairwise = pairwise;
1262 g_add_gtk_key_params.mac_addr = NULL;
1264 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1265 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1267 g_key_gtk_params.key_len = params->key_len;
1268 g_key_gtk_params.seq_len = params->seq_len;
1269 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
1270 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1271 if (params->seq_len > 0) {
1272 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
1273 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1275 g_key_gtk_params.cipher = params->cipher;
1277 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1278 g_key_gtk_params.key[1],
1279 g_key_gtk_params.key[2]);
1280 g_gtk_keys_saved = true;
1283 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1284 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
1286 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1287 /* swap the tx mic by rx mic */
1288 pu8RxMic = params->key + 24;
1289 pu8TxMic = params->key + 16;
1290 KeyLen = params->key_len - 16;
1293 /*save keys only on interface 0 (wifi interface)*/
1294 if (!g_ptk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
1295 g_add_ptk_key_params.key_idx = key_index;
1296 g_add_ptk_key_params.pairwise = pairwise;
1298 g_add_ptk_key_params.mac_addr = NULL;
1300 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
1301 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1303 g_key_ptk_params.key_len = params->key_len;
1304 g_key_ptk_params.seq_len = params->seq_len;
1305 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
1306 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1307 if (params->seq_len > 0) {
1308 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
1309 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1311 g_key_ptk_params.cipher = params->cipher;
1313 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1314 g_key_ptk_params.key[1],
1315 g_key_ptk_params.key[2]);
1316 g_ptk_keys_saved = true;
1319 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1320 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1321 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1323 for (i = 0; i < params->key_len; i++)
1324 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1331 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1332 s32Error = -ENOTSUPP;
1341 * @details Remove a key given the @mac_addr (%NULL for a group key)
1342 * and @key_index, return -ENOENT if the key doesn't exist.
1344 * @return int : Return 0 on Success
1349 static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1354 struct wilc_priv *priv;
1356 priv = wiphy_priv(wiphy);
1358 /*delete saved keys, if any*/
1359 if (netdev == g_linux_wlan->vif[0].ndev) {
1360 g_ptk_keys_saved = false;
1361 g_gtk_keys_saved = false;
1362 g_wep_keys_saved = false;
1364 /*Delete saved WEP keys params, if any*/
1365 kfree(g_key_wep_params.key);
1366 g_key_wep_params.key = NULL;
1368 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1370 if ((priv->wilc_gtk[key_index]) != NULL) {
1372 kfree(priv->wilc_gtk[key_index]->key);
1373 priv->wilc_gtk[key_index]->key = NULL;
1374 kfree(priv->wilc_gtk[key_index]->seq);
1375 priv->wilc_gtk[key_index]->seq = NULL;
1377 kfree(priv->wilc_gtk[key_index]);
1378 priv->wilc_gtk[key_index] = NULL;
1382 if ((priv->wilc_ptk[key_index]) != NULL) {
1384 kfree(priv->wilc_ptk[key_index]->key);
1385 priv->wilc_ptk[key_index]->key = NULL;
1386 kfree(priv->wilc_ptk[key_index]->seq);
1387 priv->wilc_ptk[key_index]->seq = NULL;
1388 kfree(priv->wilc_ptk[key_index]);
1389 priv->wilc_ptk[key_index] = NULL;
1392 /*Delete saved PTK and GTK keys params, if any*/
1393 kfree(g_key_ptk_params.key);
1394 g_key_ptk_params.key = NULL;
1395 kfree(g_key_ptk_params.seq);
1396 g_key_ptk_params.seq = NULL;
1398 kfree(g_key_gtk_params.key);
1399 g_key_gtk_params.key = NULL;
1400 kfree(g_key_gtk_params.seq);
1401 g_key_gtk_params.seq = NULL;
1403 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
1404 Set_machw_change_vir_if(false);
1407 if (key_index >= 0 && key_index <= 3) {
1408 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
1409 priv->WILC_WFI_wep_key_len[key_index] = 0;
1411 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1412 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1414 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1415 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1423 * @details Get information about the key with the given parameters.
1424 * @mac_addr will be %NULL when requesting information for a group
1425 * key. All pointers given to the @callback function need not be valid
1426 * after it returns. This function should return an error if it is
1427 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1429 * @return int : Return 0 on Success
1434 static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1436 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
1438 struct wilc_priv *priv;
1439 struct key_params key_params;
1442 priv = wiphy_priv(wiphy);
1446 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1448 key_params.key = priv->wilc_gtk[key_index]->key;
1449 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1450 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1451 key_params.seq = priv->wilc_gtk[key_index]->seq;
1452 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1454 for (i = 0; i < key_params.key_len; i++)
1455 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1458 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1460 key_params.key = priv->wilc_ptk[key_index]->key;
1461 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1462 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1463 key_params.seq = priv->wilc_ptk[key_index]->seq;
1464 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1467 callback(cookie, &key_params);
1469 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
1473 * @brief set_default_key
1474 * @details Set the default management frame key on an interface
1476 * @return int : Return 0 on Success.
1481 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1482 bool unicast, bool multicast)
1484 struct wilc_priv *priv;
1487 priv = wiphy_priv(wiphy);
1489 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
1491 if (key_index != priv->WILC_WFI_wep_default) {
1493 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
1500 * @brief get_station
1501 * @details Get station information for the station identified by @mac
1503 * @return int : Return 0 on Success.
1509 static int get_station(struct wiphy *wiphy, struct net_device *dev,
1510 const u8 *mac, struct station_info *sinfo)
1512 struct wilc_priv *priv;
1513 perInterface_wlan_t *nic;
1515 u32 associatedsta = 0;
1516 u32 inactive_time = 0;
1517 priv = wiphy_priv(wiphy);
1518 nic = netdev_priv(dev);
1520 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1521 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1523 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1525 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1527 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1534 if (associatedsta == -1) {
1535 PRINT_ER("Station required is not associated\n");
1539 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
1541 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1542 sinfo->inactive_time = 1000 * inactive_time;
1543 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1547 if (nic->iftype == STATION_MODE) {
1548 struct rf_info strStatistics;
1550 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1552 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
1553 BIT(NL80211_STA_INFO_RX_PACKETS) |
1554 BIT(NL80211_STA_INFO_TX_PACKETS) |
1555 BIT(NL80211_STA_INFO_TX_FAILED) |
1556 BIT(NL80211_STA_INFO_TX_BITRATE);
1558 sinfo->signal = strStatistics.s8RSSI;
1559 sinfo->rx_packets = strStatistics.u32RxCount;
1560 sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
1561 sinfo->tx_failed = strStatistics.u32TxFailureCount;
1562 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1564 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
1565 Enable_TCP_ACK_Filter(true);
1566 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
1567 Enable_TCP_ACK_Filter(false);
1569 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1570 sinfo->tx_failed, sinfo->txrate.legacy);
1578 * @details Modify parameters for a given BSS.
1580 * -use_cts_prot: Whether to use CTS protection
1581 * (0 = no, 1 = yes, -1 = do not change)
1582 * -use_short_preamble: Whether the use of short preambles is allowed
1583 * (0 = no, 1 = yes, -1 = do not change)
1584 * -use_short_slot_time: Whether the use of short slot time is allowed
1585 * (0 = no, 1 = yes, -1 = do not change)
1586 * -basic_rates: basic rates in IEEE 802.11 format
1587 * (or NULL for no change)
1588 * -basic_rates_len: number of basic rates
1589 * -ap_isolate: do not forward packets between connected stations
1590 * -ht_opmode: HT Operation mode
1591 * (u16 = opmode, -1 = do not change)
1592 * @return int : Return 0 on Success.
1597 static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1598 struct bss_parameters *params)
1600 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1605 * @brief set_wiphy_params
1606 * @details Notify that wiphy parameters have changed;
1607 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1609 * @return int : Return 0 on Success
1614 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
1617 struct cfg_param_val pstrCfgParamVal;
1618 struct wilc_priv *priv;
1620 priv = wiphy_priv(wiphy);
1622 pstrCfgParamVal.flag = 0;
1623 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
1625 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1626 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1627 priv->dev->ieee80211_ptr->wiphy->retry_short);
1628 pstrCfgParamVal.flag |= RETRY_SHORT;
1629 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1631 if (changed & WIPHY_PARAM_RETRY_LONG) {
1633 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
1634 pstrCfgParamVal.flag |= RETRY_LONG;
1635 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1638 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1639 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
1640 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
1641 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1645 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1646 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1648 pstrCfgParamVal.flag |= RTS_THRESHOLD;
1649 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1653 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1654 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1656 PRINT_ER("Error in setting WIPHY PARAMS\n");
1664 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1665 * devices running firmwares capable of generating the (re) association
1666 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1668 * @return int : Return 0 on Success
1673 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1674 struct cfg80211_pmksa *pmksa)
1680 struct wilc_priv *priv = wiphy_priv(wiphy);
1682 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1685 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1686 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1688 /*If bssid already exists and pmkid value needs to reset*/
1690 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1694 if (i < WILC_MAX_NUM_PMKIDS) {
1695 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
1696 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
1698 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
1700 if (!(flag == PMKID_FOUND))
1701 priv->pmkid_list.numpmkid++;
1703 PRINT_ER("Invalid PMKID index\n");
1708 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1709 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1716 * @details Delete a cached PMKID.
1718 * @return int : Return 0 on Success
1723 static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1724 struct cfg80211_pmksa *pmksa)
1730 struct wilc_priv *priv = wiphy_priv(wiphy);
1732 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1734 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1735 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1737 /*If bssid is found, reset the values*/
1738 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
1739 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
1744 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1745 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
1746 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
1747 priv->pmkid_list.pmkidlist[i + 1].bssid,
1749 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
1750 priv->pmkid_list.pmkidlist[i].pmkid,
1753 priv->pmkid_list.numpmkid--;
1762 * @brief flush_pmksa
1763 * @details Flush all cached PMKIDs.
1765 * @return int : Return 0 on Success
1770 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1772 struct wilc_priv *priv = wiphy_priv(wiphy);
1774 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1776 /*Get cashed Pmkids and set all with zeros*/
1777 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
1784 * @brief WILC_WFI_CfgParseRxAction
1785 * @details Function parses the received frames and modifies the following attributes:
1788 * -Operating Channel
1790 * @param[in] u8* Buffer, u32 length
1797 void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
1802 u8 op_channel_attr_index = 0;
1803 u8 channel_list_attr_index = 0;
1805 while (index < len) {
1806 if (buf[index] == GO_INTENT_ATTR_ID) {
1807 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
1810 if (buf[index] == CHANLIST_ATTR_ID)
1811 channel_list_attr_index = index;
1812 else if (buf[index] == OPERCHAN_ATTR_ID)
1813 op_channel_attr_index = index;
1814 index += buf[index + 1] + 3; /* ID,Length byte */
1816 if (u8WLANChannel != INVALID_CHANNEL) {
1818 /*Modify channel list attribute*/
1819 if (channel_list_attr_index) {
1820 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1821 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1822 if (buf[i] == 0x51) {
1823 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1824 buf[j] = u8WLANChannel;
1830 /*Modify operating channel attribute*/
1831 if (op_channel_attr_index) {
1832 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1833 buf[op_channel_attr_index + 6] = 0x51;
1834 buf[op_channel_attr_index + 7] = u8WLANChannel;
1840 * @brief WILC_WFI_CfgParseTxAction
1841 * @details Function parses the transmitted action frames and modifies the
1842 * GO Intent attribute
1843 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1849 void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
1854 u8 op_channel_attr_index = 0;
1855 u8 channel_list_attr_index = 0;
1857 while (index < len) {
1858 if (buf[index] == GO_INTENT_ATTR_ID) {
1859 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
1864 if (buf[index] == CHANLIST_ATTR_ID)
1865 channel_list_attr_index = index;
1866 else if (buf[index] == OPERCHAN_ATTR_ID)
1867 op_channel_attr_index = index;
1868 index += buf[index + 1] + 3; /* ID,Length byte */
1870 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
1872 /*Modify channel list attribute*/
1873 if (channel_list_attr_index) {
1874 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1875 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1876 if (buf[i] == 0x51) {
1877 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1878 buf[j] = u8WLANChannel;
1884 /*Modify operating channel attribute*/
1885 if (op_channel_attr_index) {
1886 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1887 buf[op_channel_attr_index + 6] = 0x51;
1888 buf[op_channel_attr_index + 7] = u8WLANChannel;
1893 /* @brief WILC_WFI_p2p_rx
1898 * @author Mai Daftedar
1903 void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
1906 struct wilc_priv *priv;
1907 u32 header, pkt_offset;
1908 struct host_if_drv *pstrWFIDrv;
1912 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1913 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1915 /* Get WILC header */
1916 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
1918 /* The packet offset field conain info about what type of managment frame */
1919 /* we are dealing with and ack status */
1920 pkt_offset = GET_PKT_OFFSET(header);
1922 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1923 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1924 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
1925 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
1928 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1929 PRINT_D(GENERIC_DBG, "Success Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1930 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
1931 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
1933 PRINT_D(GENERIC_DBG, "Fail Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1934 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
1935 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
1941 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1943 /*Upper layer is informed that the frame is received on this freq*/
1944 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
1946 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1947 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1949 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
1950 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1953 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1955 switch (buff[ACTION_SUBTYPE_ID]) {
1956 case GAS_INTIAL_REQ:
1957 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
1960 case GAS_INTIAL_RSP:
1961 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1964 case PUBLIC_ACT_VENDORSPEC:
1965 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1966 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
1967 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
1968 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1970 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
1971 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
1972 u8P2Precvrandom = buff[i + 6];
1974 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1980 if (u8P2Plocalrandom > u8P2Precvrandom) {
1981 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1982 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1983 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
1984 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
1985 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1991 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
1995 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
1996 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
1997 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
1998 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2004 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2010 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
2015 * @brief WILC_WFI_mgmt_tx_complete
2016 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2018 * transmitting status
2020 * @author Amr Abdelmoghny
2024 static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2026 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2029 kfree(pv_data->buff);
2034 * @brief WILC_WFI_RemainOnChannelReady
2035 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2038 * @author Amr abdelmoghny
2043 static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2045 struct wilc_priv *priv;
2047 priv = (struct wilc_priv *)pUserVoid;
2049 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
2051 priv->bInP2PlistenState = true;
2053 cfg80211_ready_on_channel(priv->wdev,
2054 priv->strRemainOnChanParams.u64ListenCookie,
2055 priv->strRemainOnChanParams.pstrListenChan,
2056 priv->strRemainOnChanParams.u32ListenDuration,
2061 * @brief WILC_WFI_RemainOnChannelExpired
2062 * @details Callback function, called on expiration of remain-on-channel duration
2065 * @author Amr abdelmoghny
2070 static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
2072 struct wilc_priv *priv;
2074 priv = (struct wilc_priv *)pUserVoid;
2076 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
2077 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
2079 priv->bInP2PlistenState = false;
2081 /*Inform wpas of remain-on-channel expiration*/
2082 cfg80211_remain_on_channel_expired(priv->wdev,
2083 priv->strRemainOnChanParams.u64ListenCookie,
2084 priv->strRemainOnChanParams.pstrListenChan,
2087 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2088 , priv->strRemainOnChanParams.u32ListenSessionID);
2094 * @brief remain_on_channel
2095 * @details Request the driver to remain awake on the specified
2096 * channel for the specified duration to complete an off-channel
2097 * operation (e.g., public action frame exchange). When the driver is
2098 * ready on the requested channel, it must indicate this with an event
2099 * notification by calling cfg80211_ready_on_channel().
2101 * @return int : Return 0 on Success
2106 static int remain_on_channel(struct wiphy *wiphy,
2107 struct wireless_dev *wdev,
2108 struct ieee80211_channel *chan,
2109 unsigned int duration, u64 *cookie)
2112 struct wilc_priv *priv;
2114 priv = wiphy_priv(wiphy);
2116 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2119 if (wdev->iftype == NL80211_IFTYPE_AP) {
2120 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2124 curr_channel = chan->hw_value;
2126 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2127 priv->strRemainOnChanParams.pstrListenChan = chan;
2128 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
2129 priv->strRemainOnChanParams.u32ListenDuration = duration;
2130 priv->strRemainOnChanParams.u32ListenSessionID++;
2132 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2133 , priv->strRemainOnChanParams.u32ListenSessionID
2136 , WILC_WFI_RemainOnChannelExpired
2137 , WILC_WFI_RemainOnChannelReady
2144 * @brief cancel_remain_on_channel
2145 * @details Cancel an on-going remain-on-channel operation.
2146 * This allows the operation to be terminated prior to timeout based on
2147 * the duration value.
2148 * @param[in] struct wiphy *wiphy,
2149 * @param[in] struct net_device *dev
2150 * @param[in] u64 cookie,
2151 * @return int : Return 0 on Success
2156 static int cancel_remain_on_channel(struct wiphy *wiphy,
2157 struct wireless_dev *wdev,
2161 struct wilc_priv *priv;
2163 priv = wiphy_priv(wiphy);
2165 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2167 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2171 * @brief WILC_WFI_add_wilcvendorspec
2172 * @details Adding WILC information elemet to allow two WILC devices to
2173 * identify each other and connect
2174 * @param[in] u8 * buf
2180 void WILC_WFI_add_wilcvendorspec(u8 *buff)
2182 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
2185 * @brief WILC_WFI_mgmt_tx_frame
2194 extern bool bEnablePS;
2195 static int mgmt_tx(struct wiphy *wiphy,
2196 struct wireless_dev *wdev,
2197 struct cfg80211_mgmt_tx_params *params,
2200 struct ieee80211_channel *chan = params->chan;
2201 unsigned int wait = params->wait;
2202 const u8 *buf = params->buf;
2203 size_t len = params->len;
2204 const struct ieee80211_mgmt *mgmt;
2205 struct p2p_mgmt_data *mgmt_tx;
2206 struct wilc_priv *priv;
2207 struct host_if_drv *pstrWFIDrv;
2209 perInterface_wlan_t *nic;
2210 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
2212 nic = netdev_priv(wdev->netdev);
2213 priv = wiphy_priv(wiphy);
2214 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
2216 *cookie = (unsigned long)buf;
2217 priv->u64tx_cookie = *cookie;
2218 mgmt = (const struct ieee80211_mgmt *) buf;
2220 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2222 /*mgmt frame allocation*/
2223 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
2224 if (mgmt_tx == NULL) {
2225 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
2228 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
2229 if (mgmt_tx->buff == NULL) {
2230 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
2234 memcpy(mgmt_tx->buff, buf, len);
2235 mgmt_tx->size = len;
2238 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2239 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2240 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2241 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2242 /*Save the current channel after we tune to it*/
2243 curr_channel = chan->hw_value;
2244 } else if (ieee80211_is_action(mgmt->frame_control)) {
2245 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
2248 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
2249 /*Only set the channel, if not a negotiation confirmation frame
2250 * (If Negotiation confirmation frame, force it
2251 * to be transmitted on the same negotiation channel)*/
2253 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2254 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2255 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2256 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2257 /*Save the current channel after we tune to it*/
2258 curr_channel = chan->hw_value;
2260 switch (buf[ACTION_SUBTYPE_ID]) {
2261 case GAS_INTIAL_REQ:
2263 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2267 case GAS_INTIAL_RSP:
2269 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2273 case PUBLIC_ACT_VENDORSPEC:
2275 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2276 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2277 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
2278 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2279 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2280 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2281 get_random_bytes(&u8P2Plocalrandom, 1);
2282 /*Increment the number to prevent if its 0*/
2287 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2288 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2289 if (u8P2Plocalrandom > u8P2Precvrandom) {
2290 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2292 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2293 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
2294 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
2295 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
2296 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
2298 /*If using supplicant go intent, no need at all*/
2299 /*to parse transmitted negotiation frames*/
2301 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
2306 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
2307 WILC_WFI_add_wilcvendorspec(&mgmt_tx->buff[len]);
2308 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2309 mgmt_tx->size = buf_len;
2312 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2316 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2324 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2331 PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
2332 pstrWFIDrv->u64P2p_MgmtTimeout = (jiffies + msecs_to_jiffies(wait));
2334 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2338 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2340 WILC_WFI_mgmt_tx_complete);
2342 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2347 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2348 struct wireless_dev *wdev,
2351 struct wilc_priv *priv;
2352 struct host_if_drv *pstrWFIDrv;
2354 priv = wiphy_priv(wiphy);
2355 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
2358 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2359 pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2361 if (!priv->bInP2PlistenState) {
2362 cfg80211_remain_on_channel_expired(priv->wdev,
2363 priv->strRemainOnChanParams.u64ListenCookie,
2364 priv->strRemainOnChanParams.pstrListenChan,
2372 * @brief wilc_mgmt_frame_register
2373 * @details Notify driver that a management frame type was
2374 * registered. Note that this callback may not sleep, and cannot run
2375 * concurrently with itself.
2382 void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2383 u16 frame_type, bool reg)
2386 struct wilc_priv *priv;
2387 perInterface_wlan_t *nic;
2390 priv = wiphy_priv(wiphy);
2391 nic = netdev_priv(priv->wdev->netdev);
2398 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2399 switch (frame_type) {
2402 nic->g_struct_frame_reg[0].frame_type = frame_type;
2403 nic->g_struct_frame_reg[0].reg = reg;
2409 nic->g_struct_frame_reg[1].frame_type = frame_type;
2410 nic->g_struct_frame_reg[1].reg = reg;
2420 /*If mac is closed, then return*/
2421 if (!g_linux_wlan->initialized) {
2422 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2425 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2431 * @brief set_cqm_rssi_config
2432 * @details Configure connection quality monitor RSSI threshold.
2433 * @param[in] struct wiphy *wiphy:
2434 * @param[in] struct net_device *dev:
2435 * @param[in] s32 rssi_thold:
2436 * @param[in] u32 rssi_hyst:
2437 * @return int : Return 0 on Success
2442 static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2443 s32 rssi_thold, u32 rssi_hyst)
2445 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2450 * @brief dump_station
2451 * @details Configure connection quality monitor RSSI threshold.
2452 * @param[in] struct wiphy *wiphy:
2453 * @param[in] struct net_device *dev
2454 * @param[in] int idx
2455 * @param[in] u8 *mac
2456 * @param[in] struct station_info *sinfo
2457 * @return int : Return 0 on Success
2462 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2463 int idx, u8 *mac, struct station_info *sinfo)
2465 struct wilc_priv *priv;
2467 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2472 priv = wiphy_priv(wiphy);
2474 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2476 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2484 * @brief set_power_mgmt
2487 * @return int : Return 0 on Success.
2492 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2493 bool enabled, int timeout)
2495 struct wilc_priv *priv;
2497 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2502 priv = wiphy_priv(wiphy);
2503 if (priv->hWILCWFIDrv == NULL) {
2504 PRINT_ER("Driver is NULL\n");
2509 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2517 * @brief change_virtual_intf
2518 * @details Change type/configuration of virtual interface,
2519 * keep the struct wireless_dev's iftype updated.
2521 * @return int : Return 0 on Success.
2526 void wilc1000_wlan_deinit(struct wilc *nic);
2527 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2529 static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2530 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
2532 struct wilc_priv *priv;
2533 perInterface_wlan_t *nic;
2538 nic = netdev_priv(dev);
2539 priv = wiphy_priv(wiphy);
2541 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2542 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2543 u8P2Plocalrandom = 0x01;
2544 u8P2Precvrandom = 0x00;
2548 g_obtainingIP = false;
2549 del_timer(&hDuringIpTimer);
2550 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
2551 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2552 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2553 Set_machw_change_vir_if(true);
2557 case NL80211_IFTYPE_STATION:
2559 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
2561 /* send delba over wlan interface */
2564 dev->ieee80211_ptr->iftype = type;
2565 priv->wdev->iftype = type;
2566 nic->monitor_flag = 0;
2567 nic->iftype = STATION_MODE;
2569 /*Remove the enteries of the previously connected clients*/
2570 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
2571 interface_type = nic->iftype;
2572 nic->iftype = STATION_MODE;
2574 if (g_linux_wlan->initialized) {
2575 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->vif[0].bssid, TID);
2576 /* ensure that the message Q is empty */
2577 host_int_wait_msg_queue_idle();
2579 /*Eliminate host interface blocking state*/
2580 up(&g_linux_wlan->cfg_event);
2582 wilc1000_wlan_deinit(g_linux_wlan);
2583 wilc1000_wlan_init(dev, nic);
2584 g_wilc_initialized = 1;
2585 nic->iftype = interface_type;
2587 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2588 host_int_set_wfi_drv_handler(g_linux_wlan->vif[0].hif_drv);
2589 host_int_set_MacAddress(g_linux_wlan->vif[0].hif_drv,
2590 g_linux_wlan->vif[0].src_addr);
2591 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2593 /*Add saved WEP keys, if any*/
2594 if (g_wep_keys_saved) {
2595 host_int_set_WEPDefaultKeyID(g_linux_wlan->vif[0].hif_drv,
2596 g_key_wep_params.key_idx);
2597 host_int_add_wep_key_bss_sta(g_linux_wlan->vif[0].hif_drv,
2598 g_key_wep_params.key,
2599 g_key_wep_params.key_len,
2600 g_key_wep_params.key_idx);
2603 /*No matter the driver handler passed here, it will be overwriiten*/
2604 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2605 host_int_flush_join_req(priv->hWILCWFIDrv);
2607 /*Add saved PTK and GTK keys, if any*/
2608 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2609 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2610 g_key_ptk_params.key[1],
2611 g_key_ptk_params.key[2]);
2612 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2613 g_key_gtk_params.key[1],
2614 g_key_gtk_params.key[2]);
2615 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2616 g_linux_wlan->vif[0].ndev,
2617 g_add_ptk_key_params.key_idx,
2618 g_add_ptk_key_params.pairwise,
2619 g_add_ptk_key_params.mac_addr,
2620 (struct key_params *)(&g_key_ptk_params));
2622 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2623 g_linux_wlan->vif[0].ndev,
2624 g_add_gtk_key_params.key_idx,
2625 g_add_gtk_key_params.pairwise,
2626 g_add_gtk_key_params.mac_addr,
2627 (struct key_params *)(&g_key_gtk_params));
2630 if (g_linux_wlan->initialized) {
2631 for (i = 0; i < num_reg_frame; i++) {
2632 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2633 nic->g_struct_frame_reg[i].reg);
2634 host_int_frame_register(priv->hWILCWFIDrv,
2635 nic->g_struct_frame_reg[i].frame_type,
2636 nic->g_struct_frame_reg[i].reg);
2641 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2645 case NL80211_IFTYPE_P2P_CLIENT:
2647 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2649 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
2651 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->vif[0].bssid, TID);
2653 dev->ieee80211_ptr->iftype = type;
2654 priv->wdev->iftype = type;
2655 nic->monitor_flag = 0;
2657 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2658 nic->iftype = CLIENT_MODE;
2661 if (g_linux_wlan->initialized) {
2662 /* ensure that the message Q is empty */
2663 host_int_wait_msg_queue_idle();
2665 wilc1000_wlan_deinit(g_linux_wlan);
2666 wilc1000_wlan_init(dev, nic);
2667 g_wilc_initialized = 1;
2669 host_int_set_wfi_drv_handler(g_linux_wlan->vif[0].hif_drv);
2670 host_int_set_MacAddress(g_linux_wlan->vif[0].hif_drv,
2671 g_linux_wlan->vif[0].src_addr);
2672 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2674 /*Add saved WEP keys, if any*/
2675 if (g_wep_keys_saved) {
2676 host_int_set_WEPDefaultKeyID(g_linux_wlan->vif[0].hif_drv,
2677 g_key_wep_params.key_idx);
2678 host_int_add_wep_key_bss_sta(g_linux_wlan->vif[0].hif_drv,
2679 g_key_wep_params.key,
2680 g_key_wep_params.key_len,
2681 g_key_wep_params.key_idx);
2684 /*No matter the driver handler passed here, it will be overwriiten*/
2685 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2686 host_int_flush_join_req(priv->hWILCWFIDrv);
2688 /*Add saved PTK and GTK keys, if any*/
2689 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2690 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2691 g_key_ptk_params.key[1],
2692 g_key_ptk_params.key[2]);
2693 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2694 g_key_gtk_params.key[1],
2695 g_key_gtk_params.key[2]);
2696 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2697 g_linux_wlan->vif[0].ndev,
2698 g_add_ptk_key_params.key_idx,
2699 g_add_ptk_key_params.pairwise,
2700 g_add_ptk_key_params.mac_addr,
2701 (struct key_params *)(&g_key_ptk_params));
2703 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2704 g_linux_wlan->vif[0].ndev,
2705 g_add_gtk_key_params.key_idx,
2706 g_add_gtk_key_params.pairwise,
2707 g_add_gtk_key_params.mac_addr,
2708 (struct key_params *)(&g_key_gtk_params));
2711 /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
2712 refresh_scan(priv, 1, true);
2713 Set_machw_change_vir_if(false);
2715 if (g_linux_wlan->initialized) {
2716 for (i = 0; i < num_reg_frame; i++) {
2717 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2718 nic->g_struct_frame_reg[i].reg);
2719 host_int_frame_register(priv->hWILCWFIDrv,
2720 nic->g_struct_frame_reg[i].frame_type,
2721 nic->g_struct_frame_reg[i].reg);
2727 case NL80211_IFTYPE_AP:
2729 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
2730 dev->ieee80211_ptr->iftype = type;
2731 priv->wdev->iftype = type;
2732 nic->iftype = AP_MODE;
2733 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
2735 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2736 linux_wlan_get_firmware(nic);
2737 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
2738 if (g_linux_wlan->initialized) {
2739 nic->iftype = AP_MODE;
2743 for (i = 0; i < num_reg_frame; i++) {
2744 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2745 nic->g_struct_frame_reg[i].reg);
2746 host_int_frame_register(priv->hWILCWFIDrv,
2747 nic->g_struct_frame_reg[i].frame_type,
2748 nic->g_struct_frame_reg[i].reg);
2753 case NL80211_IFTYPE_P2P_GO:
2754 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2756 g_obtainingIP = true;
2757 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
2758 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2759 /*Delete block ack has to be the latest config packet*/
2760 /*sent before downloading new FW. This is because it blocks on*/
2761 /*hWaitResponse semaphore, which allows previous config*/
2762 /*packets to actually take action on old FW*/
2763 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->vif[0].bssid, TID);
2765 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
2766 dev->ieee80211_ptr->iftype = type;
2767 priv->wdev->iftype = type;
2769 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
2771 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2774 nic->iftype = GO_MODE;
2776 /* ensure that the message Q is empty */
2777 host_int_wait_msg_queue_idle();
2778 wilc1000_wlan_deinit(g_linux_wlan);
2779 wilc1000_wlan_init(dev, nic);
2780 g_wilc_initialized = 1;
2783 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2784 host_int_set_wfi_drv_handler(g_linux_wlan->vif[0].hif_drv);
2785 host_int_set_MacAddress(g_linux_wlan->vif[0].hif_drv,
2786 g_linux_wlan->vif[0].src_addr);
2787 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2789 /*Add saved WEP keys, if any*/
2790 if (g_wep_keys_saved) {
2791 host_int_set_WEPDefaultKeyID(g_linux_wlan->vif[0].hif_drv,
2792 g_key_wep_params.key_idx);
2793 host_int_add_wep_key_bss_sta(g_linux_wlan->vif[0].hif_drv,
2794 g_key_wep_params.key,
2795 g_key_wep_params.key_len,
2796 g_key_wep_params.key_idx);
2799 /*No matter the driver handler passed here, it will be overwriiten*/
2800 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2801 host_int_flush_join_req(priv->hWILCWFIDrv);
2803 /*Add saved PTK and GTK keys, if any*/
2804 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2805 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2806 g_key_ptk_params.key[1],
2807 g_key_ptk_params.key[2],
2808 g_key_ptk_params.cipher);
2809 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2810 g_key_gtk_params.key[1],
2811 g_key_gtk_params.key[2],
2812 g_key_gtk_params.cipher);
2813 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2814 g_linux_wlan->vif[0].ndev,
2815 g_add_ptk_key_params.key_idx,
2816 g_add_ptk_key_params.pairwise,
2817 g_add_ptk_key_params.mac_addr,
2818 (struct key_params *)(&g_key_ptk_params));
2820 add_key(g_linux_wlan->vif[0].ndev->ieee80211_ptr->wiphy,
2821 g_linux_wlan->vif[0].ndev,
2822 g_add_gtk_key_params.key_idx,
2823 g_add_gtk_key_params.pairwise,
2824 g_add_gtk_key_params.mac_addr,
2825 (struct key_params *)(&g_key_gtk_params));
2828 if (g_linux_wlan->initialized) {
2829 for (i = 0; i < num_reg_frame; i++) {
2830 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2831 nic->g_struct_frame_reg[i].reg);
2832 host_int_frame_register(priv->hWILCWFIDrv,
2833 nic->g_struct_frame_reg[i].frame_type,
2834 nic->g_struct_frame_reg[i].reg);
2840 PRINT_ER("Unknown interface type= %d\n", type);
2847 /* (austin.2013-07-23)
2849 * To support revised cfg80211_ops
2851 * add_beacon --> start_ap
2852 * set_beacon --> change_beacon
2853 * del_beacon --> stop_ap
2855 * beacon_parameters --> cfg80211_ap_settings
2856 * cfg80211_beacon_data
2858 * applicable for linux kernel 3.4+
2863 * @details Add a beacon with given parameters, @head, @interval
2864 * and @dtim_period will be valid, @tail is optional.
2866 * @param[in] dev The net device structure
2867 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2868 * @return int : Return 0 on Success.
2873 static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2874 struct cfg80211_ap_settings *settings)
2876 struct cfg80211_beacon_data *beacon = &(settings->beacon);
2877 struct wilc_priv *priv;
2880 priv = wiphy_priv(wiphy);
2881 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2883 PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
2884 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2886 s32Error = set_channel(wiphy, &settings->chandef);
2889 PRINT_ER("Error in setting channel\n");
2891 linux_wlan_set_bssid(dev, g_linux_wlan->vif[0].src_addr);
2893 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2894 settings->beacon_interval,
2895 settings->dtim_period,
2896 beacon->head_len, (u8 *)beacon->head,
2897 beacon->tail_len, (u8 *)beacon->tail);
2903 * @brief change_beacon
2904 * @details Add a beacon with given parameters, @head, @interval
2905 * and @dtim_period will be valid, @tail is optional.
2907 * @param[in] dev The net device structure
2908 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2909 * @return int : Return 0 on Success.
2914 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2915 struct cfg80211_beacon_data *beacon)
2917 struct wilc_priv *priv;
2920 priv = wiphy_priv(wiphy);
2921 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2924 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2927 beacon->head_len, (u8 *)beacon->head,
2928 beacon->tail_len, (u8 *)beacon->tail);
2935 * @details Remove beacon configuration and stop sending the beacon.
2937 * @return int : Return 0 on Success.
2942 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
2945 struct wilc_priv *priv;
2946 u8 NullBssid[ETH_ALEN] = {0};
2951 priv = wiphy_priv(wiphy);
2953 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2955 linux_wlan_set_bssid(dev, NullBssid);
2957 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
2960 PRINT_ER("Host delete beacon fail\n");
2966 * @brief add_station
2967 * @details Add a new station.
2969 * @return int : Return 0 on Success.
2974 static int add_station(struct wiphy *wiphy, struct net_device *dev,
2975 const u8 *mac, struct station_parameters *params)
2978 struct wilc_priv *priv;
2979 struct add_sta_param strStaParams = { {0} };
2980 perInterface_wlan_t *nic;
2985 priv = wiphy_priv(wiphy);
2986 nic = netdev_priv(dev);
2988 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
2989 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
2990 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
2991 strStaParams.u16AssocID = params->aid;
2992 strStaParams.u8NumRates = params->supported_rates_len;
2993 strStaParams.pu8Rates = params->supported_rates;
2995 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
2997 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4],
2998 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
2999 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3000 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3002 if (params->ht_capa == NULL) {
3003 strStaParams.bIsHTSupported = false;
3005 strStaParams.bIsHTSupported = true;
3006 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3007 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3008 memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3009 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3010 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3011 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3014 strStaParams.u16FlagsMask = params->sta_flags_mask;
3015 strStaParams.u16FlagsSet = params->sta_flags_set;
3017 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3018 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3019 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3020 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3021 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3022 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3023 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3024 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3026 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
3028 PRINT_ER("Host add station fail\n");
3035 * @brief del_station
3036 * @details Remove a station; @mac may be NULL to remove all stations.
3038 * @return int : Return 0 on Success.
3043 static int del_station(struct wiphy *wiphy, struct net_device *dev,
3044 struct station_del_parameters *params)
3046 const u8 *mac = params->mac;
3048 struct wilc_priv *priv;
3049 perInterface_wlan_t *nic;
3054 priv = wiphy_priv(wiphy);
3055 nic = netdev_priv(dev);
3057 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3058 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3062 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
3063 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3065 PRINT_D(HOSTAPD_DBG, "With mac address: %x%x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
3068 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
3071 PRINT_ER("Host delete station fail\n");
3077 * @brief change_station
3078 * @details Modify a given station.
3080 * @return int : Return 0 on Success.
3085 static int change_station(struct wiphy *wiphy, struct net_device *dev,
3086 const u8 *mac, struct station_parameters *params)
3089 struct wilc_priv *priv;
3090 struct add_sta_param strStaParams = { {0} };
3091 perInterface_wlan_t *nic;
3094 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3099 priv = wiphy_priv(wiphy);
3100 nic = netdev_priv(dev);
3102 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3103 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3104 strStaParams.u16AssocID = params->aid;
3105 strStaParams.u8NumRates = params->supported_rates_len;
3106 strStaParams.pu8Rates = params->supported_rates;
3108 PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n", strStaParams.au8BSSID[0], strStaParams.au8BSSID[1], strStaParams.au8BSSID[2], strStaParams.au8BSSID[3], strStaParams.au8BSSID[4],
3109 strStaParams.au8BSSID[5]);
3110 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3111 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3113 if (params->ht_capa == NULL) {
3114 strStaParams.bIsHTSupported = false;
3116 strStaParams.bIsHTSupported = true;
3117 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3118 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3119 memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3120 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3121 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3122 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3126 strStaParams.u16FlagsMask = params->sta_flags_mask;
3127 strStaParams.u16FlagsSet = params->sta_flags_set;
3129 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3130 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3131 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3132 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3133 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3134 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3135 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3136 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3138 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
3140 PRINT_ER("Host edit station fail\n");
3147 * @brief add_virtual_intf
3150 * @return int : Return 0 on Success.
3155 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3157 unsigned char name_assign_type,
3158 enum nl80211_iftype type,
3160 struct vif_params *params)
3162 perInterface_wlan_t *nic;
3163 struct wilc_priv *priv;
3164 struct net_device *new_ifc = NULL;
3166 priv = wiphy_priv(wiphy);
3170 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3172 nic = netdev_priv(priv->wdev->netdev);
3175 if (type == NL80211_IFTYPE_MONITOR) {
3176 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3177 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3178 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3179 if (new_ifc != NULL) {
3180 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
3181 nic = netdev_priv(priv->wdev->netdev);
3182 nic->monitor_flag = 1;
3184 PRINT_ER("Error in initializing monitor interface\n ");
3190 * @brief del_virtual_intf
3193 * @return int : Return 0 on Success.
3198 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3200 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
3204 static struct cfg80211_ops wilc_cfg80211_ops = {
3206 .set_monitor_channel = set_channel,
3209 .disconnect = disconnect,
3213 .set_default_key = set_default_key,
3214 .add_virtual_intf = add_virtual_intf,
3215 .del_virtual_intf = del_virtual_intf,
3216 .change_virtual_intf = change_virtual_intf,
3218 .start_ap = start_ap,
3219 .change_beacon = change_beacon,
3221 .add_station = add_station,
3222 .del_station = del_station,
3223 .change_station = change_station,
3224 .get_station = get_station,
3225 .dump_station = dump_station,
3226 .change_bss = change_bss,
3227 .set_wiphy_params = set_wiphy_params,
3229 .set_pmksa = set_pmksa,
3230 .del_pmksa = del_pmksa,
3231 .flush_pmksa = flush_pmksa,
3232 .remain_on_channel = remain_on_channel,
3233 .cancel_remain_on_channel = cancel_remain_on_channel,
3234 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
3236 .mgmt_frame_register = wilc_mgmt_frame_register,
3237 .set_power_mgmt = set_power_mgmt,
3238 .set_cqm_rssi_config = set_cqm_rssi_config,
3247 * @brief WILC_WFI_update_stats
3248 * @details Modify parameters for a given BSS.
3250 * @return int : Return 0 on Success.
3255 int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3258 struct wilc_priv *priv;
3260 priv = wiphy_priv(wiphy);
3263 case WILC_WFI_RX_PKT:
3265 priv->netstats.rx_packets++;
3266 priv->netstats.rx_bytes += pktlen;
3267 priv->netstats.rx_time = get_jiffies_64();
3271 case WILC_WFI_TX_PKT:
3273 priv->netstats.tx_packets++;
3274 priv->netstats.tx_bytes += pktlen;
3275 priv->netstats.tx_time = get_jiffies_64();
3287 * @brief WILC_WFI_CfgAlloc
3288 * @details Allocation of the wireless device structure and assigning it
3289 * to the cfg80211 operations structure.
3291 * @return wireless_dev : Returns pointer to wireless_dev structure.
3296 struct wireless_dev *WILC_WFI_CfgAlloc(void)
3299 struct wireless_dev *wdev;
3302 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3303 /*Allocating the wireless device structure*/
3304 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3306 PRINT_ER("Cannot allocate wireless device\n");
3310 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
3311 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
3313 PRINT_ER("Cannot allocate wiphy\n");
3318 /* enable 802.11n HT */
3319 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3320 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3321 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3322 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3323 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
3326 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3337 * @brief wilc_create_wiphy
3338 * @details Registering of the wiphy structure and interface modes
3345 struct wireless_dev *wilc_create_wiphy(struct net_device *net)
3347 struct wilc_priv *priv;
3348 struct wireless_dev *wdev;
3351 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3353 wdev = WILC_WFI_CfgAlloc();
3355 PRINT_ER("CfgAlloc Failed\n");
3360 /*Return hardware description structure (wiphy)'s priv*/
3361 priv = wdev_priv(wdev);
3362 sema_init(&(priv->SemHandleUpdateStats), 1);
3364 /*Link the wiphy with wireless structure*/
3367 /*Maximum number of probed ssid to be added by user for the scan request*/
3368 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
3369 /*Maximum number of pmkids to be cashed*/
3370 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3371 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
3373 wdev->wiphy->max_scan_ie_len = 1000;
3375 /*signal strength in mBm (100*dBm) */
3376 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3378 /*Set the availaible cipher suites*/
3379 wdev->wiphy->cipher_suites = cipher_suites;
3380 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3381 /*Setting default managment types: for register action frame: */
3382 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
3384 wdev->wiphy->max_remain_on_channel_duration = 500;
3385 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3386 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3387 BIT(NL80211_IFTYPE_P2P_CLIENT);
3388 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3389 wdev->iftype = NL80211_IFTYPE_STATION;
3393 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3394 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3395 wdev->wiphy->interface_modes, wdev->iftype);
3398 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
3401 /*Register wiphy structure*/
3402 s32Error = wiphy_register(wdev->wiphy);
3404 PRINT_ER("Cannot register wiphy device\n");
3405 /*should define what action to be taken in such failure*/
3407 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3416 * @brief WILC_WFI_WiphyFree
3417 * @details Freeing allocation of the wireless device structure
3424 int wilc_init_host_int(struct net_device *net)
3429 struct wilc_priv *priv;
3431 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3432 priv = wdev_priv(net->ieee80211_ptr);
3434 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
3435 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
3439 PRINT_ER("Failed to creat refresh Timer\n");
3443 priv->gbAutoRateAdjusted = false;
3445 priv->bInP2PlistenState = false;
3447 sema_init(&(priv->hSemScanReq), 1);
3448 s32Error = host_int_init(&priv->hWILCWFIDrv);
3450 PRINT_ER("Error while initializing hostinterface\n");
3456 * @brief WILC_WFI_WiphyFree
3457 * @details Freeing allocation of the wireless device structure
3464 int wilc_deinit_host_int(struct net_device *net)
3468 struct wilc_priv *priv;
3470 priv = wdev_priv(net->ieee80211_ptr);
3472 priv->gbAutoRateAdjusted = false;
3474 priv->bInP2PlistenState = false;
3478 s32Error = host_int_deinit(priv->hWILCWFIDrv);
3480 /* Clear the Shadow scan */
3481 clear_shadow_scan(priv);
3483 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
3484 del_timer_sync(&hDuringIpTimer);
3488 PRINT_ER("Error while deintializing host interface\n");
3495 * @brief WILC_WFI_WiphyFree
3496 * @details Freeing allocation of the wireless device structure
3503 void wilc_free_wiphy(struct net_device *net)
3505 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3508 PRINT_D(INIT_DBG, "net_device is NULL\n");
3512 if (!net->ieee80211_ptr) {
3513 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3517 if (!net->ieee80211_ptr->wiphy) {
3518 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3522 wiphy_unregister(net->ieee80211_ptr->wiphy);
3524 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3525 wiphy_free(net->ieee80211_ptr->wiphy);
3526 kfree(net->ieee80211_ptr);