blob: 15338049042514926bb056328a8f767a161c5764 [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};
Glen Leec1ec2c12015-10-20 17:13:58 +0900540 struct wilc *wl;
541 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900542
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900543 connecting = 0;
544
Chaehyun Lim27268872015-09-15 14:06:13 +0900545 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900546 dev = priv->dev;
Glen Leec1ec2c12015-10-20 17:13:58 +0900547 nic = netdev_priv(dev);
548 wl = nic->wilc;
Leo Kim441dc602015-10-12 16:55:35 +0900549 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900550
551 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
552 /*Initialization*/
Amitoj Kaur Chawlababa7c72015-10-15 13:48:29 +0530553 u16 u16ConnectStatus;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900554
555 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
556
557 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
558
559 if ((u8MacStatus == MAC_DISCONNECTED) &&
560 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
561 /* The case here is that our station was waiting for association response frame and has just received it containing status code
562 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
563 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
564 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530565 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900567 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568 if (!pstrWFIDrv->u8P2PConnect)
569 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530571 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900572 }
573
574 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900575 bool bNeedScanRefresh = false;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900576 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577
578 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
579 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900580 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900582
583 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900584 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900585 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
586 unsigned long now = jiffies;
587
588 if (time_after(now,
589 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900590 bNeedScanRefresh = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591 }
592
593 break;
594 }
595 }
596
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000597 if (bNeedScanRefresh) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900598 /*Also, refrsh DIRECT- results if */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900599 refresh_scan(priv, 1, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900600
601 }
602
603 }
604
605
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530606 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900607
608 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
609
610 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
611 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
612 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
613 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
614 /* be replaced by pstrConnectInfo->u16ConnectStatus */
615 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900616 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900617 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
618 pstrDisconnectNotifInfo->u16reason, priv->dev);
619 u8P2Plocalrandom = 0x01;
620 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900621 bWilc_ie = false;
Shraddha Barkebcf02652015-10-05 17:00:32 +0530622 eth_zero_addr(priv->au8AssociatedBss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530624 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900626 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 if (!pstrWFIDrv->u8P2PConnect)
628 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900629 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
630 * virtual interface to station*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900631 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900632 pstrDisconnectNotifInfo->u16reason = 3;
633 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900634 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
635 * to scan again and retry the connection*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900636 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900637 pstrDisconnectNotifInfo->u16reason = 1;
638 }
639 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
Sudip Mukherjeee26bb712015-06-30 13:51:51 +0530640 pstrDisconnectNotifInfo->ie_len, false,
641 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900642
643 }
644
645}
646
647
648/**
Chaehyun Lim80785a92015-09-14 12:24:01 +0900649 * @brief set_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900650 * @details Set channel for a given wireless interface. Some devices
651 * may support multi-channel operation (by channel hopping) so cfg80211
652 * doesn't verify much. Note, however, that the passed netdev may be
653 * %NULL as well if the user requested changing the channel for the
654 * device itself, or for a monitor interface.
655 * @param[in]
656 * @return int : Return 0 on Success
657 * @author mdaftedar
658 * @date 01 MAR 2012
659 * @version 1.0
660 */
Chaehyun Lim80785a92015-09-14 12:24:01 +0900661static int set_channel(struct wiphy *wiphy,
662 struct cfg80211_chan_def *chandef)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900663{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900664 u32 channelnum = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +0900665 struct wilc_priv *priv;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900666 int result = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900667
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668 priv = wiphy_priv(wiphy);
669
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900670 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
671 PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900672
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900673 curr_channel = channelnum;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900674 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900675
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900676 if (result != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677 PRINT_ER("Error in setting channel %d\n", channelnum);
678
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900679 return result;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900680}
681
682/**
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900683 * @brief scan
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900684 * @details Request to do a scan. If returning zero, the scan request is given
685 * the driver, and will be valid until passed to cfg80211_scan_done().
686 * For scan results, call cfg80211_inform_bss(); you can call this outside
687 * the scan/scan_done bracket too.
688 * @param[in]
689 * @return int : Return 0 on Success
690 * @author mabubakr
691 * @date 01 MAR 2012
692 * @version 1.0
693 */
694
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900695static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900696{
Chaehyun Lim27268872015-09-15 14:06:13 +0900697 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900698 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900699 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900700 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
Leo Kim607db442015-10-05 15:25:37 +0900701 struct hidden_network strHiddenNetwork;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900702
703 priv = wiphy_priv(wiphy);
704
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900705 priv->pstrScanReq = request;
706
707 priv->u32RcvdChCount = 0;
708
Johnny Kim218dc402015-08-13 13:41:19 +0900709 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900710
711
712 reset_shadow_found(priv);
713
Dean Lee72ed4dc2015-06-12 14:11:44 +0900714 priv->bCfgScanning = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900715 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
716 /* max_scan_ssids */
717 for (i = 0; i < request->n_channels; i++) {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900718 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900719 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
720 }
721
722 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530723 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900724
725 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
726
727 if (request->n_ssids >= 1) {
728
729
Leo Kim607db442015-10-05 15:25:37 +0900730 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 strHiddenNetwork.u8ssidnum = request->n_ssids;
732
733
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900734 for (i = 0; i < request->n_ssids; i++) {
735
736 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
Glen Leef3052582015-09-10 12:03:04 +0900737 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900738 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900739 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
740 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530741 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900742 strHiddenNetwork.u8ssidnum -= 1;
743 }
744 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530745 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900746 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
747 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900748 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 CfgScanResult, (void *)priv, &strHiddenNetwork);
750 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530751 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900752 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
753 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900754 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900755 CfgScanResult, (void *)priv, NULL);
756 }
757
758 } else {
759 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530760 " channels\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900761 }
762
Leo Kime6e12662015-09-16 18:36:03 +0900763 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900764 s32Error = -EBUSY;
765 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
766 }
767
768 return s32Error;
769}
770
771/**
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900772 * @brief connect
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900773 * @details Connect to the ESS with the specified parameters. When connected,
774 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
775 * If the connection fails for some reason, call cfg80211_connect_result()
776 * with the status from the AP.
777 * @param[in]
778 * @return int : Return 0 on Success
779 * @author mabubakr
780 * @date 01 MAR 2012
781 * @version 1.0
782 */
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900783static int connect(struct wiphy *wiphy, struct net_device *dev,
784 struct cfg80211_connect_params *sme)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900785{
Leo Kime6e12662015-09-16 18:36:03 +0900786 s32 s32Error = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900787 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900788 u8 u8security = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +0900789 enum AUTHTYPE tenuAuth_type = ANY;
Dean Lee576917a2015-06-15 11:58:57 +0900790 char *pcgroup_encrypt_val = NULL;
791 char *pccipher_group = NULL;
792 char *pcwpa_version = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900793
Chaehyun Lim27268872015-09-15 14:06:13 +0900794 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +0900795 struct host_if_drv *pstrWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900796 tstrNetworkInfo *pstrNetworkInfo = NULL;
797
798
799 connecting = 1;
800 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +0900801 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900802
Johnny Kim218dc402015-08-13 13:41:19 +0900803 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900804
Johnny Kim8a143302015-06-10 17:06:46 +0900805 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 +0900806 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900807 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
808 pstrWFIDrv->u8P2PConnect = 1;
809 } else
810 pstrWFIDrv->u8P2PConnect = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530811 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900812
813 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
814 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900815 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900816 sme->ssid,
817 sme->ssid_len) == 0) {
818 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
819 if (sme->bssid == NULL) {
820 /* BSSID is not passed from the user, so decision of matching
821 * is done by SSID only */
822 PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n");
823 break;
824 } else {
825 /* BSSID is also passed from the user, so decision of matching
826 * should consider also this passed BSSID */
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900827 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900828 sme->bssid,
829 ETH_ALEN) == 0) {
830 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
831 break;
832 }
833 }
834 }
835 }
836
837 if (i < u32LastScannedNtwrksCountShadow) {
838 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
839
840 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
841
842 PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n",
843 pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1],
844 pstrNetworkInfo->au8bssid[2], pstrNetworkInfo->au8bssid[3],
845 pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]);
846 } else {
847 s32Error = -ENOENT;
848 if (u32LastScannedNtwrksCountShadow == 0)
849 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
850 else
851 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
852
853 goto done;
854 }
855
856 priv->WILC_WFI_wep_default = 0;
Chaehyun Lim2cc46832015-08-07 09:02:01 +0900857 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
858 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900859
860 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
861 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
862
863 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
864
865 if (INFO) {
866 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
867 PRINT_D(CORECONFIG_DBG, "sme->crypto.ciphers_pairwise[%d]=%x\n", i, sme->crypto.ciphers_pairwise[i]);
868 }
869
870 if (sme->crypto.cipher_group != NO_ENCRYPT) {
871 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
872 * we will add to it the pairwise cipher suite(s) */
873 pcwpa_version = "Default";
874 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900875 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900876 u8security = ENCRYPT_ENABLED | WEP;
877 pcgroup_encrypt_val = "WEP40";
878 pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
879 PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
880
881 if (INFO) {
882 for (i = 0; i < sme->key_len; i++)
883 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
884 }
885 priv->WILC_WFI_wep_default = sme->key_idx;
886 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900887 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900888
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900889 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900890 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900891 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
892 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900893 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894
895 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
896 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
897 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900898 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
899 pcgroup_encrypt_val = "WEP104";
900 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
901
902 priv->WILC_WFI_wep_default = sme->key_idx;
903 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900904 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900905
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900906 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900907 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900908 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
909 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900910 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900911
912 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
913 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
914 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900915 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900916 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
917 pcgroup_encrypt_val = "WPA2_TKIP";
918 pccipher_group = "TKIP";
919 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
920 /* tenuSecurity_t = WPA2_AES; */
921 u8security = ENCRYPT_ENABLED | WPA2 | AES;
922 pcgroup_encrypt_val = "WPA2_AES";
923 pccipher_group = "AES";
924 }
925 pcwpa_version = "WPA_VERSION_2";
926 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
927 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900928 u8security = ENCRYPT_ENABLED | WPA | TKIP;
929 pcgroup_encrypt_val = "WPA_TKIP";
930 pccipher_group = "TKIP";
931 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
932 /* tenuSecurity_t = WPA_AES; */
933 u8security = ENCRYPT_ENABLED | WPA | AES;
934 pcgroup_encrypt_val = "WPA_AES";
935 pccipher_group = "AES";
936
937 }
938 pcwpa_version = "WPA_VERSION_1";
939
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900940 } else {
941 s32Error = -ENOTSUPP;
942 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
943
944 goto done;
945 }
946
947 }
948
949 /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will
950 * add to it the pairwise cipher suite(s) */
951 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
952 || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
953 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
954 if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) {
955 u8security = u8security | TKIP;
956 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
957 u8security = u8security | AES;
958 }
959 }
960 }
961
962 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
963
964 PRINT_D(CFG80211_DBG, "Authentication Type = %d\n", sme->auth_type);
965 switch (sme->auth_type) {
966 case NL80211_AUTHTYPE_OPEN_SYSTEM:
967 PRINT_D(CFG80211_DBG, "In OPEN SYSTEM\n");
968 tenuAuth_type = OPEN_SYSTEM;
969 break;
970
971 case NL80211_AUTHTYPE_SHARED_KEY:
972 tenuAuth_type = SHARED_KEY;
973 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
974 break;
975
976 default:
977 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
978 }
979
980
981 /* ai: key_mgmt: enterprise case */
982 if (sme->crypto.n_akm_suites) {
983 switch (sme->crypto.akm_suites[0]) {
984 case WLAN_AKM_SUITE_8021X:
985 tenuAuth_type = IEEE8021;
986 break;
987
988 default:
989 break;
990 }
991 }
992
993
994 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
995
996 PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
997 pcgroup_encrypt_val, pccipher_group, pcwpa_version);
998
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900999 curr_channel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001000
1001 if (!pstrWFIDrv->u8P2PConnect) {
1002 u8WLANChannel = pstrNetworkInfo->u8channel;
1003 }
1004
1005 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1006
1007 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1008 sme->ssid_len, sme->ie, sme->ie_len,
1009 CfgConnectResult, (void *)priv, u8security,
1010 tenuAuth_type, pstrNetworkInfo->u8channel,
1011 pstrNetworkInfo->pJoinParams);
Leo Kime6e12662015-09-16 18:36:03 +09001012 if (s32Error != 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301013 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001014 s32Error = -ENOENT;
1015 goto done;
1016 }
1017
1018done:
1019
1020 return s32Error;
1021}
1022
1023
1024/**
Chaehyun Limb027cde2015-09-14 12:24:04 +09001025 * @brief disconnect
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001026 * @details Disconnect from the BSS/ESS.
1027 * @param[in]
1028 * @return int : Return 0 on Success
1029 * @author mdaftedar
1030 * @date 01 MAR 2012
1031 * @version 1.0
1032 */
Chaehyun Limb027cde2015-09-14 12:24:04 +09001033static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001034{
Leo Kime6e12662015-09-16 18:36:03 +09001035 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001036 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09001037 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001038 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001039
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001040 connecting = 0;
1041 priv = wiphy_priv(wiphy);
1042
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001043 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kim441dc602015-10-12 16:55:35 +09001044 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001045 if (!pstrWFIDrv->u8P2PConnect)
1046 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001047 linux_wlan_set_bssid(priv->dev, NullBssid);
1048
1049 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1050
1051 u8P2Plocalrandom = 0x01;
1052 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +09001053 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001054 pstrWFIDrv->u64P2p_MgmtTimeout = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055
1056 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
Leo Kime6e12662015-09-16 18:36:03 +09001057 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001058 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1059 s32Error = -EINVAL;
1060 }
1061
1062 return s32Error;
1063}
1064
1065/**
Chaehyun Lim953d4172015-09-14 12:24:05 +09001066 * @brief add_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001067 * @details Add a key with the given parameters. @mac_addr will be %NULL
1068 * when adding a group key.
1069 * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1070 * @return int : Return 0 on Success
1071 * @author mdaftedar
1072 * @date 01 MAR 2012
1073 * @version 1.0
1074 */
Chaehyun Lim953d4172015-09-14 12:24:05 +09001075static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1076 bool pairwise,
1077 const u8 *mac_addr, struct key_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001078
1079{
Leo Kime6e12662015-09-16 18:36:03 +09001080 s32 s32Error = 0, KeyLen = params->key_len;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001081 u32 i;
Chaehyun Lim27268872015-09-15 14:06:13 +09001082 struct wilc_priv *priv;
Arnd Bergmann057d1e92015-06-01 21:06:44 +02001083 const u8 *pu8RxMic = NULL;
1084 const u8 *pu8TxMic = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001085 u8 u8mode = NO_ENCRYPT;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001086 u8 u8gmode = NO_ENCRYPT;
1087 u8 u8pmode = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +09001088 enum AUTHTYPE tenuAuth_type = ANY;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001089
1090 priv = wiphy_priv(wiphy);
1091
1092 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1093
Johnny Kim8a143302015-06-10 17:06:46 +09001094 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001095
1096 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1097 params->key[1],
1098 params->key[2]);
1099
1100
1101 switch (params->cipher) {
1102 case WLAN_CIPHER_SUITE_WEP40:
1103 case WLAN_CIPHER_SUITE_WEP104:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001104 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1105
1106 priv->WILC_WFI_wep_default = key_index;
1107 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001108 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001109
1110 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1111 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1112
1113 for (i = 0; i < params->key_len; i++)
1114 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1115
1116 tenuAuth_type = OPEN_SYSTEM;
1117
1118 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1119 u8mode = ENCRYPT_ENABLED | WEP;
1120 else
1121 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1122
1123 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1124 break;
1125 }
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001126 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001127 priv->WILC_WFI_wep_default = key_index;
1128 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001129 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001130
1131 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1132 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1133 if (INFO) {
1134 for (i = 0; i < params->key_len; i++)
1135 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1136 }
1137 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1138 }
1139
1140 break;
1141
1142 case WLAN_CIPHER_SUITE_TKIP:
1143 case WLAN_CIPHER_SUITE_CCMP:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001144 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1145
1146 if (priv->wilc_gtk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001147 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001148 priv->wilc_gtk[key_index]->key = NULL;
1149 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001150
1151 }
1152 if (priv->wilc_ptk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001153 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001154 priv->wilc_ptk[key_index]->key = NULL;
1155 priv->wilc_ptk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001156 }
1157
1158
1159
Daniel Machon19132212015-08-05 08:18:31 +02001160 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001161 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1162 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1163 else
1164 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1165
1166 priv->wilc_groupkey = u8gmode;
1167
1168 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1169
1170 pu8TxMic = params->key + 24;
1171 pu8RxMic = params->key + 16;
1172 KeyLen = params->key_len - 16;
1173 }
1174 /* 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 +05301175 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001176
Glen Leef3052582015-09-10 12:03:04 +09001177 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001178 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001179
1180 /* 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 +05301181 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182
1183 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001184 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001185 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001186 }
1187
1188 priv->wilc_gtk[key_index]->cipher = params->cipher;
1189 priv->wilc_gtk[key_index]->key_len = params->key_len;
1190 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1191
1192 if (INFO) {
1193 for (i = 0; i < params->key_len; i++)
1194 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1195 for (i = 0; i < params->seq_len; i++)
1196 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1197 }
1198
1199
1200 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1201 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1202
1203 } else {
1204 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]);
1205
1206 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1207 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1208 else
1209 u8pmode = priv->wilc_groupkey | AES;
1210
1211
1212 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1213
1214 pu8TxMic = params->key + 24;
1215 pu8RxMic = params->key + 16;
1216 KeyLen = params->key_len - 16;
1217 }
1218
Shraddha Barkecccfc392015-10-12 20:49:19 +05301219 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001220
Glen Leef3052582015-09-10 12:03:04 +09001221 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001222
Shraddha Barkecccfc392015-10-12 20:49:19 +05301223 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001224
1225 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001226 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001227
1228 if (INFO) {
1229 for (i = 0; i < params->key_len; i++)
1230 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1231
1232 for (i = 0; i < params->seq_len; i++)
1233 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1234 }
1235
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001236 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001237
1238 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001239 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001240
1241 priv->wilc_ptk[key_index]->cipher = params->cipher;
1242 priv->wilc_ptk[key_index]->key_len = params->key_len;
1243 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1244
1245 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1246 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1247 }
1248 break;
1249 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001250
1251 {
1252 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001253 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001254 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1255 /* swap the tx mic by rx mic */
1256 pu8RxMic = params->key + 24;
1257 pu8TxMic = params->key + 16;
1258 KeyLen = params->key_len - 16;
1259 }
1260
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001261 /*save keys only on interface 0 (wifi interface)*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001262 if (!g_gtk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001263 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001265 if (!mac_addr) {
1266 g_add_gtk_key_params.mac_addr = NULL;
1267 } else {
Glen Leef3052582015-09-10 12:03:04 +09001268 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001269 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1270 }
1271 g_key_gtk_params.key_len = params->key_len;
1272 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001273 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001274 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1275 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001276 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001277 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1278 }
1279 g_key_gtk_params.cipher = params->cipher;
1280
1281 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1282 g_key_gtk_params.key[1],
1283 g_key_gtk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001284 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001285 }
1286
1287 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1288 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001289 } else {
1290 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1291 /* swap the tx mic by rx mic */
1292 pu8RxMic = params->key + 24;
1293 pu8TxMic = params->key + 16;
1294 KeyLen = params->key_len - 16;
1295 }
1296
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001297 /*save keys only on interface 0 (wifi interface)*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001298 if (!g_ptk_keys_saved && netdev == g_linux_wlan->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001299 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001300 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301 if (!mac_addr) {
1302 g_add_ptk_key_params.mac_addr = NULL;
1303 } else {
Glen Leef3052582015-09-10 12:03:04 +09001304 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001305 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1306 }
1307 g_key_ptk_params.key_len = params->key_len;
1308 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001309 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001310 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1311 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001312 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001313 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1314 }
1315 g_key_ptk_params.cipher = params->cipher;
1316
1317 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1318 g_key_ptk_params.key[1],
1319 g_key_ptk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001320 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001321 }
1322
1323 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1324 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1325 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1326 if (INFO) {
1327 for (i = 0; i < params->key_len; i++)
1328 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1329 }
1330 }
1331 }
1332 break;
1333
1334 default:
1335 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1336 s32Error = -ENOTSUPP;
1337
1338 }
1339
1340 return s32Error;
1341}
1342
1343/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001344 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001345 * @details Remove a key given the @mac_addr (%NULL for a group key)
1346 * and @key_index, return -ENOENT if the key doesn't exist.
1347 * @param[in]
1348 * @return int : Return 0 on Success
1349 * @author mdaftedar
1350 * @date 01 MAR 2012
1351 * @version 1.0
1352 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001353static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1354 u8 key_index,
1355 bool pairwise,
1356 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001357{
Chaehyun Lim27268872015-09-15 14:06:13 +09001358 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001359
1360 priv = wiphy_priv(wiphy);
1361
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001362 /*delete saved keys, if any*/
Tony Cho817f3fb2015-10-20 14:26:51 +09001363 if (netdev == g_linux_wlan->vif[0].ndev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001364 g_ptk_keys_saved = false;
1365 g_gtk_keys_saved = false;
1366 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367
1368 /*Delete saved WEP keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301369 kfree(g_key_wep_params.key);
1370 g_key_wep_params.key = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001371
1372 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1373
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374 if ((priv->wilc_gtk[key_index]) != NULL) {
1375
Shraddha Barkecccfc392015-10-12 20:49:19 +05301376 kfree(priv->wilc_gtk[key_index]->key);
1377 priv->wilc_gtk[key_index]->key = NULL;
1378 kfree(priv->wilc_gtk[key_index]->seq);
1379 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001380
Chaehyun Lim49188af2015-08-11 10:32:41 +09001381 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001382 priv->wilc_gtk[key_index] = NULL;
1383
1384 }
1385
1386 if ((priv->wilc_ptk[key_index]) != NULL) {
1387
Shraddha Barkecccfc392015-10-12 20:49:19 +05301388 kfree(priv->wilc_ptk[key_index]->key);
1389 priv->wilc_ptk[key_index]->key = NULL;
1390 kfree(priv->wilc_ptk[key_index]->seq);
1391 priv->wilc_ptk[key_index]->seq = NULL;
Chaehyun Lim49188af2015-08-11 10:32:41 +09001392 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001393 priv->wilc_ptk[key_index] = NULL;
1394 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001395
1396 /*Delete saved PTK and GTK keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301397 kfree(g_key_ptk_params.key);
1398 g_key_ptk_params.key = NULL;
1399 kfree(g_key_ptk_params.seq);
1400 g_key_ptk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001401
Shraddha Barkecccfc392015-10-12 20:49:19 +05301402 kfree(g_key_gtk_params.key);
1403 g_key_gtk_params.key = NULL;
1404 kfree(g_key_gtk_params.seq);
1405 g_key_gtk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001406
1407 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Dean Lee72ed4dc2015-06-12 14:11:44 +09001408 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409 }
1410
1411 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001412 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001413 priv->WILC_WFI_wep_key_len[key_index] = 0;
1414
1415 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1416 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1417 } else {
1418 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1419 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1420 }
1421
Leo Kimaaed3292015-10-12 16:55:38 +09001422 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001423}
1424
1425/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001426 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001427 * @details Get information about the key with the given parameters.
1428 * @mac_addr will be %NULL when requesting information for a group
1429 * key. All pointers given to the @callback function need not be valid
1430 * after it returns. This function should return an error if it is
1431 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1432 * @param[in]
1433 * @return int : Return 0 on Success
1434 * @author mdaftedar
1435 * @date 01 MAR 2012
1436 * @version 1.0
1437 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001438static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1439 bool pairwise,
1440 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001441{
Chaehyun Lim27268872015-09-15 14:06:13 +09001442 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001443 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001444 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001445
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446 priv = wiphy_priv(wiphy);
1447
1448
Alison Schofield3604af52015-10-12 13:22:44 -07001449 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001450 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1451
1452 key_params.key = priv->wilc_gtk[key_index]->key;
1453 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1454 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1455 key_params.seq = priv->wilc_gtk[key_index]->seq;
1456 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1457 if (INFO) {
1458 for (i = 0; i < key_params.key_len; i++)
1459 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1460 }
1461 } else {
1462 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1463
1464 key_params.key = priv->wilc_ptk[key_index]->key;
1465 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1466 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1467 key_params.seq = priv->wilc_ptk[key_index]->seq;
1468 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1469 }
1470
1471 callback(cookie, &key_params);
1472
Leo Kimaaed3292015-10-12 16:55:38 +09001473 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001474}
1475
1476/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001477 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001478 * @details Set the default management frame key on an interface
1479 * @param[in]
1480 * @return int : Return 0 on Success.
1481 * @author mdaftedar
1482 * @date 01 MAR 2012
1483 * @version 1.0
1484 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001485static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1486 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001487{
Chaehyun Lim27268872015-09-15 14:06:13 +09001488 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001489
1490
1491 priv = wiphy_priv(wiphy);
1492
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301493 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494
1495 if (key_index != priv->WILC_WFI_wep_default) {
1496
1497 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
1498 }
1499
Leo Kimaaed3292015-10-12 16:55:38 +09001500 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001501}
1502
1503/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001504 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001505 * @details Get station information for the station identified by @mac
1506 * @param[in] NONE
1507 * @return int : Return 0 on Success.
1508 * @author mdaftedar
1509 * @date 01 MAR 2012
1510 * @version 1.0
1511 */
1512
Chaehyun Limf06f5622015-09-14 12:24:18 +09001513static int get_station(struct wiphy *wiphy, struct net_device *dev,
1514 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001515{
Chaehyun Lim27268872015-09-15 14:06:13 +09001516 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001517 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001518 u32 i = 0;
1519 u32 associatedsta = 0;
1520 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001521 priv = wiphy_priv(wiphy);
1522 nic = netdev_priv(dev);
1523
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1525 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1526
1527 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1528
1529 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1530
1531 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1532 associatedsta = i;
1533 break;
1534 }
1535
1536 }
1537
1538 if (associatedsta == -1) {
Leo Kimaaed3292015-10-12 16:55:38 +09001539 PRINT_ER("Station required is not associated\n");
1540 return -ENOENT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001541 }
1542
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001543 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001544
1545 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1546 sinfo->inactive_time = 1000 * inactive_time;
1547 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1548
1549 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001550
1551 if (nic->iftype == STATION_MODE) {
Leo Kim03e7b9c2015-10-12 16:55:58 +09001552 struct rf_info strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001553
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001554 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1555
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001556 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301557 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001558 BIT(NL80211_STA_INFO_TX_PACKETS) |
1559 BIT(NL80211_STA_INFO_TX_FAILED) |
1560 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561
1562 sinfo->signal = strStatistics.s8RSSI;
1563 sinfo->rx_packets = strStatistics.u32RxCount;
1564 sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001565 sinfo->tx_failed = strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001566 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1567
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301568 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001569 Enable_TCP_ACK_Filter(true);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301570 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001571 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001572
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001573 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1574 sinfo->tx_failed, sinfo->txrate.legacy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001575 }
Leo Kimaaed3292015-10-12 16:55:38 +09001576 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001577}
1578
1579
1580/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001581 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001582 * @details Modify parameters for a given BSS.
1583 * @param[in]
1584 * -use_cts_prot: Whether to use CTS protection
1585 * (0 = no, 1 = yes, -1 = do not change)
1586 * -use_short_preamble: Whether the use of short preambles is allowed
1587 * (0 = no, 1 = yes, -1 = do not change)
1588 * -use_short_slot_time: Whether the use of short slot time is allowed
1589 * (0 = no, 1 = yes, -1 = do not change)
1590 * -basic_rates: basic rates in IEEE 802.11 format
1591 * (or NULL for no change)
1592 * -basic_rates_len: number of basic rates
1593 * -ap_isolate: do not forward packets between connected stations
1594 * -ht_opmode: HT Operation mode
1595 * (u16 = opmode, -1 = do not change)
1596 * @return int : Return 0 on Success.
1597 * @author mdaftedar
1598 * @date 01 MAR 2012
1599 * @version 1.0
1600 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001601static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1602 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001603{
1604 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1605 return 0;
1606}
1607
1608/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001609 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001610 * @details Notify that wiphy parameters have changed;
1611 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1612 * have changed.
1613 * @return int : Return 0 on Success
1614 * @author mdaftedar
1615 * @date 01 MAR 2012
1616 * @version 1.0
1617 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001618static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001619{
Leo Kime6e12662015-09-16 18:36:03 +09001620 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001621 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001622 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001623
1624 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001625
Tony Cho87c05b22015-10-12 16:56:07 +09001626 pstrCfgParamVal.flag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301627 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001628
1629 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1630 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1631 priv->dev->ieee80211_ptr->wiphy->retry_short);
Tony Cho87c05b22015-10-12 16:56:07 +09001632 pstrCfgParamVal.flag |= RETRY_SHORT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001633 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1634 }
1635 if (changed & WIPHY_PARAM_RETRY_LONG) {
1636
1637 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 +09001638 pstrCfgParamVal.flag |= RETRY_LONG;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001639 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1640
1641 }
1642 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1643 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 +09001644 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001645 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1646
1647 }
1648
1649 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1650 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1651
Tony Cho87c05b22015-10-12 16:56:07 +09001652 pstrCfgParamVal.flag |= RTS_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001653 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1654
1655 }
1656
1657 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1658 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1659 if (s32Error)
1660 PRINT_ER("Error in setting WIPHY PARAMS\n");
1661
1662
1663 return s32Error;
1664}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001665
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001666/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001667 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001668 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1669 * devices running firmwares capable of generating the (re) association
1670 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1671 * @param[in]
1672 * @return int : Return 0 on Success
1673 * @author mdaftedar
1674 * @date 01 MAR 2012
1675 * @version 1.0
1676 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001677static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1678 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001679{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001680 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001681 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001682 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001683
Chaehyun Lim27268872015-09-15 14:06:13 +09001684 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001685
1686 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1687
1688
1689 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001690 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691 ETH_ALEN)) {
1692 /*If bssid already exists and pmkid value needs to reset*/
1693 flag = PMKID_FOUND;
1694 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1695 break;
1696 }
1697 }
1698 if (i < WILC_MAX_NUM_PMKIDS) {
1699 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001700 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001701 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001702 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001703 PMKID_LEN);
1704 if (!(flag == PMKID_FOUND))
1705 priv->pmkid_list.numpmkid++;
1706 } else {
1707 PRINT_ER("Invalid PMKID index\n");
1708 s32Error = -EINVAL;
1709 }
1710
1711 if (!s32Error) {
1712 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1713 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1714 }
1715 return s32Error;
1716}
1717
1718/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001719 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001720 * @details Delete a cached PMKID.
1721 * @param[in]
1722 * @return int : Return 0 on Success
1723 * @author mdaftedar
1724 * @date 01 MAR 2012
1725 * @version 1.0
1726 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001727static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1728 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001729{
1730
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001731 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001732 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001733
Chaehyun Lim27268872015-09-15 14:06:13 +09001734 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001735
1736 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1737
1738 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001739 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001740 ETH_ALEN)) {
1741 /*If bssid is found, reset the values*/
1742 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001743 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001744 break;
1745 }
1746 }
1747
1748 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1749 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001750 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001751 priv->pmkid_list.pmkidlist[i + 1].bssid,
1752 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001753 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001754 priv->pmkid_list.pmkidlist[i].pmkid,
1755 PMKID_LEN);
1756 }
1757 priv->pmkid_list.numpmkid--;
1758 } else {
1759 s32Error = -EINVAL;
1760 }
1761
1762 return s32Error;
1763}
1764
1765/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001766 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001767 * @details Flush all cached PMKIDs.
1768 * @param[in]
1769 * @return int : Return 0 on Success
1770 * @author mdaftedar
1771 * @date 01 MAR 2012
1772 * @version 1.0
1773 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001774static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001775{
Chaehyun Lim27268872015-09-15 14:06:13 +09001776 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001777
1778 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1779
1780 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001781 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001782
1783 return 0;
1784}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001785
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001786
1787/**
1788 * @brief WILC_WFI_CfgParseRxAction
1789 * @details Function parses the received frames and modifies the following attributes:
1790 * -GO Intent
1791 * -Channel list
1792 * -Operating Channel
1793 *
1794 * @param[in] u8* Buffer, u32 length
1795 * @return NONE.
1796 * @author mdaftedar
1797 * @date 12 DEC 2012
1798 * @version
1799 */
1800
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001801void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001802{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001803 u32 index = 0;
1804 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001805
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001806 u8 op_channel_attr_index = 0;
1807 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808
1809 while (index < len) {
1810 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001812 }
1813
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301814 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001815 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301816 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001817 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001818 index += buf[index + 1] + 3; /* ID,Length byte */
1819 }
Alison Schofield3604af52015-10-12 13:22:44 -07001820 if (u8WLANChannel != INVALID_CHANNEL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001821
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001822 /*Modify channel list attribute*/
1823 if (channel_list_attr_index) {
1824 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1825 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1826 if (buf[i] == 0x51) {
1827 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1828 buf[j] = u8WLANChannel;
1829 }
1830 break;
1831 }
1832 }
1833 }
1834 /*Modify operating channel attribute*/
1835 if (op_channel_attr_index) {
1836 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1837 buf[op_channel_attr_index + 6] = 0x51;
1838 buf[op_channel_attr_index + 7] = u8WLANChannel;
1839 }
1840 }
1841}
1842
1843/**
1844 * @brief WILC_WFI_CfgParseTxAction
1845 * @details Function parses the transmitted action frames and modifies the
1846 * GO Intent attribute
1847 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1848 * @return NONE.
1849 * @author mdaftedar
1850 * @date 12 DEC 2012
1851 * @version
1852 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001853void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001854{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001855 u32 index = 0;
1856 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001857
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001858 u8 op_channel_attr_index = 0;
1859 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860
1861 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001864
1865 break;
1866 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001867
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301868 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001869 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301870 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001871 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001872 index += buf[index + 1] + 3; /* ID,Length byte */
1873 }
Alison Schofield3604af52015-10-12 13:22:44 -07001874 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001875
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001876 /*Modify channel list attribute*/
1877 if (channel_list_attr_index) {
1878 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1879 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1880 if (buf[i] == 0x51) {
1881 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1882 buf[j] = u8WLANChannel;
1883 }
1884 break;
1885 }
1886 }
1887 }
1888 /*Modify operating channel attribute*/
1889 if (op_channel_attr_index) {
1890 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1891 buf[op_channel_attr_index + 6] = 0x51;
1892 buf[op_channel_attr_index + 7] = u8WLANChannel;
1893 }
1894 }
1895}
1896
1897/* @brief WILC_WFI_p2p_rx
1898 * @details
1899 * @param[in]
1900 *
1901 * @return None
1902 * @author Mai Daftedar
1903 * @date 2 JUN 2013
1904 * @version 1.0
1905 */
1906
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001907void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001908{
1909
Chaehyun Lim27268872015-09-15 14:06:13 +09001910 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001911 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001912 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001913 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001914 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001915
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001916 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001917 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001918
1919 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001920 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001921
1922 /* The packet offset field conain info about what type of managment frame */
1923 /* we are dealing with and ack status */
1924 pkt_offset = GET_PKT_OFFSET(header);
1925
1926 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1927 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1928 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001929 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001930 return;
1931 } else {
1932 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1933 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],
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, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001936 } else {
1937 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],
1938 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001939 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001940 }
1941 return;
1942 }
1943 } else {
1944
1945 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1946
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001947 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001948 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001949
1950 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1951 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1952
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01001953 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001954 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1955 return;
1956 }
1957 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1958
1959 switch (buff[ACTION_SUBTYPE_ID]) {
1960 case GAS_INTIAL_REQ:
1961 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
1962 break;
1963
1964 case GAS_INTIAL_RSP:
1965 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1966 break;
1967
1968 case PUBLIC_ACT_VENDORSPEC:
1969 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1970 * 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 +09001971 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001972 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1973 if (!bWilc_ie) {
1974 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001975 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001976 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09001977 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001978 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1979 break;
1980 }
1981 }
1982 }
1983 }
1984 if (u8P2Plocalrandom > u8P2Precvrandom) {
1985 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1986 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1987 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001988 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001989 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1990 break;
1991 }
1992 }
1993 }
1994 } else
1995 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
1996 }
1997
1998
1999 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2000 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2001 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002002 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002003 return;
2004 }
2005 break;
2006
2007 default:
2008 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2009 break;
2010 }
2011 }
2012 }
2013
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002014 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002015 }
2016}
2017
2018/**
2019 * @brief WILC_WFI_mgmt_tx_complete
2020 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2021 * @param[in] priv
2022 * transmitting status
2023 * @return None
2024 * @author Amr Abdelmoghny
2025 * @date 20 MAY 2013
2026 * @version 1.0
2027 */
2028static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2029{
2030 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2031
2032
2033 kfree(pv_data->buff);
2034 kfree(pv_data);
2035}
2036
2037/**
2038 * @brief WILC_WFI_RemainOnChannelReady
2039 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2040 * @param
2041 * @return none
2042 * @author Amr abdelmoghny
2043 * @date 9 JUNE 2013
2044 * @version
2045 */
2046
2047static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2048{
Chaehyun Lim27268872015-09-15 14:06:13 +09002049 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002050
Chaehyun Lim27268872015-09-15 14:06:13 +09002051 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002052
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302053 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002054
Dean Lee72ed4dc2015-06-12 14:11:44 +09002055 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002057 cfg80211_ready_on_channel(priv->wdev,
2058 priv->strRemainOnChanParams.u64ListenCookie,
2059 priv->strRemainOnChanParams.pstrListenChan,
2060 priv->strRemainOnChanParams.u32ListenDuration,
2061 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002062}
2063
2064/**
2065 * @brief WILC_WFI_RemainOnChannelExpired
2066 * @details Callback function, called on expiration of remain-on-channel duration
2067 * @param
2068 * @return none
2069 * @author Amr abdelmoghny
2070 * @date 15 MAY 2013
2071 * @version
2072 */
2073
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002074static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002075{
Chaehyun Lim27268872015-09-15 14:06:13 +09002076 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002077
Chaehyun Lim27268872015-09-15 14:06:13 +09002078 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002079
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002080 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302081 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002082
Dean Lee72ed4dc2015-06-12 14:11:44 +09002083 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002084
2085 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002086 cfg80211_remain_on_channel_expired(priv->wdev,
2087 priv->strRemainOnChanParams.u64ListenCookie,
2088 priv->strRemainOnChanParams.pstrListenChan,
2089 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002090 } else {
2091 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2092 , priv->strRemainOnChanParams.u32ListenSessionID);
2093 }
2094}
2095
2096
2097/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002098 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002099 * @details Request the driver to remain awake on the specified
2100 * channel for the specified duration to complete an off-channel
2101 * operation (e.g., public action frame exchange). When the driver is
2102 * ready on the requested channel, it must indicate this with an event
2103 * notification by calling cfg80211_ready_on_channel().
2104 * @param[in]
2105 * @return int : Return 0 on Success
2106 * @author mdaftedar
2107 * @date 01 MAR 2012
2108 * @version 1.0
2109 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002110static int remain_on_channel(struct wiphy *wiphy,
2111 struct wireless_dev *wdev,
2112 struct ieee80211_channel *chan,
2113 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002114{
Leo Kime6e12662015-09-16 18:36:03 +09002115 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002116 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002117
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002118 priv = wiphy_priv(wiphy);
2119
2120 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2121
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002122
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002123 if (wdev->iftype == NL80211_IFTYPE_AP) {
2124 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2125 return s32Error;
2126 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002127
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002128 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002129
2130 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2131 priv->strRemainOnChanParams.pstrListenChan = chan;
2132 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002133 priv->strRemainOnChanParams.u32ListenDuration = duration;
2134 priv->strRemainOnChanParams.u32ListenSessionID++;
2135
2136 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2137 , priv->strRemainOnChanParams.u32ListenSessionID
2138 , duration
2139 , chan->hw_value
2140 , WILC_WFI_RemainOnChannelExpired
2141 , WILC_WFI_RemainOnChannelReady
2142 , (void *)priv);
2143
2144 return s32Error;
2145}
2146
2147/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002148 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002149 * @details Cancel an on-going remain-on-channel operation.
2150 * This allows the operation to be terminated prior to timeout based on
2151 * the duration value.
2152 * @param[in] struct wiphy *wiphy,
2153 * @param[in] struct net_device *dev
2154 * @param[in] u64 cookie,
2155 * @return int : Return 0 on Success
2156 * @author mdaftedar
2157 * @date 01 MAR 2012
2158 * @version 1.0
2159 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002160static int cancel_remain_on_channel(struct wiphy *wiphy,
2161 struct wireless_dev *wdev,
2162 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002163{
Leo Kime6e12662015-09-16 18:36:03 +09002164 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002165 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002166
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002167 priv = wiphy_priv(wiphy);
2168
2169 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2170
2171 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2172 return s32Error;
2173}
2174/**
2175 * @brief WILC_WFI_add_wilcvendorspec
2176 * @details Adding WILC information elemet to allow two WILC devices to
2177 * identify each other and connect
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002178 * @param[in] u8 * buf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002179 * @return void
2180 * @author mdaftedar
2181 * @date 01 JAN 2014
2182 * @version 1.0
2183 */
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002184void WILC_WFI_add_wilcvendorspec(u8 *buff)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002185{
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002186 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002187}
2188/**
2189 * @brief WILC_WFI_mgmt_tx_frame
2190 * @details
2191 *
2192 * @param[in]
2193 * @return NONE.
2194 * @author mdaftedar
2195 * @date 01 JUL 2012
2196 * @version
2197 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09002198extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002199static int mgmt_tx(struct wiphy *wiphy,
2200 struct wireless_dev *wdev,
2201 struct cfg80211_mgmt_tx_params *params,
2202 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002203{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002204 struct ieee80211_channel *chan = params->chan;
2205 unsigned int wait = params->wait;
2206 const u8 *buf = params->buf;
2207 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002208 const struct ieee80211_mgmt *mgmt;
2209 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002210 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002211 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002212 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002213 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002214 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002215
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002216 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002217 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002218 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002219
2220 *cookie = (unsigned long)buf;
2221 priv->u64tx_cookie = *cookie;
2222 mgmt = (const struct ieee80211_mgmt *) buf;
2223
2224 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2225
2226 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002227 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002228 if (mgmt_tx == NULL) {
2229 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002230 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002231 }
Glen Leef3052582015-09-10 12:03:04 +09002232 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002233 if (mgmt_tx->buff == NULL) {
2234 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002235 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002236 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002237 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002238 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002239 mgmt_tx->size = len;
2240
2241
2242 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2243 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2244 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2245 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2246 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002247 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002248 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002249 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002250
2251
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002252 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002253 /*Only set the channel, if not a negotiation confirmation frame
2254 * (If Negotiation confirmation frame, force it
2255 * to be transmitted on the same negotiation channel)*/
2256
2257 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2258 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2259 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2260 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2261 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002262 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002263 }
2264 switch (buf[ACTION_SUBTYPE_ID]) {
2265 case GAS_INTIAL_REQ:
2266 {
2267 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2268 break;
2269 }
2270
2271 case GAS_INTIAL_RSP:
2272 {
2273 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2274 break;
2275 }
2276
2277 case PUBLIC_ACT_VENDORSPEC:
2278 {
2279 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2280 * 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 +09002281 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002282 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2283 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2284 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2285 get_random_bytes(&u8P2Plocalrandom, 1);
2286 /*Increment the number to prevent if its 0*/
2287 u8P2Plocalrandom++;
2288 }
2289 }
2290
2291 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2292 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2293 if (u8P2Plocalrandom > u8P2Precvrandom) {
2294 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2295
2296 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2297 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002298 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002299 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002300 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002301
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002302 /*If using supplicant go intent, no need at all*/
2303 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002304 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002305 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002306 break;
2307 }
2308 }
2309
2310 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
2311 WILC_WFI_add_wilcvendorspec(&mgmt_tx->buff[len]);
2312 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2313 mgmt_tx->size = buf_len;
2314 }
2315 } else
2316 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2317 }
2318
2319 } else {
2320 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2321 }
2322
2323 break;
2324 }
2325
2326 default:
2327 {
2328 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2329 break;
2330 }
2331 }
2332
2333 }
2334
2335 PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
2336 pstrWFIDrv->u64P2p_MgmtTimeout = (jiffies + msecs_to_jiffies(wait));
2337
2338 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2339
2340 }
2341
Glen Leec9d48342015-10-01 16:03:43 +09002342 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2343 mgmt_tx->size,
2344 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002345 } else {
2346 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2347 }
Leo Kimaaed3292015-10-12 16:55:38 +09002348 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002349}
2350
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002351static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2352 struct wireless_dev *wdev,
2353 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002354{
Chaehyun Lim27268872015-09-15 14:06:13 +09002355 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002356 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002357
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002358 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002359 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002360
2361
2362 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2363 pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2364
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01002365 if (!priv->bInP2PlistenState) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002366 cfg80211_remain_on_channel_expired(priv->wdev,
2367 priv->strRemainOnChanParams.u64ListenCookie,
2368 priv->strRemainOnChanParams.pstrListenChan,
2369 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002370 }
2371
2372 return 0;
2373}
2374
2375/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002376 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002377 * @details Notify driver that a management frame type was
2378 * registered. Note that this callback may not sleep, and cannot run
2379 * concurrently with itself.
2380 * @param[in]
2381 * @return NONE.
2382 * @author mdaftedar
2383 * @date 01 JUL 2012
2384 * @version
2385 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002386void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2387 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002388{
2389
Chaehyun Lim27268872015-09-15 14:06:13 +09002390 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002391 perInterface_wlan_t *nic;
2392
2393
2394 priv = wiphy_priv(wiphy);
2395 nic = netdev_priv(priv->wdev->netdev);
2396
2397
2398
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002399 if (!frame_type)
2400 return;
2401
2402 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2403 switch (frame_type) {
2404 case PROBE_REQ:
2405 {
2406 nic->g_struct_frame_reg[0].frame_type = frame_type;
2407 nic->g_struct_frame_reg[0].reg = reg;
2408 }
2409 break;
2410
2411 case ACTION:
2412 {
2413 nic->g_struct_frame_reg[1].frame_type = frame_type;
2414 nic->g_struct_frame_reg[1].reg = reg;
2415 }
2416 break;
2417
2418 default:
2419 {
2420 break;
2421 }
2422
2423 }
2424 /*If mac is closed, then return*/
Tony Cho080f11b2015-10-20 14:26:45 +09002425 if (!g_linux_wlan->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002426 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2427 return;
2428 }
2429 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2430
2431
2432}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002433
2434/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002435 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002436 * @details Configure connection quality monitor RSSI threshold.
2437 * @param[in] struct wiphy *wiphy:
2438 * @param[in] struct net_device *dev:
2439 * @param[in] s32 rssi_thold:
2440 * @param[in] u32 rssi_hyst:
2441 * @return int : Return 0 on Success
2442 * @author mdaftedar
2443 * @date 01 MAR 2012
2444 * @version 1.0
2445 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002446static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2447 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002448{
2449 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2450 return 0;
2451
2452}
2453/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002454 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002455 * @details Configure connection quality monitor RSSI threshold.
2456 * @param[in] struct wiphy *wiphy:
2457 * @param[in] struct net_device *dev
2458 * @param[in] int idx
2459 * @param[in] u8 *mac
2460 * @param[in] struct station_info *sinfo
2461 * @return int : Return 0 on Success
2462 * @author mdaftedar
2463 * @date 01 MAR 2012
2464 * @version 1.0
2465 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002466static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2467 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002468{
Chaehyun Lim27268872015-09-15 14:06:13 +09002469 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002470
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002471 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2472
2473 if (idx != 0)
2474 return -ENOENT;
2475
2476 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002477
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002478 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002479
2480 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2481
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002482 return 0;
2483
2484}
2485
2486
2487/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002488 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002489 * @details
2490 * @param[in]
2491 * @return int : Return 0 on Success.
2492 * @author mdaftedar
2493 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002494 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002495 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002496static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2497 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002498{
Chaehyun Lim27268872015-09-15 14:06:13 +09002499 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002500
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002501 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2502
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002503 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002504 return -ENOENT;
2505
2506 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002507 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002508 PRINT_ER("Driver is NULL\n");
2509 return -EIO;
2510 }
2511
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002512 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002513 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2514
2515
Leo Kime6e12662015-09-16 18:36:03 +09002516 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002517
2518}
Glen Lee108b3432015-09-16 18:53:20 +09002519
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002520/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002521 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002522 * @details Change type/configuration of virtual interface,
2523 * keep the struct wireless_dev's iftype updated.
2524 * @param[in] NONE
2525 * @return int : Return 0 on Success.
2526 * @author mdaftedar
2527 * @date 01 MAR 2012
2528 * @version 1.0
2529 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002530int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2531
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002532static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2533 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002534{
Chaehyun Lim27268872015-09-15 14:06:13 +09002535 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002536 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002537 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002538 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002539 u8 i;
Glen Lee299382c2015-10-20 17:13:56 +09002540 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002541
2542 nic = netdev_priv(dev);
2543 priv = wiphy_priv(wiphy);
Glen Lee299382c2015-10-20 17:13:56 +09002544 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002545
2546 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2547 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2548 u8P2Plocalrandom = 0x01;
2549 u8P2Precvrandom = 0x00;
2550
Dean Lee72ed4dc2015-06-12 14:11:44 +09002551 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002552
Dean Lee72ed4dc2015-06-12 14:11:44 +09002553 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002554 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002555 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002556 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2557 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09002558 Set_machw_change_vir_if(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002559 }
2560
2561 switch (type) {
2562 case NL80211_IFTYPE_STATION:
2563 connecting = 0;
2564 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002565
2566 /* send delba over wlan interface */
2567
2568
2569 dev->ieee80211_ptr->iftype = type;
2570 priv->wdev->iftype = type;
2571 nic->monitor_flag = 0;
2572 nic->iftype = STATION_MODE;
2573
2574 /*Remove the enteries of the previously connected clients*/
2575 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002576 interface_type = nic->iftype;
2577 nic->iftype = STATION_MODE;
2578
Glen Lee299382c2015-10-20 17:13:56 +09002579 if (wl->initialized) {
2580 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2581 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002582 /* ensure that the message Q is empty */
2583 host_int_wait_msg_queue_idle();
2584
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002585 /*Eliminate host interface blocking state*/
Glen Lee299382c2015-10-20 17:13:56 +09002586 up(&wl->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002587
Glen Lee53dc0cf2015-10-20 17:13:57 +09002588 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002589 wilc1000_wlan_init(dev, nic);
2590 g_wilc_initialized = 1;
2591 nic->iftype = interface_type;
2592
2593 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002594 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2595 host_int_set_MacAddress(wl->vif[0].hif_drv,
2596 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002597 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2598
2599 /*Add saved WEP keys, if any*/
2600 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002601 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002602 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002603 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002604 g_key_wep_params.key,
2605 g_key_wep_params.key_len,
2606 g_key_wep_params.key_idx);
2607 }
2608
2609 /*No matter the driver handler passed here, it will be overwriiten*/
2610 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2611 host_int_flush_join_req(priv->hWILCWFIDrv);
2612
2613 /*Add saved PTK and GTK keys, if any*/
2614 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2615 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2616 g_key_ptk_params.key[1],
2617 g_key_ptk_params.key[2]);
2618 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2619 g_key_gtk_params.key[1],
2620 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002621 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2622 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002623 g_add_ptk_key_params.key_idx,
2624 g_add_ptk_key_params.pairwise,
2625 g_add_ptk_key_params.mac_addr,
2626 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002627
Glen Lee299382c2015-10-20 17:13:56 +09002628 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2629 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002630 g_add_gtk_key_params.key_idx,
2631 g_add_gtk_key_params.pairwise,
2632 g_add_gtk_key_params.mac_addr,
2633 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002634 }
2635
Glen Lee299382c2015-10-20 17:13:56 +09002636 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002637 for (i = 0; i < num_reg_frame; i++) {
2638 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2639 nic->g_struct_frame_reg[i].reg);
2640 host_int_frame_register(priv->hWILCWFIDrv,
2641 nic->g_struct_frame_reg[i].frame_type,
2642 nic->g_struct_frame_reg[i].reg);
2643 }
2644 }
2645
Dean Lee72ed4dc2015-06-12 14:11:44 +09002646 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002647 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2648 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002649 break;
2650
2651 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002652 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002653 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2654 connecting = 0;
2655 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002656
Glen Lee299382c2015-10-20 17:13:56 +09002657 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2658 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002659
2660 dev->ieee80211_ptr->iftype = type;
2661 priv->wdev->iftype = type;
2662 nic->monitor_flag = 0;
2663
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002664 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2665 nic->iftype = CLIENT_MODE;
2666
2667
Glen Lee299382c2015-10-20 17:13:56 +09002668 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002669 /* ensure that the message Q is empty */
2670 host_int_wait_msg_queue_idle();
2671
Glen Lee53dc0cf2015-10-20 17:13:57 +09002672 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002673 wilc1000_wlan_init(dev, nic);
2674 g_wilc_initialized = 1;
2675
Glen Lee299382c2015-10-20 17:13:56 +09002676 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2677 host_int_set_MacAddress(wl->vif[0].hif_drv,
2678 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002679 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2680
2681 /*Add saved WEP keys, if any*/
2682 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002683 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002684 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002685 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002686 g_key_wep_params.key,
2687 g_key_wep_params.key_len,
2688 g_key_wep_params.key_idx);
2689 }
2690
2691 /*No matter the driver handler passed here, it will be overwriiten*/
2692 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2693 host_int_flush_join_req(priv->hWILCWFIDrv);
2694
2695 /*Add saved PTK and GTK keys, if any*/
2696 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2697 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2698 g_key_ptk_params.key[1],
2699 g_key_ptk_params.key[2]);
2700 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2701 g_key_gtk_params.key[1],
2702 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002703 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2704 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002705 g_add_ptk_key_params.key_idx,
2706 g_add_ptk_key_params.pairwise,
2707 g_add_ptk_key_params.mac_addr,
2708 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002709
Glen Lee299382c2015-10-20 17:13:56 +09002710 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2711 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002712 g_add_gtk_key_params.key_idx,
2713 g_add_gtk_key_params.pairwise,
2714 g_add_gtk_key_params.mac_addr,
2715 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002716 }
2717
2718 /*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 +09002719 refresh_scan(priv, 1, true);
2720 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002721
Glen Lee299382c2015-10-20 17:13:56 +09002722 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002723 for (i = 0; i < num_reg_frame; i++) {
2724 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2725 nic->g_struct_frame_reg[i].reg);
2726 host_int_frame_register(priv->hWILCWFIDrv,
2727 nic->g_struct_frame_reg[i].frame_type,
2728 nic->g_struct_frame_reg[i].reg);
2729 }
2730 }
2731 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002732 break;
2733
2734 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002735 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002736 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002737 dev->ieee80211_ptr->iftype = type;
2738 priv->wdev->iftype = type;
2739 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002740 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002741
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002742 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2743 linux_wlan_get_firmware(nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002744 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
Glen Lee299382c2015-10-20 17:13:56 +09002745 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002746 nic->iftype = AP_MODE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002747 mac_close(dev);
2748 mac_open(dev);
2749
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002750 for (i = 0; i < num_reg_frame; i++) {
2751 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2752 nic->g_struct_frame_reg[i].reg);
2753 host_int_frame_register(priv->hWILCWFIDrv,
2754 nic->g_struct_frame_reg[i].frame_type,
2755 nic->g_struct_frame_reg[i].reg);
2756 }
2757 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002758 break;
2759
2760 case NL80211_IFTYPE_P2P_GO:
2761 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2762
Dean Lee72ed4dc2015-06-12 14:11:44 +09002763 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002764 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002765 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002766 /*Delete block ack has to be the latest config packet*/
2767 /*sent before downloading new FW. This is because it blocks on*/
2768 /*hWaitResponse semaphore, which allows previous config*/
2769 /*packets to actually take action on old FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002770 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2771 wl->vif[0].bssid, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002772 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002773 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002774 dev->ieee80211_ptr->iftype = type;
2775 priv->wdev->iftype = type;
2776
Johnny Kim8a143302015-06-10 17:06:46 +09002777 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002778
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002779 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2780
2781
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002782 nic->iftype = GO_MODE;
2783
2784 /* ensure that the message Q is empty */
2785 host_int_wait_msg_queue_idle();
Glen Lee53dc0cf2015-10-20 17:13:57 +09002786 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002787 wilc1000_wlan_init(dev, nic);
2788 g_wilc_initialized = 1;
2789
2790
2791 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002792 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2793 host_int_set_MacAddress(wl->vif[0].hif_drv,
2794 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002795 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2796
2797 /*Add saved WEP keys, if any*/
2798 if (g_wep_keys_saved) {
Glen Lee299382c2015-10-20 17:13:56 +09002799 host_int_set_WEPDefaultKeyID(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002800 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002801 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002802 g_key_wep_params.key,
2803 g_key_wep_params.key_len,
2804 g_key_wep_params.key_idx);
2805 }
2806
2807 /*No matter the driver handler passed here, it will be overwriiten*/
2808 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2809 host_int_flush_join_req(priv->hWILCWFIDrv);
2810
2811 /*Add saved PTK and GTK keys, if any*/
2812 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2813 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2814 g_key_ptk_params.key[1],
2815 g_key_ptk_params.key[2],
2816 g_key_ptk_params.cipher);
2817 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2818 g_key_gtk_params.key[1],
2819 g_key_gtk_params.key[2],
2820 g_key_gtk_params.cipher);
Glen Lee299382c2015-10-20 17:13:56 +09002821 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2822 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002823 g_add_ptk_key_params.key_idx,
2824 g_add_ptk_key_params.pairwise,
2825 g_add_ptk_key_params.mac_addr,
2826 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002827
Glen Lee299382c2015-10-20 17:13:56 +09002828 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2829 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002830 g_add_gtk_key_params.key_idx,
2831 g_add_gtk_key_params.pairwise,
2832 g_add_gtk_key_params.mac_addr,
2833 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002834 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002835
Glen Lee299382c2015-10-20 17:13:56 +09002836 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002837 for (i = 0; i < num_reg_frame; i++) {
2838 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2839 nic->g_struct_frame_reg[i].reg);
2840 host_int_frame_register(priv->hWILCWFIDrv,
2841 nic->g_struct_frame_reg[i].frame_type,
2842 nic->g_struct_frame_reg[i].reg);
2843 }
2844 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002845 break;
2846
2847 default:
2848 PRINT_ER("Unknown interface type= %d\n", type);
Leo Kimaaed3292015-10-12 16:55:38 +09002849 return -EINVAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002850 }
2851
Leo Kimaaed3292015-10-12 16:55:38 +09002852 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002853}
2854
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002855/* (austin.2013-07-23)
2856 *
2857 * To support revised cfg80211_ops
2858 *
2859 * add_beacon --> start_ap
2860 * set_beacon --> change_beacon
2861 * del_beacon --> stop_ap
2862 *
2863 * beacon_parameters --> cfg80211_ap_settings
2864 * cfg80211_beacon_data
2865 *
2866 * applicable for linux kernel 3.4+
2867 */
2868
2869/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002870 * @brief start_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002871 * @details Add a beacon with given parameters, @head, @interval
2872 * and @dtim_period will be valid, @tail is optional.
2873 * @param[in] wiphy
2874 * @param[in] dev The net device structure
2875 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2876 * @return int : Return 0 on Success.
2877 * @author austin
2878 * @date 23 JUL 2013
2879 * @version 1.0
2880 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002881static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2882 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002883{
2884 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002885 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002886 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002887
2888 priv = wiphy_priv(wiphy);
2889 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2890
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302891 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 +09002892 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2893
Chaehyun Lim80785a92015-09-14 12:24:01 +09002894 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002895
Leo Kime6e12662015-09-16 18:36:03 +09002896 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002897 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002898
Tony Cho7e7fa472015-10-20 14:26:48 +09002899 linux_wlan_set_bssid(dev, g_linux_wlan->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002900
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002901 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2902 settings->beacon_interval,
2903 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002904 beacon->head_len, (u8 *)beacon->head,
2905 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002906
2907 return s32Error;
2908}
2909
2910/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002911 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002912 * @details Add a beacon with given parameters, @head, @interval
2913 * and @dtim_period will be valid, @tail is optional.
2914 * @param[in] wiphy
2915 * @param[in] dev The net device structure
2916 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2917 * @return int : Return 0 on Success.
2918 * @author austin
2919 * @date 23 JUL 2013
2920 * @version 1.0
2921 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002922static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2923 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002924{
Chaehyun Lim27268872015-09-15 14:06:13 +09002925 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002926 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002927
2928 priv = wiphy_priv(wiphy);
2929 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2930
2931
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002932 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2933 0,
2934 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002935 beacon->head_len, (u8 *)beacon->head,
2936 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002937
2938 return s32Error;
2939}
2940
2941/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002942 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002943 * @details Remove beacon configuration and stop sending the beacon.
2944 * @param[in]
2945 * @return int : Return 0 on Success.
2946 * @author austin
2947 * @date 23 JUL 2013
2948 * @version 1.0
2949 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002950static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002951{
Leo Kime6e12662015-09-16 18:36:03 +09002952 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002953 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002954 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002955
Leo Kim7ae43362015-09-16 18:35:59 +09002956 if (!wiphy)
2957 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002958
2959 priv = wiphy_priv(wiphy);
2960
2961 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2962
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002963 linux_wlan_set_bssid(dev, NullBssid);
2964
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002965 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002966
Leo Kim7dc1d0c2015-09-16 18:36:00 +09002967 if (s32Error)
2968 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002969
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002970 return s32Error;
2971}
2972
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002973/**
Chaehyun Limed269552015-09-14 12:24:15 +09002974 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002975 * @details Add a new station.
2976 * @param[in]
2977 * @return int : Return 0 on Success.
2978 * @author mdaftedar
2979 * @date 01 MAR 2012
2980 * @version 1.0
2981 */
Chaehyun Limed269552015-09-14 12:24:15 +09002982static int add_station(struct wiphy *wiphy, struct net_device *dev,
2983 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002984{
Leo Kime6e12662015-09-16 18:36:03 +09002985 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002986 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09002987 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002988 perInterface_wlan_t *nic;
2989
Leo Kim7ae43362015-09-16 18:35:59 +09002990 if (!wiphy)
2991 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002992
2993 priv = wiphy_priv(wiphy);
2994 nic = netdev_priv(dev);
2995
2996 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002997 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
2998 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002999 strStaParams.u16AssocID = params->aid;
3000 strStaParams.u8NumRates = params->supported_rates_len;
3001 strStaParams.pu8Rates = params->supported_rates;
3002
3003 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3004
3005 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],
3006 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
3007 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3008 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3009
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003010 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003011 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003012 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003013 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003014 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3015 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003016 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003017 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3018 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3019 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3020 }
3021
3022 strStaParams.u16FlagsMask = params->sta_flags_mask;
3023 strStaParams.u16FlagsSet = params->sta_flags_set;
3024
3025 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3026 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3027 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3028 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3029 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3030 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3031 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3032 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3033
3034 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003035 if (s32Error)
3036 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003037 }
3038
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003039 return s32Error;
3040}
3041
3042/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003043 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003044 * @details Remove a station; @mac may be NULL to remove all stations.
3045 * @param[in]
3046 * @return int : Return 0 on Success.
3047 * @author mdaftedar
3048 * @date 01 MAR 2012
3049 * @version 1.0
3050 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003051static int del_station(struct wiphy *wiphy, struct net_device *dev,
3052 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003053{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003054 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003055 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003056 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003057 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003058
Leo Kim7ae43362015-09-16 18:35:59 +09003059 if (!wiphy)
3060 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003061
3062 priv = wiphy_priv(wiphy);
3063 nic = netdev_priv(dev);
3064
3065 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3066 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3067
3068
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003069 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303070 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003071 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3072 } else {
3073 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]);
3074 }
3075
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003076 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003077
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003078 if (s32Error)
3079 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003080 }
3081 return s32Error;
3082}
3083
3084/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003085 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003086 * @details Modify a given station.
3087 * @param[in]
3088 * @return int : Return 0 on Success.
3089 * @author mdaftedar
3090 * @date 01 MAR 2012
3091 * @version 1.0
3092 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003093static int change_station(struct wiphy *wiphy, struct net_device *dev,
3094 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003095{
Leo Kime6e12662015-09-16 18:36:03 +09003096 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003097 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003098 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003099 perInterface_wlan_t *nic;
3100
3101
3102 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3103
Leo Kim7ae43362015-09-16 18:35:59 +09003104 if (!wiphy)
3105 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003106
3107 priv = wiphy_priv(wiphy);
3108 nic = netdev_priv(dev);
3109
3110 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003111 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003112 strStaParams.u16AssocID = params->aid;
3113 strStaParams.u8NumRates = params->supported_rates_len;
3114 strStaParams.pu8Rates = params->supported_rates;
3115
3116 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],
3117 strStaParams.au8BSSID[5]);
3118 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3119 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3120
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003121 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003122 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003123 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003124 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003125 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3126 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003127 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003128 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3129 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3130 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3131
3132 }
3133
3134 strStaParams.u16FlagsMask = params->sta_flags_mask;
3135 strStaParams.u16FlagsSet = params->sta_flags_set;
3136
3137 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3138 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3139 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3140 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3141 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3142 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3143 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3144 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3145
3146 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003147 if (s32Error)
3148 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003149 }
3150 return s32Error;
3151}
3152
3153
3154/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003155 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003156 * @details
3157 * @param[in]
3158 * @return int : Return 0 on Success.
3159 * @author mdaftedar
3160 * @date 01 JUL 2012
3161 * @version 1.0
3162 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003163static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3164 const char *name,
3165 unsigned char name_assign_type,
3166 enum nl80211_iftype type,
3167 u32 *flags,
3168 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003169{
3170 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003171 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003172 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003173
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003174 priv = wiphy_priv(wiphy);
3175
3176
3177
3178 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3179
3180 nic = netdev_priv(priv->wdev->netdev);
3181
3182
3183 if (type == NL80211_IFTYPE_MONITOR) {
3184 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3185 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3186 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3187 if (new_ifc != NULL) {
3188 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003189 nic = netdev_priv(priv->wdev->netdev);
3190 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003191 } else
3192 PRINT_ER("Error in initializing monitor interface\n ");
3193 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003194 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003195}
3196
3197/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003198 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003199 * @details
3200 * @param[in]
3201 * @return int : Return 0 on Success.
3202 * @author mdaftedar
3203 * @date 01 JUL 2012
3204 * @version 1.0
3205 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003206static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003207{
3208 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003209 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003210}
3211
Chaehyun Lim08241922015-09-15 14:06:12 +09003212static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003213
Chaehyun Lim80785a92015-09-14 12:24:01 +09003214 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003215 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003216 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003217 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003218 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003219 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003220 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003221 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003222 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003223 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003224 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003225
Chaehyun Lima13168d2015-09-14 12:24:12 +09003226 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003227 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003228 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003229 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003230 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003231 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003232 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003233 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003234 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003235 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003236
Chaehyun Lim4d466572015-09-14 12:24:22 +09003237 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003238 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003239 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003240 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003241 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003242 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003243 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003244 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003245 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003246 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003247
3248};
3249
3250
3251
3252
3253
3254/**
3255 * @brief WILC_WFI_update_stats
3256 * @details Modify parameters for a given BSS.
3257 * @param[in]
3258 * @return int : Return 0 on Success.
3259 * @author mdaftedar
3260 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003261 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003262 */
3263int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3264{
3265
Chaehyun Lim27268872015-09-15 14:06:13 +09003266 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003267
3268 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003269 switch (changed) {
3270
3271 case WILC_WFI_RX_PKT:
3272 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003273 priv->netstats.rx_packets++;
3274 priv->netstats.rx_bytes += pktlen;
3275 priv->netstats.rx_time = get_jiffies_64();
3276 }
3277 break;
3278
3279 case WILC_WFI_TX_PKT:
3280 {
3281 priv->netstats.tx_packets++;
3282 priv->netstats.tx_bytes += pktlen;
3283 priv->netstats.tx_time = get_jiffies_64();
3284
3285 }
3286 break;
3287
3288 default:
3289 break;
3290 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003291 return 0;
3292}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003293
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003294/**
3295 * @brief WILC_WFI_CfgAlloc
3296 * @details Allocation of the wireless device structure and assigning it
3297 * to the cfg80211 operations structure.
3298 * @param[in] NONE
3299 * @return wireless_dev : Returns pointer to wireless_dev structure.
3300 * @author mdaftedar
3301 * @date 01 MAR 2012
3302 * @version 1.0
3303 */
3304struct wireless_dev *WILC_WFI_CfgAlloc(void)
3305{
3306
3307 struct wireless_dev *wdev;
3308
3309
3310 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3311 /*Allocating the wireless device structure*/
3312 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3313 if (!wdev) {
3314 PRINT_ER("Cannot allocate wireless device\n");
3315 goto _fail_;
3316 }
3317
3318 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003319 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003320 if (!wdev->wiphy) {
3321 PRINT_ER("Cannot allocate wiphy\n");
3322 goto _fail_mem_;
3323
3324 }
3325
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003326 /* enable 802.11n HT */
3327 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3328 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3329 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3330 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3331 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003332
3333 /*wiphy bands*/
3334 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3335
3336 return wdev;
3337
3338_fail_mem_:
3339 kfree(wdev);
3340_fail_:
3341 return NULL;
3342
3343}
3344/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003345 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003346 * @details Registering of the wiphy structure and interface modes
3347 * @param[in] NONE
3348 * @return NONE
3349 * @author mdaftedar
3350 * @date 01 MAR 2012
3351 * @version 1.0
3352 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003353struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003354{
Chaehyun Lim27268872015-09-15 14:06:13 +09003355 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003356 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003357 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003358
3359 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3360
3361 wdev = WILC_WFI_CfgAlloc();
3362 if (wdev == NULL) {
3363 PRINT_ER("CfgAlloc Failed\n");
3364 return NULL;
3365 }
3366
3367
3368 /*Return hardware description structure (wiphy)'s priv*/
3369 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003370 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003371
3372 /*Link the wiphy with wireless structure*/
3373 priv->wdev = wdev;
3374
3375 /*Maximum number of probed ssid to be added by user for the scan request*/
3376 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003377 /*Maximum number of pmkids to be cashed*/
3378 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3379 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003380
3381 wdev->wiphy->max_scan_ie_len = 1000;
3382
3383 /*signal strength in mBm (100*dBm) */
3384 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3385
3386 /*Set the availaible cipher suites*/
3387 wdev->wiphy->cipher_suites = cipher_suites;
3388 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003389 /*Setting default managment types: for register action frame: */
3390 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003391
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003392 wdev->wiphy->max_remain_on_channel_duration = 500;
3393 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3394 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3395 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003396 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003397 wdev->iftype = NL80211_IFTYPE_STATION;
3398
3399
3400
3401 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3402 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3403 wdev->wiphy->interface_modes, wdev->iftype);
3404
3405 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003406 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003407 #endif
3408
3409 /*Register wiphy structure*/
3410 s32Error = wiphy_register(wdev->wiphy);
3411 if (s32Error) {
3412 PRINT_ER("Cannot register wiphy device\n");
3413 /*should define what action to be taken in such failure*/
3414 } else {
3415 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3416 }
3417
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003418 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003419 return wdev;
3420
3421
3422}
3423/**
3424 * @brief WILC_WFI_WiphyFree
3425 * @details Freeing allocation of the wireless device structure
3426 * @param[in] NONE
3427 * @return NONE
3428 * @author mdaftedar
3429 * @date 01 MAR 2012
3430 * @version 1.0
3431 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003432int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003433{
3434
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003435 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003436
Chaehyun Lim27268872015-09-15 14:06:13 +09003437 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003438
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003439 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3440 priv = wdev_priv(net->ieee80211_ptr);
3441 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003442 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003443 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003444 }
3445 op_ifcs++;
3446 if (s32Error < 0) {
3447 PRINT_ER("Failed to creat refresh Timer\n");
3448 return s32Error;
3449 }
3450
Dean Lee72ed4dc2015-06-12 14:11:44 +09003451 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003452
Dean Lee72ed4dc2015-06-12 14:11:44 +09003453 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003454
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003455 sema_init(&(priv->hSemScanReq), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003456 s32Error = host_int_init(&priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003457 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003458 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003459
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003460 return s32Error;
3461}
3462
3463/**
3464 * @brief WILC_WFI_WiphyFree
3465 * @details Freeing allocation of the wireless device structure
3466 * @param[in] NONE
3467 * @return NONE
3468 * @author mdaftedar
3469 * @date 01 MAR 2012
3470 * @version 1.0
3471 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003472int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003473{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003474 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003475
Chaehyun Lim27268872015-09-15 14:06:13 +09003476 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003477
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003478 priv = wdev_priv(net->ieee80211_ptr);
3479
Dean Lee72ed4dc2015-06-12 14:11:44 +09003480 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003481
Dean Lee72ed4dc2015-06-12 14:11:44 +09003482 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003483
3484 op_ifcs--;
3485
3486 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003487
3488 /* Clear the Shadow scan */
3489 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003490 if (op_ifcs == 0) {
3491 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003492 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003493 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003494
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003495 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003496 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003497
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003498 return s32Error;
3499}
3500
3501
3502/**
3503 * @brief WILC_WFI_WiphyFree
3504 * @details Freeing allocation of the wireless device structure
3505 * @param[in] NONE
3506 * @return NONE
3507 * @author mdaftedar
3508 * @date 01 MAR 2012
3509 * @version 1.0
3510 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003511void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003512{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003513 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3514
Chaehyun Lim619837a2015-09-20 15:51:10 +09003515 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003516 PRINT_D(INIT_DBG, "net_device is NULL\n");
3517 return;
3518 }
3519
Chaehyun Lim619837a2015-09-20 15:51:10 +09003520 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003521 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3522 return;
3523 }
3524
Chaehyun Lim619837a2015-09-20 15:51:10 +09003525 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003526 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3527 return;
3528 }
3529
3530 wiphy_unregister(net->ieee80211_ptr->wiphy);
3531
3532 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3533 wiphy_free(net->ieee80211_ptr->wiphy);
3534 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003535}