blob: 04b8dae4373dc6ae1b40c1e473698488b06dd8e2 [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"
14#include "wilc_wlan.c"
15#ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +090016#include "linux_wlan_sdio.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090017#endif
Leo Kim7ae43362015-09-16 18:35:59 +090018#include <linux/errno.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090019
20#define IS_MANAGMEMENT 0x100
21#define IS_MANAGMEMENT_CALLBACK 0x080
22#define IS_MGMT_STATUS_SUCCES 0x040
23#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
24
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
Dean Lee72ed4dc2015-06-12 14:11:44 +090026extern u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090027
28extern int mac_open(struct net_device *ndev);
29extern int mac_close(struct net_device *ndev);
30
31tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090032u32 u32LastScannedNtwrksCountShadow;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070033struct timer_list hDuringIpTimer;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070034struct timer_list hAgingTimer;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090035static u8 op_ifcs;
36extern u8 u8ConnectedSSID[6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090037
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090038u8 g_wilc_initialized = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090039extern linux_wlan_t *g_linux_wlan;
Dean Lee72ed4dc2015-06-12 14:11:44 +090040extern bool g_obtainingIP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090041
42#define CHAN2G(_channel, _freq, _flags) { \
43 .band = IEEE80211_BAND_2GHZ, \
44 .center_freq = (_freq), \
45 .hw_value = (_channel), \
46 .flags = (_flags), \
47 .max_antenna_gain = 0, \
48 .max_power = 30, \
49}
50
51/*Frequency range for channels*/
52static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
53 CHAN2G(1, 2412, 0),
54 CHAN2G(2, 2417, 0),
55 CHAN2G(3, 2422, 0),
56 CHAN2G(4, 2427, 0),
57 CHAN2G(5, 2432, 0),
58 CHAN2G(6, 2437, 0),
59 CHAN2G(7, 2442, 0),
60 CHAN2G(8, 2447, 0),
61 CHAN2G(9, 2452, 0),
62 CHAN2G(10, 2457, 0),
63 CHAN2G(11, 2462, 0),
64 CHAN2G(12, 2467, 0),
65 CHAN2G(13, 2472, 0),
66 CHAN2G(14, 2484, 0),
67};
68
69#define RATETAB_ENT(_rate, _hw_value, _flags) { \
70 .bitrate = (_rate), \
71 .hw_value = (_hw_value), \
72 .flags = (_flags), \
73}
74
75
76/* Table 6 in section 3.2.1.1 */
77static struct ieee80211_rate WILC_WFI_rates[] = {
78 RATETAB_ENT(10, 0, 0),
79 RATETAB_ENT(20, 1, 0),
80 RATETAB_ENT(55, 2, 0),
81 RATETAB_ENT(110, 3, 0),
82 RATETAB_ENT(60, 9, 0),
83 RATETAB_ENT(90, 6, 0),
84 RATETAB_ENT(120, 7, 0),
85 RATETAB_ENT(180, 8, 0),
86 RATETAB_ENT(240, 9, 0),
87 RATETAB_ENT(360, 10, 0),
88 RATETAB_ENT(480, 11, 0),
89 RATETAB_ENT(540, 12, 0),
90};
91
Johnny Kimc5c77ba2015-05-11 14:30:56 +090092struct p2p_mgmt_data {
93 int size;
94 u8 *buff;
95};
96
97/*Global variable used to state the current connected STA channel*/
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090098u8 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090099
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900100u8 curr_channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900102u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
103u8 u8P2Plocalrandom = 0x01;
104u8 u8P2Precvrandom = 0x00;
105u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
Daniel Machon7fc80962015-08-05 00:09:35 +0200106bool bWilc_ie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900107
108static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
109 .channels = WILC_WFI_2ghz_channels,
110 .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
111 .bitrates = WILC_WFI_rates,
112 .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
113};
114
115
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116struct add_key_params {
117 u8 key_idx;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900118 bool pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119 u8 *mac_addr;
120};
121struct add_key_params g_add_gtk_key_params;
122struct wilc_wfi_key g_key_gtk_params;
123struct add_key_params g_add_ptk_key_params;
124struct wilc_wfi_key g_key_ptk_params;
125struct wilc_wfi_wep_key g_key_wep_params;
Daniel Machon7fc80962015-08-05 00:09:35 +0200126bool g_ptk_keys_saved;
127bool g_gtk_keys_saved;
128bool g_wep_keys_saved;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129
130#define AGING_TIME (9 * 1000)
131#define duringIP_TIME 15000
132
133void clear_shadow_scan(void *pUserVoid)
134{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900136
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900137 if (op_ifcs == 0) {
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -0700138 del_timer_sync(&hAgingTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900139 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
140
141 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
142 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900143 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900144 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
145 }
146
147 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
148 astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
149 }
150 u32LastScannedNtwrksCountShadow = 0;
151 }
152
153}
154
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900155u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900156{
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900157 u8 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900158 int rssi_v = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900159 u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900160
161 for (i = 0; i < num_rssi; i++)
162 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
163
164 rssi_v /= num_rssi;
165 return rssi_v;
166}
167
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900168void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900169{
Chaehyun Lim27268872015-09-15 14:06:13 +0900170 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900171 struct wiphy *wiphy;
172 struct cfg80211_bss *bss = NULL;
173 int i;
174 int rssi = 0;
175
Chaehyun Lim27268872015-09-15 14:06:13 +0900176 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900177 wiphy = priv->dev->ieee80211_ptr->wiphy;
178
179 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
180 tstrNetworkInfo *pstrNetworkInfo;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900181
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
183
184
185 if ((!pstrNetworkInfo->u8Found) || all) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900186 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187 struct ieee80211_channel *channel;
188
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900189 if (pstrNetworkInfo != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900191 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900192 channel = ieee80211_get_channel(wiphy, s32Freq);
193
194 rssi = get_rssi_avg(pstrNetworkInfo);
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900195 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
197 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900198 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900199 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900200 }
201 }
202
203 }
204 }
205
206}
207
208void reset_shadow_found(void *pUserVoid)
209{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900211
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900212 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
213 astrLastScannedNtwrksShadow[i].u8Found = 0;
214
215 }
216}
217
218void update_scan_time(void *pUserVoid)
219{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900221
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900222 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
223 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
224 }
225}
226
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700227static void remove_network_from_shadow(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900229 unsigned long now = jiffies;
230 int i, j;
231
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900232
233 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
234 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530235 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900236
237 if (astrLastScannedNtwrksShadow[i].pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900238 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900239 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
240 }
241
242 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
243
244 for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
245 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
246 }
247 u32LastScannedNtwrksCountShadow--;
248 }
249 }
250
251 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700252 if (u32LastScannedNtwrksCountShadow != 0) {
253 hAgingTimer.data = arg;
254 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
255 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900256 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700257 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900258}
259
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700260static void clear_duringIP(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900261{
262 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900263 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900264}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900266int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900268 int state = -1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269 int i;
270
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900271 if (u32LastScannedNtwrksCountShadow == 0) {
272 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700273 hAgingTimer.data = (unsigned long)pUserVoid;
274 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900275 state = -1;
276 } else {
277 /* Linear search for now */
278 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900279 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900280 pstrNetworkInfo->au8bssid, 6) == 0) {
281 state = i;
282 break;
283 }
284 }
285 }
286 return state;
287}
288
289void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
290{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900291 int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900292 u32 ap_index = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900293 u8 rssi_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900294
295 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
296 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
297 return;
298 }
299 if (ap_found == -1) {
300 ap_index = u32LastScannedNtwrksCountShadow;
301 u32LastScannedNtwrksCountShadow++;
302
303 } else {
304 ap_index = ap_found;
305 }
306 rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
307 astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
308 if (rssi_index == NUM_RSSI) {
309 rssi_index = 0;
310 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
311 }
312 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
313
314 astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
315 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
316
317 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900318 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900319 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
320
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900321 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900322 pstrNetworkInfo->au8bssid, ETH_ALEN);
323
324 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
325 astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
326 astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
327
328 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
329 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
330 if (ap_found != -1)
Chaehyun Lim49188af2015-08-11 10:32:41 +0900331 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900332 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
Glen Leef3052582015-09-10 12:03:04 +0900333 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900334 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900335 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
336
337 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
338 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
339 astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
340 if (ap_found != -1)
341 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
342 astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
343
344}
345
346
347/**
348 * @brief CfgScanResult
349 * @details Callback function which returns the scan results found
350 *
351 * @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is
352 * SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE
353 * tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information
354 * void* pUserVoid: Private structure associated with the wireless interface
355 * @return NONE
356 * @author mabubakr
357 * @date
358 * @version 1.0
359 */
360static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
361{
Chaehyun Lim27268872015-09-15 14:06:13 +0900362 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900363 struct wiphy *wiphy;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900364 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365 struct ieee80211_channel *channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900366 struct cfg80211_bss *bss = NULL;
367
Chaehyun Lim27268872015-09-15 14:06:13 +0900368 priv = (struct wilc_priv *)pUserVoid;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900369 if (priv->bCfgScanning == true) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900370 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
371 wiphy = priv->dev->ieee80211_ptr->wiphy;
Leo Kim7ae43362015-09-16 18:35:59 +0900372
373 if (!wiphy)
374 return;
375
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900376 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
377 &&
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900378 ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900379 ||
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900380 (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900381 ) {
Leo Kim24db7132015-09-16 18:36:01 +0900382 PRINT_ER("wiphy signal type fial\n");
383 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900384 }
385
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900386 if (pstrNetworkInfo != NULL) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900387 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900388 channel = ieee80211_get_channel(wiphy, s32Freq);
389
Leo Kim7ae43362015-09-16 18:35:59 +0900390 if (!channel)
391 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900392
393 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530394 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900395 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
396
Dean Lee72ed4dc2015-06-12 14:11:44 +0900397 if (pstrNetworkInfo->bNewNetwork == true) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900398 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
399 /* max_scan_ssids */
400 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
401
402
403 priv->u32RcvdChCount++;
404
405
406
407 if (pJoinParams == NULL) {
408 PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
409 }
410 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
411
412 /*P2P peers are sent to WPA supplicant and added to shadow table*/
413
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900414 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900415 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
416 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900417 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900418 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900419 }
420
421
422 } else {
423 PRINT_ER("Discovered networks exceeded the max limit\n");
424 }
425 } else {
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900426 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900427 /* So this network is discovered before, we'll just update its RSSI */
428 for (i = 0; i < priv->u32RcvdChCount; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900429 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530430 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900431
432 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
433 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
434 break;
435 }
436 }
437 }
438 }
439 } else if (enuScanEvent == SCAN_EVENT_DONE) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530440 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
441 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900442 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530444 if (priv->u32RcvdChCount > 0)
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530445 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530446 else
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530447 PRINT_D(CFG80211_DBG, "No networks found\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200449 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900450
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900451 if (priv->pstrScanReq != NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900452 cfg80211_scan_done(priv->pstrScanReq, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900453 priv->u32RcvdChCount = 0;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900454 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900455 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900456 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200457 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458
459 }
460 /*Aborting any scan operation during mac close*/
461 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200462 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900463
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530464 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900465 if (priv->pstrScanReq != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900466
467 update_scan_time(priv);
Dean Lee72ed4dc2015-06-12 14:11:44 +0900468 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900469
Dean Lee72ed4dc2015-06-12 14:11:44 +0900470 cfg80211_scan_done(priv->pstrScanReq, false);
471 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900472 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900473 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200474 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900475 }
476 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900477}
478
479
480/**
481 * @brief WILC_WFI_Set_PMKSA
482 * @details Check if pmksa is cached and set it.
483 * @param[in]
484 * @return int : Return 0 on Success
485 * @author mdaftedar
486 * @date 01 MAR 2012
487 * @version 1.0
488 */
Chaehyun Lim27268872015-09-15 14:06:13 +0900489int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900490{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900491 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900492 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900493
494
495 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
496
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900497 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900498 ETH_ALEN)) {
499 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
500
501 /*If bssid is found, set the values*/
502 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
503
Leo Kime6e12662015-09-16 18:36:03 +0900504 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900505 PRINT_ER("Error in pmkid\n");
506
507 break;
508 }
509 }
510
511 return s32Error;
512
513
514}
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900515int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900516
517
518/**
519 * @brief CfgConnectResult
520 * @details
521 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
522 * connection response or disconnection notification.
523 * tstrConnectInfo* pstrConnectInfo: COnnection information.
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900524 * u8 u8MacStatus: Mac Status from firmware
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900525 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
526 * void* pUserVoid: Private data associated with wireless interface
527 * @return NONE
528 * @author mabubakr
529 * @date 01 MAR 2012
530 * @version 1.0
531 */
532int connecting;
533
534static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
535 tstrConnectInfo *pstrConnectInfo,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900536 u8 u8MacStatus,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900537 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
538 void *pUserVoid)
539{
Chaehyun Lim27268872015-09-15 14:06:13 +0900540 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541 struct net_device *dev;
Leo Kim441dc602015-10-12 16:55:35 +0900542 struct host_if_drv *pstrWFIDrv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900543 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900544
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545 connecting = 0;
546
Chaehyun Lim27268872015-09-15 14:06:13 +0900547 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900548 dev = priv->dev;
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*/
Chaehyun Limd85f5322015-06-11 14:35:54 +0900553 u16 u16ConnectStatus = WLAN_STATUS_SUCCESS;
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*/
631 if ((pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
632 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*/
636 else if ((!pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
637 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*/
1175 if (priv->wilc_gtk[key_index]->key)
Chaehyun Lim49188af2015-08-11 10:32:41 +09001176 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001177
Glen Leef3052582015-09-10 12:03:04 +09001178 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001179 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001180
1181 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
1182 if (priv->wilc_gtk[key_index]->seq)
Chaehyun Lim49188af2015-08-11 10:32:41 +09001183 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184
1185 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001186 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001187 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001188 }
1189
1190 priv->wilc_gtk[key_index]->cipher = params->cipher;
1191 priv->wilc_gtk[key_index]->key_len = params->key_len;
1192 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1193
1194 if (INFO) {
1195 for (i = 0; i < params->key_len; i++)
1196 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1197 for (i = 0; i < params->seq_len; i++)
1198 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1199 }
1200
1201
1202 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1203 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1204
1205 } else {
1206 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]);
1207
1208 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1209 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1210 else
1211 u8pmode = priv->wilc_groupkey | AES;
1212
1213
1214 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1215
1216 pu8TxMic = params->key + 24;
1217 pu8RxMic = params->key + 16;
1218 KeyLen = params->key_len - 16;
1219 }
1220
1221 if (priv->wilc_ptk[key_index]->key)
Chaehyun Lim49188af2015-08-11 10:32:41 +09001222 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223
Glen Leef3052582015-09-10 12:03:04 +09001224 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001225
1226 if (priv->wilc_ptk[key_index]->seq)
Chaehyun Lim49188af2015-08-11 10:32:41 +09001227 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001228
1229 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001230 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001231
1232 if (INFO) {
1233 for (i = 0; i < params->key_len; i++)
1234 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1235
1236 for (i = 0; i < params->seq_len; i++)
1237 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1238 }
1239
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001240 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001241
1242 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001243 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001244
1245 priv->wilc_ptk[key_index]->cipher = params->cipher;
1246 priv->wilc_ptk[key_index]->key_len = params->key_len;
1247 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1248
1249 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1250 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1251 }
1252 break;
1253 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001254
1255 {
1256 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001257 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001258 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1259 /* swap the tx mic by rx mic */
1260 pu8RxMic = params->key + 24;
1261 pu8TxMic = params->key + 16;
1262 KeyLen = params->key_len - 16;
1263 }
1264
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001265 /*save keys only on interface 0 (wifi interface)*/
1266 if (!g_gtk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
1267 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001268 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001269 if (!mac_addr) {
1270 g_add_gtk_key_params.mac_addr = NULL;
1271 } else {
Glen Leef3052582015-09-10 12:03:04 +09001272 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001273 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1274 }
1275 g_key_gtk_params.key_len = params->key_len;
1276 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001277 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001278 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1279 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001280 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001281 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1282 }
1283 g_key_gtk_params.cipher = params->cipher;
1284
1285 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1286 g_key_gtk_params.key[1],
1287 g_key_gtk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001288 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001289 }
1290
1291 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1292 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001293 } else {
1294 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1295 /* swap the tx mic by rx mic */
1296 pu8RxMic = params->key + 24;
1297 pu8TxMic = params->key + 16;
1298 KeyLen = params->key_len - 16;
1299 }
1300
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301 /*save keys only on interface 0 (wifi interface)*/
1302 if (!g_ptk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
1303 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001305 if (!mac_addr) {
1306 g_add_ptk_key_params.mac_addr = NULL;
1307 } else {
Glen Leef3052582015-09-10 12:03:04 +09001308 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001309 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1310 }
1311 g_key_ptk_params.key_len = params->key_len;
1312 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001313 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001314 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1315 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001316 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001317 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1318 }
1319 g_key_ptk_params.cipher = params->cipher;
1320
1321 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1322 g_key_ptk_params.key[1],
1323 g_key_ptk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001324 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001325 }
1326
1327 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1328 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1329 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1330 if (INFO) {
1331 for (i = 0; i < params->key_len; i++)
1332 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1333 }
1334 }
1335 }
1336 break;
1337
1338 default:
1339 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1340 s32Error = -ENOTSUPP;
1341
1342 }
1343
1344 return s32Error;
1345}
1346
1347/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001348 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001349 * @details Remove a key given the @mac_addr (%NULL for a group key)
1350 * and @key_index, return -ENOENT if the key doesn't exist.
1351 * @param[in]
1352 * @return int : Return 0 on Success
1353 * @author mdaftedar
1354 * @date 01 MAR 2012
1355 * @version 1.0
1356 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001357static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1358 u8 key_index,
1359 bool pairwise,
1360 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001361{
Chaehyun Lim27268872015-09-15 14:06:13 +09001362 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09001363 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364
1365 priv = wiphy_priv(wiphy);
1366
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367 /*delete saved keys, if any*/
1368 if (netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001369 g_ptk_keys_saved = false;
1370 g_gtk_keys_saved = false;
1371 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001372
1373 /*Delete saved WEP keys params, if any*/
1374 if (g_key_wep_params.key != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +09001375 kfree(g_key_wep_params.key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001376 g_key_wep_params.key = NULL;
1377 }
1378
1379 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1380
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001381 if ((priv->wilc_gtk[key_index]) != NULL) {
1382
1383 if (priv->wilc_gtk[key_index]->key != NULL) {
1384
Chaehyun Lim49188af2015-08-11 10:32:41 +09001385 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001386 priv->wilc_gtk[key_index]->key = NULL;
1387 }
1388 if (priv->wilc_gtk[key_index]->seq) {
1389
Chaehyun Lim49188af2015-08-11 10:32:41 +09001390 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001391 priv->wilc_gtk[key_index]->seq = NULL;
1392 }
1393
Chaehyun Lim49188af2015-08-11 10:32:41 +09001394 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001395 priv->wilc_gtk[key_index] = NULL;
1396
1397 }
1398
1399 if ((priv->wilc_ptk[key_index]) != NULL) {
1400
1401 if (priv->wilc_ptk[key_index]->key) {
1402
Chaehyun Lim49188af2015-08-11 10:32:41 +09001403 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001404 priv->wilc_ptk[key_index]->key = NULL;
1405 }
1406 if (priv->wilc_ptk[key_index]->seq) {
1407
Chaehyun Lim49188af2015-08-11 10:32:41 +09001408 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409 priv->wilc_ptk[key_index]->seq = NULL;
1410 }
Chaehyun Lim49188af2015-08-11 10:32:41 +09001411 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412 priv->wilc_ptk[key_index] = NULL;
1413 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001414
1415 /*Delete saved PTK and GTK keys params, if any*/
1416 if (g_key_ptk_params.key != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +09001417 kfree(g_key_ptk_params.key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001418 g_key_ptk_params.key = NULL;
1419 }
1420 if (g_key_ptk_params.seq != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +09001421 kfree(g_key_ptk_params.seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001422 g_key_ptk_params.seq = NULL;
1423 }
1424
1425 if (g_key_gtk_params.key != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +09001426 kfree(g_key_gtk_params.key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001427 g_key_gtk_params.key = NULL;
1428 }
1429 if (g_key_gtk_params.seq != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +09001430 kfree(g_key_gtk_params.seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001431 g_key_gtk_params.seq = NULL;
1432 }
1433
1434 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Dean Lee72ed4dc2015-06-12 14:11:44 +09001435 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001436 }
1437
1438 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001439 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001440 priv->WILC_WFI_wep_key_len[key_index] = 0;
1441
1442 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1443 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1444 } else {
1445 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1446 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1447 }
1448
1449 return s32Error;
1450}
1451
1452/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001453 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001454 * @details Get information about the key with the given parameters.
1455 * @mac_addr will be %NULL when requesting information for a group
1456 * key. All pointers given to the @callback function need not be valid
1457 * after it returns. This function should return an error if it is
1458 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1459 * @param[in]
1460 * @return int : Return 0 on Success
1461 * @author mdaftedar
1462 * @date 01 MAR 2012
1463 * @version 1.0
1464 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001465static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1466 bool pairwise,
1467 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001468{
1469
Leo Kime6e12662015-09-16 18:36:03 +09001470 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001471
Chaehyun Lim27268872015-09-15 14:06:13 +09001472 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001473 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001474 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001475
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001476 priv = wiphy_priv(wiphy);
1477
1478
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001479 if (!pairwise)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001480 {
1481 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1482
1483 key_params.key = priv->wilc_gtk[key_index]->key;
1484 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1485 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1486 key_params.seq = priv->wilc_gtk[key_index]->seq;
1487 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1488 if (INFO) {
1489 for (i = 0; i < key_params.key_len; i++)
1490 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1491 }
1492 } else {
1493 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1494
1495 key_params.key = priv->wilc_ptk[key_index]->key;
1496 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1497 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1498 key_params.seq = priv->wilc_ptk[key_index]->seq;
1499 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1500 }
1501
1502 callback(cookie, &key_params);
1503
1504 return s32Error; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
1505}
1506
1507/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001508 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001509 * @details Set the default management frame key on an interface
1510 * @param[in]
1511 * @return int : Return 0 on Success.
1512 * @author mdaftedar
1513 * @date 01 MAR 2012
1514 * @version 1.0
1515 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001516static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1517 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001518{
Leo Kime6e12662015-09-16 18:36:03 +09001519 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001520 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001521
1522
1523 priv = wiphy_priv(wiphy);
1524
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301525 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001526
1527 if (key_index != priv->WILC_WFI_wep_default) {
1528
1529 host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
1530 }
1531
1532 return s32Error;
1533}
1534
1535/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001536 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001537 * @details Get station information for the station identified by @mac
1538 * @param[in] NONE
1539 * @return int : Return 0 on Success.
1540 * @author mdaftedar
1541 * @date 01 MAR 2012
1542 * @version 1.0
1543 */
1544
Chaehyun Limf06f5622015-09-14 12:24:18 +09001545static int get_station(struct wiphy *wiphy, struct net_device *dev,
1546 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001547{
Leo Kime6e12662015-09-16 18:36:03 +09001548 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001549 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001550 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001551 u32 i = 0;
1552 u32 associatedsta = 0;
1553 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001554 priv = wiphy_priv(wiphy);
1555 nic = netdev_priv(dev);
1556
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001557 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1558 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1559
1560 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1561
1562 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1563
1564 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1565 associatedsta = i;
1566 break;
1567 }
1568
1569 }
1570
1571 if (associatedsta == -1) {
1572 s32Error = -ENOENT;
1573 PRINT_ER("Station required is not associated : Error(%d)\n", s32Error);
1574
1575 return s32Error;
1576 }
1577
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001578 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001579
1580 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1581 sinfo->inactive_time = 1000 * inactive_time;
1582 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1583
1584 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001585
1586 if (nic->iftype == STATION_MODE) {
1587 tstrStatistics strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001588
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001589 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1590
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001591 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301592 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001593 BIT(NL80211_STA_INFO_TX_PACKETS) |
1594 BIT(NL80211_STA_INFO_TX_FAILED) |
1595 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001596
1597 sinfo->signal = strStatistics.s8RSSI;
1598 sinfo->rx_packets = strStatistics.u32RxCount;
1599 sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001600 sinfo->tx_failed = strStatistics.u32TxFailureCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001601 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1602
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301603 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001604 Enable_TCP_ACK_Filter(true);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301605 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001606 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001607
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001608 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1609 sinfo->tx_failed, sinfo->txrate.legacy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001610 }
1611 return s32Error;
1612}
1613
1614
1615/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001616 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001617 * @details Modify parameters for a given BSS.
1618 * @param[in]
1619 * -use_cts_prot: Whether to use CTS protection
1620 * (0 = no, 1 = yes, -1 = do not change)
1621 * -use_short_preamble: Whether the use of short preambles is allowed
1622 * (0 = no, 1 = yes, -1 = do not change)
1623 * -use_short_slot_time: Whether the use of short slot time is allowed
1624 * (0 = no, 1 = yes, -1 = do not change)
1625 * -basic_rates: basic rates in IEEE 802.11 format
1626 * (or NULL for no change)
1627 * -basic_rates_len: number of basic rates
1628 * -ap_isolate: do not forward packets between connected stations
1629 * -ht_opmode: HT Operation mode
1630 * (u16 = opmode, -1 = do not change)
1631 * @return int : Return 0 on Success.
1632 * @author mdaftedar
1633 * @date 01 MAR 2012
1634 * @version 1.0
1635 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001636static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1637 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001638{
1639 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1640 return 0;
1641}
1642
1643/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001644 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001645 * @details Notify that wiphy parameters have changed;
1646 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1647 * have changed.
1648 * @return int : Return 0 on Success
1649 * @author mdaftedar
1650 * @date 01 MAR 2012
1651 * @version 1.0
1652 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001653static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001654{
Leo Kime6e12662015-09-16 18:36:03 +09001655 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001656 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001657 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001658
1659 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001660
1661 pstrCfgParamVal.u32SetCfgFlag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301662 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001663
1664 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1665 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1666 priv->dev->ieee80211_ptr->wiphy->retry_short);
1667 pstrCfgParamVal.u32SetCfgFlag |= RETRY_SHORT;
1668 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1669 }
1670 if (changed & WIPHY_PARAM_RETRY_LONG) {
1671
1672 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
1673 pstrCfgParamVal.u32SetCfgFlag |= RETRY_LONG;
1674 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1675
1676 }
1677 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1678 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
1679 pstrCfgParamVal.u32SetCfgFlag |= FRAG_THRESHOLD;
1680 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1681
1682 }
1683
1684 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1685 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1686
1687 pstrCfgParamVal.u32SetCfgFlag |= RTS_THRESHOLD;
1688 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1689
1690 }
1691
1692 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1693 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1694 if (s32Error)
1695 PRINT_ER("Error in setting WIPHY PARAMS\n");
1696
1697
1698 return s32Error;
1699}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001700
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001701/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001702 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001703 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1704 * devices running firmwares capable of generating the (re) association
1705 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1706 * @param[in]
1707 * @return int : Return 0 on Success
1708 * @author mdaftedar
1709 * @date 01 MAR 2012
1710 * @version 1.0
1711 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001712static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1713 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001714{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001715 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001716 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001717 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001718
Chaehyun Lim27268872015-09-15 14:06:13 +09001719 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001720
1721 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1722
1723
1724 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001725 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001726 ETH_ALEN)) {
1727 /*If bssid already exists and pmkid value needs to reset*/
1728 flag = PMKID_FOUND;
1729 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1730 break;
1731 }
1732 }
1733 if (i < WILC_MAX_NUM_PMKIDS) {
1734 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001735 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001736 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001737 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001738 PMKID_LEN);
1739 if (!(flag == PMKID_FOUND))
1740 priv->pmkid_list.numpmkid++;
1741 } else {
1742 PRINT_ER("Invalid PMKID index\n");
1743 s32Error = -EINVAL;
1744 }
1745
1746 if (!s32Error) {
1747 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1748 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1749 }
1750 return s32Error;
1751}
1752
1753/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001754 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001755 * @details Delete a cached PMKID.
1756 * @param[in]
1757 * @return int : Return 0 on Success
1758 * @author mdaftedar
1759 * @date 01 MAR 2012
1760 * @version 1.0
1761 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001762static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1763 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001764{
1765
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001766 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001767 u8 flag = 0;
Leo Kime6e12662015-09-16 18:36:03 +09001768 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001769
Chaehyun Lim27268872015-09-15 14:06:13 +09001770 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001771
1772 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1773
1774 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001775 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001776 ETH_ALEN)) {
1777 /*If bssid is found, reset the values*/
1778 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001779 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001780 flag = PMKID_FOUND;
1781 break;
1782 }
1783 }
1784
1785 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1786 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001787 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001788 priv->pmkid_list.pmkidlist[i + 1].bssid,
1789 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001790 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001791 priv->pmkid_list.pmkidlist[i].pmkid,
1792 PMKID_LEN);
1793 }
1794 priv->pmkid_list.numpmkid--;
1795 } else {
1796 s32Error = -EINVAL;
1797 }
1798
1799 return s32Error;
1800}
1801
1802/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001803 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001804 * @details Flush all cached PMKIDs.
1805 * @param[in]
1806 * @return int : Return 0 on Success
1807 * @author mdaftedar
1808 * @date 01 MAR 2012
1809 * @version 1.0
1810 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001811static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001812{
Chaehyun Lim27268872015-09-15 14:06:13 +09001813 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001814
1815 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1816
1817 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001818 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001819
1820 return 0;
1821}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001822
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001823
1824/**
1825 * @brief WILC_WFI_CfgParseRxAction
1826 * @details Function parses the received frames and modifies the following attributes:
1827 * -GO Intent
1828 * -Channel list
1829 * -Operating Channel
1830 *
1831 * @param[in] u8* Buffer, u32 length
1832 * @return NONE.
1833 * @author mdaftedar
1834 * @date 12 DEC 2012
1835 * @version
1836 */
1837
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001838void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001839{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001840 u32 index = 0;
1841 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001842
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001843 u8 op_channel_attr_index = 0;
1844 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001845
1846 while (index < len) {
1847 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001848 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001849 }
1850
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301851 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001852 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301853 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001854 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001855 index += buf[index + 1] + 3; /* ID,Length byte */
1856 }
1857
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001858 if (u8WLANChannel != INVALID_CHANNEL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859 {
1860 /*Modify channel list attribute*/
1861 if (channel_list_attr_index) {
1862 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1863 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1864 if (buf[i] == 0x51) {
1865 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1866 buf[j] = u8WLANChannel;
1867 }
1868 break;
1869 }
1870 }
1871 }
1872 /*Modify operating channel attribute*/
1873 if (op_channel_attr_index) {
1874 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1875 buf[op_channel_attr_index + 6] = 0x51;
1876 buf[op_channel_attr_index + 7] = u8WLANChannel;
1877 }
1878 }
1879}
1880
1881/**
1882 * @brief WILC_WFI_CfgParseTxAction
1883 * @details Function parses the transmitted action frames and modifies the
1884 * GO Intent attribute
1885 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1886 * @return NONE.
1887 * @author mdaftedar
1888 * @date 12 DEC 2012
1889 * @version
1890 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001891void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001892{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001893 u32 index = 0;
1894 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001895
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001896 u8 op_channel_attr_index = 0;
1897 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001898
1899 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001900 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001901 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001902
1903 break;
1904 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001905
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301906 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001907 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301908 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001909 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001910 index += buf[index + 1] + 3; /* ID,Length byte */
1911 }
1912
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001913 if (u8WLANChannel != INVALID_CHANNEL && bOperChan)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001914 {
1915 /*Modify channel list attribute*/
1916 if (channel_list_attr_index) {
1917 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1918 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1919 if (buf[i] == 0x51) {
1920 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1921 buf[j] = u8WLANChannel;
1922 }
1923 break;
1924 }
1925 }
1926 }
1927 /*Modify operating channel attribute*/
1928 if (op_channel_attr_index) {
1929 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1930 buf[op_channel_attr_index + 6] = 0x51;
1931 buf[op_channel_attr_index + 7] = u8WLANChannel;
1932 }
1933 }
1934}
1935
1936/* @brief WILC_WFI_p2p_rx
1937 * @details
1938 * @param[in]
1939 *
1940 * @return None
1941 * @author Mai Daftedar
1942 * @date 2 JUN 2013
1943 * @version 1.0
1944 */
1945
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001946void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001947{
1948
Chaehyun Lim27268872015-09-15 14:06:13 +09001949 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001950 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001951 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001952 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001953 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001954
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001955 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001956 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001957
1958 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001959 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001960
1961 /* The packet offset field conain info about what type of managment frame */
1962 /* we are dealing with and ack status */
1963 pkt_offset = GET_PKT_OFFSET(header);
1964
1965 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1966 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1967 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001968 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001969 return;
1970 } else {
1971 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1972 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],
1973 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001974 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001975 } else {
1976 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],
1977 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001978 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001979 }
1980 return;
1981 }
1982 } else {
1983
1984 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1985
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001986 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001987 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001988
1989 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1990 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1991
Dean Lee72ed4dc2015-06-12 14:11:44 +09001992 if (priv->bCfgScanning == true && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001993 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1994 return;
1995 }
1996 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1997
1998 switch (buff[ACTION_SUBTYPE_ID]) {
1999 case GAS_INTIAL_REQ:
2000 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
2001 break;
2002
2003 case GAS_INTIAL_RSP:
2004 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
2005 break;
2006
2007 case PUBLIC_ACT_VENDORSPEC:
2008 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2009 * 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 +09002010 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002011 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2012 if (!bWilc_ie) {
2013 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002014 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002015 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09002016 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002017 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
2018 break;
2019 }
2020 }
2021 }
2022 }
2023 if (u8P2Plocalrandom > u8P2Precvrandom) {
2024 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2025 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2026 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002027 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002028 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
2029 break;
2030 }
2031 }
2032 }
2033 } else
2034 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2035 }
2036
2037
2038 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2039 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2040 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002041 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002042 return;
2043 }
2044 break;
2045
2046 default:
2047 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2048 break;
2049 }
2050 }
2051 }
2052
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002053 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002054 }
2055}
2056
2057/**
2058 * @brief WILC_WFI_mgmt_tx_complete
2059 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2060 * @param[in] priv
2061 * transmitting status
2062 * @return None
2063 * @author Amr Abdelmoghny
2064 * @date 20 MAY 2013
2065 * @version 1.0
2066 */
2067static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2068{
2069 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2070
2071
2072 kfree(pv_data->buff);
2073 kfree(pv_data);
2074}
2075
2076/**
2077 * @brief WILC_WFI_RemainOnChannelReady
2078 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2079 * @param
2080 * @return none
2081 * @author Amr abdelmoghny
2082 * @date 9 JUNE 2013
2083 * @version
2084 */
2085
2086static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2087{
Chaehyun Lim27268872015-09-15 14:06:13 +09002088 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002089
Chaehyun Lim27268872015-09-15 14:06:13 +09002090 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002091
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302092 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002093
Dean Lee72ed4dc2015-06-12 14:11:44 +09002094 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002095
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002096 cfg80211_ready_on_channel(priv->wdev,
2097 priv->strRemainOnChanParams.u64ListenCookie,
2098 priv->strRemainOnChanParams.pstrListenChan,
2099 priv->strRemainOnChanParams.u32ListenDuration,
2100 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002101}
2102
2103/**
2104 * @brief WILC_WFI_RemainOnChannelExpired
2105 * @details Callback function, called on expiration of remain-on-channel duration
2106 * @param
2107 * @return none
2108 * @author Amr abdelmoghny
2109 * @date 15 MAY 2013
2110 * @version
2111 */
2112
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002113static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002114{
Chaehyun Lim27268872015-09-15 14:06:13 +09002115 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002116
Chaehyun Lim27268872015-09-15 14:06:13 +09002117 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002118
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002119 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302120 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002121
Dean Lee72ed4dc2015-06-12 14:11:44 +09002122 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002123
2124 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002125 cfg80211_remain_on_channel_expired(priv->wdev,
2126 priv->strRemainOnChanParams.u64ListenCookie,
2127 priv->strRemainOnChanParams.pstrListenChan,
2128 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002129 } else {
2130 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2131 , priv->strRemainOnChanParams.u32ListenSessionID);
2132 }
2133}
2134
2135
2136/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002137 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002138 * @details Request the driver to remain awake on the specified
2139 * channel for the specified duration to complete an off-channel
2140 * operation (e.g., public action frame exchange). When the driver is
2141 * ready on the requested channel, it must indicate this with an event
2142 * notification by calling cfg80211_ready_on_channel().
2143 * @param[in]
2144 * @return int : Return 0 on Success
2145 * @author mdaftedar
2146 * @date 01 MAR 2012
2147 * @version 1.0
2148 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002149static int remain_on_channel(struct wiphy *wiphy,
2150 struct wireless_dev *wdev,
2151 struct ieee80211_channel *chan,
2152 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002153{
Leo Kime6e12662015-09-16 18:36:03 +09002154 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002155 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002156
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002157 priv = wiphy_priv(wiphy);
2158
2159 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2160
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002161
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002162 if (wdev->iftype == NL80211_IFTYPE_AP) {
2163 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2164 return s32Error;
2165 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002166
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002167 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002168
2169 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2170 priv->strRemainOnChanParams.pstrListenChan = chan;
2171 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002172 priv->strRemainOnChanParams.u32ListenDuration = duration;
2173 priv->strRemainOnChanParams.u32ListenSessionID++;
2174
2175 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2176 , priv->strRemainOnChanParams.u32ListenSessionID
2177 , duration
2178 , chan->hw_value
2179 , WILC_WFI_RemainOnChannelExpired
2180 , WILC_WFI_RemainOnChannelReady
2181 , (void *)priv);
2182
2183 return s32Error;
2184}
2185
2186/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002187 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002188 * @details Cancel an on-going remain-on-channel operation.
2189 * This allows the operation to be terminated prior to timeout based on
2190 * the duration value.
2191 * @param[in] struct wiphy *wiphy,
2192 * @param[in] struct net_device *dev
2193 * @param[in] u64 cookie,
2194 * @return int : Return 0 on Success
2195 * @author mdaftedar
2196 * @date 01 MAR 2012
2197 * @version 1.0
2198 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002199static int cancel_remain_on_channel(struct wiphy *wiphy,
2200 struct wireless_dev *wdev,
2201 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002202{
Leo Kime6e12662015-09-16 18:36:03 +09002203 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002204 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002205
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002206 priv = wiphy_priv(wiphy);
2207
2208 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2209
2210 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2211 return s32Error;
2212}
2213/**
2214 * @brief WILC_WFI_add_wilcvendorspec
2215 * @details Adding WILC information elemet to allow two WILC devices to
2216 * identify each other and connect
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002217 * @param[in] u8 * buf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002218 * @return void
2219 * @author mdaftedar
2220 * @date 01 JAN 2014
2221 * @version 1.0
2222 */
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002223void WILC_WFI_add_wilcvendorspec(u8 *buff)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002224{
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002225 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002226}
2227/**
2228 * @brief WILC_WFI_mgmt_tx_frame
2229 * @details
2230 *
2231 * @param[in]
2232 * @return NONE.
2233 * @author mdaftedar
2234 * @date 01 JUL 2012
2235 * @version
2236 */
2237extern linux_wlan_t *g_linux_wlan;
Dean Lee72ed4dc2015-06-12 14:11:44 +09002238extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002239static int mgmt_tx(struct wiphy *wiphy,
2240 struct wireless_dev *wdev,
2241 struct cfg80211_mgmt_tx_params *params,
2242 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002243{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002244 struct ieee80211_channel *chan = params->chan;
2245 unsigned int wait = params->wait;
2246 const u8 *buf = params->buf;
2247 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002248 const struct ieee80211_mgmt *mgmt;
2249 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002250 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002251 s32 s32Error = 0;
Leo Kim441dc602015-10-12 16:55:35 +09002252 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002253 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002254 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002255 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002256
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002257 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002258 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002259 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002260
2261 *cookie = (unsigned long)buf;
2262 priv->u64tx_cookie = *cookie;
2263 mgmt = (const struct ieee80211_mgmt *) buf;
2264
2265 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2266
2267 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002268 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002269 if (mgmt_tx == NULL) {
2270 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002271 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002272 }
Glen Leef3052582015-09-10 12:03:04 +09002273 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002274 if (mgmt_tx->buff == NULL) {
2275 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002276 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002277 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002278 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002279 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002280 mgmt_tx->size = len;
2281
2282
2283 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2284 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2285 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2286 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2287 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002288 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002289 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002290 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002291
2292
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002293 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002294 /*Only set the channel, if not a negotiation confirmation frame
2295 * (If Negotiation confirmation frame, force it
2296 * to be transmitted on the same negotiation channel)*/
2297
2298 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2299 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2300 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2301 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2302 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002303 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002304 }
2305 switch (buf[ACTION_SUBTYPE_ID]) {
2306 case GAS_INTIAL_REQ:
2307 {
2308 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2309 break;
2310 }
2311
2312 case GAS_INTIAL_RSP:
2313 {
2314 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2315 break;
2316 }
2317
2318 case PUBLIC_ACT_VENDORSPEC:
2319 {
2320 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2321 * 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 +09002322 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002323 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2324 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2325 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2326 get_random_bytes(&u8P2Plocalrandom, 1);
2327 /*Increment the number to prevent if its 0*/
2328 u8P2Plocalrandom++;
2329 }
2330 }
2331
2332 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2333 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2334 if (u8P2Plocalrandom > u8P2Precvrandom) {
2335 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2336
2337 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2338 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002339 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002340 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002341 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002342
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002343 /*If using supplicant go intent, no need at all*/
2344 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002345 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002346 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002347 break;
2348 }
2349 }
2350
2351 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
2352 WILC_WFI_add_wilcvendorspec(&mgmt_tx->buff[len]);
2353 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2354 mgmt_tx->size = buf_len;
2355 }
2356 } else
2357 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2358 }
2359
2360 } else {
2361 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2362 }
2363
2364 break;
2365 }
2366
2367 default:
2368 {
2369 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2370 break;
2371 }
2372 }
2373
2374 }
2375
2376 PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
2377 pstrWFIDrv->u64P2p_MgmtTimeout = (jiffies + msecs_to_jiffies(wait));
2378
2379 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
2380
2381 }
2382
Glen Leec9d48342015-10-01 16:03:43 +09002383 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2384 mgmt_tx->size,
2385 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002386 } else {
2387 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2388 }
2389 return s32Error;
2390}
2391
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002392static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2393 struct wireless_dev *wdev,
2394 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002395{
Chaehyun Lim27268872015-09-15 14:06:13 +09002396 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002397 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002398
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002399 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002400 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002401
2402
2403 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
2404 pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
2405
Dean Lee72ed4dc2015-06-12 14:11:44 +09002406 if (priv->bInP2PlistenState == false) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002407 cfg80211_remain_on_channel_expired(priv->wdev,
2408 priv->strRemainOnChanParams.u64ListenCookie,
2409 priv->strRemainOnChanParams.pstrListenChan,
2410 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002411 }
2412
2413 return 0;
2414}
2415
2416/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002417 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002418 * @details Notify driver that a management frame type was
2419 * registered. Note that this callback may not sleep, and cannot run
2420 * concurrently with itself.
2421 * @param[in]
2422 * @return NONE.
2423 * @author mdaftedar
2424 * @date 01 JUL 2012
2425 * @version
2426 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002427void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2428 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002429{
2430
Chaehyun Lim27268872015-09-15 14:06:13 +09002431 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002432 perInterface_wlan_t *nic;
2433
2434
2435 priv = wiphy_priv(wiphy);
2436 nic = netdev_priv(priv->wdev->netdev);
2437
2438
2439
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002440 if (!frame_type)
2441 return;
2442
2443 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2444 switch (frame_type) {
2445 case PROBE_REQ:
2446 {
2447 nic->g_struct_frame_reg[0].frame_type = frame_type;
2448 nic->g_struct_frame_reg[0].reg = reg;
2449 }
2450 break;
2451
2452 case ACTION:
2453 {
2454 nic->g_struct_frame_reg[1].frame_type = frame_type;
2455 nic->g_struct_frame_reg[1].reg = reg;
2456 }
2457 break;
2458
2459 default:
2460 {
2461 break;
2462 }
2463
2464 }
2465 /*If mac is closed, then return*/
2466 if (!g_linux_wlan->wilc1000_initialized) {
2467 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2468 return;
2469 }
2470 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2471
2472
2473}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002474
2475/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002476 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002477 * @details Configure connection quality monitor RSSI threshold.
2478 * @param[in] struct wiphy *wiphy:
2479 * @param[in] struct net_device *dev:
2480 * @param[in] s32 rssi_thold:
2481 * @param[in] u32 rssi_hyst:
2482 * @return int : Return 0 on Success
2483 * @author mdaftedar
2484 * @date 01 MAR 2012
2485 * @version 1.0
2486 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002487static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2488 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002489{
2490 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2491 return 0;
2492
2493}
2494/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002495 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002496 * @details Configure connection quality monitor RSSI threshold.
2497 * @param[in] struct wiphy *wiphy:
2498 * @param[in] struct net_device *dev
2499 * @param[in] int idx
2500 * @param[in] u8 *mac
2501 * @param[in] struct station_info *sinfo
2502 * @return int : Return 0 on Success
2503 * @author mdaftedar
2504 * @date 01 MAR 2012
2505 * @version 1.0
2506 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002507static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2508 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002509{
Chaehyun Lim27268872015-09-15 14:06:13 +09002510 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002511
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002512 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2513
2514 if (idx != 0)
2515 return -ENOENT;
2516
2517 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002518
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002519 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002520
2521 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2522
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002523 return 0;
2524
2525}
2526
2527
2528/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002529 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002530 * @details
2531 * @param[in]
2532 * @return int : Return 0 on Success.
2533 * @author mdaftedar
2534 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002535 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002536 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002537static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2538 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002539{
Chaehyun Lim27268872015-09-15 14:06:13 +09002540 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002541
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002542 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2543
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002544 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002545 return -ENOENT;
2546
2547 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002548 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002549 PRINT_ER("Driver is NULL\n");
2550 return -EIO;
2551 }
2552
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002553 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002554 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2555
2556
Leo Kime6e12662015-09-16 18:36:03 +09002557 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002558
2559}
Glen Lee108b3432015-09-16 18:53:20 +09002560
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002561/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002562 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002563 * @details Change type/configuration of virtual interface,
2564 * keep the struct wireless_dev's iftype updated.
2565 * @param[in] NONE
2566 * @return int : Return 0 on Success.
2567 * @author mdaftedar
2568 * @date 01 MAR 2012
2569 * @version 1.0
2570 */
2571void wilc1000_wlan_deinit(linux_wlan_t *nic);
2572int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2573
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002574static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2575 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002576{
Leo Kime6e12662015-09-16 18:36:03 +09002577 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002578 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002579 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002580 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002581 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002582 u8 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002583
2584 nic = netdev_priv(dev);
2585 priv = wiphy_priv(wiphy);
2586
2587 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2588 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2589 u8P2Plocalrandom = 0x01;
2590 u8P2Precvrandom = 0x00;
2591
Dean Lee72ed4dc2015-06-12 14:11:44 +09002592 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002593
Dean Lee72ed4dc2015-06-12 14:11:44 +09002594 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002595 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002596 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002597 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2598 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09002599 Set_machw_change_vir_if(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002600 }
2601
2602 switch (type) {
2603 case NL80211_IFTYPE_STATION:
2604 connecting = 0;
2605 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002606
2607 /* send delba over wlan interface */
2608
2609
2610 dev->ieee80211_ptr->iftype = type;
2611 priv->wdev->iftype = type;
2612 nic->monitor_flag = 0;
2613 nic->iftype = STATION_MODE;
2614
2615 /*Remove the enteries of the previously connected clients*/
2616 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002617 interface_type = nic->iftype;
2618 nic->iftype = STATION_MODE;
2619
2620 if (g_linux_wlan->wilc1000_initialized) {
2621 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
2622 /* ensure that the message Q is empty */
2623 host_int_wait_msg_queue_idle();
2624
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002625 /*Eliminate host interface blocking state*/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07002626 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002627
2628 wilc1000_wlan_deinit(g_linux_wlan);
2629 wilc1000_wlan_init(dev, nic);
2630 g_wilc_initialized = 1;
2631 nic->iftype = interface_type;
2632
2633 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2634 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
Johnny Kim218dc402015-08-13 13:41:19 +09002635 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002636 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2637 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2638
2639 /*Add saved WEP keys, if any*/
2640 if (g_wep_keys_saved) {
Johnny Kim218dc402015-08-13 13:41:19 +09002641 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002642 g_key_wep_params.key_idx);
Johnny Kim218dc402015-08-13 13:41:19 +09002643 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002644 g_key_wep_params.key,
2645 g_key_wep_params.key_len,
2646 g_key_wep_params.key_idx);
2647 }
2648
2649 /*No matter the driver handler passed here, it will be overwriiten*/
2650 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2651 host_int_flush_join_req(priv->hWILCWFIDrv);
2652
2653 /*Add saved PTK and GTK keys, if any*/
2654 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2655 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2656 g_key_ptk_params.key[1],
2657 g_key_ptk_params.key[2]);
2658 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2659 g_key_gtk_params.key[1],
2660 g_key_gtk_params.key[2]);
Chaehyun Lim953d4172015-09-14 12:24:05 +09002661 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2662 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2663 g_add_ptk_key_params.key_idx,
2664 g_add_ptk_key_params.pairwise,
2665 g_add_ptk_key_params.mac_addr,
2666 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002667
Chaehyun Lim953d4172015-09-14 12:24:05 +09002668 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2669 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2670 g_add_gtk_key_params.key_idx,
2671 g_add_gtk_key_params.pairwise,
2672 g_add_gtk_key_params.mac_addr,
2673 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002674 }
2675
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002676 if (g_linux_wlan->wilc1000_initialized) {
2677 for (i = 0; i < num_reg_frame; i++) {
2678 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2679 nic->g_struct_frame_reg[i].reg);
2680 host_int_frame_register(priv->hWILCWFIDrv,
2681 nic->g_struct_frame_reg[i].frame_type,
2682 nic->g_struct_frame_reg[i].reg);
2683 }
2684 }
2685
Dean Lee72ed4dc2015-06-12 14:11:44 +09002686 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002687 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2688 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002689 break;
2690
2691 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002692 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002693 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2694 connecting = 0;
2695 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002696
2697 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
2698
2699 dev->ieee80211_ptr->iftype = type;
2700 priv->wdev->iftype = type;
2701 nic->monitor_flag = 0;
2702
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002703 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2704 nic->iftype = CLIENT_MODE;
2705
2706
2707 if (g_linux_wlan->wilc1000_initialized) {
2708 /* ensure that the message Q is empty */
2709 host_int_wait_msg_queue_idle();
2710
2711 wilc1000_wlan_deinit(g_linux_wlan);
2712 wilc1000_wlan_init(dev, nic);
2713 g_wilc_initialized = 1;
2714
2715 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
Johnny Kim218dc402015-08-13 13:41:19 +09002716 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002717 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2718 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2719
2720 /*Add saved WEP keys, if any*/
2721 if (g_wep_keys_saved) {
Johnny Kim218dc402015-08-13 13:41:19 +09002722 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002723 g_key_wep_params.key_idx);
Johnny Kim218dc402015-08-13 13:41:19 +09002724 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002725 g_key_wep_params.key,
2726 g_key_wep_params.key_len,
2727 g_key_wep_params.key_idx);
2728 }
2729
2730 /*No matter the driver handler passed here, it will be overwriiten*/
2731 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2732 host_int_flush_join_req(priv->hWILCWFIDrv);
2733
2734 /*Add saved PTK and GTK keys, if any*/
2735 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2736 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2737 g_key_ptk_params.key[1],
2738 g_key_ptk_params.key[2]);
2739 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2740 g_key_gtk_params.key[1],
2741 g_key_gtk_params.key[2]);
Chaehyun Lim953d4172015-09-14 12:24:05 +09002742 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2743 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2744 g_add_ptk_key_params.key_idx,
2745 g_add_ptk_key_params.pairwise,
2746 g_add_ptk_key_params.mac_addr,
2747 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002748
Chaehyun Lim953d4172015-09-14 12:24:05 +09002749 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2750 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2751 g_add_gtk_key_params.key_idx,
2752 g_add_gtk_key_params.pairwise,
2753 g_add_gtk_key_params.mac_addr,
2754 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002755 }
2756
2757 /*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 +09002758 refresh_scan(priv, 1, true);
2759 Set_machw_change_vir_if(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002760
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002761 if (g_linux_wlan->wilc1000_initialized) {
2762 for (i = 0; i < num_reg_frame; i++) {
2763 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2764 nic->g_struct_frame_reg[i].reg);
2765 host_int_frame_register(priv->hWILCWFIDrv,
2766 nic->g_struct_frame_reg[i].frame_type,
2767 nic->g_struct_frame_reg[i].reg);
2768 }
2769 }
2770 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002771 break;
2772
2773 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002774 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002775 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002776 dev->ieee80211_ptr->iftype = type;
2777 priv->wdev->iftype = type;
2778 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002779 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002780
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002781 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2782 linux_wlan_get_firmware(nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002783 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
2784 if (g_linux_wlan->wilc1000_initialized) {
2785 nic->iftype = AP_MODE;
2786 g_linux_wlan->wilc1000_initialized = 1;
2787 mac_close(dev);
2788 mac_open(dev);
2789
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002790 for (i = 0; i < num_reg_frame; i++) {
2791 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2792 nic->g_struct_frame_reg[i].reg);
2793 host_int_frame_register(priv->hWILCWFIDrv,
2794 nic->g_struct_frame_reg[i].frame_type,
2795 nic->g_struct_frame_reg[i].reg);
2796 }
2797 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002798 break;
2799
2800 case NL80211_IFTYPE_P2P_GO:
2801 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2802
Dean Lee72ed4dc2015-06-12 14:11:44 +09002803 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002804 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002805 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002806 /*Delete block ack has to be the latest config packet*/
2807 /*sent before downloading new FW. This is because it blocks on*/
2808 /*hWaitResponse semaphore, which allows previous config*/
2809 /*packets to actually take action on old FW*/
2810 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002811 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002812 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002813 dev->ieee80211_ptr->iftype = type;
2814 priv->wdev->iftype = type;
2815
Johnny Kim8a143302015-06-10 17:06:46 +09002816 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002817
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002818 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2819
2820
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002821 nic->iftype = GO_MODE;
2822
2823 /* ensure that the message Q is empty */
2824 host_int_wait_msg_queue_idle();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002825 wilc1000_wlan_deinit(g_linux_wlan);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002826 wilc1000_wlan_init(dev, nic);
2827 g_wilc_initialized = 1;
2828
2829
2830 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2831 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
Johnny Kim218dc402015-08-13 13:41:19 +09002832 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002833 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2834 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2835
2836 /*Add saved WEP keys, if any*/
2837 if (g_wep_keys_saved) {
Johnny Kim218dc402015-08-13 13:41:19 +09002838 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002839 g_key_wep_params.key_idx);
Johnny Kim218dc402015-08-13 13:41:19 +09002840 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002841 g_key_wep_params.key,
2842 g_key_wep_params.key_len,
2843 g_key_wep_params.key_idx);
2844 }
2845
2846 /*No matter the driver handler passed here, it will be overwriiten*/
2847 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2848 host_int_flush_join_req(priv->hWILCWFIDrv);
2849
2850 /*Add saved PTK and GTK keys, if any*/
2851 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2852 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2853 g_key_ptk_params.key[1],
2854 g_key_ptk_params.key[2],
2855 g_key_ptk_params.cipher);
2856 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2857 g_key_gtk_params.key[1],
2858 g_key_gtk_params.key[2],
2859 g_key_gtk_params.cipher);
Chaehyun Lim953d4172015-09-14 12:24:05 +09002860 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2861 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2862 g_add_ptk_key_params.key_idx,
2863 g_add_ptk_key_params.pairwise,
2864 g_add_ptk_key_params.mac_addr,
2865 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002866
Chaehyun Lim953d4172015-09-14 12:24:05 +09002867 add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
2868 g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
2869 g_add_gtk_key_params.key_idx,
2870 g_add_gtk_key_params.pairwise,
2871 g_add_gtk_key_params.mac_addr,
2872 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002873 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002874
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002875 if (g_linux_wlan->wilc1000_initialized) {
2876 for (i = 0; i < num_reg_frame; i++) {
2877 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2878 nic->g_struct_frame_reg[i].reg);
2879 host_int_frame_register(priv->hWILCWFIDrv,
2880 nic->g_struct_frame_reg[i].frame_type,
2881 nic->g_struct_frame_reg[i].reg);
2882 }
2883 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002884 break;
2885
2886 default:
2887 PRINT_ER("Unknown interface type= %d\n", type);
2888 s32Error = -EINVAL;
2889 return s32Error;
2890 break;
2891 }
2892
2893 return s32Error;
2894}
2895
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002896/* (austin.2013-07-23)
2897 *
2898 * To support revised cfg80211_ops
2899 *
2900 * add_beacon --> start_ap
2901 * set_beacon --> change_beacon
2902 * del_beacon --> stop_ap
2903 *
2904 * beacon_parameters --> cfg80211_ap_settings
2905 * cfg80211_beacon_data
2906 *
2907 * applicable for linux kernel 3.4+
2908 */
2909
2910/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002911 * @brief start_ap
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] settings cfg80211_ap_settings parameters for the beacon to be added
2917 * @return int : Return 0 on Success.
2918 * @author austin
2919 * @date 23 JUL 2013
2920 * @version 1.0
2921 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002922static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2923 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002924{
2925 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002926 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002927 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002928
2929 priv = wiphy_priv(wiphy);
2930 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2931
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302932 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 +09002933 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2934
Chaehyun Lim80785a92015-09-14 12:24:01 +09002935 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002936
Leo Kime6e12662015-09-16 18:36:03 +09002937 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002938 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002939
2940 linux_wlan_set_bssid(dev, g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2941
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002942 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2943 settings->beacon_interval,
2944 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002945 beacon->head_len, (u8 *)beacon->head,
2946 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002947
2948 return s32Error;
2949}
2950
2951/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002952 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002953 * @details Add a beacon with given parameters, @head, @interval
2954 * and @dtim_period will be valid, @tail is optional.
2955 * @param[in] wiphy
2956 * @param[in] dev The net device structure
2957 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2958 * @return int : Return 0 on Success.
2959 * @author austin
2960 * @date 23 JUL 2013
2961 * @version 1.0
2962 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002963static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2964 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002965{
Chaehyun Lim27268872015-09-15 14:06:13 +09002966 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002967 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002968
2969 priv = wiphy_priv(wiphy);
2970 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2971
2972
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002973 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2974 0,
2975 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002976 beacon->head_len, (u8 *)beacon->head,
2977 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002978
2979 return s32Error;
2980}
2981
2982/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002983 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002984 * @details Remove beacon configuration and stop sending the beacon.
2985 * @param[in]
2986 * @return int : Return 0 on Success.
2987 * @author austin
2988 * @date 23 JUL 2013
2989 * @version 1.0
2990 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002991static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002992{
Leo Kime6e12662015-09-16 18:36:03 +09002993 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002994 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002995 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002996
Leo Kim7ae43362015-09-16 18:35:59 +09002997 if (!wiphy)
2998 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002999
3000 priv = wiphy_priv(wiphy);
3001
3002 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
3003
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003004 linux_wlan_set_bssid(dev, NullBssid);
3005
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003006 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003007
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003008 if (s32Error)
3009 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003010
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003011 return s32Error;
3012}
3013
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003014/**
Chaehyun Limed269552015-09-14 12:24:15 +09003015 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003016 * @details Add a new station.
3017 * @param[in]
3018 * @return int : Return 0 on Success.
3019 * @author mdaftedar
3020 * @date 01 MAR 2012
3021 * @version 1.0
3022 */
Chaehyun Limed269552015-09-14 12:24:15 +09003023static int add_station(struct wiphy *wiphy, struct net_device *dev,
3024 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003025{
Leo Kime6e12662015-09-16 18:36:03 +09003026 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003027 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003028 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003029 perInterface_wlan_t *nic;
3030
Leo Kim7ae43362015-09-16 18:35:59 +09003031 if (!wiphy)
3032 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003033
3034 priv = wiphy_priv(wiphy);
3035 nic = netdev_priv(dev);
3036
3037 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003038 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3039 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003040 strStaParams.u16AssocID = params->aid;
3041 strStaParams.u8NumRates = params->supported_rates_len;
3042 strStaParams.pu8Rates = params->supported_rates;
3043
3044 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3045
3046 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],
3047 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
3048 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3049 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3050
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003051 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003052 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003053 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003054 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003055 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3056 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003057 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003058 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3059 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3060 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3061 }
3062
3063 strStaParams.u16FlagsMask = params->sta_flags_mask;
3064 strStaParams.u16FlagsSet = params->sta_flags_set;
3065
3066 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3067 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3068 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3069 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3070 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3071 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3072 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3073 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3074
3075 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003076 if (s32Error)
3077 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003078 }
3079
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003080 return s32Error;
3081}
3082
3083/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003084 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003085 * @details Remove a station; @mac may be NULL to remove all stations.
3086 * @param[in]
3087 * @return int : Return 0 on Success.
3088 * @author mdaftedar
3089 * @date 01 MAR 2012
3090 * @version 1.0
3091 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003092static int del_station(struct wiphy *wiphy, struct net_device *dev,
3093 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003094{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003095 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003096 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003097 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003098 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003099
Leo Kim7ae43362015-09-16 18:35:59 +09003100 if (!wiphy)
3101 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003102
3103 priv = wiphy_priv(wiphy);
3104 nic = netdev_priv(dev);
3105
3106 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3107 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3108
3109
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003110 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303111 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003112 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3113 } else {
3114 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]);
3115 }
3116
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003117 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003118
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003119 if (s32Error)
3120 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003121 }
3122 return s32Error;
3123}
3124
3125/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003126 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003127 * @details Modify a given station.
3128 * @param[in]
3129 * @return int : Return 0 on Success.
3130 * @author mdaftedar
3131 * @date 01 MAR 2012
3132 * @version 1.0
3133 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003134static int change_station(struct wiphy *wiphy, struct net_device *dev,
3135 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003136{
Leo Kime6e12662015-09-16 18:36:03 +09003137 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003138 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003139 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003140 perInterface_wlan_t *nic;
3141
3142
3143 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3144
Leo Kim7ae43362015-09-16 18:35:59 +09003145 if (!wiphy)
3146 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003147
3148 priv = wiphy_priv(wiphy);
3149 nic = netdev_priv(dev);
3150
3151 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003152 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003153 strStaParams.u16AssocID = params->aid;
3154 strStaParams.u8NumRates = params->supported_rates_len;
3155 strStaParams.pu8Rates = params->supported_rates;
3156
3157 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],
3158 strStaParams.au8BSSID[5]);
3159 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID);
3160 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates);
3161
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003162 if (params->ht_capa == NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003163 strStaParams.bIsHTSupported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003164 } else {
Dean Lee72ed4dc2015-06-12 14:11:44 +09003165 strStaParams.bIsHTSupported = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003166 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3167 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09003168 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003169 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3170 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3171 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
3172
3173 }
3174
3175 strStaParams.u16FlagsMask = params->sta_flags_mask;
3176 strStaParams.u16FlagsSet = params->sta_flags_set;
3177
3178 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported);
3179 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo);
3180 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams);
3181 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams);
3182 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap);
3183 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap);
3184 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask);
3185 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
3186
3187 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003188 if (s32Error)
3189 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003190 }
3191 return s32Error;
3192}
3193
3194
3195/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003196 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003197 * @details
3198 * @param[in]
3199 * @return int : Return 0 on Success.
3200 * @author mdaftedar
3201 * @date 01 JUL 2012
3202 * @version 1.0
3203 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003204static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3205 const char *name,
3206 unsigned char name_assign_type,
3207 enum nl80211_iftype type,
3208 u32 *flags,
3209 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003210{
3211 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003212 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003213 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003214
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003215 priv = wiphy_priv(wiphy);
3216
3217
3218
3219 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3220
3221 nic = netdev_priv(priv->wdev->netdev);
3222
3223
3224 if (type == NL80211_IFTYPE_MONITOR) {
3225 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3226 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3227 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3228 if (new_ifc != NULL) {
3229 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003230 nic = netdev_priv(priv->wdev->netdev);
3231 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003232 } else
3233 PRINT_ER("Error in initializing monitor interface\n ");
3234 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003235 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003236}
3237
3238/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003239 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003240 * @details
3241 * @param[in]
3242 * @return int : Return 0 on Success.
3243 * @author mdaftedar
3244 * @date 01 JUL 2012
3245 * @version 1.0
3246 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003247static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003248{
3249 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003250 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003251}
3252
Chaehyun Lim08241922015-09-15 14:06:12 +09003253static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003254
Chaehyun Lim80785a92015-09-14 12:24:01 +09003255 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003256 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003257 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003258 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003259 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003260 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003261 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003262 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003263 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003264 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003265 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003266
Chaehyun Lima13168d2015-09-14 12:24:12 +09003267 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003268 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003269 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003270 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003271 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003272 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003273 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003274 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003275 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003276 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003277
Chaehyun Lim4d466572015-09-14 12:24:22 +09003278 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003279 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003280 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003281 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003282 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003283 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003284 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003285 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003286 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003287 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003288
3289};
3290
3291
3292
3293
3294
3295/**
3296 * @brief WILC_WFI_update_stats
3297 * @details Modify parameters for a given BSS.
3298 * @param[in]
3299 * @return int : Return 0 on Success.
3300 * @author mdaftedar
3301 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003302 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003303 */
3304int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3305{
3306
Chaehyun Lim27268872015-09-15 14:06:13 +09003307 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003308
3309 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003310 switch (changed) {
3311
3312 case WILC_WFI_RX_PKT:
3313 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003314 priv->netstats.rx_packets++;
3315 priv->netstats.rx_bytes += pktlen;
3316 priv->netstats.rx_time = get_jiffies_64();
3317 }
3318 break;
3319
3320 case WILC_WFI_TX_PKT:
3321 {
3322 priv->netstats.tx_packets++;
3323 priv->netstats.tx_bytes += pktlen;
3324 priv->netstats.tx_time = get_jiffies_64();
3325
3326 }
3327 break;
3328
3329 default:
3330 break;
3331 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003332 return 0;
3333}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003334
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003335/**
3336 * @brief WILC_WFI_CfgAlloc
3337 * @details Allocation of the wireless device structure and assigning it
3338 * to the cfg80211 operations structure.
3339 * @param[in] NONE
3340 * @return wireless_dev : Returns pointer to wireless_dev structure.
3341 * @author mdaftedar
3342 * @date 01 MAR 2012
3343 * @version 1.0
3344 */
3345struct wireless_dev *WILC_WFI_CfgAlloc(void)
3346{
3347
3348 struct wireless_dev *wdev;
3349
3350
3351 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3352 /*Allocating the wireless device structure*/
3353 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3354 if (!wdev) {
3355 PRINT_ER("Cannot allocate wireless device\n");
3356 goto _fail_;
3357 }
3358
3359 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003360 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003361 if (!wdev->wiphy) {
3362 PRINT_ER("Cannot allocate wiphy\n");
3363 goto _fail_mem_;
3364
3365 }
3366
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003367 /* enable 802.11n HT */
3368 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3369 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3370 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3371 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3372 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003373
3374 /*wiphy bands*/
3375 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3376
3377 return wdev;
3378
3379_fail_mem_:
3380 kfree(wdev);
3381_fail_:
3382 return NULL;
3383
3384}
3385/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003386 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003387 * @details Registering of the wiphy structure and interface modes
3388 * @param[in] NONE
3389 * @return NONE
3390 * @author mdaftedar
3391 * @date 01 MAR 2012
3392 * @version 1.0
3393 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003394struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003395{
Chaehyun Lim27268872015-09-15 14:06:13 +09003396 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003397 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003398 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003399
3400 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3401
3402 wdev = WILC_WFI_CfgAlloc();
3403 if (wdev == NULL) {
3404 PRINT_ER("CfgAlloc Failed\n");
3405 return NULL;
3406 }
3407
3408
3409 /*Return hardware description structure (wiphy)'s priv*/
3410 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003411 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003412
3413 /*Link the wiphy with wireless structure*/
3414 priv->wdev = wdev;
3415
3416 /*Maximum number of probed ssid to be added by user for the scan request*/
3417 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003418 /*Maximum number of pmkids to be cashed*/
3419 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3420 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003421
3422 wdev->wiphy->max_scan_ie_len = 1000;
3423
3424 /*signal strength in mBm (100*dBm) */
3425 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3426
3427 /*Set the availaible cipher suites*/
3428 wdev->wiphy->cipher_suites = cipher_suites;
3429 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003430 /*Setting default managment types: for register action frame: */
3431 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003432
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003433 wdev->wiphy->max_remain_on_channel_duration = 500;
3434 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3435 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3436 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003437 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003438 wdev->iftype = NL80211_IFTYPE_STATION;
3439
3440
3441
3442 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3443 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3444 wdev->wiphy->interface_modes, wdev->iftype);
3445
3446 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003447 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003448 #endif
3449
3450 /*Register wiphy structure*/
3451 s32Error = wiphy_register(wdev->wiphy);
3452 if (s32Error) {
3453 PRINT_ER("Cannot register wiphy device\n");
3454 /*should define what action to be taken in such failure*/
3455 } else {
3456 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3457 }
3458
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003459 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003460 return wdev;
3461
3462
3463}
3464/**
3465 * @brief WILC_WFI_WiphyFree
3466 * @details Freeing allocation of the wireless device structure
3467 * @param[in] NONE
3468 * @return NONE
3469 * @author mdaftedar
3470 * @date 01 MAR 2012
3471 * @version 1.0
3472 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003473int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003474{
3475
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003476 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003477
Chaehyun Lim27268872015-09-15 14:06:13 +09003478 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003479
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003480 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3481 priv = wdev_priv(net->ieee80211_ptr);
3482 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003483 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003484 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003485 }
3486 op_ifcs++;
3487 if (s32Error < 0) {
3488 PRINT_ER("Failed to creat refresh Timer\n");
3489 return s32Error;
3490 }
3491
Dean Lee72ed4dc2015-06-12 14:11:44 +09003492 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003493
Dean Lee72ed4dc2015-06-12 14:11:44 +09003494 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003495
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003496 sema_init(&(priv->hSemScanReq), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003497 s32Error = host_int_init(&priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003498 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003499 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003500
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003501 return s32Error;
3502}
3503
3504/**
3505 * @brief WILC_WFI_WiphyFree
3506 * @details Freeing allocation of the wireless device structure
3507 * @param[in] NONE
3508 * @return NONE
3509 * @author mdaftedar
3510 * @date 01 MAR 2012
3511 * @version 1.0
3512 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003513int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003514{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003515 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003516
Chaehyun Lim27268872015-09-15 14:06:13 +09003517 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003518
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003519 priv = wdev_priv(net->ieee80211_ptr);
3520
Dean Lee72ed4dc2015-06-12 14:11:44 +09003521 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003522
Dean Lee72ed4dc2015-06-12 14:11:44 +09003523 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003524
3525 op_ifcs--;
3526
3527 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003528
3529 /* Clear the Shadow scan */
3530 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003531 if (op_ifcs == 0) {
3532 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003533 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003534 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003535
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003536 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003537 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003538
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003539 return s32Error;
3540}
3541
3542
3543/**
3544 * @brief WILC_WFI_WiphyFree
3545 * @details Freeing allocation of the wireless device structure
3546 * @param[in] NONE
3547 * @return NONE
3548 * @author mdaftedar
3549 * @date 01 MAR 2012
3550 * @version 1.0
3551 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003552void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003553{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003554 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3555
Chaehyun Lim619837a2015-09-20 15:51:10 +09003556 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003557 PRINT_D(INIT_DBG, "net_device is NULL\n");
3558 return;
3559 }
3560
Chaehyun Lim619837a2015-09-20 15:51:10 +09003561 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003562 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3563 return;
3564 }
3565
Chaehyun Lim619837a2015-09-20 15:51:10 +09003566 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003567 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3568 return;
3569 }
3570
3571 wiphy_unregister(net->ieee80211_ptr->wiphy);
3572
3573 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3574 wiphy_free(net->ieee80211_ptr->wiphy);
3575 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003576}