blob: 422d4624b9cddb1cc03462b1f3c9946724bb9401 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/*!
2 * @file wilc_wfi_cfgopertaions.c
3 * @brief CFG80211 Function Implementation functionality
4 * @author aabouzaeid
5 * mabubakr
6 * mdaftedar
7 * zsalah
8 * @sa wilc_wfi_cfgopertaions.h top level OS wrapper file
9 * @date 31 Aug 2010
10 * @version 1.0
11 */
12
13#include "wilc_wfi_cfgoperations.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090014#ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +090015#include "linux_wlan_sdio.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090016#endif
Leo Kim7ae43362015-09-16 18:35:59 +090017#include <linux/errno.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090018
19#define IS_MANAGMEMENT 0x100
20#define IS_MANAGMEMENT_CALLBACK 0x080
21#define IS_MGMT_STATUS_SUCCES 0x040
22#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
23
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
Dean Lee72ed4dc2015-06-12 14:11:44 +090025extern u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090026
27extern int mac_open(struct net_device *ndev);
28extern int mac_close(struct net_device *ndev);
29
30tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090031u32 u32LastScannedNtwrksCountShadow;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070032struct timer_list hDuringIpTimer;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070033struct timer_list hAgingTimer;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090034static u8 op_ifcs;
35extern u8 u8ConnectedSSID[6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090036
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090037u8 g_wilc_initialized = 1;
Dean Lee72ed4dc2015-06-12 14:11:44 +090038extern bool g_obtainingIP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090039
40#define CHAN2G(_channel, _freq, _flags) { \
41 .band = IEEE80211_BAND_2GHZ, \
42 .center_freq = (_freq), \
43 .hw_value = (_channel), \
44 .flags = (_flags), \
45 .max_antenna_gain = 0, \
46 .max_power = 30, \
47}
48
49/*Frequency range for channels*/
50static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
51 CHAN2G(1, 2412, 0),
52 CHAN2G(2, 2417, 0),
53 CHAN2G(3, 2422, 0),
54 CHAN2G(4, 2427, 0),
55 CHAN2G(5, 2432, 0),
56 CHAN2G(6, 2437, 0),
57 CHAN2G(7, 2442, 0),
58 CHAN2G(8, 2447, 0),
59 CHAN2G(9, 2452, 0),
60 CHAN2G(10, 2457, 0),
61 CHAN2G(11, 2462, 0),
62 CHAN2G(12, 2467, 0),
63 CHAN2G(13, 2472, 0),
64 CHAN2G(14, 2484, 0),
65};
66
67#define RATETAB_ENT(_rate, _hw_value, _flags) { \
68 .bitrate = (_rate), \
69 .hw_value = (_hw_value), \
70 .flags = (_flags), \
71}
72
73
74/* Table 6 in section 3.2.1.1 */
75static struct ieee80211_rate WILC_WFI_rates[] = {
76 RATETAB_ENT(10, 0, 0),
77 RATETAB_ENT(20, 1, 0),
78 RATETAB_ENT(55, 2, 0),
79 RATETAB_ENT(110, 3, 0),
80 RATETAB_ENT(60, 9, 0),
81 RATETAB_ENT(90, 6, 0),
82 RATETAB_ENT(120, 7, 0),
83 RATETAB_ENT(180, 8, 0),
84 RATETAB_ENT(240, 9, 0),
85 RATETAB_ENT(360, 10, 0),
86 RATETAB_ENT(480, 11, 0),
87 RATETAB_ENT(540, 12, 0),
88};
89
Johnny Kimc5c77ba2015-05-11 14:30:56 +090090struct p2p_mgmt_data {
91 int size;
92 u8 *buff;
93};
94
95/*Global variable used to state the current connected STA channel*/
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090096u8 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097
Chaehyun Lim866a2c22015-10-02 16:41:21 +090098u8 curr_channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090099
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900100u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
101u8 u8P2Plocalrandom = 0x01;
102u8 u8P2Precvrandom = 0x00;
103u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
Daniel Machon7fc80962015-08-05 00:09:35 +0200104bool bWilc_ie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900105
106static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
107 .channels = WILC_WFI_2ghz_channels,
108 .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
109 .bitrates = WILC_WFI_rates,
110 .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
111};
112
113
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114struct add_key_params {
115 u8 key_idx;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116 bool pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900117 u8 *mac_addr;
118};
119struct add_key_params g_add_gtk_key_params;
120struct wilc_wfi_key g_key_gtk_params;
121struct add_key_params g_add_ptk_key_params;
122struct wilc_wfi_key g_key_ptk_params;
123struct wilc_wfi_wep_key g_key_wep_params;
Daniel Machon7fc80962015-08-05 00:09:35 +0200124bool g_ptk_keys_saved;
125bool g_gtk_keys_saved;
126bool g_wep_keys_saved;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900127
128#define AGING_TIME (9 * 1000)
129#define duringIP_TIME 15000
130
131void clear_shadow_scan(void *pUserVoid)
132{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900133 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900134
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135 if (op_ifcs == 0) {
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -0700136 del_timer_sync(&hAgingTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900137 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
138
139 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
140 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900141 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900142 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
143 }
144
145 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
146 astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
147 }
148 u32LastScannedNtwrksCountShadow = 0;
149 }
150
151}
152
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900153u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900154{
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900155 u8 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900156 int rssi_v = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900157 u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900158
159 for (i = 0; i < num_rssi; i++)
160 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
161
162 rssi_v /= num_rssi;
163 return rssi_v;
164}
165
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900166void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900167{
Chaehyun Lim27268872015-09-15 14:06:13 +0900168 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900169 struct wiphy *wiphy;
170 struct cfg80211_bss *bss = NULL;
171 int i;
172 int rssi = 0;
173
Chaehyun Lim27268872015-09-15 14:06:13 +0900174 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900175 wiphy = priv->dev->ieee80211_ptr->wiphy;
176
177 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
178 tstrNetworkInfo *pstrNetworkInfo;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900179
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900180 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
181
182
183 if ((!pstrNetworkInfo->u8Found) || all) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900184 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185 struct ieee80211_channel *channel;
186
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900187 if (pstrNetworkInfo != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900189 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 channel = ieee80211_get_channel(wiphy, s32Freq);
191
192 rssi = get_rssi_avg(pstrNetworkInfo);
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900193 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
195 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900196 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900198 }
199 }
200
201 }
202 }
203
204}
205
206void reset_shadow_found(void *pUserVoid)
207{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900209
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
211 astrLastScannedNtwrksShadow[i].u8Found = 0;
212
213 }
214}
215
216void update_scan_time(void *pUserVoid)
217{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900218 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900219
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
221 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
222 }
223}
224
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700225static void remove_network_from_shadow(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900226{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227 unsigned long now = jiffies;
228 int i, j;
229
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900230
231 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
232 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530233 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900234
Shraddha Barkecccfc392015-10-12 20:49:19 +0530235 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
236 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900237
238 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
239
240 for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
241 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
242 }
243 u32LastScannedNtwrksCountShadow--;
244 }
245 }
246
247 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700248 if (u32LastScannedNtwrksCountShadow != 0) {
249 hAgingTimer.data = arg;
250 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
251 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900252 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700253 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900254}
255
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700256static void clear_duringIP(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900257{
258 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900259 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900260}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900261
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900262int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900263{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900264 int state = -1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265 int i;
266
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267 if (u32LastScannedNtwrksCountShadow == 0) {
268 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700269 hAgingTimer.data = (unsigned long)pUserVoid;
270 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900271 state = -1;
272 } else {
273 /* Linear search for now */
274 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900275 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900276 pstrNetworkInfo->au8bssid, 6) == 0) {
277 state = i;
278 break;
279 }
280 }
281 }
282 return state;
283}
284
285void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
286{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900287 int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900288 u32 ap_index = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900289 u8 rssi_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900290
291 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
292 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
293 return;
294 }
295 if (ap_found == -1) {
296 ap_index = u32LastScannedNtwrksCountShadow;
297 u32LastScannedNtwrksCountShadow++;
298
299 } else {
300 ap_index = ap_found;
301 }
302 rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
303 astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
304 if (rssi_index == NUM_RSSI) {
305 rssi_index = 0;
306 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
307 }
308 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
309
310 astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
311 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
312
313 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900314 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900315 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
316
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900317 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900318 pstrNetworkInfo->au8bssid, ETH_ALEN);
319
320 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
321 astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
322 astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
323
324 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
325 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
326 if (ap_found != -1)
Chaehyun Lim49188af2015-08-11 10:32:41 +0900327 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900328 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
Glen Leef3052582015-09-10 12:03:04 +0900329 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900330 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900331 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
332
333 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
334 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
335 astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
336 if (ap_found != -1)
337 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
338 astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
339
340}
341
342
343/**
344 * @brief CfgScanResult
345 * @details Callback function which returns the scan results found
346 *
347 * @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is
348 * SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE
349 * tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information
350 * void* pUserVoid: Private structure associated with the wireless interface
351 * @return NONE
352 * @author mabubakr
353 * @date
354 * @version 1.0
355 */
Leo Kim1ec38152015-10-12 16:55:59 +0900356static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900357{
Chaehyun Lim27268872015-09-15 14:06:13 +0900358 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900359 struct wiphy *wiphy;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900360 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900361 struct ieee80211_channel *channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362 struct cfg80211_bss *bss = NULL;
363
Chaehyun Lim27268872015-09-15 14:06:13 +0900364 priv = (struct wilc_priv *)pUserVoid;
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100365 if (priv->bCfgScanning) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900366 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
367 wiphy = priv->dev->ieee80211_ptr->wiphy;
Leo Kim7ae43362015-09-16 18:35:59 +0900368
369 if (!wiphy)
370 return;
371
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900372 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
373 &&
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900374 ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900375 ||
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900376 (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900377 ) {
Leo Kim24db7132015-09-16 18:36:01 +0900378 PRINT_ER("wiphy signal type fial\n");
379 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900380 }
381
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900382 if (pstrNetworkInfo != NULL) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900383 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900384 channel = ieee80211_get_channel(wiphy, s32Freq);
385
Leo Kim7ae43362015-09-16 18:35:59 +0900386 if (!channel)
387 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900388
389 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530390 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
392
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100393 if (pstrNetworkInfo->bNewNetwork) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900394 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
395 /* max_scan_ssids */
396 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
397
398
399 priv->u32RcvdChCount++;
400
401
402
403 if (pJoinParams == NULL) {
404 PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
405 }
406 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
407
408 /*P2P peers are sent to WPA supplicant and added to shadow table*/
409
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900410 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900411 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
412 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900413 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900414 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900415 }
416
417
418 } else {
419 PRINT_ER("Discovered networks exceeded the max limit\n");
420 }
421 } else {
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900422 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900423 /* So this network is discovered before, we'll just update its RSSI */
424 for (i = 0; i < priv->u32RcvdChCount; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900425 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530426 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900427
428 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
429 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
430 break;
431 }
432 }
433 }
434 }
435 } else if (enuScanEvent == SCAN_EVENT_DONE) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530436 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
437 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900438 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900439
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530440 if (priv->u32RcvdChCount > 0)
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530441 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530442 else
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530443 PRINT_D(CFG80211_DBG, "No networks found\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900444
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200445 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900446
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900447 if (priv->pstrScanReq != NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900448 cfg80211_scan_done(priv->pstrScanReq, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 priv->u32RcvdChCount = 0;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900450 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900451 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900452 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200453 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900454
455 }
456 /*Aborting any scan operation during mac close*/
457 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200458 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530460 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900461 if (priv->pstrScanReq != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900462
463 update_scan_time(priv);
Dean Lee72ed4dc2015-06-12 14:11:44 +0900464 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900465
Dean Lee72ed4dc2015-06-12 14:11:44 +0900466 cfg80211_scan_done(priv->pstrScanReq, false);
467 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900468 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900469 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200470 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900471 }
472 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900473}
474
475
476/**
477 * @brief WILC_WFI_Set_PMKSA
478 * @details Check if pmksa is cached and set it.
479 * @param[in]
480 * @return int : Return 0 on Success
481 * @author mdaftedar
482 * @date 01 MAR 2012
483 * @version 1.0
484 */
Chaehyun Lim27268872015-09-15 14:06:13 +0900485int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900487 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900488 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900489
490
491 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
492
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900493 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900494 ETH_ALEN)) {
495 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
496
497 /*If bssid is found, set the values*/
498 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
499
Leo Kime6e12662015-09-16 18:36:03 +0900500 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900501 PRINT_ER("Error in pmkid\n");
502
503 break;
504 }
505 }
506
507 return s32Error;
508
509
510}
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900511int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900512
513
514/**
515 * @brief CfgConnectResult
516 * @details
517 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
518 * connection response or disconnection notification.
519 * tstrConnectInfo* pstrConnectInfo: COnnection information.
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900520 * u8 u8MacStatus: Mac Status from firmware
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900521 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
522 * void* pUserVoid: Private data associated with wireless interface
523 * @return NONE
524 * @author mabubakr
525 * @date 01 MAR 2012
526 * @version 1.0
527 */
528int connecting;
529
Leo Kimed3f0372015-10-12 16:56:01 +0900530static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900531 tstrConnectInfo *pstrConnectInfo,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900532 u8 u8MacStatus,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900533 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
534 void *pUserVoid)
535{
Chaehyun Lim27268872015-09-15 14:06:13 +0900536 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900537 struct net_device *dev;
Leo Kim441dc602015-10-12 16:55:35 +0900538 struct host_if_drv *pstrWFIDrv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900539 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900540
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541 connecting = 0;
542
Chaehyun Lim27268872015-09-15 14:06:13 +0900543 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900544 dev = priv->dev;
Leo Kim441dc602015-10-12 16:55:35 +0900545 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900546
547 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
548 /*Initialization*/
Amitoj Kaur Chawlababa7c72015-10-15 13:48:29 +0530549 u16 u16ConnectStatus;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900550
551 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
552
553 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
554
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);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530561 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900562
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900563 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564 if (!pstrWFIDrv->u8P2PConnect)
565 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530567 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568 }
569
570 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900571 bool bNeedScanRefresh = false;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900572 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900573
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]);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900576 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900578
579 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900580 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
582 unsigned long now = jiffies;
583
584 if (time_after(now,
585 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900586 bNeedScanRefresh = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900587 }
588
589 break;
590 }
591 }
592
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000593 if (bNeedScanRefresh) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900594 /*Also, refrsh DIRECT- results if */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900595 refresh_scan(priv, 1, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900596
597 }
598
599 }
600
601
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530602 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900603
604 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
605
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) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900612 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900613 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;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900617 bWilc_ie = false;
Shraddha Barkebcf02652015-10-05 17:00:32 +0530618 eth_zero_addr(priv->au8AssociatedBss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900619 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530620 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900621
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900622 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 if (!pstrWFIDrv->u8P2PConnect)
624 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
626 * virtual interface to station*/
Tony Cho817f3fb2015-10-20 14:26:51 +0900627 if ((pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900628 pstrDisconnectNotifInfo->u16reason = 3;
629 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900630 /*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*/
Tony Cho817f3fb2015-10-20 14:26:51 +0900632 else if ((!pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900633 pstrDisconnectNotifInfo->u16reason = 1;
634 }
635 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
Sudip Mukherjeee26bb712015-06-30 13:51:51 +0530636 pstrDisconnectNotifInfo->ie_len, false,
637 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900638
639 }
640
641}
642
643
644/**
Chaehyun Lim80785a92015-09-14 12:24:01 +0900645 * @brief set_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900646 * @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.
651 * @param[in]
652 * @return int : Return 0 on Success
653 * @author mdaftedar
654 * @date 01 MAR 2012
655 * @version 1.0
656 */
Chaehyun Lim80785a92015-09-14 12:24:01 +0900657static int set_channel(struct wiphy *wiphy,
658 struct cfg80211_chan_def *chandef)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900659{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900660 u32 channelnum = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +0900661 struct wilc_priv *priv;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900662 int result = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900663
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900664 priv = wiphy_priv(wiphy);
665
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900666 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);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900669 curr_channel = channelnum;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900670 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900671
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900672 if (result != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900673 PRINT_ER("Error in setting channel %d\n", channelnum);
674
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900675 return result;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676}
677
678/**
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900679 * @brief scan
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900680 * @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.
684 * @param[in]
685 * @return int : Return 0 on Success
686 * @author mabubakr
687 * @date 01 MAR 2012
688 * @version 1.0
689 */
690
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900691static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900692{
Chaehyun Lim27268872015-09-15 14:06:13 +0900693 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900694 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900695 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900696 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
Leo Kim607db442015-10-05 15:25:37 +0900697 struct hidden_network strHiddenNetwork;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900698
699 priv = wiphy_priv(wiphy);
700
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900701 priv->pstrScanReq = request;
702
703 priv->u32RcvdChCount = 0;
704
Johnny Kim218dc402015-08-13 13:41:19 +0900705 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900706
707
708 reset_shadow_found(priv);
709
Dean Lee72ed4dc2015-06-12 14:11:44 +0900710 priv->bCfgScanning = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900711 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
712 /* max_scan_ssids */
713 for (i = 0; i < request->n_channels; i++) {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900714 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900715 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
716 }
717
718 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530719 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900720
721 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
722
723 if (request->n_ssids >= 1) {
724
725
Leo Kim607db442015-10-05 15:25:37 +0900726 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900727 strHiddenNetwork.u8ssidnum = request->n_ssids;
728
729
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900730 for (i = 0; i < request->n_ssids; i++) {
731
732 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
Glen Leef3052582015-09-10 12:03:04 +0900733 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900734 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900735 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
736 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530737 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738 strHiddenNetwork.u8ssidnum -= 1;
739 }
740 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530741 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900742 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
743 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900744 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900745 CfgScanResult, (void *)priv, &strHiddenNetwork);
746 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530747 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900748 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
749 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900750 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900751 CfgScanResult, (void *)priv, NULL);
752 }
753
754 } else {
755 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530756 " channels\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900757 }
758
Leo Kime6e12662015-09-16 18:36:03 +0900759 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900760 s32Error = -EBUSY;
761 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
762 }
763
764 return s32Error;
765}
766
767/**
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900768 * @brief connect
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900769 * @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.
773 * @param[in]
774 * @return int : Return 0 on Success
775 * @author mabubakr
776 * @date 01 MAR 2012
777 * @version 1.0
778 */
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900779static int connect(struct wiphy *wiphy, struct net_device *dev,
780 struct cfg80211_connect_params *sme)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781{
Leo Kime6e12662015-09-16 18:36:03 +0900782 s32 s32Error = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900783 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900784 u8 u8security = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +0900785 enum AUTHTYPE tenuAuth_type = ANY;
Dean Lee576917a2015-06-15 11:58:57 +0900786 char *pcgroup_encrypt_val = NULL;
787 char *pccipher_group = NULL;
788 char *pcwpa_version = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900789
Chaehyun Lim27268872015-09-15 14:06:13 +0900790 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +0900791 struct host_if_drv *pstrWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900792 tstrNetworkInfo *pstrNetworkInfo = NULL;
793
794
795 connecting = 1;
796 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +0900797 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900798
Johnny Kim218dc402015-08-13 13:41:19 +0900799 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900800
Johnny Kim8a143302015-06-10 17:06:46 +0900801 PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
Chaehyun Lim3f882892015-08-10 11:33:17 +0900802 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900803 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
804 pstrWFIDrv->u8P2PConnect = 1;
805 } else
806 pstrWFIDrv->u8P2PConnect = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530807 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900808
809 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
810 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900811 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900812 sme->ssid,
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");
819 break;
820 } else {
821 /* BSSID is also passed from the user, so decision of matching
822 * should consider also this passed BSSID */
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900823 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900824 sme->bssid,
825 ETH_ALEN) == 0) {
826 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
827 break;
828 }
829 }
830 }
831 }
832
833 if (i < u32LastScannedNtwrksCountShadow) {
834 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
835
836 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
837
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]);
842 } else {
843 s32Error = -ENOENT;
844 if (u32LastScannedNtwrksCountShadow == 0)
845 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
846 else
847 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
848
849 goto done;
850 }
851
852 priv->WILC_WFI_wep_default = 0;
Chaehyun Lim2cc46832015-08-07 09:02:01 +0900853 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));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900855
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);
858
859 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
860
861 if (INFO) {
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]);
864 }
865
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);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900871 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900872 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);
876
877 if (INFO) {
878 for (i = 0; i < sme->key_len; i++)
879 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
880 }
881 priv->WILC_WFI_wep_default = sme->key_idx;
882 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900883 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900884
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900885 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900886 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900887 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
888 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900889 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900890
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) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
895 pcgroup_encrypt_val = "WEP104";
896 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
897
898 priv->WILC_WFI_wep_default = sme->key_idx;
899 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900900 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900901
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900902 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900903 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900904 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
905 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900906 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900907
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) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900911 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900912 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";
920 }
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) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900924 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";
932
933 }
934 pcwpa_version = "WPA_VERSION_1";
935
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900936 } else {
937 s32Error = -ENOTSUPP;
938 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
939
940 goto done;
941 }
942
943 }
944
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;
954 }
955 }
956 }
957
958 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
959
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;
965 break;
966
967 case NL80211_AUTHTYPE_SHARED_KEY:
968 tenuAuth_type = SHARED_KEY;
969 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
970 break;
971
972 default:
973 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
974 }
975
976
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;
982 break;
983
984 default:
985 break;
986 }
987 }
988
989
990 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
991
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);
994
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900995 curr_channel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900996
997 if (!pstrWFIDrv->u8P2PConnect) {
998 u8WLANChannel = pstrNetworkInfo->u8channel;
999 }
1000
1001 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1002
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);
Leo Kime6e12662015-09-16 18:36:03 +09001008 if (s32Error != 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301009 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001010 s32Error = -ENOENT;
1011 goto done;
1012 }
1013
1014done:
1015
1016 return s32Error;
1017}
1018
1019
1020/**
Chaehyun Limb027cde2015-09-14 12:24:04 +09001021 * @brief disconnect
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001022 * @details Disconnect from the BSS/ESS.
1023 * @param[in]
1024 * @return int : Return 0 on Success
1025 * @author mdaftedar
1026 * @date 01 MAR 2012
1027 * @version 1.0
1028 */
Chaehyun Limb027cde2015-09-14 12:24:04 +09001029static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001030{
Leo Kime6e12662015-09-16 18:36:03 +09001031 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001032 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09001033 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001034 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001035
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001036 connecting = 0;
1037 priv = wiphy_priv(wiphy);
1038
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001039 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kim441dc602015-10-12 16:55:35 +09001040 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001041 if (!pstrWFIDrv->u8P2PConnect)
1042 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001043 linux_wlan_set_bssid(priv->dev, NullBssid);
1044
1045 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1046
1047 u8P2Plocalrandom = 0x01;
1048 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +09001049 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001050 pstrWFIDrv->u64P2p_MgmtTimeout = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001051
1052 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
Leo Kime6e12662015-09-16 18:36:03 +09001053 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001054 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1055 s32Error = -EINVAL;
1056 }
1057
1058 return s32Error;
1059}
1060
1061/**
Chaehyun Lim953d4172015-09-14 12:24:05 +09001062 * @brief add_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001063 * @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
1067 * @author mdaftedar
1068 * @date 01 MAR 2012
1069 * @version 1.0
1070 */
Chaehyun Lim953d4172015-09-14 12:24:05 +09001071static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1072 bool pairwise,
1073 const u8 *mac_addr, struct key_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001074
1075{
Leo Kime6e12662015-09-16 18:36:03 +09001076 s32 s32Error = 0, KeyLen = params->key_len;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001077 u32 i;
Chaehyun Lim27268872015-09-15 14:06:13 +09001078 struct wilc_priv *priv;
Arnd Bergmann057d1e92015-06-01 21:06:44 +02001079 const u8 *pu8RxMic = NULL;
1080 const u8 *pu8TxMic = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001081 u8 u8mode = NO_ENCRYPT;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001082 u8 u8gmode = NO_ENCRYPT;
1083 u8 u8pmode = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +09001084 enum AUTHTYPE tenuAuth_type = ANY;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001085
1086 priv = wiphy_priv(wiphy);
1087
1088 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1089
Johnny Kim8a143302015-06-10 17:06:46 +09001090 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001091
1092 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1093 params->key[1],
1094 params->key[2]);
1095
1096
1097 switch (params->cipher) {
1098 case WLAN_CIPHER_SUITE_WEP40:
1099 case WLAN_CIPHER_SUITE_WEP104:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001100 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1101
1102 priv->WILC_WFI_wep_default = key_index;
1103 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001104 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001105
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);
1108
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]);
1111
1112 tenuAuth_type = OPEN_SYSTEM;
1113
1114 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1115 u8mode = ENCRYPT_ENABLED | WEP;
1116 else
1117 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1118
1119 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1120 break;
1121 }
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001122 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001123 priv->WILC_WFI_wep_default = key_index;
1124 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001125 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001126
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);
1129 if (INFO) {
1130 for (i = 0; i < params->key_len; i++)
1131 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1132 }
1133 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1134 }
1135
1136 break;
1137
1138 case WLAN_CIPHER_SUITE_TKIP:
1139 case WLAN_CIPHER_SUITE_CCMP:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001140 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1141
1142 if (priv->wilc_gtk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001143 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001144 priv->wilc_gtk[key_index]->key = NULL;
1145 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001146
1147 }
1148 if (priv->wilc_ptk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001149 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001150 priv->wilc_ptk[key_index]->key = NULL;
1151 priv->wilc_ptk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001152 }
1153
1154
1155
Daniel Machon19132212015-08-05 08:18:31 +02001156 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001157 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1158 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1159 else
1160 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1161
1162 priv->wilc_groupkey = u8gmode;
1163
1164 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1165
1166 pu8TxMic = params->key + 24;
1167 pu8RxMic = params->key + 16;
1168 KeyLen = params->key_len - 16;
1169 }
1170 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301171 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001172
Glen Leef3052582015-09-10 12:03:04 +09001173 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001174 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001175
1176 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301177 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001178
1179 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001180 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001181 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182 }
1183
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;
1187
1188 if (INFO) {
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]);
1193 }
1194
1195
1196 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1197 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1198
1199 } else {
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]);
1201
1202 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1203 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1204 else
1205 u8pmode = priv->wilc_groupkey | AES;
1206
1207
1208 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1209
1210 pu8TxMic = params->key + 24;
1211 pu8RxMic = params->key + 16;
1212 KeyLen = params->key_len - 16;
1213 }
1214
Shraddha Barkecccfc392015-10-12 20:49:19 +05301215 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001216
Glen Leef3052582015-09-10 12:03:04 +09001217 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001218
Shraddha Barkecccfc392015-10-12 20:49:19 +05301219 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001220
1221 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001222 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223
1224 if (INFO) {
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]);
1227
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]);
1230 }
1231
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001232 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001233
1234 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001235 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001236
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;
1240
1241 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1242 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1243 }
1244 break;
1245 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001246
1247 {
1248 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001249 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001250 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;
1255 }
1256
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001257 /*save keys only on interface 0 (wifi interface)*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001258 if (!g_gtk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001259 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001260 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001261 if (!mac_addr) {
1262 g_add_gtk_key_params.mac_addr = NULL;
1263 } else {
Glen Leef3052582015-09-10 12:03:04 +09001264 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001265 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1266 }
1267 g_key_gtk_params.key_len = params->key_len;
1268 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001269 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001270 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1271 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001272 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001273 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1274 }
1275 g_key_gtk_params.cipher = params->cipher;
1276
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]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001280 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001281 }
1282
1283 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1284 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001285 } else {
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;
1291 }
1292
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001293 /*save keys only on interface 0 (wifi interface)*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001294 if (!g_ptk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001295 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001296 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001297 if (!mac_addr) {
1298 g_add_ptk_key_params.mac_addr = NULL;
1299 } else {
Glen Leef3052582015-09-10 12:03:04 +09001300 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1302 }
1303 g_key_ptk_params.key_len = params->key_len;
1304 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001305 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001306 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1307 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001308 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001309 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1310 }
1311 g_key_ptk_params.cipher = params->cipher;
1312
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]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001316 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001317 }
1318
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");
1322 if (INFO) {
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]);
1325 }
1326 }
1327 }
1328 break;
1329
1330 default:
1331 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1332 s32Error = -ENOTSUPP;
1333
1334 }
1335
1336 return s32Error;
1337}
1338
1339/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001340 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001341 * @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.
1343 * @param[in]
1344 * @return int : Return 0 on Success
1345 * @author mdaftedar
1346 * @date 01 MAR 2012
1347 * @version 1.0
1348 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001349static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1350 u8 key_index,
1351 bool pairwise,
1352 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001353{
Chaehyun Lim27268872015-09-15 14:06:13 +09001354 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001355
1356 priv = wiphy_priv(wiphy);
1357
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001358 /*delete saved keys, if any*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001359 if (netdev == g_linux_wlan->vif[0].ndev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001360 g_ptk_keys_saved = false;
1361 g_gtk_keys_saved = false;
1362 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001363
1364 /*Delete saved WEP keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301365 kfree(g_key_wep_params.key);
1366 g_key_wep_params.key = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367
1368 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1369
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001370 if ((priv->wilc_gtk[key_index]) != NULL) {
1371
Shraddha Barkecccfc392015-10-12 20:49:19 +05301372 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;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001376
Chaehyun Lim49188af2015-08-11 10:32:41 +09001377 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001378 priv->wilc_gtk[key_index] = NULL;
1379
1380 }
1381
1382 if ((priv->wilc_ptk[key_index]) != NULL) {
1383
Shraddha Barkecccfc392015-10-12 20:49:19 +05301384 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;
Chaehyun Lim49188af2015-08-11 10:32:41 +09001388 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001389 priv->wilc_ptk[key_index] = NULL;
1390 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001391
1392 /*Delete saved PTK and GTK keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301393 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;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001397
Shraddha Barkecccfc392015-10-12 20:49:19 +05301398 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;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001402
1403 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Dean Lee72ed4dc2015-06-12 14:11:44 +09001404 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001405 }
1406
1407 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001408 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409 priv->WILC_WFI_wep_key_len[key_index] = 0;
1410
1411 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1412 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1413 } else {
1414 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1415 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1416 }
1417
Leo Kimaaed3292015-10-12 16:55:38 +09001418 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001419}
1420
1421/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001422 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001423 * @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.
1428 * @param[in]
1429 * @return int : Return 0 on Success
1430 * @author mdaftedar
1431 * @date 01 MAR 2012
1432 * @version 1.0
1433 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001434static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1435 bool pairwise,
1436 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001437{
Chaehyun Lim27268872015-09-15 14:06:13 +09001438 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001439 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001440 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001441
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001442 priv = wiphy_priv(wiphy);
1443
1444
Alison Schofield3604af52015-10-12 13:22:44 -07001445 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1447
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;
1453 if (INFO) {
1454 for (i = 0; i < key_params.key_len; i++)
1455 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1456 }
1457 } else {
1458 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1459
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;
1465 }
1466
1467 callback(cookie, &key_params);
1468
Leo Kimaaed3292015-10-12 16:55:38 +09001469 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001470}
1471
1472/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001473 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001474 * @details Set the default management frame key on an interface
1475 * @param[in]
1476 * @return int : Return 0 on Success.
1477 * @author mdaftedar
1478 * @date 01 MAR 2012
1479 * @version 1.0
1480 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001481static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1482 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001483{
Chaehyun Lim27268872015-09-15 14:06:13 +09001484 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001485
1486
1487 priv = wiphy_priv(wiphy);
1488
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301489 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001490
1491 if (key_index != priv->WILC_WFI_wep_default) {
1492
1493 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
1494 }
1495
Leo Kimaaed3292015-10-12 16:55:38 +09001496 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001497}
1498
1499/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001500 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001501 * @details Get station information for the station identified by @mac
1502 * @param[in] NONE
1503 * @return int : Return 0 on Success.
1504 * @author mdaftedar
1505 * @date 01 MAR 2012
1506 * @version 1.0
1507 */
1508
Chaehyun Limf06f5622015-09-14 12:24:18 +09001509static int get_station(struct wiphy *wiphy, struct net_device *dev,
1510 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001511{
Chaehyun Lim27268872015-09-15 14:06:13 +09001512 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001513 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001514 u32 i = 0;
1515 u32 associatedsta = 0;
1516 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001517 priv = wiphy_priv(wiphy);
1518 nic = netdev_priv(dev);
1519
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001520 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1521 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1522
1523 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1524
1525 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1526
1527 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1528 associatedsta = i;
1529 break;
1530 }
1531
1532 }
1533
1534 if (associatedsta == -1) {
Leo Kimaaed3292015-10-12 16:55:38 +09001535 PRINT_ER("Station required is not associated\n");
1536 return -ENOENT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001537 }
1538
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001539 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001540
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);
1544
1545 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001546
1547 if (nic->iftype == STATION_MODE) {
Leo Kim03e7b9c2015-10-12 16:55:58 +09001548 struct rf_info strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001549
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001550 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1551
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001552 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301553 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001554 BIT(NL80211_STA_INFO_TX_PACKETS) |
1555 BIT(NL80211_STA_INFO_TX_FAILED) |
1556 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001557
1558 sinfo->signal = strStatistics.s8RSSI;
1559 sinfo->rx_packets = strStatistics.u32RxCount;
1560 sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561 sinfo->tx_failed = strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001562 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1563
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301564 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001565 Enable_TCP_ACK_Filter(true);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301566 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001567 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001568
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001569 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);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001571 }
Leo Kimaaed3292015-10-12 16:55:38 +09001572 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001573}
1574
1575
1576/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001577 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001578 * @details Modify parameters for a given BSS.
1579 * @param[in]
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.
1593 * @author mdaftedar
1594 * @date 01 MAR 2012
1595 * @version 1.0
1596 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001597static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1598 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001599{
1600 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1601 return 0;
1602}
1603
1604/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001605 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001606 * @details Notify that wiphy parameters have changed;
1607 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1608 * have changed.
1609 * @return int : Return 0 on Success
1610 * @author mdaftedar
1611 * @date 01 MAR 2012
1612 * @version 1.0
1613 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001614static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001615{
Leo Kime6e12662015-09-16 18:36:03 +09001616 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001617 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001618 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001619
1620 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001621
Tony Cho87c05b22015-10-12 16:56:07 +09001622 pstrCfgParamVal.flag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301623 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001624
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);
Tony Cho87c05b22015-10-12 16:56:07 +09001628 pstrCfgParamVal.flag |= RETRY_SHORT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001629 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1630 }
1631 if (changed & WIPHY_PARAM_RETRY_LONG) {
1632
1633 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
Tony Cho87c05b22015-10-12 16:56:07 +09001634 pstrCfgParamVal.flag |= RETRY_LONG;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001635 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1636
1637 }
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);
Tony Cho87c05b22015-10-12 16:56:07 +09001640 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001641 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1642
1643 }
1644
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);
1647
Tony Cho87c05b22015-10-12 16:56:07 +09001648 pstrCfgParamVal.flag |= RTS_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001649 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1650
1651 }
1652
1653 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1654 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1655 if (s32Error)
1656 PRINT_ER("Error in setting WIPHY PARAMS\n");
1657
1658
1659 return s32Error;
1660}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001661
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001662/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001663 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001664 * @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.
1667 * @param[in]
1668 * @return int : Return 0 on Success
1669 * @author mdaftedar
1670 * @date 01 MAR 2012
1671 * @version 1.0
1672 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001673static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1674 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001675{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001676 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001677 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001678 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001679
Chaehyun Lim27268872015-09-15 14:06:13 +09001680 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001681
1682 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1683
1684
1685 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001686 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001687 ETH_ALEN)) {
1688 /*If bssid already exists and pmkid value needs to reset*/
1689 flag = PMKID_FOUND;
1690 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1691 break;
1692 }
1693 }
1694 if (i < WILC_MAX_NUM_PMKIDS) {
1695 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001696 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001697 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001698 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001699 PMKID_LEN);
1700 if (!(flag == PMKID_FOUND))
1701 priv->pmkid_list.numpmkid++;
1702 } else {
1703 PRINT_ER("Invalid PMKID index\n");
1704 s32Error = -EINVAL;
1705 }
1706
1707 if (!s32Error) {
1708 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1709 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1710 }
1711 return s32Error;
1712}
1713
1714/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001715 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001716 * @details Delete a cached PMKID.
1717 * @param[in]
1718 * @return int : Return 0 on Success
1719 * @author mdaftedar
1720 * @date 01 MAR 2012
1721 * @version 1.0
1722 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001723static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1724 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001725{
1726
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001727 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001728 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001729
Chaehyun Lim27268872015-09-15 14:06:13 +09001730 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001731
1732 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1733
1734 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001735 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001736 ETH_ALEN)) {
1737 /*If bssid is found, reset the values*/
1738 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001739 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001740 break;
1741 }
1742 }
1743
1744 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1745 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001746 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001747 priv->pmkid_list.pmkidlist[i + 1].bssid,
1748 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001749 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001750 priv->pmkid_list.pmkidlist[i].pmkid,
1751 PMKID_LEN);
1752 }
1753 priv->pmkid_list.numpmkid--;
1754 } else {
1755 s32Error = -EINVAL;
1756 }
1757
1758 return s32Error;
1759}
1760
1761/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001762 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001763 * @details Flush all cached PMKIDs.
1764 * @param[in]
1765 * @return int : Return 0 on Success
1766 * @author mdaftedar
1767 * @date 01 MAR 2012
1768 * @version 1.0
1769 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001770static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001771{
Chaehyun Lim27268872015-09-15 14:06:13 +09001772 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001773
1774 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1775
1776 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001777 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001778
1779 return 0;
1780}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001781
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001782
1783/**
1784 * @brief WILC_WFI_CfgParseRxAction
1785 * @details Function parses the received frames and modifies the following attributes:
1786 * -GO Intent
1787 * -Channel list
1788 * -Operating Channel
1789 *
1790 * @param[in] u8* Buffer, u32 length
1791 * @return NONE.
1792 * @author mdaftedar
1793 * @date 12 DEC 2012
1794 * @version
1795 */
1796
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001797void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001798{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001799 u32 index = 0;
1800 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001801
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001802 u8 op_channel_attr_index = 0;
1803 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001804
1805 while (index < len) {
1806 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001807 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808 }
1809
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301810 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301812 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001813 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001814 index += buf[index + 1] + 3; /* ID,Length byte */
1815 }
Alison Schofield3604af52015-10-12 13:22:44 -07001816 if (u8WLANChannel != INVALID_CHANNEL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001817
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001818 /*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;
1825 }
1826 break;
1827 }
1828 }
1829 }
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;
1835 }
1836 }
1837}
1838
1839/**
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
1844 * @return NONE.
1845 * @author mdaftedar
1846 * @date 12 DEC 2012
1847 * @version
1848 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001849void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001850{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001851 u32 index = 0;
1852 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001853
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001854 u8 op_channel_attr_index = 0;
1855 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001856
1857 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001858 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860
1861 break;
1862 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301864 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001865 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301866 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001867 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001868 index += buf[index + 1] + 3; /* ID,Length byte */
1869 }
Alison Schofield3604af52015-10-12 13:22:44 -07001870 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001871
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001872 /*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;
1879 }
1880 break;
1881 }
1882 }
1883 }
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;
1889 }
1890 }
1891}
1892
1893/* @brief WILC_WFI_p2p_rx
1894 * @details
1895 * @param[in]
1896 *
1897 * @return None
1898 * @author Mai Daftedar
1899 * @date 2 JUN 2013
1900 * @version 1.0
1901 */
1902
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001903void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001904{
1905
Chaehyun Lim27268872015-09-15 14:06:13 +09001906 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001907 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001908 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001909 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001910 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001911
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001912 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001913 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001914
1915 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001916 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001917
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);
1921
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");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001925 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001926 return;
1927 } else {
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]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001931 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001932 } else {
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]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001935 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001936 }
1937 return;
1938 }
1939 } else {
1940
1941 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1942
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001943 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001944 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001945
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]);
1948
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01001949 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001950 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1951 return;
1952 }
1953 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1954
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]);
1958 break;
1959
1960 case GAS_INTIAL_RSP:
1961 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1962 break;
1963
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*/
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001967 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001968 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1969 if (!bWilc_ie) {
1970 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001971 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001972 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09001973 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001974 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1975 break;
1976 }
1977 }
1978 }
1979 }
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++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001984 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001985 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1986 break;
1987 }
1988 }
1989 }
1990 } else
1991 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
1992 }
1993
1994
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 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001998 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001999 return;
2000 }
2001 break;
2002
2003 default:
2004 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2005 break;
2006 }
2007 }
2008 }
2009
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002010 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002011 }
2012}
2013
2014/**
2015 * @brief WILC_WFI_mgmt_tx_complete
2016 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2017 * @param[in] priv
2018 * transmitting status
2019 * @return None
2020 * @author Amr Abdelmoghny
2021 * @date 20 MAY 2013
2022 * @version 1.0
2023 */
2024static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2025{
2026 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2027
2028
2029 kfree(pv_data->buff);
2030 kfree(pv_data);
2031}
2032
2033/**
2034 * @brief WILC_WFI_RemainOnChannelReady
2035 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2036 * @param
2037 * @return none
2038 * @author Amr abdelmoghny
2039 * @date 9 JUNE 2013
2040 * @version
2041 */
2042
2043static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2044{
Chaehyun Lim27268872015-09-15 14:06:13 +09002045 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002046
Chaehyun Lim27268872015-09-15 14:06:13 +09002047 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002048
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302049 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050
Dean Lee72ed4dc2015-06-12 14:11:44 +09002051 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002052
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002053 cfg80211_ready_on_channel(priv->wdev,
2054 priv->strRemainOnChanParams.u64ListenCookie,
2055 priv->strRemainOnChanParams.pstrListenChan,
2056 priv->strRemainOnChanParams.u32ListenDuration,
2057 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058}
2059
2060/**
2061 * @brief WILC_WFI_RemainOnChannelExpired
2062 * @details Callback function, called on expiration of remain-on-channel duration
2063 * @param
2064 * @return none
2065 * @author Amr abdelmoghny
2066 * @date 15 MAY 2013
2067 * @version
2068 */
2069
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002070static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002071{
Chaehyun Lim27268872015-09-15 14:06:13 +09002072 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002073
Chaehyun Lim27268872015-09-15 14:06:13 +09002074 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002075
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002076 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302077 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002078
Dean Lee72ed4dc2015-06-12 14:11:44 +09002079 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002080
2081 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002082 cfg80211_remain_on_channel_expired(priv->wdev,
2083 priv->strRemainOnChanParams.u64ListenCookie,
2084 priv->strRemainOnChanParams.pstrListenChan,
2085 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002086 } else {
2087 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2088 , priv->strRemainOnChanParams.u32ListenSessionID);
2089 }
2090}
2091
2092
2093/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002094 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002095 * @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().
2100 * @param[in]
2101 * @return int : Return 0 on Success
2102 * @author mdaftedar
2103 * @date 01 MAR 2012
2104 * @version 1.0
2105 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002106static int remain_on_channel(struct wiphy *wiphy,
2107 struct wireless_dev *wdev,
2108 struct ieee80211_channel *chan,
2109 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002110{
Leo Kime6e12662015-09-16 18:36:03 +09002111 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002112 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002113
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002114 priv = wiphy_priv(wiphy);
2115
2116 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2117
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002118
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002119 if (wdev->iftype == NL80211_IFTYPE_AP) {
2120 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2121 return s32Error;
2122 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002123
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002124 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002125
2126 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2127 priv->strRemainOnChanParams.pstrListenChan = chan;
2128 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002129 priv->strRemainOnChanParams.u32ListenDuration = duration;
2130 priv->strRemainOnChanParams.u32ListenSessionID++;
2131
2132 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2133 , priv->strRemainOnChanParams.u32ListenSessionID
2134 , duration
2135 , chan->hw_value
2136 , WILC_WFI_RemainOnChannelExpired
2137 , WILC_WFI_RemainOnChannelReady
2138 , (void *)priv);
2139
2140 return s32Error;
2141}
2142
2143/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002144 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002145 * @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
2152 * @author mdaftedar
2153 * @date 01 MAR 2012
2154 * @version 1.0
2155 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002156static int cancel_remain_on_channel(struct wiphy *wiphy,
2157 struct wireless_dev *wdev,
2158 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002159{
Leo Kime6e12662015-09-16 18:36:03 +09002160 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002161 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002162
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002163 priv = wiphy_priv(wiphy);
2164
2165 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2166
2167 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2168 return s32Error;
2169}
2170/**
2171 * @brief WILC_WFI_add_wilcvendorspec
2172 * @details Adding WILC information elemet to allow two WILC devices to
2173 * identify each other and connect
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002174 * @param[in] u8 * buf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002175 * @return void
2176 * @author mdaftedar
2177 * @date 01 JAN 2014
2178 * @version 1.0
2179 */
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002180void WILC_WFI_add_wilcvendorspec(u8 *buff)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002181{
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002182 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002183}
2184/**
2185 * @brief WILC_WFI_mgmt_tx_frame
2186 * @details
2187 *
2188 * @param[in]
2189 * @return NONE.
2190 * @author mdaftedar
2191 * @date 01 JUL 2012
2192 * @version
2193 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09002194extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002195static int mgmt_tx(struct wiphy *wiphy,
2196 struct wireless_dev *wdev,
2197 struct cfg80211_mgmt_tx_params *params,
2198 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002199{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002200 struct ieee80211_channel *chan = params->chan;
2201 unsigned int wait = params->wait;
2202 const u8 *buf = params->buf;
2203 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002204 const struct ieee80211_mgmt *mgmt;
2205 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002206 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002207 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002208 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002209 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002210 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002211
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002212 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002213 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002214 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002215
2216 *cookie = (unsigned long)buf;
2217 priv->u64tx_cookie = *cookie;
2218 mgmt = (const struct ieee80211_mgmt *) buf;
2219
2220 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2221
2222 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002223 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002224 if (mgmt_tx == NULL) {
2225 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002226 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002227 }
Glen Leef3052582015-09-10 12:03:04 +09002228 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002229 if (mgmt_tx->buff == NULL) {
2230 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002231 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002232 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002233 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002234 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002235 mgmt_tx->size = len;
2236
2237
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*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002243 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002244 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002245 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002246
2247
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002248 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002249 /*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)*/
2252
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*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002258 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002259 }
2260 switch (buf[ACTION_SUBTYPE_ID]) {
2261 case GAS_INTIAL_REQ:
2262 {
2263 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2264 break;
2265 }
2266
2267 case GAS_INTIAL_RSP:
2268 {
2269 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2270 break;
2271 }
2272
2273 case PUBLIC_ACT_VENDORSPEC:
2274 {
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*/
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002277 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002278 /*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*/
2283 u8P2Plocalrandom++;
2284 }
2285 }
2286
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);
2291
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++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002294 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002295 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002296 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002297
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002298 /*If using supplicant go intent, no need at all*/
2299 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002300 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002301 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002302 break;
2303 }
2304 }
2305
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;
2310 }
2311 } else
2312 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2313 }
2314
2315 } else {
2316 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2317 }
2318
2319 break;
2320 }
2321
2322 default:
2323 {
2324 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2325 break;
2326 }
2327 }
2328
2329 }
2330
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));
2333
2334 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2335
2336 }
2337
Glen Leec9d48342015-10-01 16:03:43 +09002338 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2339 mgmt_tx->size,
2340 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002341 } else {
2342 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2343 }
Leo Kimaaed3292015-10-12 16:55:38 +09002344 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002345}
2346
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002347static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2348 struct wireless_dev *wdev,
2349 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002350{
Chaehyun Lim27268872015-09-15 14:06:13 +09002351 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002352 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002353
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002354 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002355 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002356
2357
2358 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2359 pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2360
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01002361 if (!priv->bInP2PlistenState) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002362 cfg80211_remain_on_channel_expired(priv->wdev,
2363 priv->strRemainOnChanParams.u64ListenCookie,
2364 priv->strRemainOnChanParams.pstrListenChan,
2365 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002366 }
2367
2368 return 0;
2369}
2370
2371/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002372 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002373 * @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.
2376 * @param[in]
2377 * @return NONE.
2378 * @author mdaftedar
2379 * @date 01 JUL 2012
2380 * @version
2381 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002382void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2383 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002384{
2385
Chaehyun Lim27268872015-09-15 14:06:13 +09002386 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002387 perInterface_wlan_t *nic;
2388
2389
2390 priv = wiphy_priv(wiphy);
2391 nic = netdev_priv(priv->wdev->netdev);
2392
2393
2394
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002395 if (!frame_type)
2396 return;
2397
2398 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2399 switch (frame_type) {
2400 case PROBE_REQ:
2401 {
2402 nic->g_struct_frame_reg[0].frame_type = frame_type;
2403 nic->g_struct_frame_reg[0].reg = reg;
2404 }
2405 break;
2406
2407 case ACTION:
2408 {
2409 nic->g_struct_frame_reg[1].frame_type = frame_type;
2410 nic->g_struct_frame_reg[1].reg = reg;
2411 }
2412 break;
2413
2414 default:
2415 {
2416 break;
2417 }
2418
2419 }
2420 /*If mac is closed, then return*/
Tony Cho080f11b2015-10-20 14:26:45 +09002421 if (!g_linux_wlan->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002422 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2423 return;
2424 }
2425 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2426
2427
2428}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002429
2430/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002431 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002432 * @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
2438 * @author mdaftedar
2439 * @date 01 MAR 2012
2440 * @version 1.0
2441 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002442static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2443 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002444{
2445 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2446 return 0;
2447
2448}
2449/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002450 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002451 * @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
2458 * @author mdaftedar
2459 * @date 01 MAR 2012
2460 * @version 1.0
2461 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002462static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2463 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002464{
Chaehyun Lim27268872015-09-15 14:06:13 +09002465 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002466
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002467 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2468
2469 if (idx != 0)
2470 return -ENOENT;
2471
2472 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002473
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002474 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002475
2476 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2477
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002478 return 0;
2479
2480}
2481
2482
2483/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002484 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002485 * @details
2486 * @param[in]
2487 * @return int : Return 0 on Success.
2488 * @author mdaftedar
2489 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002490 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002491 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002492static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2493 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002494{
Chaehyun Lim27268872015-09-15 14:06:13 +09002495 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002496
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002497 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2498
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002499 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002500 return -ENOENT;
2501
2502 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002503 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002504 PRINT_ER("Driver is NULL\n");
2505 return -EIO;
2506 }
2507
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002508 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002509 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2510
2511
Leo Kime6e12662015-09-16 18:36:03 +09002512 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002513
2514}
Glen Lee108b3432015-09-16 18:53:20 +09002515
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002516/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002517 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002518 * @details Change type/configuration of virtual interface,
2519 * keep the struct wireless_dev's iftype updated.
2520 * @param[in] NONE
2521 * @return int : Return 0 on Success.
2522 * @author mdaftedar
2523 * @date 01 MAR 2012
2524 * @version 1.0
2525 */
Tony Chof61c5af2015-10-14 20:46:30 +09002526void wilc1000_wlan_deinit(struct wilc *nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002527int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2528
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002529static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2530 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002531{
Chaehyun Lim27268872015-09-15 14:06:13 +09002532 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002533 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002534 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002535 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002536 u8 i;
Glen Lee299382c2015-10-20 17:13:56 +09002537 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002538
2539 nic = netdev_priv(dev);
2540 priv = wiphy_priv(wiphy);
Glen Lee299382c2015-10-20 17:13:56 +09002541 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002542
2543 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2544 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2545 u8P2Plocalrandom = 0x01;
2546 u8P2Precvrandom = 0x00;
2547
Dean Lee72ed4dc2015-06-12 14:11:44 +09002548 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002549
Dean Lee72ed4dc2015-06-12 14:11:44 +09002550 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002551 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002552 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002553 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2554 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09002555 Set_machw_change_vir_if(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002556 }
2557
2558 switch (type) {
2559 case NL80211_IFTYPE_STATION:
2560 connecting = 0;
2561 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002562
2563 /* send delba over wlan interface */
2564
2565
2566 dev->ieee80211_ptr->iftype = type;
2567 priv->wdev->iftype = type;
2568 nic->monitor_flag = 0;
2569 nic->iftype = STATION_MODE;
2570
2571 /*Remove the enteries of the previously connected clients*/
2572 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002573 interface_type = nic->iftype;
2574 nic->iftype = STATION_MODE;
2575
Glen Lee299382c2015-10-20 17:13:56 +09002576 if (wl->initialized) {
2577 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2578 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002579 /* ensure that the message Q is empty */
2580 host_int_wait_msg_queue_idle();
2581
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002582 /*Eliminate host interface blocking state*/
Glen Lee299382c2015-10-20 17:13:56 +09002583 up(&wl->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002584
Glen Lee299382c2015-10-20 17:13:56 +09002585 wilc1000_wlan_deinit(wl);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002586 wilc1000_wlan_init(dev, nic);
2587 g_wilc_initialized = 1;
2588 nic->iftype = interface_type;
2589
2590 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002591 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2592 host_int_set_MacAddress(wl->vif[0].hif_drv,
2593 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002594 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2595
2596 /*Add saved WEP keys, if any*/
2597 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002598 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002599 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002600 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002601 g_key_wep_params.key,
2602 g_key_wep_params.key_len,
2603 g_key_wep_params.key_idx);
2604 }
2605
2606 /*No matter the driver handler passed here, it will be overwriiten*/
2607 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2608 host_int_flush_join_req(priv->hWILCWFIDrv);
2609
2610 /*Add saved PTK and GTK keys, if any*/
2611 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2612 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2613 g_key_ptk_params.key[1],
2614 g_key_ptk_params.key[2]);
2615 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2616 g_key_gtk_params.key[1],
2617 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002618 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2619 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002620 g_add_ptk_key_params.key_idx,
2621 g_add_ptk_key_params.pairwise,
2622 g_add_ptk_key_params.mac_addr,
2623 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002624
Glen Lee299382c2015-10-20 17:13:56 +09002625 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2626 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002627 g_add_gtk_key_params.key_idx,
2628 g_add_gtk_key_params.pairwise,
2629 g_add_gtk_key_params.mac_addr,
2630 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002631 }
2632
Glen Lee299382c2015-10-20 17:13:56 +09002633 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002634 for (i = 0; i < num_reg_frame; i++) {
2635 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2636 nic->g_struct_frame_reg[i].reg);
2637 host_int_frame_register(priv->hWILCWFIDrv,
2638 nic->g_struct_frame_reg[i].frame_type,
2639 nic->g_struct_frame_reg[i].reg);
2640 }
2641 }
2642
Dean Lee72ed4dc2015-06-12 14:11:44 +09002643 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002644 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2645 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002646 break;
2647
2648 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002649 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002650 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2651 connecting = 0;
2652 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002653
Glen Lee299382c2015-10-20 17:13:56 +09002654 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2655 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002656
2657 dev->ieee80211_ptr->iftype = type;
2658 priv->wdev->iftype = type;
2659 nic->monitor_flag = 0;
2660
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002661 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2662 nic->iftype = CLIENT_MODE;
2663
2664
Glen Lee299382c2015-10-20 17:13:56 +09002665 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002666 /* ensure that the message Q is empty */
2667 host_int_wait_msg_queue_idle();
2668
Glen Lee299382c2015-10-20 17:13:56 +09002669 wilc1000_wlan_deinit(wl);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002670 wilc1000_wlan_init(dev, nic);
2671 g_wilc_initialized = 1;
2672
Glen Lee299382c2015-10-20 17:13:56 +09002673 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2674 host_int_set_MacAddress(wl->vif[0].hif_drv,
2675 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002676 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2677
2678 /*Add saved WEP keys, if any*/
2679 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002680 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002681 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002682 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002683 g_key_wep_params.key,
2684 g_key_wep_params.key_len,
2685 g_key_wep_params.key_idx);
2686 }
2687
2688 /*No matter the driver handler passed here, it will be overwriiten*/
2689 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2690 host_int_flush_join_req(priv->hWILCWFIDrv);
2691
2692 /*Add saved PTK and GTK keys, if any*/
2693 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2694 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2695 g_key_ptk_params.key[1],
2696 g_key_ptk_params.key[2]);
2697 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2698 g_key_gtk_params.key[1],
2699 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002700 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2701 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002702 g_add_ptk_key_params.key_idx,
2703 g_add_ptk_key_params.pairwise,
2704 g_add_ptk_key_params.mac_addr,
2705 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002706
Glen Lee299382c2015-10-20 17:13:56 +09002707 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2708 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002709 g_add_gtk_key_params.key_idx,
2710 g_add_gtk_key_params.pairwise,
2711 g_add_gtk_key_params.mac_addr,
2712 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002713 }
2714
2715 /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
Dean Lee72ed4dc2015-06-12 14:11:44 +09002716 refresh_scan(priv, 1, true);
2717 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002718
Glen Lee299382c2015-10-20 17:13:56 +09002719 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002720 for (i = 0; i < num_reg_frame; i++) {
2721 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2722 nic->g_struct_frame_reg[i].reg);
2723 host_int_frame_register(priv->hWILCWFIDrv,
2724 nic->g_struct_frame_reg[i].frame_type,
2725 nic->g_struct_frame_reg[i].reg);
2726 }
2727 }
2728 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002729 break;
2730
2731 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002732 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002733 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002734 dev->ieee80211_ptr->iftype = type;
2735 priv->wdev->iftype = type;
2736 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002737 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002738
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002739 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2740 linux_wlan_get_firmware(nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002741 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
Glen Lee299382c2015-10-20 17:13:56 +09002742 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002743 nic->iftype = AP_MODE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002744 mac_close(dev);
2745 mac_open(dev);
2746
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002747 for (i = 0; i < num_reg_frame; i++) {
2748 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2749 nic->g_struct_frame_reg[i].reg);
2750 host_int_frame_register(priv->hWILCWFIDrv,
2751 nic->g_struct_frame_reg[i].frame_type,
2752 nic->g_struct_frame_reg[i].reg);
2753 }
2754 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002755 break;
2756
2757 case NL80211_IFTYPE_P2P_GO:
2758 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2759
Dean Lee72ed4dc2015-06-12 14:11:44 +09002760 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002761 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002762 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002763 /*Delete block ack has to be the latest config packet*/
2764 /*sent before downloading new FW. This is because it blocks on*/
2765 /*hWaitResponse semaphore, which allows previous config*/
2766 /*packets to actually take action on old FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002767 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2768 wl->vif[0].bssid, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002769 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002770 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002771 dev->ieee80211_ptr->iftype = type;
2772 priv->wdev->iftype = type;
2773
Johnny Kim8a143302015-06-10 17:06:46 +09002774 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002775
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002776 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2777
2778
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002779 nic->iftype = GO_MODE;
2780
2781 /* ensure that the message Q is empty */
2782 host_int_wait_msg_queue_idle();
Glen Lee299382c2015-10-20 17:13:56 +09002783 wilc1000_wlan_deinit(wl);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002784 wilc1000_wlan_init(dev, nic);
2785 g_wilc_initialized = 1;
2786
2787
2788 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002789 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2790 host_int_set_MacAddress(wl->vif[0].hif_drv,
2791 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002792 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2793
2794 /*Add saved WEP keys, if any*/
2795 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002796 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002797 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002798 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002799 g_key_wep_params.key,
2800 g_key_wep_params.key_len,
2801 g_key_wep_params.key_idx);
2802 }
2803
2804 /*No matter the driver handler passed here, it will be overwriiten*/
2805 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2806 host_int_flush_join_req(priv->hWILCWFIDrv);
2807
2808 /*Add saved PTK and GTK keys, if any*/
2809 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2810 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2811 g_key_ptk_params.key[1],
2812 g_key_ptk_params.key[2],
2813 g_key_ptk_params.cipher);
2814 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2815 g_key_gtk_params.key[1],
2816 g_key_gtk_params.key[2],
2817 g_key_gtk_params.cipher);
Glen Lee299382c2015-10-20 17:13:56 +09002818 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2819 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002820 g_add_ptk_key_params.key_idx,
2821 g_add_ptk_key_params.pairwise,
2822 g_add_ptk_key_params.mac_addr,
2823 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002824
Glen Lee299382c2015-10-20 17:13:56 +09002825 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2826 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002827 g_add_gtk_key_params.key_idx,
2828 g_add_gtk_key_params.pairwise,
2829 g_add_gtk_key_params.mac_addr,
2830 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002831 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002832
Glen Lee299382c2015-10-20 17:13:56 +09002833 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002834 for (i = 0; i < num_reg_frame; i++) {
2835 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2836 nic->g_struct_frame_reg[i].reg);
2837 host_int_frame_register(priv->hWILCWFIDrv,
2838 nic->g_struct_frame_reg[i].frame_type,
2839 nic->g_struct_frame_reg[i].reg);
2840 }
2841 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002842 break;
2843
2844 default:
2845 PRINT_ER("Unknown interface type= %d\n", type);
Leo Kimaaed3292015-10-12 16:55:38 +09002846 return -EINVAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002847 }
2848
Leo Kimaaed3292015-10-12 16:55:38 +09002849 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002850}
2851
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002852/* (austin.2013-07-23)
2853 *
2854 * To support revised cfg80211_ops
2855 *
2856 * add_beacon --> start_ap
2857 * set_beacon --> change_beacon
2858 * del_beacon --> stop_ap
2859 *
2860 * beacon_parameters --> cfg80211_ap_settings
2861 * cfg80211_beacon_data
2862 *
2863 * applicable for linux kernel 3.4+
2864 */
2865
2866/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002867 * @brief start_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002868 * @details Add a beacon with given parameters, @head, @interval
2869 * and @dtim_period will be valid, @tail is optional.
2870 * @param[in] wiphy
2871 * @param[in] dev The net device structure
2872 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2873 * @return int : Return 0 on Success.
2874 * @author austin
2875 * @date 23 JUL 2013
2876 * @version 1.0
2877 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002878static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2879 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002880{
2881 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002882 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002883 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002884
2885 priv = wiphy_priv(wiphy);
2886 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2887
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302888 PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002889 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2890
Chaehyun Lim80785a92015-09-14 12:24:01 +09002891 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002892
Leo Kime6e12662015-09-16 18:36:03 +09002893 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002894 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002895
Tony Cho7e7fa472015-10-20 14:26:48 +09002896 linux_wlan_set_bssid(dev, g_linux_wlan->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002897
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002898 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2899 settings->beacon_interval,
2900 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002901 beacon->head_len, (u8 *)beacon->head,
2902 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002903
2904 return s32Error;
2905}
2906
2907/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002908 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002909 * @details Add a beacon with given parameters, @head, @interval
2910 * and @dtim_period will be valid, @tail is optional.
2911 * @param[in] wiphy
2912 * @param[in] dev The net device structure
2913 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2914 * @return int : Return 0 on Success.
2915 * @author austin
2916 * @date 23 JUL 2013
2917 * @version 1.0
2918 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002919static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2920 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002921{
Chaehyun Lim27268872015-09-15 14:06:13 +09002922 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002923 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002924
2925 priv = wiphy_priv(wiphy);
2926 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2927
2928
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002929 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2930 0,
2931 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002932 beacon->head_len, (u8 *)beacon->head,
2933 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002934
2935 return s32Error;
2936}
2937
2938/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002939 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002940 * @details Remove beacon configuration and stop sending the beacon.
2941 * @param[in]
2942 * @return int : Return 0 on Success.
2943 * @author austin
2944 * @date 23 JUL 2013
2945 * @version 1.0
2946 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002947static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002948{
Leo Kime6e12662015-09-16 18:36:03 +09002949 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002950 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002951 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002952
Leo Kim7ae43362015-09-16 18:35:59 +09002953 if (!wiphy)
2954 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002955
2956 priv = wiphy_priv(wiphy);
2957
2958 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2959
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002960 linux_wlan_set_bssid(dev, NullBssid);
2961
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002962 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002963
Leo Kim7dc1d0c2015-09-16 18:36:00 +09002964 if (s32Error)
2965 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002966
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002967 return s32Error;
2968}
2969
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002970/**
Chaehyun Limed269552015-09-14 12:24:15 +09002971 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002972 * @details Add a new station.
2973 * @param[in]
2974 * @return int : Return 0 on Success.
2975 * @author mdaftedar
2976 * @date 01 MAR 2012
2977 * @version 1.0
2978 */
Chaehyun Limed269552015-09-14 12:24:15 +09002979static int add_station(struct wiphy *wiphy, struct net_device *dev,
2980 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002981{
Leo Kime6e12662015-09-16 18:36:03 +09002982 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002983 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09002984 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002985 perInterface_wlan_t *nic;
2986
Leo Kim7ae43362015-09-16 18:35:59 +09002987 if (!wiphy)
2988 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002989
2990 priv = wiphy_priv(wiphy);
2991 nic = netdev_priv(dev);
2992
2993 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002994 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
2995 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002996 strStaParams.u16AssocID = params->aid;
2997 strStaParams.u8NumRates = params->supported_rates_len;
2998 strStaParams.pu8Rates = params->supported_rates;
2999
3000 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3001
3002 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],
3003 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
3004 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3005 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3006
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003007 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003008 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003009 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003010 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003011 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3012 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003013 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003014 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3015 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3016 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3017 }
3018
3019 strStaParams.u16FlagsMask = params->sta_flags_mask;
3020 strStaParams.u16FlagsSet = params->sta_flags_set;
3021
3022 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3023 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3024 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3025 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3026 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3027 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3028 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3029 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3030
3031 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003032 if (s32Error)
3033 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003034 }
3035
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003036 return s32Error;
3037}
3038
3039/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003040 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003041 * @details Remove a station; @mac may be NULL to remove all stations.
3042 * @param[in]
3043 * @return int : Return 0 on Success.
3044 * @author mdaftedar
3045 * @date 01 MAR 2012
3046 * @version 1.0
3047 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003048static int del_station(struct wiphy *wiphy, struct net_device *dev,
3049 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003050{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003051 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003052 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003053 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003054 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003055
Leo Kim7ae43362015-09-16 18:35:59 +09003056 if (!wiphy)
3057 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003058
3059 priv = wiphy_priv(wiphy);
3060 nic = netdev_priv(dev);
3061
3062 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3063 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3064
3065
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003066 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303067 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003068 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3069 } else {
3070 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]);
3071 }
3072
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003073 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003074
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003075 if (s32Error)
3076 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003077 }
3078 return s32Error;
3079}
3080
3081/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003082 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003083 * @details Modify a given station.
3084 * @param[in]
3085 * @return int : Return 0 on Success.
3086 * @author mdaftedar
3087 * @date 01 MAR 2012
3088 * @version 1.0
3089 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003090static int change_station(struct wiphy *wiphy, struct net_device *dev,
3091 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003092{
Leo Kime6e12662015-09-16 18:36:03 +09003093 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003094 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003095 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003096 perInterface_wlan_t *nic;
3097
3098
3099 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3100
Leo Kim7ae43362015-09-16 18:35:59 +09003101 if (!wiphy)
3102 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003103
3104 priv = wiphy_priv(wiphy);
3105 nic = netdev_priv(dev);
3106
3107 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003108 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003109 strStaParams.u16AssocID = params->aid;
3110 strStaParams.u8NumRates = params->supported_rates_len;
3111 strStaParams.pu8Rates = params->supported_rates;
3112
3113 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],
3114 strStaParams.au8BSSID[5]);
3115 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3116 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3117
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003118 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003119 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003120 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003121 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003122 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3123 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003124 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003125 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3126 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3127 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3128
3129 }
3130
3131 strStaParams.u16FlagsMask = params->sta_flags_mask;
3132 strStaParams.u16FlagsSet = params->sta_flags_set;
3133
3134 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3135 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3136 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3137 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3138 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3139 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3140 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3141 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3142
3143 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003144 if (s32Error)
3145 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003146 }
3147 return s32Error;
3148}
3149
3150
3151/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003152 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003153 * @details
3154 * @param[in]
3155 * @return int : Return 0 on Success.
3156 * @author mdaftedar
3157 * @date 01 JUL 2012
3158 * @version 1.0
3159 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003160static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3161 const char *name,
3162 unsigned char name_assign_type,
3163 enum nl80211_iftype type,
3164 u32 *flags,
3165 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003166{
3167 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003168 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003169 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003170
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003171 priv = wiphy_priv(wiphy);
3172
3173
3174
3175 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3176
3177 nic = netdev_priv(priv->wdev->netdev);
3178
3179
3180 if (type == NL80211_IFTYPE_MONITOR) {
3181 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3182 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3183 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3184 if (new_ifc != NULL) {
3185 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003186 nic = netdev_priv(priv->wdev->netdev);
3187 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003188 } else
3189 PRINT_ER("Error in initializing monitor interface\n ");
3190 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003191 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003192}
3193
3194/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003195 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003196 * @details
3197 * @param[in]
3198 * @return int : Return 0 on Success.
3199 * @author mdaftedar
3200 * @date 01 JUL 2012
3201 * @version 1.0
3202 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003203static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003204{
3205 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003206 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003207}
3208
Chaehyun Lim08241922015-09-15 14:06:12 +09003209static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003210
Chaehyun Lim80785a92015-09-14 12:24:01 +09003211 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003212 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003213 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003214 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003215 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003216 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003217 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003218 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003219 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003220 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003221 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003222
Chaehyun Lima13168d2015-09-14 12:24:12 +09003223 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003224 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003225 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003226 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003227 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003228 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003229 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003230 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003231 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003232 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003233
Chaehyun Lim4d466572015-09-14 12:24:22 +09003234 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003235 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003236 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003237 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003238 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003239 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003240 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003241 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003242 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003243 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003244
3245};
3246
3247
3248
3249
3250
3251/**
3252 * @brief WILC_WFI_update_stats
3253 * @details Modify parameters for a given BSS.
3254 * @param[in]
3255 * @return int : Return 0 on Success.
3256 * @author mdaftedar
3257 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003258 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003259 */
3260int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3261{
3262
Chaehyun Lim27268872015-09-15 14:06:13 +09003263 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003264
3265 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003266 switch (changed) {
3267
3268 case WILC_WFI_RX_PKT:
3269 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003270 priv->netstats.rx_packets++;
3271 priv->netstats.rx_bytes += pktlen;
3272 priv->netstats.rx_time = get_jiffies_64();
3273 }
3274 break;
3275
3276 case WILC_WFI_TX_PKT:
3277 {
3278 priv->netstats.tx_packets++;
3279 priv->netstats.tx_bytes += pktlen;
3280 priv->netstats.tx_time = get_jiffies_64();
3281
3282 }
3283 break;
3284
3285 default:
3286 break;
3287 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003288 return 0;
3289}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003290
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003291/**
3292 * @brief WILC_WFI_CfgAlloc
3293 * @details Allocation of the wireless device structure and assigning it
3294 * to the cfg80211 operations structure.
3295 * @param[in] NONE
3296 * @return wireless_dev : Returns pointer to wireless_dev structure.
3297 * @author mdaftedar
3298 * @date 01 MAR 2012
3299 * @version 1.0
3300 */
3301struct wireless_dev *WILC_WFI_CfgAlloc(void)
3302{
3303
3304 struct wireless_dev *wdev;
3305
3306
3307 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3308 /*Allocating the wireless device structure*/
3309 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3310 if (!wdev) {
3311 PRINT_ER("Cannot allocate wireless device\n");
3312 goto _fail_;
3313 }
3314
3315 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003316 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003317 if (!wdev->wiphy) {
3318 PRINT_ER("Cannot allocate wiphy\n");
3319 goto _fail_mem_;
3320
3321 }
3322
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003323 /* enable 802.11n HT */
3324 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3325 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3326 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3327 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3328 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003329
3330 /*wiphy bands*/
3331 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3332
3333 return wdev;
3334
3335_fail_mem_:
3336 kfree(wdev);
3337_fail_:
3338 return NULL;
3339
3340}
3341/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003342 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003343 * @details Registering of the wiphy structure and interface modes
3344 * @param[in] NONE
3345 * @return NONE
3346 * @author mdaftedar
3347 * @date 01 MAR 2012
3348 * @version 1.0
3349 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003350struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003351{
Chaehyun Lim27268872015-09-15 14:06:13 +09003352 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003353 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003354 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003355
3356 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3357
3358 wdev = WILC_WFI_CfgAlloc();
3359 if (wdev == NULL) {
3360 PRINT_ER("CfgAlloc Failed\n");
3361 return NULL;
3362 }
3363
3364
3365 /*Return hardware description structure (wiphy)'s priv*/
3366 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003367 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003368
3369 /*Link the wiphy with wireless structure*/
3370 priv->wdev = wdev;
3371
3372 /*Maximum number of probed ssid to be added by user for the scan request*/
3373 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003374 /*Maximum number of pmkids to be cashed*/
3375 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3376 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003377
3378 wdev->wiphy->max_scan_ie_len = 1000;
3379
3380 /*signal strength in mBm (100*dBm) */
3381 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3382
3383 /*Set the availaible cipher suites*/
3384 wdev->wiphy->cipher_suites = cipher_suites;
3385 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003386 /*Setting default managment types: for register action frame: */
3387 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003388
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003389 wdev->wiphy->max_remain_on_channel_duration = 500;
3390 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3391 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3392 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003393 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003394 wdev->iftype = NL80211_IFTYPE_STATION;
3395
3396
3397
3398 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3399 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3400 wdev->wiphy->interface_modes, wdev->iftype);
3401
3402 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003403 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003404 #endif
3405
3406 /*Register wiphy structure*/
3407 s32Error = wiphy_register(wdev->wiphy);
3408 if (s32Error) {
3409 PRINT_ER("Cannot register wiphy device\n");
3410 /*should define what action to be taken in such failure*/
3411 } else {
3412 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3413 }
3414
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003415 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003416 return wdev;
3417
3418
3419}
3420/**
3421 * @brief WILC_WFI_WiphyFree
3422 * @details Freeing allocation of the wireless device structure
3423 * @param[in] NONE
3424 * @return NONE
3425 * @author mdaftedar
3426 * @date 01 MAR 2012
3427 * @version 1.0
3428 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003429int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003430{
3431
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003432 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003433
Chaehyun Lim27268872015-09-15 14:06:13 +09003434 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003435
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003436 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3437 priv = wdev_priv(net->ieee80211_ptr);
3438 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003439 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003440 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003441 }
3442 op_ifcs++;
3443 if (s32Error < 0) {
3444 PRINT_ER("Failed to creat refresh Timer\n");
3445 return s32Error;
3446 }
3447
Dean Lee72ed4dc2015-06-12 14:11:44 +09003448 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003449
Dean Lee72ed4dc2015-06-12 14:11:44 +09003450 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003451
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003452 sema_init(&(priv->hSemScanReq), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003453 s32Error = host_int_init(&priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003454 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003455 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003456
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003457 return s32Error;
3458}
3459
3460/**
3461 * @brief WILC_WFI_WiphyFree
3462 * @details Freeing allocation of the wireless device structure
3463 * @param[in] NONE
3464 * @return NONE
3465 * @author mdaftedar
3466 * @date 01 MAR 2012
3467 * @version 1.0
3468 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003469int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003470{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003471 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003472
Chaehyun Lim27268872015-09-15 14:06:13 +09003473 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003474
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003475 priv = wdev_priv(net->ieee80211_ptr);
3476
Dean Lee72ed4dc2015-06-12 14:11:44 +09003477 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003478
Dean Lee72ed4dc2015-06-12 14:11:44 +09003479 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003480
3481 op_ifcs--;
3482
3483 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003484
3485 /* Clear the Shadow scan */
3486 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003487 if (op_ifcs == 0) {
3488 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003489 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003490 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003491
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003492 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003493 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003494
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003495 return s32Error;
3496}
3497
3498
3499/**
3500 * @brief WILC_WFI_WiphyFree
3501 * @details Freeing allocation of the wireless device structure
3502 * @param[in] NONE
3503 * @return NONE
3504 * @author mdaftedar
3505 * @date 01 MAR 2012
3506 * @version 1.0
3507 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003508void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003509{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003510 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3511
Chaehyun Lim619837a2015-09-20 15:51:10 +09003512 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003513 PRINT_D(INIT_DBG, "net_device is NULL\n");
3514 return;
3515 }
3516
Chaehyun Lim619837a2015-09-20 15:51:10 +09003517 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003518 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3519 return;
3520 }
3521
Chaehyun Lim619837a2015-09-20 15:51:10 +09003522 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003523 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3524 return;
3525 }
3526
3527 wiphy_unregister(net->ieee80211_ptr->wiphy);
3528
3529 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3530 wiphy_free(net->ieee80211_ptr->wiphy);
3531 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003532}