blob: 4de27ef5b6e4990e48e8753f46447eb90e0185f3 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/*!
2 * @file wilc_wfi_cfgopertaions.c
3 * @brief CFG80211 Function Implementation functionality
4 * @author aabouzaeid
5 * mabubakr
6 * mdaftedar
7 * zsalah
8 * @sa wilc_wfi_cfgopertaions.h top level OS wrapper file
9 * @date 31 Aug 2010
10 * @version 1.0
11 */
12
13#include "wilc_wfi_cfgoperations.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090014#ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +090015#include "linux_wlan_sdio.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090016#endif
Leo Kim7ae43362015-09-16 18:35:59 +090017#include <linux/errno.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090018
19#define IS_MANAGMEMENT 0x100
20#define IS_MANAGMEMENT_CALLBACK 0x080
21#define IS_MGMT_STATUS_SUCCES 0x040
22#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
23
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
26extern int mac_open(struct net_device *ndev);
27extern int mac_close(struct net_device *ndev);
28
29tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090030u32 u32LastScannedNtwrksCountShadow;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070031struct timer_list hDuringIpTimer;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070032struct timer_list hAgingTimer;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090033static u8 op_ifcs;
34extern u8 u8ConnectedSSID[6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090036u8 g_wilc_initialized = 1;
Dean Lee72ed4dc2015-06-12 14:11:44 +090037extern bool g_obtainingIP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090038
39#define CHAN2G(_channel, _freq, _flags) { \
40 .band = IEEE80211_BAND_2GHZ, \
41 .center_freq = (_freq), \
42 .hw_value = (_channel), \
43 .flags = (_flags), \
44 .max_antenna_gain = 0, \
45 .max_power = 30, \
46}
47
48/*Frequency range for channels*/
49static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
50 CHAN2G(1, 2412, 0),
51 CHAN2G(2, 2417, 0),
52 CHAN2G(3, 2422, 0),
53 CHAN2G(4, 2427, 0),
54 CHAN2G(5, 2432, 0),
55 CHAN2G(6, 2437, 0),
56 CHAN2G(7, 2442, 0),
57 CHAN2G(8, 2447, 0),
58 CHAN2G(9, 2452, 0),
59 CHAN2G(10, 2457, 0),
60 CHAN2G(11, 2462, 0),
61 CHAN2G(12, 2467, 0),
62 CHAN2G(13, 2472, 0),
63 CHAN2G(14, 2484, 0),
64};
65
66#define RATETAB_ENT(_rate, _hw_value, _flags) { \
67 .bitrate = (_rate), \
68 .hw_value = (_hw_value), \
69 .flags = (_flags), \
70}
71
72
73/* Table 6 in section 3.2.1.1 */
74static struct ieee80211_rate WILC_WFI_rates[] = {
75 RATETAB_ENT(10, 0, 0),
76 RATETAB_ENT(20, 1, 0),
77 RATETAB_ENT(55, 2, 0),
78 RATETAB_ENT(110, 3, 0),
79 RATETAB_ENT(60, 9, 0),
80 RATETAB_ENT(90, 6, 0),
81 RATETAB_ENT(120, 7, 0),
82 RATETAB_ENT(180, 8, 0),
83 RATETAB_ENT(240, 9, 0),
84 RATETAB_ENT(360, 10, 0),
85 RATETAB_ENT(480, 11, 0),
86 RATETAB_ENT(540, 12, 0),
87};
88
Johnny Kimc5c77ba2015-05-11 14:30:56 +090089struct p2p_mgmt_data {
90 int size;
91 u8 *buff;
92};
93
94/*Global variable used to state the current connected STA channel*/
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090095u8 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090096
Chaehyun Lim866a2c22015-10-02 16:41:21 +090097u8 curr_channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090098
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090099u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
100u8 u8P2Plocalrandom = 0x01;
101u8 u8P2Precvrandom = 0x00;
102u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
Daniel Machon7fc80962015-08-05 00:09:35 +0200103bool bWilc_ie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104
105static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
106 .channels = WILC_WFI_2ghz_channels,
107 .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
108 .bitrates = WILC_WFI_rates,
109 .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
110};
111
112
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113struct add_key_params {
114 u8 key_idx;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900115 bool pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116 u8 *mac_addr;
117};
118struct add_key_params g_add_gtk_key_params;
119struct wilc_wfi_key g_key_gtk_params;
120struct add_key_params g_add_ptk_key_params;
121struct wilc_wfi_key g_key_ptk_params;
122struct wilc_wfi_wep_key g_key_wep_params;
Daniel Machon7fc80962015-08-05 00:09:35 +0200123bool g_ptk_keys_saved;
124bool g_gtk_keys_saved;
125bool g_wep_keys_saved;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126
127#define AGING_TIME (9 * 1000)
128#define duringIP_TIME 15000
129
130void clear_shadow_scan(void *pUserVoid)
131{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900133
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900134 if (op_ifcs == 0) {
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -0700135 del_timer_sync(&hAgingTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900136 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
137
138 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
139 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900140 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900141 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
142 }
143
144 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
145 astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
146 }
147 u32LastScannedNtwrksCountShadow = 0;
148 }
149
150}
151
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900152u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900153{
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900154 u8 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900155 int rssi_v = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900156 u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900157
158 for (i = 0; i < num_rssi; i++)
159 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
160
161 rssi_v /= num_rssi;
162 return rssi_v;
163}
164
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900165void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900166{
Chaehyun Lim27268872015-09-15 14:06:13 +0900167 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900168 struct wiphy *wiphy;
169 struct cfg80211_bss *bss = NULL;
170 int i;
171 int rssi = 0;
172
Chaehyun Lim27268872015-09-15 14:06:13 +0900173 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900174 wiphy = priv->dev->ieee80211_ptr->wiphy;
175
176 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
177 tstrNetworkInfo *pstrNetworkInfo;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900178
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
180
181
182 if ((!pstrNetworkInfo->u8Found) || all) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900183 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900184 struct ieee80211_channel *channel;
185
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900186 if (pstrNetworkInfo != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900188 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189 channel = ieee80211_get_channel(wiphy, s32Freq);
190
191 rssi = get_rssi_avg(pstrNetworkInfo);
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900192 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900193 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
194 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900195 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 }
198 }
199
200 }
201 }
202
203}
204
205void reset_shadow_found(void *pUserVoid)
206{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900207 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900208
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900209 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
210 astrLastScannedNtwrksShadow[i].u8Found = 0;
211
212 }
213}
214
215void update_scan_time(void *pUserVoid)
216{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900217 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900218
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
220 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
221 }
222}
223
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700224static void remove_network_from_shadow(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900226 unsigned long now = jiffies;
227 int i, j;
228
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900229
230 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
231 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530232 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900233
Shraddha Barkecccfc392015-10-12 20:49:19 +0530234 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
235 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900236
237 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
238
239 for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
240 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
241 }
242 u32LastScannedNtwrksCountShadow--;
243 }
244 }
245
246 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700247 if (u32LastScannedNtwrksCountShadow != 0) {
248 hAgingTimer.data = arg;
249 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
250 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900251 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700252 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900253}
254
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700255static void clear_duringIP(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900256{
257 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900258 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900260
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900261int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900262{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900263 int state = -1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900264 int i;
265
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900266 if (u32LastScannedNtwrksCountShadow == 0) {
267 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700268 hAgingTimer.data = (unsigned long)pUserVoid;
269 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900270 state = -1;
271 } else {
272 /* Linear search for now */
273 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900274 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900275 pstrNetworkInfo->au8bssid, 6) == 0) {
276 state = i;
277 break;
278 }
279 }
280 }
281 return state;
282}
283
284void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
285{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900286 int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900287 u32 ap_index = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900288 u8 rssi_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900289
290 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
291 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
292 return;
293 }
294 if (ap_found == -1) {
295 ap_index = u32LastScannedNtwrksCountShadow;
296 u32LastScannedNtwrksCountShadow++;
297
298 } else {
299 ap_index = ap_found;
300 }
301 rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
302 astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
303 if (rssi_index == NUM_RSSI) {
304 rssi_index = 0;
305 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
306 }
307 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
308
309 astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
310 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
311
312 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900313 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
315
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900316 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900317 pstrNetworkInfo->au8bssid, ETH_ALEN);
318
319 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
320 astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
321 astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
322
323 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
324 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
325 if (ap_found != -1)
Chaehyun Lim49188af2015-08-11 10:32:41 +0900326 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900327 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
Glen Leef3052582015-09-10 12:03:04 +0900328 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900329 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900330 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
331
332 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
333 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
334 astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
335 if (ap_found != -1)
336 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
337 astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
338
339}
340
341
342/**
343 * @brief CfgScanResult
344 * @details Callback function which returns the scan results found
345 *
346 * @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is
347 * SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE
348 * tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information
349 * void* pUserVoid: Private structure associated with the wireless interface
350 * @return NONE
351 * @author mabubakr
352 * @date
353 * @version 1.0
354 */
Leo Kim1ec38152015-10-12 16:55:59 +0900355static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900356{
Chaehyun Lim27268872015-09-15 14:06:13 +0900357 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900358 struct wiphy *wiphy;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900359 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900360 struct ieee80211_channel *channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900361 struct cfg80211_bss *bss = NULL;
362
Chaehyun Lim27268872015-09-15 14:06:13 +0900363 priv = (struct wilc_priv *)pUserVoid;
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100364 if (priv->bCfgScanning) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
366 wiphy = priv->dev->ieee80211_ptr->wiphy;
Leo Kim7ae43362015-09-16 18:35:59 +0900367
368 if (!wiphy)
369 return;
370
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900371 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
372 &&
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900373 ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900374 ||
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900375 (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900376 ) {
Leo Kim24db7132015-09-16 18:36:01 +0900377 PRINT_ER("wiphy signal type fial\n");
378 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900379 }
380
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900381 if (pstrNetworkInfo != NULL) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900382 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900383 channel = ieee80211_get_channel(wiphy, s32Freq);
384
Leo Kim7ae43362015-09-16 18:35:59 +0900385 if (!channel)
386 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900387
388 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530389 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900390 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
391
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100392 if (pstrNetworkInfo->bNewNetwork) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900393 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
394 /* max_scan_ssids */
395 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
396
397
398 priv->u32RcvdChCount++;
399
400
401
402 if (pJoinParams == NULL) {
403 PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
404 }
405 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
406
407 /*P2P peers are sent to WPA supplicant and added to shadow table*/
408
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900409 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900410 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
411 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900412 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900413 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900414 }
415
416
417 } else {
418 PRINT_ER("Discovered networks exceeded the max limit\n");
419 }
420 } else {
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900421 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900422 /* So this network is discovered before, we'll just update its RSSI */
423 for (i = 0; i < priv->u32RcvdChCount; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900424 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530425 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900426
427 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
428 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
429 break;
430 }
431 }
432 }
433 }
434 } else if (enuScanEvent == SCAN_EVENT_DONE) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530435 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
436 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900437 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900438
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530439 if (priv->u32RcvdChCount > 0)
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530440 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530441 else
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530442 PRINT_D(CFG80211_DBG, "No networks found\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200444 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900445
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900446 if (priv->pstrScanReq != NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900447 cfg80211_scan_done(priv->pstrScanReq, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448 priv->u32RcvdChCount = 0;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900449 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900450 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200452 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900453
454 }
455 /*Aborting any scan operation during mac close*/
456 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200457 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530459 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900460 if (priv->pstrScanReq != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900461
462 update_scan_time(priv);
Dean Lee72ed4dc2015-06-12 14:11:44 +0900463 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900464
Dean Lee72ed4dc2015-06-12 14:11:44 +0900465 cfg80211_scan_done(priv->pstrScanReq, false);
466 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900467 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200469 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470 }
471 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900472}
473
474
475/**
476 * @brief WILC_WFI_Set_PMKSA
477 * @details Check if pmksa is cached and set it.
478 * @param[in]
479 * @return int : Return 0 on Success
480 * @author mdaftedar
481 * @date 01 MAR 2012
482 * @version 1.0
483 */
Chaehyun Lim27268872015-09-15 14:06:13 +0900484int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900485{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900486 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900487 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900488
489
490 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
491
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900492 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900493 ETH_ALEN)) {
494 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
495
496 /*If bssid is found, set the values*/
497 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
498
Leo Kime6e12662015-09-16 18:36:03 +0900499 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900500 PRINT_ER("Error in pmkid\n");
501
502 break;
503 }
504 }
505
506 return s32Error;
507
508
509}
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900510int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900511
512
513/**
514 * @brief CfgConnectResult
515 * @details
516 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
517 * connection response or disconnection notification.
518 * tstrConnectInfo* pstrConnectInfo: COnnection information.
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900519 * u8 u8MacStatus: Mac Status from firmware
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900520 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
521 * void* pUserVoid: Private data associated with wireless interface
522 * @return NONE
523 * @author mabubakr
524 * @date 01 MAR 2012
525 * @version 1.0
526 */
527int connecting;
528
Leo Kimed3f0372015-10-12 16:56:01 +0900529static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900530 tstrConnectInfo *pstrConnectInfo,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900531 u8 u8MacStatus,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900532 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
533 void *pUserVoid)
534{
Chaehyun Lim27268872015-09-15 14:06:13 +0900535 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900536 struct net_device *dev;
Leo Kim441dc602015-10-12 16:55:35 +0900537 struct host_if_drv *pstrWFIDrv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900538 u8 NullBssid[ETH_ALEN] = {0};
Glen Leec1ec2c12015-10-20 17:13:58 +0900539 struct wilc *wl;
540 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900541
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900542 connecting = 0;
543
Chaehyun Lim27268872015-09-15 14:06:13 +0900544 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545 dev = priv->dev;
Glen Leec1ec2c12015-10-20 17:13:58 +0900546 nic = netdev_priv(dev);
547 wl = nic->wilc;
Leo Kim441dc602015-10-12 16:55:35 +0900548 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900549
550 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
551 /*Initialization*/
Amitoj Kaur Chawlababa7c72015-10-15 13:48:29 +0530552 u16 u16ConnectStatus;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900553
554 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
555
556 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
557
558 if ((u8MacStatus == MAC_DISCONNECTED) &&
559 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
560 /* The case here is that our station was waiting for association response frame and has just received it containing status code
561 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
562 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
563 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530564 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900565
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900567 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900569
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530570 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571 }
572
573 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900574 bool bNeedScanRefresh = false;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900575 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900576
577 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
578 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900579 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581
582 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900583 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
585 unsigned long now = jiffies;
586
587 if (time_after(now,
588 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900589 bNeedScanRefresh = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900590 }
591
592 break;
593 }
594 }
595
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000596 if (bNeedScanRefresh) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900597 /*Also, refrsh DIRECT- results if */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900598 refresh_scan(priv, 1, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599
600 }
601
602 }
603
604
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530605 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900606
607 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
608
609 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
610 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
611 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
612 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
613 /* be replaced by pstrConnectInfo->u16ConnectStatus */
614 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900615 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900616 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
617 pstrDisconnectNotifInfo->u16reason, priv->dev);
618 u8P2Plocalrandom = 0x01;
619 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900620 bWilc_ie = false;
Shraddha Barkebcf02652015-10-05 17:00:32 +0530621 eth_zero_addr(priv->au8AssociatedBss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900622 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530623 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900624
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900626 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900628 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
629 * virtual interface to station*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900630 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900631 pstrDisconnectNotifInfo->u16reason = 3;
632 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900633 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
634 * to scan again and retry the connection*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900635 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900636 pstrDisconnectNotifInfo->u16reason = 1;
637 }
638 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
Sudip Mukherjeee26bb712015-06-30 13:51:51 +0530639 pstrDisconnectNotifInfo->ie_len, false,
640 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900641
642 }
643
644}
645
646
647/**
Chaehyun Lim80785a92015-09-14 12:24:01 +0900648 * @brief set_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900649 * @details Set channel for a given wireless interface. Some devices
650 * may support multi-channel operation (by channel hopping) so cfg80211
651 * doesn't verify much. Note, however, that the passed netdev may be
652 * %NULL as well if the user requested changing the channel for the
653 * device itself, or for a monitor interface.
654 * @param[in]
655 * @return int : Return 0 on Success
656 * @author mdaftedar
657 * @date 01 MAR 2012
658 * @version 1.0
659 */
Chaehyun Lim80785a92015-09-14 12:24:01 +0900660static int set_channel(struct wiphy *wiphy,
661 struct cfg80211_chan_def *chandef)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900662{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900663 u32 channelnum = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +0900664 struct wilc_priv *priv;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900665 int result = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900666
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900667 priv = wiphy_priv(wiphy);
668
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900669 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
670 PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900671
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900672 curr_channel = channelnum;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900673 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900674
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900675 if (result != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676 PRINT_ER("Error in setting channel %d\n", channelnum);
677
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900678 return result;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679}
680
681/**
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900682 * @brief scan
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900683 * @details Request to do a scan. If returning zero, the scan request is given
684 * the driver, and will be valid until passed to cfg80211_scan_done().
685 * For scan results, call cfg80211_inform_bss(); you can call this outside
686 * the scan/scan_done bracket too.
687 * @param[in]
688 * @return int : Return 0 on Success
689 * @author mabubakr
690 * @date 01 MAR 2012
691 * @version 1.0
692 */
693
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900694static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900695{
Chaehyun Lim27268872015-09-15 14:06:13 +0900696 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900697 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900698 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900699 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
Leo Kim607db442015-10-05 15:25:37 +0900700 struct hidden_network strHiddenNetwork;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900701
702 priv = wiphy_priv(wiphy);
703
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900704 priv->pstrScanReq = request;
705
706 priv->u32RcvdChCount = 0;
707
Johnny Kim218dc402015-08-13 13:41:19 +0900708 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900709
710
711 reset_shadow_found(priv);
712
Dean Lee72ed4dc2015-06-12 14:11:44 +0900713 priv->bCfgScanning = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900714 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
715 /* max_scan_ssids */
716 for (i = 0; i < request->n_channels; i++) {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900717 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900718 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
719 }
720
721 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530722 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900723
724 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
725
726 if (request->n_ssids >= 1) {
727
728
Leo Kim607db442015-10-05 15:25:37 +0900729 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900730 strHiddenNetwork.u8ssidnum = request->n_ssids;
731
732
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900733 for (i = 0; i < request->n_ssids; i++) {
734
735 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
Glen Leef3052582015-09-10 12:03:04 +0900736 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900737 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
739 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530740 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900741 strHiddenNetwork.u8ssidnum -= 1;
742 }
743 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530744 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900745 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
746 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900747 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900748 CfgScanResult, (void *)priv, &strHiddenNetwork);
749 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530750 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900751 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
752 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900753 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900754 CfgScanResult, (void *)priv, NULL);
755 }
756
757 } else {
758 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530759 " channels\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900760 }
761
Leo Kime6e12662015-09-16 18:36:03 +0900762 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900763 s32Error = -EBUSY;
764 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
765 }
766
767 return s32Error;
768}
769
770/**
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900771 * @brief connect
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900772 * @details Connect to the ESS with the specified parameters. When connected,
773 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
774 * If the connection fails for some reason, call cfg80211_connect_result()
775 * with the status from the AP.
776 * @param[in]
777 * @return int : Return 0 on Success
778 * @author mabubakr
779 * @date 01 MAR 2012
780 * @version 1.0
781 */
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900782static int connect(struct wiphy *wiphy, struct net_device *dev,
783 struct cfg80211_connect_params *sme)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900784{
Leo Kime6e12662015-09-16 18:36:03 +0900785 s32 s32Error = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900786 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900787 u8 u8security = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +0900788 enum AUTHTYPE tenuAuth_type = ANY;
Dean Lee576917a2015-06-15 11:58:57 +0900789 char *pcgroup_encrypt_val = NULL;
790 char *pccipher_group = NULL;
791 char *pcwpa_version = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900792
Chaehyun Lim27268872015-09-15 14:06:13 +0900793 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +0900794 struct host_if_drv *pstrWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900795 tstrNetworkInfo *pstrNetworkInfo = NULL;
796
797
798 connecting = 1;
799 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +0900800 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900801
Johnny Kim218dc402015-08-13 13:41:19 +0900802 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900803
Johnny Kim8a143302015-06-10 17:06:46 +0900804 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 +0900805 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900806 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
Leo Kimab16ec02015-10-29 12:05:40 +0900807 pstrWFIDrv->p2p_connect = 1;
808 } else {
809 pstrWFIDrv->p2p_connect = 0;
810 }
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
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900895 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900896 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
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900912 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900913 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
Leo Kimab16ec02015-10-29 12:05:40 +09001001 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001002 u8WLANChannel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001003
1004 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1005
1006 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1007 sme->ssid_len, sme->ie, sme->ie_len,
1008 CfgConnectResult, (void *)priv, u8security,
1009 tenuAuth_type, pstrNetworkInfo->u8channel,
1010 pstrNetworkInfo->pJoinParams);
Leo Kime6e12662015-09-16 18:36:03 +09001011 if (s32Error != 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301012 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001013 s32Error = -ENOENT;
1014 goto done;
1015 }
1016
1017done:
1018
1019 return s32Error;
1020}
1021
1022
1023/**
Chaehyun Limb027cde2015-09-14 12:24:04 +09001024 * @brief disconnect
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001025 * @details Disconnect from the BSS/ESS.
1026 * @param[in]
1027 * @return int : Return 0 on Success
1028 * @author mdaftedar
1029 * @date 01 MAR 2012
1030 * @version 1.0
1031 */
Chaehyun Limb027cde2015-09-14 12:24:04 +09001032static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001033{
Leo Kime6e12662015-09-16 18:36:03 +09001034 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001035 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09001036 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001037 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001038
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001039 connecting = 0;
1040 priv = wiphy_priv(wiphy);
1041
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001042 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kim441dc602015-10-12 16:55:35 +09001043 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Leo Kimab16ec02015-10-29 12:05:40 +09001044 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001045 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001046 linux_wlan_set_bssid(priv->dev, NullBssid);
1047
1048 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1049
1050 u8P2Plocalrandom = 0x01;
1051 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +09001052 bWilc_ie = false;
Leo Kim1229b1a2015-10-29 12:05:39 +09001053 pstrWFIDrv->p2p_timeout = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001054
1055 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
Leo Kime6e12662015-09-16 18:36:03 +09001056 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001057 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1058 s32Error = -EINVAL;
1059 }
1060
1061 return s32Error;
1062}
1063
1064/**
Chaehyun Lim953d4172015-09-14 12:24:05 +09001065 * @brief add_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001066 * @details Add a key with the given parameters. @mac_addr will be %NULL
1067 * when adding a group key.
1068 * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1069 * @return int : Return 0 on Success
1070 * @author mdaftedar
1071 * @date 01 MAR 2012
1072 * @version 1.0
1073 */
Chaehyun Lim953d4172015-09-14 12:24:05 +09001074static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1075 bool pairwise,
1076 const u8 *mac_addr, struct key_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001077
1078{
Leo Kime6e12662015-09-16 18:36:03 +09001079 s32 s32Error = 0, KeyLen = params->key_len;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001080 u32 i;
Chaehyun Lim27268872015-09-15 14:06:13 +09001081 struct wilc_priv *priv;
Arnd Bergmann057d1e92015-06-01 21:06:44 +02001082 const u8 *pu8RxMic = NULL;
1083 const u8 *pu8TxMic = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001084 u8 u8mode = NO_ENCRYPT;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001085 u8 u8gmode = NO_ENCRYPT;
1086 u8 u8pmode = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +09001087 enum AUTHTYPE tenuAuth_type = ANY;
Glen Lee76469202015-10-20 17:13:59 +09001088 struct wilc *wl;
1089 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001090
1091 priv = wiphy_priv(wiphy);
Glen Lee76469202015-10-20 17:13:59 +09001092 nic = netdev_priv(netdev);
1093 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001094
1095 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1096
Johnny Kim8a143302015-06-10 17:06:46 +09001097 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001098
1099 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1100 params->key[1],
1101 params->key[2]);
1102
1103
1104 switch (params->cipher) {
1105 case WLAN_CIPHER_SUITE_WEP40:
1106 case WLAN_CIPHER_SUITE_WEP104:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001107 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1108
1109 priv->WILC_WFI_wep_default = key_index;
1110 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001111 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001112
1113 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1114 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1115
1116 for (i = 0; i < params->key_len; i++)
1117 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1118
1119 tenuAuth_type = OPEN_SYSTEM;
1120
1121 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1122 u8mode = ENCRYPT_ENABLED | WEP;
1123 else
1124 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1125
1126 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1127 break;
1128 }
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001129 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001130 priv->WILC_WFI_wep_default = key_index;
1131 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001132 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001133
1134 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1135 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1136 if (INFO) {
1137 for (i = 0; i < params->key_len; i++)
1138 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1139 }
1140 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1141 }
1142
1143 break;
1144
1145 case WLAN_CIPHER_SUITE_TKIP:
1146 case WLAN_CIPHER_SUITE_CCMP:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001147 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1148
1149 if (priv->wilc_gtk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001150 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001151 priv->wilc_gtk[key_index]->key = NULL;
1152 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001153
1154 }
1155 if (priv->wilc_ptk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001156 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001157 priv->wilc_ptk[key_index]->key = NULL;
1158 priv->wilc_ptk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001159 }
1160
1161
1162
Daniel Machon19132212015-08-05 08:18:31 +02001163 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001164 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1165 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1166 else
1167 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1168
1169 priv->wilc_groupkey = u8gmode;
1170
1171 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1172
1173 pu8TxMic = params->key + 24;
1174 pu8RxMic = params->key + 16;
1175 KeyLen = params->key_len - 16;
1176 }
1177 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301178 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001179
Glen Leef3052582015-09-10 12:03:04 +09001180 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001181 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182
1183 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301184 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001185
1186 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001187 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001188 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001189 }
1190
1191 priv->wilc_gtk[key_index]->cipher = params->cipher;
1192 priv->wilc_gtk[key_index]->key_len = params->key_len;
1193 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1194
1195 if (INFO) {
1196 for (i = 0; i < params->key_len; i++)
1197 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1198 for (i = 0; i < params->seq_len; i++)
1199 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1200 }
1201
1202
1203 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1204 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1205
1206 } else {
1207 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]);
1208
1209 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1210 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1211 else
1212 u8pmode = priv->wilc_groupkey | AES;
1213
1214
1215 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1216
1217 pu8TxMic = params->key + 24;
1218 pu8RxMic = params->key + 16;
1219 KeyLen = params->key_len - 16;
1220 }
1221
Shraddha Barkecccfc392015-10-12 20:49:19 +05301222 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
Shraddha Barkecccfc392015-10-12 20:49:19 +05301226 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001227
1228 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001229 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001230
1231 if (INFO) {
1232 for (i = 0; i < params->key_len; i++)
1233 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1234
1235 for (i = 0; i < params->seq_len; i++)
1236 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1237 }
1238
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001239 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001240
1241 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001242 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001243
1244 priv->wilc_ptk[key_index]->cipher = params->cipher;
1245 priv->wilc_ptk[key_index]->key_len = params->key_len;
1246 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1247
1248 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1249 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1250 }
1251 break;
1252 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001253
1254 {
1255 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001256 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001257 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1258 /* swap the tx mic by rx mic */
1259 pu8RxMic = params->key + 24;
1260 pu8TxMic = params->key + 16;
1261 KeyLen = params->key_len - 16;
1262 }
1263
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001265 if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001266 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001267 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001268 if (!mac_addr) {
1269 g_add_gtk_key_params.mac_addr = NULL;
1270 } else {
Glen Leef3052582015-09-10 12:03:04 +09001271 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001272 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1273 }
1274 g_key_gtk_params.key_len = params->key_len;
1275 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001276 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001277 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1278 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001279 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001280 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1281 }
1282 g_key_gtk_params.cipher = params->cipher;
1283
1284 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1285 g_key_gtk_params.key[1],
1286 g_key_gtk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001287 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001288 }
1289
1290 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1291 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001292 } else {
1293 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1294 /* swap the tx mic by rx mic */
1295 pu8RxMic = params->key + 24;
1296 pu8TxMic = params->key + 16;
1297 KeyLen = params->key_len - 16;
1298 }
1299
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001300 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001301 if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001302 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001303 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 if (!mac_addr) {
1305 g_add_ptk_key_params.mac_addr = NULL;
1306 } else {
Glen Leef3052582015-09-10 12:03:04 +09001307 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001308 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1309 }
1310 g_key_ptk_params.key_len = params->key_len;
1311 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001312 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001313 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1314 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001315 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001316 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1317 }
1318 g_key_ptk_params.cipher = params->cipher;
1319
1320 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1321 g_key_ptk_params.key[1],
1322 g_key_ptk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001323 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001324 }
1325
1326 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1327 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1328 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1329 if (INFO) {
1330 for (i = 0; i < params->key_len; i++)
1331 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1332 }
1333 }
1334 }
1335 break;
1336
1337 default:
1338 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1339 s32Error = -ENOTSUPP;
1340
1341 }
1342
1343 return s32Error;
1344}
1345
1346/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001347 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001348 * @details Remove a key given the @mac_addr (%NULL for a group key)
1349 * and @key_index, return -ENOENT if the key doesn't exist.
1350 * @param[in]
1351 * @return int : Return 0 on Success
1352 * @author mdaftedar
1353 * @date 01 MAR 2012
1354 * @version 1.0
1355 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001356static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1357 u8 key_index,
1358 bool pairwise,
1359 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001360{
Chaehyun Lim27268872015-09-15 14:06:13 +09001361 struct wilc_priv *priv;
Glen Lee692e2ac2015-10-20 17:14:00 +09001362 struct wilc *wl;
1363 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364
1365 priv = wiphy_priv(wiphy);
Glen Lee692e2ac2015-10-20 17:14:00 +09001366 nic = netdev_priv(netdev);
1367 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001368
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001369 /*delete saved keys, if any*/
Glen Lee692e2ac2015-10-20 17:14:00 +09001370 if (netdev == wl->vif[0].ndev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001371 g_ptk_keys_saved = false;
1372 g_gtk_keys_saved = false;
1373 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374
1375 /*Delete saved WEP keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301376 kfree(g_key_wep_params.key);
1377 g_key_wep_params.key = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001378
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
Shraddha Barkecccfc392015-10-12 20:49:19 +05301383 kfree(priv->wilc_gtk[key_index]->key);
1384 priv->wilc_gtk[key_index]->key = NULL;
1385 kfree(priv->wilc_gtk[key_index]->seq);
1386 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001387
Chaehyun Lim49188af2015-08-11 10:32:41 +09001388 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001389 priv->wilc_gtk[key_index] = NULL;
1390
1391 }
1392
1393 if ((priv->wilc_ptk[key_index]) != NULL) {
1394
Shraddha Barkecccfc392015-10-12 20:49:19 +05301395 kfree(priv->wilc_ptk[key_index]->key);
1396 priv->wilc_ptk[key_index]->key = NULL;
1397 kfree(priv->wilc_ptk[key_index]->seq);
1398 priv->wilc_ptk[key_index]->seq = NULL;
Chaehyun Lim49188af2015-08-11 10:32:41 +09001399 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001400 priv->wilc_ptk[key_index] = NULL;
1401 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001402
1403 /*Delete saved PTK and GTK keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301404 kfree(g_key_ptk_params.key);
1405 g_key_ptk_params.key = NULL;
1406 kfree(g_key_ptk_params.seq);
1407 g_key_ptk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001408
Shraddha Barkecccfc392015-10-12 20:49:19 +05301409 kfree(g_key_gtk_params.key);
1410 g_key_gtk_params.key = NULL;
1411 kfree(g_key_gtk_params.seq);
1412 g_key_gtk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001413
1414 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee178c3832015-10-27 18:27:58 +09001415 Set_machw_change_vir_if(netdev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001416 }
1417
1418 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001419 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001420 priv->WILC_WFI_wep_key_len[key_index] = 0;
1421
1422 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1423 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1424 } else {
1425 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1426 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1427 }
1428
Leo Kimaaed3292015-10-12 16:55:38 +09001429 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001430}
1431
1432/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001433 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001434 * @details Get information about the key with the given parameters.
1435 * @mac_addr will be %NULL when requesting information for a group
1436 * key. All pointers given to the @callback function need not be valid
1437 * after it returns. This function should return an error if it is
1438 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1439 * @param[in]
1440 * @return int : Return 0 on Success
1441 * @author mdaftedar
1442 * @date 01 MAR 2012
1443 * @version 1.0
1444 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001445static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1446 bool pairwise,
1447 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001448{
Chaehyun Lim27268872015-09-15 14:06:13 +09001449 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001450 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001451 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001452
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001453 priv = wiphy_priv(wiphy);
1454
1455
Alison Schofield3604af52015-10-12 13:22:44 -07001456 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001457 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1458
1459 key_params.key = priv->wilc_gtk[key_index]->key;
1460 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1461 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1462 key_params.seq = priv->wilc_gtk[key_index]->seq;
1463 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1464 if (INFO) {
1465 for (i = 0; i < key_params.key_len; i++)
1466 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1467 }
1468 } else {
1469 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1470
1471 key_params.key = priv->wilc_ptk[key_index]->key;
1472 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1473 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1474 key_params.seq = priv->wilc_ptk[key_index]->seq;
1475 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1476 }
1477
1478 callback(cookie, &key_params);
1479
Leo Kimaaed3292015-10-12 16:55:38 +09001480 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001481}
1482
1483/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001484 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001485 * @details Set the default management frame key on an interface
1486 * @param[in]
1487 * @return int : Return 0 on Success.
1488 * @author mdaftedar
1489 * @date 01 MAR 2012
1490 * @version 1.0
1491 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001492static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1493 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494{
Chaehyun Lim27268872015-09-15 14:06:13 +09001495 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001496
1497
1498 priv = wiphy_priv(wiphy);
1499
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301500 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001501
1502 if (key_index != priv->WILC_WFI_wep_default) {
1503
Chaehyun Limdf8b4832015-10-26 09:44:45 +09001504 host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001505 }
1506
Leo Kimaaed3292015-10-12 16:55:38 +09001507 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001508}
1509
1510/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001511 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001512 * @details Get station information for the station identified by @mac
1513 * @param[in] NONE
1514 * @return int : Return 0 on Success.
1515 * @author mdaftedar
1516 * @date 01 MAR 2012
1517 * @version 1.0
1518 */
1519
Chaehyun Limf06f5622015-09-14 12:24:18 +09001520static int get_station(struct wiphy *wiphy, struct net_device *dev,
1521 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001522{
Chaehyun Lim27268872015-09-15 14:06:13 +09001523 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001525 u32 i = 0;
1526 u32 associatedsta = 0;
1527 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001528 priv = wiphy_priv(wiphy);
1529 nic = netdev_priv(dev);
1530
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001531 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1532 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1533
1534 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1535
1536 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1537
1538 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1539 associatedsta = i;
1540 break;
1541 }
1542
1543 }
1544
1545 if (associatedsta == -1) {
Leo Kimaaed3292015-10-12 16:55:38 +09001546 PRINT_ER("Station required is not associated\n");
1547 return -ENOENT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001548 }
1549
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001550 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001551
1552 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1553 sinfo->inactive_time = 1000 * inactive_time;
1554 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1555
1556 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001557
1558 if (nic->iftype == STATION_MODE) {
Leo Kim03e7b9c2015-10-12 16:55:58 +09001559 struct rf_info strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001560
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1562
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001563 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301564 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001565 BIT(NL80211_STA_INFO_TX_PACKETS) |
1566 BIT(NL80211_STA_INFO_TX_FAILED) |
1567 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001568
Leo Kim00c8dfc2015-10-29 12:05:30 +09001569 sinfo->signal = strStatistics.rssi;
Leo Kim9b992742015-10-29 12:05:32 +09001570 sinfo->rx_packets = strStatistics.rx_cnt;
Leo Kim54160372015-10-29 12:05:33 +09001571 sinfo->tx_packets = strStatistics.tx_cnt + strStatistics.tx_fail_cnt;
1572 sinfo->tx_failed = strStatistics.tx_fail_cnt;
Leo Kim5babeec2015-10-29 12:05:29 +09001573 sinfo->txrate.legacy = strStatistics.link_speed * 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001574
Leo Kim5babeec2015-10-29 12:05:29 +09001575 if ((strStatistics.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH) &&
1576 (strStatistics.link_speed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001577 Enable_TCP_ACK_Filter(true);
Leo Kim5babeec2015-10-29 12:05:29 +09001578 else if (strStatistics.link_speed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001579 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001580
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001581 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1582 sinfo->tx_failed, sinfo->txrate.legacy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001583 }
Leo Kimaaed3292015-10-12 16:55:38 +09001584 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001585}
1586
1587
1588/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001589 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001590 * @details Modify parameters for a given BSS.
1591 * @param[in]
1592 * -use_cts_prot: Whether to use CTS protection
1593 * (0 = no, 1 = yes, -1 = do not change)
1594 * -use_short_preamble: Whether the use of short preambles is allowed
1595 * (0 = no, 1 = yes, -1 = do not change)
1596 * -use_short_slot_time: Whether the use of short slot time is allowed
1597 * (0 = no, 1 = yes, -1 = do not change)
1598 * -basic_rates: basic rates in IEEE 802.11 format
1599 * (or NULL for no change)
1600 * -basic_rates_len: number of basic rates
1601 * -ap_isolate: do not forward packets between connected stations
1602 * -ht_opmode: HT Operation mode
1603 * (u16 = opmode, -1 = do not change)
1604 * @return int : Return 0 on Success.
1605 * @author mdaftedar
1606 * @date 01 MAR 2012
1607 * @version 1.0
1608 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001609static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1610 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001611{
1612 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1613 return 0;
1614}
1615
1616/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001617 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001618 * @details Notify that wiphy parameters have changed;
1619 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1620 * have changed.
1621 * @return int : Return 0 on Success
1622 * @author mdaftedar
1623 * @date 01 MAR 2012
1624 * @version 1.0
1625 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001626static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001627{
Leo Kime6e12662015-09-16 18:36:03 +09001628 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001629 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001630 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001631
1632 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001633
Tony Cho87c05b22015-10-12 16:56:07 +09001634 pstrCfgParamVal.flag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301635 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001636
1637 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1638 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1639 priv->dev->ieee80211_ptr->wiphy->retry_short);
Tony Cho87c05b22015-10-12 16:56:07 +09001640 pstrCfgParamVal.flag |= RETRY_SHORT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001641 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1642 }
1643 if (changed & WIPHY_PARAM_RETRY_LONG) {
1644
1645 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
Tony Cho87c05b22015-10-12 16:56:07 +09001646 pstrCfgParamVal.flag |= RETRY_LONG;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001647 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1648
1649 }
1650 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1651 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
Tony Cho87c05b22015-10-12 16:56:07 +09001652 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001653 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1654
1655 }
1656
1657 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1658 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1659
Tony Cho87c05b22015-10-12 16:56:07 +09001660 pstrCfgParamVal.flag |= RTS_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001661 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1662
1663 }
1664
1665 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1666 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1667 if (s32Error)
1668 PRINT_ER("Error in setting WIPHY PARAMS\n");
1669
1670
1671 return s32Error;
1672}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001673
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001674/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001675 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001676 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1677 * devices running firmwares capable of generating the (re) association
1678 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1679 * @param[in]
1680 * @return int : Return 0 on Success
1681 * @author mdaftedar
1682 * @date 01 MAR 2012
1683 * @version 1.0
1684 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001685static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1686 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001687{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001688 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001689 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001690 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691
Chaehyun Lim27268872015-09-15 14:06:13 +09001692 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001693
1694 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1695
1696
1697 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001698 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001699 ETH_ALEN)) {
1700 /*If bssid already exists and pmkid value needs to reset*/
1701 flag = PMKID_FOUND;
1702 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1703 break;
1704 }
1705 }
1706 if (i < WILC_MAX_NUM_PMKIDS) {
1707 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001708 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001709 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001710 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001711 PMKID_LEN);
1712 if (!(flag == PMKID_FOUND))
1713 priv->pmkid_list.numpmkid++;
1714 } else {
1715 PRINT_ER("Invalid PMKID index\n");
1716 s32Error = -EINVAL;
1717 }
1718
1719 if (!s32Error) {
1720 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1721 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1722 }
1723 return s32Error;
1724}
1725
1726/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001727 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001728 * @details Delete a cached PMKID.
1729 * @param[in]
1730 * @return int : Return 0 on Success
1731 * @author mdaftedar
1732 * @date 01 MAR 2012
1733 * @version 1.0
1734 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001735static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1736 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001737{
1738
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001739 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001740 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741
Chaehyun Lim27268872015-09-15 14:06:13 +09001742 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001743
1744 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1745
1746 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001747 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001748 ETH_ALEN)) {
1749 /*If bssid is found, reset the values*/
1750 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001751 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001752 break;
1753 }
1754 }
1755
1756 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1757 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001758 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001759 priv->pmkid_list.pmkidlist[i + 1].bssid,
1760 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001761 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001762 priv->pmkid_list.pmkidlist[i].pmkid,
1763 PMKID_LEN);
1764 }
1765 priv->pmkid_list.numpmkid--;
1766 } else {
1767 s32Error = -EINVAL;
1768 }
1769
1770 return s32Error;
1771}
1772
1773/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001774 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001775 * @details Flush all cached PMKIDs.
1776 * @param[in]
1777 * @return int : Return 0 on Success
1778 * @author mdaftedar
1779 * @date 01 MAR 2012
1780 * @version 1.0
1781 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001782static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001783{
Chaehyun Lim27268872015-09-15 14:06:13 +09001784 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001785
1786 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1787
1788 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001789 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001790
1791 return 0;
1792}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001793
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001794
1795/**
1796 * @brief WILC_WFI_CfgParseRxAction
1797 * @details Function parses the received frames and modifies the following attributes:
1798 * -GO Intent
1799 * -Channel list
1800 * -Operating Channel
1801 *
1802 * @param[in] u8* Buffer, u32 length
1803 * @return NONE.
1804 * @author mdaftedar
1805 * @date 12 DEC 2012
1806 * @version
1807 */
1808
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001809void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001810{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001811 u32 index = 0;
1812 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001813
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001814 u8 op_channel_attr_index = 0;
1815 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001816
1817 while (index < len) {
1818 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001819 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001820 }
1821
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301822 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001823 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301824 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001825 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001826 index += buf[index + 1] + 3; /* ID,Length byte */
1827 }
Alison Schofield3604af52015-10-12 13:22:44 -07001828 if (u8WLANChannel != INVALID_CHANNEL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001829
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001830 /*Modify channel list attribute*/
1831 if (channel_list_attr_index) {
1832 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1833 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1834 if (buf[i] == 0x51) {
1835 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1836 buf[j] = u8WLANChannel;
1837 }
1838 break;
1839 }
1840 }
1841 }
1842 /*Modify operating channel attribute*/
1843 if (op_channel_attr_index) {
1844 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1845 buf[op_channel_attr_index + 6] = 0x51;
1846 buf[op_channel_attr_index + 7] = u8WLANChannel;
1847 }
1848 }
1849}
1850
1851/**
1852 * @brief WILC_WFI_CfgParseTxAction
1853 * @details Function parses the transmitted action frames and modifies the
1854 * GO Intent attribute
1855 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1856 * @return NONE.
1857 * @author mdaftedar
1858 * @date 12 DEC 2012
1859 * @version
1860 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001861void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001863 u32 index = 0;
1864 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001865
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001866 u8 op_channel_attr_index = 0;
1867 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001868
1869 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001870 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001871 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001872
1873 break;
1874 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001875
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301876 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301878 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001879 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001880 index += buf[index + 1] + 3; /* ID,Length byte */
1881 }
Alison Schofield3604af52015-10-12 13:22:44 -07001882 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001883
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001884 /*Modify channel list attribute*/
1885 if (channel_list_attr_index) {
1886 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1887 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1888 if (buf[i] == 0x51) {
1889 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1890 buf[j] = u8WLANChannel;
1891 }
1892 break;
1893 }
1894 }
1895 }
1896 /*Modify operating channel attribute*/
1897 if (op_channel_attr_index) {
1898 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1899 buf[op_channel_attr_index + 6] = 0x51;
1900 buf[op_channel_attr_index + 7] = u8WLANChannel;
1901 }
1902 }
1903}
1904
1905/* @brief WILC_WFI_p2p_rx
1906 * @details
1907 * @param[in]
1908 *
1909 * @return None
1910 * @author Mai Daftedar
1911 * @date 2 JUN 2013
1912 * @version 1.0
1913 */
1914
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001915void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001916{
1917
Chaehyun Lim27268872015-09-15 14:06:13 +09001918 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001919 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001920 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001921 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001922 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001923
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001924 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001925 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001926
1927 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001928 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001929
1930 /* The packet offset field conain info about what type of managment frame */
1931 /* we are dealing with and ack status */
1932 pkt_offset = GET_PKT_OFFSET(header);
1933
1934 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1935 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1936 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001937 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001938 return;
1939 } else {
1940 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1941 PRINT_D(GENERIC_DBG, "Success Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1942 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001943 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001944 } else {
1945 PRINT_D(GENERIC_DBG, "Fail Ack - Action frame category: %x Action Subtype: %d Dialog T: %x OR %x\n", buff[ACTION_CAT_ID], buff[ACTION_SUBTYPE_ID],
1946 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001947 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001948 }
1949 return;
1950 }
1951 } else {
1952
1953 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1954
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001955 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001956 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001957
1958 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1959 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1960
Leo Kim1229b1a2015-10-29 12:05:39 +09001961 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->p2p_timeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001962 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1963 return;
1964 }
1965 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1966
1967 switch (buff[ACTION_SUBTYPE_ID]) {
1968 case GAS_INTIAL_REQ:
1969 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
1970 break;
1971
1972 case GAS_INTIAL_RSP:
1973 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1974 break;
1975
1976 case PUBLIC_ACT_VENDORSPEC:
1977 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1978 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001979 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001980 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1981 if (!bWilc_ie) {
1982 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001983 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001984 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09001985 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001986 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1987 break;
1988 }
1989 }
1990 }
1991 }
1992 if (u8P2Plocalrandom > u8P2Precvrandom) {
1993 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1994 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1995 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001996 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001997 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1998 break;
1999 }
2000 }
2001 }
2002 } else
2003 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2004 }
2005
2006
2007 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2008 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2009 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002010 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002011 return;
2012 }
2013 break;
2014
2015 default:
2016 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2017 break;
2018 }
2019 }
2020 }
2021
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002022 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002023 }
2024}
2025
2026/**
2027 * @brief WILC_WFI_mgmt_tx_complete
2028 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2029 * @param[in] priv
2030 * transmitting status
2031 * @return None
2032 * @author Amr Abdelmoghny
2033 * @date 20 MAY 2013
2034 * @version 1.0
2035 */
2036static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2037{
2038 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2039
2040
2041 kfree(pv_data->buff);
2042 kfree(pv_data);
2043}
2044
2045/**
2046 * @brief WILC_WFI_RemainOnChannelReady
2047 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2048 * @param
2049 * @return none
2050 * @author Amr abdelmoghny
2051 * @date 9 JUNE 2013
2052 * @version
2053 */
2054
2055static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2056{
Chaehyun Lim27268872015-09-15 14:06:13 +09002057 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002058
Chaehyun Lim27268872015-09-15 14:06:13 +09002059 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302061 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002062
Dean Lee72ed4dc2015-06-12 14:11:44 +09002063 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002064
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002065 cfg80211_ready_on_channel(priv->wdev,
2066 priv->strRemainOnChanParams.u64ListenCookie,
2067 priv->strRemainOnChanParams.pstrListenChan,
2068 priv->strRemainOnChanParams.u32ListenDuration,
2069 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002070}
2071
2072/**
2073 * @brief WILC_WFI_RemainOnChannelExpired
2074 * @details Callback function, called on expiration of remain-on-channel duration
2075 * @param
2076 * @return none
2077 * @author Amr abdelmoghny
2078 * @date 15 MAY 2013
2079 * @version
2080 */
2081
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002082static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002083{
Chaehyun Lim27268872015-09-15 14:06:13 +09002084 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002085
Chaehyun Lim27268872015-09-15 14:06:13 +09002086 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002087
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002088 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302089 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002090
Dean Lee72ed4dc2015-06-12 14:11:44 +09002091 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002092
2093 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002094 cfg80211_remain_on_channel_expired(priv->wdev,
2095 priv->strRemainOnChanParams.u64ListenCookie,
2096 priv->strRemainOnChanParams.pstrListenChan,
2097 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002098 } else {
2099 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2100 , priv->strRemainOnChanParams.u32ListenSessionID);
2101 }
2102}
2103
2104
2105/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002106 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002107 * @details Request the driver to remain awake on the specified
2108 * channel for the specified duration to complete an off-channel
2109 * operation (e.g., public action frame exchange). When the driver is
2110 * ready on the requested channel, it must indicate this with an event
2111 * notification by calling cfg80211_ready_on_channel().
2112 * @param[in]
2113 * @return int : Return 0 on Success
2114 * @author mdaftedar
2115 * @date 01 MAR 2012
2116 * @version 1.0
2117 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002118static int remain_on_channel(struct wiphy *wiphy,
2119 struct wireless_dev *wdev,
2120 struct ieee80211_channel *chan,
2121 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002122{
Leo Kime6e12662015-09-16 18:36:03 +09002123 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002124 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002125
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002126 priv = wiphy_priv(wiphy);
2127
2128 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2129
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002130
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002131 if (wdev->iftype == NL80211_IFTYPE_AP) {
2132 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2133 return s32Error;
2134 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002135
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002136 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002137
2138 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2139 priv->strRemainOnChanParams.pstrListenChan = chan;
2140 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002141 priv->strRemainOnChanParams.u32ListenDuration = duration;
2142 priv->strRemainOnChanParams.u32ListenSessionID++;
2143
2144 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2145 , priv->strRemainOnChanParams.u32ListenSessionID
2146 , duration
2147 , chan->hw_value
2148 , WILC_WFI_RemainOnChannelExpired
2149 , WILC_WFI_RemainOnChannelReady
2150 , (void *)priv);
2151
2152 return s32Error;
2153}
2154
2155/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002156 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002157 * @details Cancel an on-going remain-on-channel operation.
2158 * This allows the operation to be terminated prior to timeout based on
2159 * the duration value.
2160 * @param[in] struct wiphy *wiphy,
2161 * @param[in] struct net_device *dev
2162 * @param[in] u64 cookie,
2163 * @return int : Return 0 on Success
2164 * @author mdaftedar
2165 * @date 01 MAR 2012
2166 * @version 1.0
2167 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002168static int cancel_remain_on_channel(struct wiphy *wiphy,
2169 struct wireless_dev *wdev,
2170 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002171{
Leo Kime6e12662015-09-16 18:36:03 +09002172 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002173 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002174
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002175 priv = wiphy_priv(wiphy);
2176
2177 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2178
2179 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2180 return s32Error;
2181}
2182/**
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002183 * @brief WILC_WFI_mgmt_tx_frame
2184 * @details
2185 *
2186 * @param[in]
2187 * @return NONE.
2188 * @author mdaftedar
2189 * @date 01 JUL 2012
2190 * @version
2191 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09002192extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002193static int mgmt_tx(struct wiphy *wiphy,
2194 struct wireless_dev *wdev,
2195 struct cfg80211_mgmt_tx_params *params,
2196 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002197{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002198 struct ieee80211_channel *chan = params->chan;
2199 unsigned int wait = params->wait;
2200 const u8 *buf = params->buf;
2201 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002202 const struct ieee80211_mgmt *mgmt;
2203 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002204 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002205 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002206 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002207 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002208 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002209
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002210 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002211 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002212 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002213
2214 *cookie = (unsigned long)buf;
2215 priv->u64tx_cookie = *cookie;
2216 mgmt = (const struct ieee80211_mgmt *) buf;
2217
2218 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2219
2220 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002221 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002222 if (mgmt_tx == NULL) {
2223 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002224 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002225 }
Glen Leef3052582015-09-10 12:03:04 +09002226 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002227 if (mgmt_tx->buff == NULL) {
2228 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002229 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002230 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002231 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002232 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002233 mgmt_tx->size = len;
2234
2235
2236 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2237 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2238 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2239 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2240 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002241 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002242 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002243 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002244
2245
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002246 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002247 /*Only set the channel, if not a negotiation confirmation frame
2248 * (If Negotiation confirmation frame, force it
2249 * to be transmitted on the same negotiation channel)*/
2250
2251 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2252 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2253 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2254 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2255 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002256 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002257 }
2258 switch (buf[ACTION_SUBTYPE_ID]) {
2259 case GAS_INTIAL_REQ:
2260 {
2261 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2262 break;
2263 }
2264
2265 case GAS_INTIAL_RSP:
2266 {
2267 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2268 break;
2269 }
2270
2271 case PUBLIC_ACT_VENDORSPEC:
2272 {
2273 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2274 * 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 +09002275 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002276 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2277 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2278 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2279 get_random_bytes(&u8P2Plocalrandom, 1);
2280 /*Increment the number to prevent if its 0*/
2281 u8P2Plocalrandom++;
2282 }
2283 }
2284
2285 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2286 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2287 if (u8P2Plocalrandom > u8P2Precvrandom) {
2288 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2289
2290 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2291 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002292 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002293 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002294 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002295
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002296 /*If using supplicant go intent, no need at all*/
2297 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002298 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002299 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002300 break;
2301 }
2302 }
2303
2304 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
Shivani Bhardwajd8060fc2015-10-29 00:30:01 +05302305 /*
2306 * Adding WILC information element to allow two WILC devices to
2307 * identify each other and connect
2308 */
2309 memcpy(&mgmt_tx->buff[len], u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002310 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2311 mgmt_tx->size = buf_len;
2312 }
2313 } else
2314 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2315 }
2316
2317 } else {
2318 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2319 }
2320
2321 break;
2322 }
2323
2324 default:
2325 {
2326 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2327 break;
2328 }
2329 }
2330
2331 }
2332
2333 PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
Leo Kim1229b1a2015-10-29 12:05:39 +09002334 pstrWFIDrv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002335
Leo Kim1229b1a2015-10-29 12:05:39 +09002336 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n",
2337 jiffies, pstrWFIDrv->p2p_timeout);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002338 }
2339
Glen Leec9d48342015-10-01 16:03:43 +09002340 wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
2341 mgmt_tx->size,
2342 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002343 } else {
2344 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2345 }
Leo Kimaaed3292015-10-12 16:55:38 +09002346 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002347}
2348
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002349static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2350 struct wireless_dev *wdev,
2351 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002352{
Chaehyun Lim27268872015-09-15 14:06:13 +09002353 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002354 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002355
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002356 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002357 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002358
2359
2360 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
Leo Kim1229b1a2015-10-29 12:05:39 +09002361 pstrWFIDrv->p2p_timeout = jiffies;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002362
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01002363 if (!priv->bInP2PlistenState) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002364 cfg80211_remain_on_channel_expired(priv->wdev,
2365 priv->strRemainOnChanParams.u64ListenCookie,
2366 priv->strRemainOnChanParams.pstrListenChan,
2367 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002368 }
2369
2370 return 0;
2371}
2372
2373/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002374 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002375 * @details Notify driver that a management frame type was
2376 * registered. Note that this callback may not sleep, and cannot run
2377 * concurrently with itself.
2378 * @param[in]
2379 * @return NONE.
2380 * @author mdaftedar
2381 * @date 01 JUL 2012
2382 * @version
2383 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002384void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2385 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002386{
2387
Chaehyun Lim27268872015-09-15 14:06:13 +09002388 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002389 perInterface_wlan_t *nic;
Glen Lee1b869352015-10-20 17:14:01 +09002390 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002391
2392 priv = wiphy_priv(wiphy);
2393 nic = netdev_priv(priv->wdev->netdev);
Glen Lee1b869352015-10-20 17:14:01 +09002394 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002395
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002396 if (!frame_type)
2397 return;
2398
2399 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2400 switch (frame_type) {
2401 case PROBE_REQ:
2402 {
2403 nic->g_struct_frame_reg[0].frame_type = frame_type;
2404 nic->g_struct_frame_reg[0].reg = reg;
2405 }
2406 break;
2407
2408 case ACTION:
2409 {
2410 nic->g_struct_frame_reg[1].frame_type = frame_type;
2411 nic->g_struct_frame_reg[1].reg = reg;
2412 }
2413 break;
2414
2415 default:
2416 {
2417 break;
2418 }
2419
2420 }
2421 /*If mac is closed, then return*/
Glen Lee1b869352015-10-20 17:14:01 +09002422 if (!wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002423 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2424 return;
2425 }
2426 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2427
2428
2429}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002430
2431/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002432 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002433 * @details Configure connection quality monitor RSSI threshold.
2434 * @param[in] struct wiphy *wiphy:
2435 * @param[in] struct net_device *dev:
2436 * @param[in] s32 rssi_thold:
2437 * @param[in] u32 rssi_hyst:
2438 * @return int : Return 0 on Success
2439 * @author mdaftedar
2440 * @date 01 MAR 2012
2441 * @version 1.0
2442 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002443static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2444 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002445{
2446 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2447 return 0;
2448
2449}
2450/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002451 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002452 * @details Configure connection quality monitor RSSI threshold.
2453 * @param[in] struct wiphy *wiphy:
2454 * @param[in] struct net_device *dev
2455 * @param[in] int idx
2456 * @param[in] u8 *mac
2457 * @param[in] struct station_info *sinfo
2458 * @return int : Return 0 on Success
2459 * @author mdaftedar
2460 * @date 01 MAR 2012
2461 * @version 1.0
2462 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002463static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2464 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002465{
Chaehyun Lim27268872015-09-15 14:06:13 +09002466 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002467
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002468 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2469
2470 if (idx != 0)
2471 return -ENOENT;
2472
2473 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002474
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002475 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002476
2477 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2478
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002479 return 0;
2480
2481}
2482
2483
2484/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002485 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002486 * @details
2487 * @param[in]
2488 * @return int : Return 0 on Success.
2489 * @author mdaftedar
2490 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002491 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002492 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002493static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2494 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002495{
Chaehyun Lim27268872015-09-15 14:06:13 +09002496 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002497
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002498 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2499
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002500 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002501 return -ENOENT;
2502
2503 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002504 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002505 PRINT_ER("Driver is NULL\n");
2506 return -EIO;
2507 }
2508
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002509 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002510 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2511
2512
Leo Kime6e12662015-09-16 18:36:03 +09002513 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002514
2515}
Glen Lee108b3432015-09-16 18:53:20 +09002516
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002517/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002518 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002519 * @details Change type/configuration of virtual interface,
2520 * keep the struct wireless_dev's iftype updated.
2521 * @param[in] NONE
2522 * @return int : Return 0 on Success.
2523 * @author mdaftedar
2524 * @date 01 MAR 2012
2525 * @version 1.0
2526 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002527int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2528
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002529static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2530 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002531{
Chaehyun Lim27268872015-09-15 14:06:13 +09002532 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002533 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002534 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002535 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002536 u8 i;
Glen Lee299382c2015-10-20 17:13:56 +09002537 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002538
2539 nic = netdev_priv(dev);
2540 priv = wiphy_priv(wiphy);
Glen Lee299382c2015-10-20 17:13:56 +09002541 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002542
2543 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2544 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2545 u8P2Plocalrandom = 0x01;
2546 u8P2Precvrandom = 0x00;
2547
Dean Lee72ed4dc2015-06-12 14:11:44 +09002548 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002549
Dean Lee72ed4dc2015-06-12 14:11:44 +09002550 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002551 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002552 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002553 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2554 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Glen Lee178c3832015-10-27 18:27:58 +09002555 Set_machw_change_vir_if(dev, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002556 }
2557
2558 switch (type) {
2559 case NL80211_IFTYPE_STATION:
2560 connecting = 0;
2561 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002562
2563 /* send delba over wlan interface */
2564
2565
2566 dev->ieee80211_ptr->iftype = type;
2567 priv->wdev->iftype = type;
2568 nic->monitor_flag = 0;
2569 nic->iftype = STATION_MODE;
2570
2571 /*Remove the enteries of the previously connected clients*/
2572 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002573 interface_type = nic->iftype;
2574 nic->iftype = STATION_MODE;
2575
Glen Lee299382c2015-10-20 17:13:56 +09002576 if (wl->initialized) {
2577 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2578 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002579 /* ensure that the message Q is empty */
2580 host_int_wait_msg_queue_idle();
2581
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002582 /*Eliminate host interface blocking state*/
Glen Lee299382c2015-10-20 17:13:56 +09002583 up(&wl->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002584
Glen Lee53dc0cf2015-10-20 17:13:57 +09002585 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002586 wilc1000_wlan_init(dev, nic);
2587 g_wilc_initialized = 1;
2588 nic->iftype = interface_type;
2589
2590 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002591 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2592 host_int_set_MacAddress(wl->vif[0].hif_drv,
2593 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002594 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2595
2596 /*Add saved WEP keys, if any*/
2597 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002598 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002599 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002600 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002601 g_key_wep_params.key,
2602 g_key_wep_params.key_len,
2603 g_key_wep_params.key_idx);
2604 }
2605
2606 /*No matter the driver handler passed here, it will be overwriiten*/
2607 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2608 host_int_flush_join_req(priv->hWILCWFIDrv);
2609
2610 /*Add saved PTK and GTK keys, if any*/
2611 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2612 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2613 g_key_ptk_params.key[1],
2614 g_key_ptk_params.key[2]);
2615 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2616 g_key_gtk_params.key[1],
2617 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002618 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2619 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002620 g_add_ptk_key_params.key_idx,
2621 g_add_ptk_key_params.pairwise,
2622 g_add_ptk_key_params.mac_addr,
2623 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002624
Glen Lee299382c2015-10-20 17:13:56 +09002625 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2626 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002627 g_add_gtk_key_params.key_idx,
2628 g_add_gtk_key_params.pairwise,
2629 g_add_gtk_key_params.mac_addr,
2630 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002631 }
2632
Glen Lee299382c2015-10-20 17:13:56 +09002633 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002634 for (i = 0; i < num_reg_frame; i++) {
2635 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2636 nic->g_struct_frame_reg[i].reg);
2637 host_int_frame_register(priv->hWILCWFIDrv,
2638 nic->g_struct_frame_reg[i].frame_type,
2639 nic->g_struct_frame_reg[i].reg);
2640 }
2641 }
2642
Dean Lee72ed4dc2015-06-12 14:11:44 +09002643 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002644 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2645 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002646 break;
2647
2648 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002649 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002650 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2651 connecting = 0;
2652 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002653
Glen Lee299382c2015-10-20 17:13:56 +09002654 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2655 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002656
2657 dev->ieee80211_ptr->iftype = type;
2658 priv->wdev->iftype = type;
2659 nic->monitor_flag = 0;
2660
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002661 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2662 nic->iftype = CLIENT_MODE;
2663
2664
Glen Lee299382c2015-10-20 17:13:56 +09002665 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002666 /* ensure that the message Q is empty */
2667 host_int_wait_msg_queue_idle();
2668
Glen Lee53dc0cf2015-10-20 17:13:57 +09002669 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002670 wilc1000_wlan_init(dev, nic);
2671 g_wilc_initialized = 1;
2672
Glen Lee299382c2015-10-20 17:13:56 +09002673 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2674 host_int_set_MacAddress(wl->vif[0].hif_drv,
2675 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002676 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2677
2678 /*Add saved WEP keys, if any*/
2679 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002680 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002681 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002682 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002683 g_key_wep_params.key,
2684 g_key_wep_params.key_len,
2685 g_key_wep_params.key_idx);
2686 }
2687
2688 /*No matter the driver handler passed here, it will be overwriiten*/
2689 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2690 host_int_flush_join_req(priv->hWILCWFIDrv);
2691
2692 /*Add saved PTK and GTK keys, if any*/
2693 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2694 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2695 g_key_ptk_params.key[1],
2696 g_key_ptk_params.key[2]);
2697 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2698 g_key_gtk_params.key[1],
2699 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002700 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2701 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002702 g_add_ptk_key_params.key_idx,
2703 g_add_ptk_key_params.pairwise,
2704 g_add_ptk_key_params.mac_addr,
2705 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002706
Glen Lee299382c2015-10-20 17:13:56 +09002707 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2708 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002709 g_add_gtk_key_params.key_idx,
2710 g_add_gtk_key_params.pairwise,
2711 g_add_gtk_key_params.mac_addr,
2712 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002713 }
2714
2715 /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
Dean Lee72ed4dc2015-06-12 14:11:44 +09002716 refresh_scan(priv, 1, true);
Glen Lee178c3832015-10-27 18:27:58 +09002717 Set_machw_change_vir_if(dev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002718
Glen Lee299382c2015-10-20 17:13:56 +09002719 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002720 for (i = 0; i < num_reg_frame; i++) {
2721 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2722 nic->g_struct_frame_reg[i].reg);
2723 host_int_frame_register(priv->hWILCWFIDrv,
2724 nic->g_struct_frame_reg[i].frame_type,
2725 nic->g_struct_frame_reg[i].reg);
2726 }
2727 }
2728 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002729 break;
2730
2731 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002732 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002733 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002734 dev->ieee80211_ptr->iftype = type;
2735 priv->wdev->iftype = type;
2736 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002737 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002738
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002739 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
2740 linux_wlan_get_firmware(nic);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002741 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
Glen Lee299382c2015-10-20 17:13:56 +09002742 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002743 nic->iftype = AP_MODE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002744 mac_close(dev);
2745 mac_open(dev);
2746
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002747 for (i = 0; i < num_reg_frame; i++) {
2748 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2749 nic->g_struct_frame_reg[i].reg);
2750 host_int_frame_register(priv->hWILCWFIDrv,
2751 nic->g_struct_frame_reg[i].frame_type,
2752 nic->g_struct_frame_reg[i].reg);
2753 }
2754 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002755 break;
2756
2757 case NL80211_IFTYPE_P2P_GO:
2758 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2759
Dean Lee72ed4dc2015-06-12 14:11:44 +09002760 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002761 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002762 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002763 /*Delete block ack has to be the latest config packet*/
2764 /*sent before downloading new FW. This is because it blocks on*/
2765 /*hWaitResponse semaphore, which allows previous config*/
2766 /*packets to actually take action on old FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002767 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2768 wl->vif[0].bssid, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002769 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002770 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002771 dev->ieee80211_ptr->iftype = type;
2772 priv->wdev->iftype = type;
2773
Johnny Kim8a143302015-06-10 17:06:46 +09002774 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002775
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002776 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2777
2778
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002779 nic->iftype = GO_MODE;
2780
2781 /* ensure that the message Q is empty */
2782 host_int_wait_msg_queue_idle();
Glen Lee53dc0cf2015-10-20 17:13:57 +09002783 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002784 wilc1000_wlan_init(dev, nic);
2785 g_wilc_initialized = 1;
2786
2787
2788 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002789 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2790 host_int_set_MacAddress(wl->vif[0].hif_drv,
2791 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002792 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2793
2794 /*Add saved WEP keys, if any*/
2795 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002796 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002797 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002798 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002799 g_key_wep_params.key,
2800 g_key_wep_params.key_len,
2801 g_key_wep_params.key_idx);
2802 }
2803
2804 /*No matter the driver handler passed here, it will be overwriiten*/
2805 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2806 host_int_flush_join_req(priv->hWILCWFIDrv);
2807
2808 /*Add saved PTK and GTK keys, if any*/
2809 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2810 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2811 g_key_ptk_params.key[1],
2812 g_key_ptk_params.key[2],
2813 g_key_ptk_params.cipher);
2814 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2815 g_key_gtk_params.key[1],
2816 g_key_gtk_params.key[2],
2817 g_key_gtk_params.cipher);
Glen Lee299382c2015-10-20 17:13:56 +09002818 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2819 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002820 g_add_ptk_key_params.key_idx,
2821 g_add_ptk_key_params.pairwise,
2822 g_add_ptk_key_params.mac_addr,
2823 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002824
Glen Lee299382c2015-10-20 17:13:56 +09002825 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2826 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002827 g_add_gtk_key_params.key_idx,
2828 g_add_gtk_key_params.pairwise,
2829 g_add_gtk_key_params.mac_addr,
2830 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002831 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002832
Glen Lee299382c2015-10-20 17:13:56 +09002833 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002834 for (i = 0; i < num_reg_frame; i++) {
2835 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2836 nic->g_struct_frame_reg[i].reg);
2837 host_int_frame_register(priv->hWILCWFIDrv,
2838 nic->g_struct_frame_reg[i].frame_type,
2839 nic->g_struct_frame_reg[i].reg);
2840 }
2841 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002842 break;
2843
2844 default:
2845 PRINT_ER("Unknown interface type= %d\n", type);
Leo Kimaaed3292015-10-12 16:55:38 +09002846 return -EINVAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002847 }
2848
Leo Kimaaed3292015-10-12 16:55:38 +09002849 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002850}
2851
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002852/* (austin.2013-07-23)
2853 *
2854 * To support revised cfg80211_ops
2855 *
2856 * add_beacon --> start_ap
2857 * set_beacon --> change_beacon
2858 * del_beacon --> stop_ap
2859 *
2860 * beacon_parameters --> cfg80211_ap_settings
2861 * cfg80211_beacon_data
2862 *
2863 * applicable for linux kernel 3.4+
2864 */
2865
2866/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002867 * @brief start_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002868 * @details Add a beacon with given parameters, @head, @interval
2869 * and @dtim_period will be valid, @tail is optional.
2870 * @param[in] wiphy
2871 * @param[in] dev The net device structure
2872 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2873 * @return int : Return 0 on Success.
2874 * @author austin
2875 * @date 23 JUL 2013
2876 * @version 1.0
2877 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002878static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2879 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002880{
2881 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002882 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002883 s32 s32Error = 0;
Glen Lee684dc182015-10-20 17:14:02 +09002884 struct wilc *wl;
2885 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002886
2887 priv = wiphy_priv(wiphy);
Glen Lee684dc182015-10-20 17:14:02 +09002888 nic = netdev_priv(dev);
2889 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002890 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2891
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302892 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 +09002893 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2894
Chaehyun Lim80785a92015-09-14 12:24:01 +09002895 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002896
Leo Kime6e12662015-09-16 18:36:03 +09002897 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002898 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002899
Glen Lee684dc182015-10-20 17:14:02 +09002900 linux_wlan_set_bssid(dev, wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002901
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002902 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2903 settings->beacon_interval,
2904 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002905 beacon->head_len, (u8 *)beacon->head,
2906 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002907
2908 return s32Error;
2909}
2910
2911/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002912 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002913 * @details Add a beacon with given parameters, @head, @interval
2914 * and @dtim_period will be valid, @tail is optional.
2915 * @param[in] wiphy
2916 * @param[in] dev The net device structure
2917 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2918 * @return int : Return 0 on Success.
2919 * @author austin
2920 * @date 23 JUL 2013
2921 * @version 1.0
2922 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002923static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2924 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002925{
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, "Setting beacon\n");
2931
2932
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002933 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2934 0,
2935 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002936 beacon->head_len, (u8 *)beacon->head,
2937 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002938
2939 return s32Error;
2940}
2941
2942/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002943 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002944 * @details Remove beacon configuration and stop sending the beacon.
2945 * @param[in]
2946 * @return int : Return 0 on Success.
2947 * @author austin
2948 * @date 23 JUL 2013
2949 * @version 1.0
2950 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002951static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002952{
Leo Kime6e12662015-09-16 18:36:03 +09002953 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002954 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002955 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002956
Leo Kim7ae43362015-09-16 18:35:59 +09002957 if (!wiphy)
2958 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002959
2960 priv = wiphy_priv(wiphy);
2961
2962 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2963
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002964 linux_wlan_set_bssid(dev, NullBssid);
2965
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002966 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002967
Leo Kim7dc1d0c2015-09-16 18:36:00 +09002968 if (s32Error)
2969 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002970
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002971 return s32Error;
2972}
2973
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002974/**
Chaehyun Limed269552015-09-14 12:24:15 +09002975 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002976 * @details Add a new station.
2977 * @param[in]
2978 * @return int : Return 0 on Success.
2979 * @author mdaftedar
2980 * @date 01 MAR 2012
2981 * @version 1.0
2982 */
Chaehyun Limed269552015-09-14 12:24:15 +09002983static int add_station(struct wiphy *wiphy, struct net_device *dev,
2984 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002985{
Leo Kime6e12662015-09-16 18:36:03 +09002986 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002987 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09002988 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002989 perInterface_wlan_t *nic;
2990
Leo Kim7ae43362015-09-16 18:35:59 +09002991 if (!wiphy)
2992 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002993
2994 priv = wiphy_priv(wiphy);
2995 nic = netdev_priv(dev);
2996
2997 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09002998 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002999 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09003000 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09003001 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09003002 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003003
3004 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3005
3006 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],
3007 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003008 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003009 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3010 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003011
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003012 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003013 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003014 } else {
Leo Kim22520122015-10-29 12:05:45 +09003015 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003016 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003017 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003018 memcpy(strStaParams.ht_supp_mcs_set,
3019 &params->ht_capa->mcs,
3020 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003021 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003022 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003023 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003024 }
3025
Leo Kimf676e172015-10-29 12:05:52 +09003026 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003027 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003028
Leo Kim22520122015-10-29 12:05:45 +09003029 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3030 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003031 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3032 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003033 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3034 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003035 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3036 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003037 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3038 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003039 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3040 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003041 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3042 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003043 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3044 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003045
3046 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003047 if (s32Error)
3048 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003049 }
3050
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003051 return s32Error;
3052}
3053
3054/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003055 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003056 * @details Remove a station; @mac may be NULL to remove all stations.
3057 * @param[in]
3058 * @return int : Return 0 on Success.
3059 * @author mdaftedar
3060 * @date 01 MAR 2012
3061 * @version 1.0
3062 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003063static int del_station(struct wiphy *wiphy, struct net_device *dev,
3064 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003065{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003066 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003067 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003068 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003069 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003070
Leo Kim7ae43362015-09-16 18:35:59 +09003071 if (!wiphy)
3072 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003073
3074 priv = wiphy_priv(wiphy);
3075 nic = netdev_priv(dev);
3076
3077 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3078 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3079
3080
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003081 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303082 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003083 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3084 } else {
3085 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]);
3086 }
3087
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003088 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003089
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003090 if (s32Error)
3091 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003092 }
3093 return s32Error;
3094}
3095
3096/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003097 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003098 * @details Modify a given station.
3099 * @param[in]
3100 * @return int : Return 0 on Success.
3101 * @author mdaftedar
3102 * @date 01 MAR 2012
3103 * @version 1.0
3104 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003105static int change_station(struct wiphy *wiphy, struct net_device *dev,
3106 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003107{
Leo Kime6e12662015-09-16 18:36:03 +09003108 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003109 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003110 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003111 perInterface_wlan_t *nic;
3112
3113
3114 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3115
Leo Kim7ae43362015-09-16 18:35:59 +09003116 if (!wiphy)
3117 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003118
3119 priv = wiphy_priv(wiphy);
3120 nic = netdev_priv(dev);
3121
3122 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09003123 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09003124 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09003125 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09003126 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003127
Leo Kim2353c382015-10-29 12:05:41 +09003128 PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n",
3129 strStaParams.bssid[0], strStaParams.bssid[1],
3130 strStaParams.bssid[2], strStaParams.bssid[3],
3131 strStaParams.bssid[4], strStaParams.bssid[5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003132 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003133 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3134 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003135
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003136 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003137 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003138 } else {
Leo Kim22520122015-10-29 12:05:45 +09003139 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003140 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003141 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003142 memcpy(strStaParams.ht_supp_mcs_set,
3143 &params->ht_capa->mcs,
3144 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003145 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003146 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003147 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003148 }
3149
Leo Kimf676e172015-10-29 12:05:52 +09003150 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003151 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003152
Leo Kim22520122015-10-29 12:05:45 +09003153 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3154 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003155 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3156 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003157 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3158 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003159 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3160 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003161 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3162 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003163 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3164 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003165 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3166 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003167 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3168 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003169
3170 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003171 if (s32Error)
3172 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003173 }
3174 return s32Error;
3175}
3176
3177
3178/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003179 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003180 * @details
3181 * @param[in]
3182 * @return int : Return 0 on Success.
3183 * @author mdaftedar
3184 * @date 01 JUL 2012
3185 * @version 1.0
3186 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003187static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3188 const char *name,
3189 unsigned char name_assign_type,
3190 enum nl80211_iftype type,
3191 u32 *flags,
3192 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003193{
3194 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003195 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003196 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003197
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003198 priv = wiphy_priv(wiphy);
3199
3200
3201
3202 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3203
3204 nic = netdev_priv(priv->wdev->netdev);
3205
3206
3207 if (type == NL80211_IFTYPE_MONITOR) {
3208 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3209 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3210 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3211 if (new_ifc != NULL) {
3212 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003213 nic = netdev_priv(priv->wdev->netdev);
3214 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003215 } else
3216 PRINT_ER("Error in initializing monitor interface\n ");
3217 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003218 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003219}
3220
3221/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003222 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003223 * @details
3224 * @param[in]
3225 * @return int : Return 0 on Success.
3226 * @author mdaftedar
3227 * @date 01 JUL 2012
3228 * @version 1.0
3229 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003230static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003231{
3232 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003233 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003234}
3235
Chaehyun Lim08241922015-09-15 14:06:12 +09003236static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003237
Chaehyun Lim80785a92015-09-14 12:24:01 +09003238 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003239 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003240 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003241 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003242 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003243 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003244 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003245 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003246 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003247 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003248 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003249
Chaehyun Lima13168d2015-09-14 12:24:12 +09003250 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003251 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003252 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003253 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003254 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003255 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003256 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003257 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003258 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003259 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003260
Chaehyun Lim4d466572015-09-14 12:24:22 +09003261 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003262 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003263 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003264 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003265 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003266 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003267 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003268 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003269 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003270 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003271
3272};
3273
3274
3275
3276
3277
3278/**
3279 * @brief WILC_WFI_update_stats
3280 * @details Modify parameters for a given BSS.
3281 * @param[in]
3282 * @return int : Return 0 on Success.
3283 * @author mdaftedar
3284 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003285 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003286 */
3287int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3288{
3289
Chaehyun Lim27268872015-09-15 14:06:13 +09003290 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003291
3292 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003293 switch (changed) {
3294
3295 case WILC_WFI_RX_PKT:
3296 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003297 priv->netstats.rx_packets++;
3298 priv->netstats.rx_bytes += pktlen;
3299 priv->netstats.rx_time = get_jiffies_64();
3300 }
3301 break;
3302
3303 case WILC_WFI_TX_PKT:
3304 {
3305 priv->netstats.tx_packets++;
3306 priv->netstats.tx_bytes += pktlen;
3307 priv->netstats.tx_time = get_jiffies_64();
3308
3309 }
3310 break;
3311
3312 default:
3313 break;
3314 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003315 return 0;
3316}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003317
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003318/**
3319 * @brief WILC_WFI_CfgAlloc
3320 * @details Allocation of the wireless device structure and assigning it
3321 * to the cfg80211 operations structure.
3322 * @param[in] NONE
3323 * @return wireless_dev : Returns pointer to wireless_dev structure.
3324 * @author mdaftedar
3325 * @date 01 MAR 2012
3326 * @version 1.0
3327 */
3328struct wireless_dev *WILC_WFI_CfgAlloc(void)
3329{
3330
3331 struct wireless_dev *wdev;
3332
3333
3334 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3335 /*Allocating the wireless device structure*/
3336 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3337 if (!wdev) {
3338 PRINT_ER("Cannot allocate wireless device\n");
3339 goto _fail_;
3340 }
3341
3342 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003343 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003344 if (!wdev->wiphy) {
3345 PRINT_ER("Cannot allocate wiphy\n");
3346 goto _fail_mem_;
3347
3348 }
3349
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003350 /* enable 802.11n HT */
3351 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3352 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3353 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3354 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3355 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003356
3357 /*wiphy bands*/
3358 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3359
3360 return wdev;
3361
3362_fail_mem_:
3363 kfree(wdev);
3364_fail_:
3365 return NULL;
3366
3367}
3368/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003369 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003370 * @details Registering of the wiphy structure and interface modes
3371 * @param[in] NONE
3372 * @return NONE
3373 * @author mdaftedar
3374 * @date 01 MAR 2012
3375 * @version 1.0
3376 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003377struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003378{
Chaehyun Lim27268872015-09-15 14:06:13 +09003379 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003380 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003381 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003382
3383 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3384
3385 wdev = WILC_WFI_CfgAlloc();
3386 if (wdev == NULL) {
3387 PRINT_ER("CfgAlloc Failed\n");
3388 return NULL;
3389 }
3390
3391
3392 /*Return hardware description structure (wiphy)'s priv*/
3393 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003394 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003395
3396 /*Link the wiphy with wireless structure*/
3397 priv->wdev = wdev;
3398
3399 /*Maximum number of probed ssid to be added by user for the scan request*/
3400 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003401 /*Maximum number of pmkids to be cashed*/
3402 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3403 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003404
3405 wdev->wiphy->max_scan_ie_len = 1000;
3406
3407 /*signal strength in mBm (100*dBm) */
3408 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3409
3410 /*Set the availaible cipher suites*/
3411 wdev->wiphy->cipher_suites = cipher_suites;
3412 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003413 /*Setting default managment types: for register action frame: */
3414 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003415
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003416 wdev->wiphy->max_remain_on_channel_duration = 500;
3417 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3418 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3419 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003420 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003421 wdev->iftype = NL80211_IFTYPE_STATION;
3422
3423
3424
3425 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3426 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3427 wdev->wiphy->interface_modes, wdev->iftype);
3428
3429 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003430 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003431 #endif
3432
3433 /*Register wiphy structure*/
3434 s32Error = wiphy_register(wdev->wiphy);
3435 if (s32Error) {
3436 PRINT_ER("Cannot register wiphy device\n");
3437 /*should define what action to be taken in such failure*/
3438 } else {
3439 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3440 }
3441
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003442 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003443 return wdev;
3444
3445
3446}
3447/**
3448 * @brief WILC_WFI_WiphyFree
3449 * @details Freeing allocation of the wireless device structure
3450 * @param[in] NONE
3451 * @return NONE
3452 * @author mdaftedar
3453 * @date 01 MAR 2012
3454 * @version 1.0
3455 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003456int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003457{
3458
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003459 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003460
Chaehyun Lim27268872015-09-15 14:06:13 +09003461 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003462
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003463 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3464 priv = wdev_priv(net->ieee80211_ptr);
3465 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003466 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003467 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003468 }
3469 op_ifcs++;
3470 if (s32Error < 0) {
3471 PRINT_ER("Failed to creat refresh Timer\n");
3472 return s32Error;
3473 }
3474
Dean Lee72ed4dc2015-06-12 14:11:44 +09003475 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003476
Dean Lee72ed4dc2015-06-12 14:11:44 +09003477 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003478
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003479 sema_init(&(priv->hSemScanReq), 1);
Glen Leed53822192015-10-27 18:27:49 +09003480 s32Error = host_int_init(net, &priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003481 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003482 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003483
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003484 return s32Error;
3485}
3486
3487/**
3488 * @brief WILC_WFI_WiphyFree
3489 * @details Freeing allocation of the wireless device structure
3490 * @param[in] NONE
3491 * @return NONE
3492 * @author mdaftedar
3493 * @date 01 MAR 2012
3494 * @version 1.0
3495 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003496int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003497{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003498 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003499
Chaehyun Lim27268872015-09-15 14:06:13 +09003500 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003501
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003502 priv = wdev_priv(net->ieee80211_ptr);
3503
Dean Lee72ed4dc2015-06-12 14:11:44 +09003504 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003505
Dean Lee72ed4dc2015-06-12 14:11:44 +09003506 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003507
3508 op_ifcs--;
3509
3510 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003511
3512 /* Clear the Shadow scan */
3513 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003514 if (op_ifcs == 0) {
3515 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003516 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003517 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003518
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003519 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003520 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003521
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003522 return s32Error;
3523}
3524
3525
3526/**
3527 * @brief WILC_WFI_WiphyFree
3528 * @details Freeing allocation of the wireless device structure
3529 * @param[in] NONE
3530 * @return NONE
3531 * @author mdaftedar
3532 * @date 01 MAR 2012
3533 * @version 1.0
3534 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003535void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003536{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003537 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3538
Chaehyun Lim619837a2015-09-20 15:51:10 +09003539 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003540 PRINT_D(INIT_DBG, "net_device is NULL\n");
3541 return;
3542 }
3543
Chaehyun Lim619837a2015-09-20 15:51:10 +09003544 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003545 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3546 return;
3547 }
3548
Chaehyun Lim619837a2015-09-20 15:51:10 +09003549 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003550 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3551 return;
3552 }
3553
3554 wiphy_unregister(net->ieee80211_ptr->wiphy);
3555
3556 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3557 wiphy_free(net->ieee80211_ptr->wiphy);
3558 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003559}