blob: 32b93d3f806da61332d033c07125c5d60eee8eac [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 mac_open(struct net_device *ndev);
25extern int mac_close(struct net_device *ndev);
26
27tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090028u32 u32LastScannedNtwrksCountShadow;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070029struct timer_list hDuringIpTimer;
Greg Kroah-Hartmanda711eb2015-08-14 19:46:06 -070030struct timer_list hAgingTimer;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090031static u8 op_ifcs;
32extern u8 u8ConnectedSSID[6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090033
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090034u8 g_wilc_initialized = 1;
Dean Lee72ed4dc2015-06-12 14:11:44 +090035extern bool g_obtainingIP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090036
37#define CHAN2G(_channel, _freq, _flags) { \
38 .band = IEEE80211_BAND_2GHZ, \
39 .center_freq = (_freq), \
40 .hw_value = (_channel), \
41 .flags = (_flags), \
42 .max_antenna_gain = 0, \
43 .max_power = 30, \
44}
45
46/*Frequency range for channels*/
47static struct ieee80211_channel WILC_WFI_2ghz_channels[] = {
48 CHAN2G(1, 2412, 0),
49 CHAN2G(2, 2417, 0),
50 CHAN2G(3, 2422, 0),
51 CHAN2G(4, 2427, 0),
52 CHAN2G(5, 2432, 0),
53 CHAN2G(6, 2437, 0),
54 CHAN2G(7, 2442, 0),
55 CHAN2G(8, 2447, 0),
56 CHAN2G(9, 2452, 0),
57 CHAN2G(10, 2457, 0),
58 CHAN2G(11, 2462, 0),
59 CHAN2G(12, 2467, 0),
60 CHAN2G(13, 2472, 0),
61 CHAN2G(14, 2484, 0),
62};
63
64#define RATETAB_ENT(_rate, _hw_value, _flags) { \
65 .bitrate = (_rate), \
66 .hw_value = (_hw_value), \
67 .flags = (_flags), \
68}
69
70
71/* Table 6 in section 3.2.1.1 */
72static struct ieee80211_rate WILC_WFI_rates[] = {
73 RATETAB_ENT(10, 0, 0),
74 RATETAB_ENT(20, 1, 0),
75 RATETAB_ENT(55, 2, 0),
76 RATETAB_ENT(110, 3, 0),
77 RATETAB_ENT(60, 9, 0),
78 RATETAB_ENT(90, 6, 0),
79 RATETAB_ENT(120, 7, 0),
80 RATETAB_ENT(180, 8, 0),
81 RATETAB_ENT(240, 9, 0),
82 RATETAB_ENT(360, 10, 0),
83 RATETAB_ENT(480, 11, 0),
84 RATETAB_ENT(540, 12, 0),
85};
86
Johnny Kimc5c77ba2015-05-11 14:30:56 +090087struct p2p_mgmt_data {
88 int size;
89 u8 *buff;
90};
91
92/*Global variable used to state the current connected STA channel*/
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090093u8 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090094
Chaehyun Lim866a2c22015-10-02 16:41:21 +090095u8 curr_channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090096
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090097u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
98u8 u8P2Plocalrandom = 0x01;
99u8 u8P2Precvrandom = 0x00;
100u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
Daniel Machon7fc80962015-08-05 00:09:35 +0200101bool bWilc_ie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900102
103static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
104 .channels = WILC_WFI_2ghz_channels,
105 .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels),
106 .bitrates = WILC_WFI_rates,
107 .n_bitrates = ARRAY_SIZE(WILC_WFI_rates),
108};
109
110
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111struct add_key_params {
112 u8 key_idx;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113 bool pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114 u8 *mac_addr;
115};
116struct add_key_params g_add_gtk_key_params;
117struct wilc_wfi_key g_key_gtk_params;
118struct add_key_params g_add_ptk_key_params;
119struct wilc_wfi_key g_key_ptk_params;
120struct wilc_wfi_wep_key g_key_wep_params;
Daniel Machon7fc80962015-08-05 00:09:35 +0200121bool g_ptk_keys_saved;
122bool g_gtk_keys_saved;
123bool g_wep_keys_saved;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900124
125#define AGING_TIME (9 * 1000)
126#define duringIP_TIME 15000
127
128void clear_shadow_scan(void *pUserVoid)
129{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900130 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900131
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132 if (op_ifcs == 0) {
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -0700133 del_timer_sync(&hAgingTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900134 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
135
136 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
137 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900138 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900139 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
140 }
141
142 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
143 astrLastScannedNtwrksShadow[i].pJoinParams = NULL;
144 }
145 u32LastScannedNtwrksCountShadow = 0;
146 }
147
148}
149
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900150u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900151{
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900152 u8 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900153 int rssi_v = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900154 u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900155
156 for (i = 0; i < num_rssi; i++)
157 rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
158
159 rssi_v /= num_rssi;
160 return rssi_v;
161}
162
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900163void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900164{
Chaehyun Lim27268872015-09-15 14:06:13 +0900165 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900166 struct wiphy *wiphy;
167 struct cfg80211_bss *bss = NULL;
168 int i;
169 int rssi = 0;
170
Chaehyun Lim27268872015-09-15 14:06:13 +0900171 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172 wiphy = priv->dev->ieee80211_ptr->wiphy;
173
174 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
175 tstrNetworkInfo *pstrNetworkInfo;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900176
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900177 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
178
179
180 if ((!pstrNetworkInfo->u8Found) || all) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900181 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182 struct ieee80211_channel *channel;
183
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900184 if (pstrNetworkInfo != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900186 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187 channel = ieee80211_get_channel(wiphy, s32Freq);
188
189 rssi = get_rssi_avg(pstrNetworkInfo);
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900190 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900191 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
192 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900193 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195 }
196 }
197
198 }
199 }
200
201}
202
203void reset_shadow_found(void *pUserVoid)
204{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900205 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900206
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900207 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
208 astrLastScannedNtwrksShadow[i].u8Found = 0;
209
210 }
211}
212
213void update_scan_time(void *pUserVoid)
214{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900215 int i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900216
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900217 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
218 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
219 }
220}
221
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700222static void remove_network_from_shadow(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900223{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900224 unsigned long now = jiffies;
225 int i, j;
226
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227
228 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
229 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530230 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900231
Shraddha Barkecccfc392015-10-12 20:49:19 +0530232 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
233 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900234
235 host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
236
237 for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) {
238 astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1];
239 }
240 u32LastScannedNtwrksCountShadow--;
241 }
242 }
243
244 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700245 if (u32LastScannedNtwrksCountShadow != 0) {
246 hAgingTimer.data = arg;
247 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
248 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900249 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700250 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900251}
252
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -0700253static void clear_duringIP(unsigned long arg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900254{
255 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900256 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900257}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900258
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900259int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900260{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900261 int state = -1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900262 int i;
263
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900264 if (u32LastScannedNtwrksCountShadow == 0) {
265 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -0700266 hAgingTimer.data = (unsigned long)pUserVoid;
267 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900268 state = -1;
269 } else {
270 /* Linear search for now */
271 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900272 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900273 pstrNetworkInfo->au8bssid, 6) == 0) {
274 state = i;
275 break;
276 }
277 }
278 }
279 return state;
280}
281
282void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
283{
Chaehyun Lima74cc6b2015-10-02 16:41:17 +0900284 int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900285 u32 ap_index = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900286 u8 rssi_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900287
288 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
289 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
290 return;
291 }
292 if (ap_found == -1) {
293 ap_index = u32LastScannedNtwrksCountShadow;
294 u32LastScannedNtwrksCountShadow++;
295
296 } else {
297 ap_index = ap_found;
298 }
299 rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index;
300 astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi;
301 if (rssi_index == NUM_RSSI) {
302 rssi_index = 0;
303 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1;
304 }
305 astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index;
306
307 astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi;
308 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
309
310 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900311 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900312 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
313
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900314 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900315 pstrNetworkInfo->au8bssid, ETH_ALEN);
316
317 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
318 astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod;
319 astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel;
320
321 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
322 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
323 if (ap_found != -1)
Chaehyun Lim49188af2015-08-11 10:32:41 +0900324 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900325 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
Glen Leef3052582015-09-10 12:03:04 +0900326 kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900327 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900328 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
329
330 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
331 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies;
332 astrLastScannedNtwrksShadow[ap_index].u8Found = 1;
333 if (ap_found != -1)
334 host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams);
335 astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams;
336
337}
338
339
340/**
341 * @brief CfgScanResult
342 * @details Callback function which returns the scan results found
343 *
344 * @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is
345 * SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE
346 * tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information
347 * void* pUserVoid: Private structure associated with the wireless interface
348 * @return NONE
349 * @author mabubakr
350 * @date
351 * @version 1.0
352 */
Leo Kim1ec38152015-10-12 16:55:59 +0900353static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354{
Chaehyun Lim27268872015-09-15 14:06:13 +0900355 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900356 struct wiphy *wiphy;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900357 s32 s32Freq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900358 struct ieee80211_channel *channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900359 struct cfg80211_bss *bss = NULL;
360
Chaehyun Lim27268872015-09-15 14:06:13 +0900361 priv = (struct wilc_priv *)pUserVoid;
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100362 if (priv->bCfgScanning) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900363 if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
364 wiphy = priv->dev->ieee80211_ptr->wiphy;
Leo Kim7ae43362015-09-16 18:35:59 +0900365
366 if (!wiphy)
367 return;
368
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900369 if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
370 &&
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900371 ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900372 ||
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900373 (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900374 ) {
Leo Kim24db7132015-09-16 18:36:01 +0900375 PRINT_ER("wiphy signal type fial\n");
376 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900377 }
378
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900379 if (pstrNetworkInfo != NULL) {
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900380 s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900381 channel = ieee80211_get_channel(wiphy, s32Freq);
382
Leo Kim7ae43362015-09-16 18:35:59 +0900383 if (!channel)
384 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900385
386 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530387 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900388 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
389
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +0100390 if (pstrNetworkInfo->bNewNetwork) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
392 /* max_scan_ssids */
393 PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
394
395
396 priv->u32RcvdChCount++;
397
398
399
400 if (pJoinParams == NULL) {
401 PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n");
402 }
403 add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams);
404
405 /*P2P peers are sent to WPA supplicant and added to shadow table*/
406
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900407 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900408 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
409 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900410 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900411 cfg80211_put_bss(wiphy, bss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900412 }
413
414
415 } else {
416 PRINT_ER("Discovered networks exceeded the max limit\n");
417 }
418 } else {
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900419 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900420 /* So this network is discovered before, we'll just update its RSSI */
421 for (i = 0; i < priv->u32RcvdChCount; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900422 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530423 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900424
425 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
426 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
427 break;
428 }
429 }
430 }
431 }
432 } else if (enuScanEvent == SCAN_EVENT_DONE) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530433 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
434 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
Dean Lee72ed4dc2015-06-12 14:11:44 +0900435 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900436
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530437 if (priv->u32RcvdChCount > 0)
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530438 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530439 else
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530440 PRINT_D(CFG80211_DBG, "No networks found\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200442 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900444 if (priv->pstrScanReq != NULL) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900445 cfg80211_scan_done(priv->pstrScanReq, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900446 priv->u32RcvdChCount = 0;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900447 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900448 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200450 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451
452 }
453 /*Aborting any scan operation during mac close*/
454 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200455 down(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900456
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530457 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900458 if (priv->pstrScanReq != NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459
460 update_scan_time(priv);
Dean Lee72ed4dc2015-06-12 14:11:44 +0900461 refresh_scan(priv, 1, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900462
Dean Lee72ed4dc2015-06-12 14:11:44 +0900463 cfg80211_scan_done(priv->pstrScanReq, false);
464 priv->bCfgScanning = false;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900465 priv->pstrScanReq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900466 }
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200467 up(&(priv->hSemScanReq));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468 }
469 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470}
471
472
473/**
474 * @brief WILC_WFI_Set_PMKSA
475 * @details Check if pmksa is cached and set it.
476 * @param[in]
477 * @return int : Return 0 on Success
478 * @author mdaftedar
479 * @date 01 MAR 2012
480 * @version 1.0
481 */
Chaehyun Lim27268872015-09-15 14:06:13 +0900482int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900484 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900485 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486
487
488 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
489
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900490 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900491 ETH_ALEN)) {
492 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
493
494 /*If bssid is found, set the values*/
495 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
496
Leo Kime6e12662015-09-16 18:36:03 +0900497 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900498 PRINT_ER("Error in pmkid\n");
499
500 break;
501 }
502 }
503
504 return s32Error;
505
506
507}
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900508int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900509
510
511/**
512 * @brief CfgConnectResult
513 * @details
514 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
515 * connection response or disconnection notification.
516 * tstrConnectInfo* pstrConnectInfo: COnnection information.
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900517 * u8 u8MacStatus: Mac Status from firmware
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900518 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
519 * void* pUserVoid: Private data associated with wireless interface
520 * @return NONE
521 * @author mabubakr
522 * @date 01 MAR 2012
523 * @version 1.0
524 */
525int connecting;
526
Leo Kimed3f0372015-10-12 16:56:01 +0900527static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900528 tstrConnectInfo *pstrConnectInfo,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900529 u8 u8MacStatus,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900530 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
531 void *pUserVoid)
532{
Chaehyun Lim27268872015-09-15 14:06:13 +0900533 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900534 struct net_device *dev;
Leo Kim441dc602015-10-12 16:55:35 +0900535 struct host_if_drv *pstrWFIDrv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900536 u8 NullBssid[ETH_ALEN] = {0};
Glen Leec1ec2c12015-10-20 17:13:58 +0900537 struct wilc *wl;
538 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900539
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900540 connecting = 0;
541
Chaehyun Lim27268872015-09-15 14:06:13 +0900542 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900543 dev = priv->dev;
Glen Leec1ec2c12015-10-20 17:13:58 +0900544 nic = netdev_priv(dev);
545 wl = nic->wilc;
Leo Kim441dc602015-10-12 16:55:35 +0900546 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900547
548 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
549 /*Initialization*/
Amitoj Kaur Chawlababa7c72015-10-15 13:48:29 +0530550 u16 u16ConnectStatus;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900551
552 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
553
554 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
555
556 if ((u8MacStatus == MAC_DISCONNECTED) &&
557 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
558 /* The case here is that our station was waiting for association response frame and has just received it containing status code
559 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
560 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
561 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530562 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900563
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900565 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900567
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530568 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900569 }
570
571 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900572 bool bNeedScanRefresh = false;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900573 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900574
575 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
576 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900577 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900578
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900579
580 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900581 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900582 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
583 unsigned long now = jiffies;
584
585 if (time_after(now,
586 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900587 bNeedScanRefresh = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900588 }
589
590 break;
591 }
592 }
593
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000594 if (bNeedScanRefresh) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595 /*Also, refrsh DIRECT- results if */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900596 refresh_scan(priv, 1, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900597
598 }
599
600 }
601
602
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530603 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900604
605 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
606
607 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
608 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
609 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
610 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
611 /* be replaced by pstrConnectInfo->u16ConnectStatus */
612 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900613 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900614 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
615 pstrDisconnectNotifInfo->u16reason, priv->dev);
616 u8P2Plocalrandom = 0x01;
617 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900618 bWilc_ie = false;
Shraddha Barkebcf02652015-10-05 17:00:32 +0530619 eth_zero_addr(priv->au8AssociatedBss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900620 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530621 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900622
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900624 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900626 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
627 * virtual interface to station*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900628 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900629 pstrDisconnectNotifInfo->u16reason = 3;
630 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900631 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
632 * to scan again and retry the connection*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900633 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900634 pstrDisconnectNotifInfo->u16reason = 1;
635 }
636 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
Sudip Mukherjeee26bb712015-06-30 13:51:51 +0530637 pstrDisconnectNotifInfo->ie_len, false,
638 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900639
640 }
641
642}
643
644
645/**
Chaehyun Lim80785a92015-09-14 12:24:01 +0900646 * @brief set_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900647 * @details Set channel for a given wireless interface. Some devices
648 * may support multi-channel operation (by channel hopping) so cfg80211
649 * doesn't verify much. Note, however, that the passed netdev may be
650 * %NULL as well if the user requested changing the channel for the
651 * device itself, or for a monitor interface.
652 * @param[in]
653 * @return int : Return 0 on Success
654 * @author mdaftedar
655 * @date 01 MAR 2012
656 * @version 1.0
657 */
Chaehyun Lim80785a92015-09-14 12:24:01 +0900658static int set_channel(struct wiphy *wiphy,
659 struct cfg80211_chan_def *chandef)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900660{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900661 u32 channelnum = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +0900662 struct wilc_priv *priv;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900663 int result = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900664
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900665 priv = wiphy_priv(wiphy);
666
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900667 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
668 PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900669
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900670 curr_channel = channelnum;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900671 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900672
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900673 if (result != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900674 PRINT_ER("Error in setting channel %d\n", channelnum);
675
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900676 return result;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677}
678
679/**
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900680 * @brief scan
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900681 * @details Request to do a scan. If returning zero, the scan request is given
682 * the driver, and will be valid until passed to cfg80211_scan_done().
683 * For scan results, call cfg80211_inform_bss(); you can call this outside
684 * the scan/scan_done bracket too.
685 * @param[in]
686 * @return int : Return 0 on Success
687 * @author mabubakr
688 * @date 01 MAR 2012
689 * @version 1.0
690 */
691
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900692static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900693{
Chaehyun Lim27268872015-09-15 14:06:13 +0900694 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900695 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900696 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900697 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
Leo Kim607db442015-10-05 15:25:37 +0900698 struct hidden_network strHiddenNetwork;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900699
700 priv = wiphy_priv(wiphy);
701
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900702 priv->pstrScanReq = request;
703
704 priv->u32RcvdChCount = 0;
705
Johnny Kim218dc402015-08-13 13:41:19 +0900706 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900707
708
709 reset_shadow_found(priv);
710
Dean Lee72ed4dc2015-06-12 14:11:44 +0900711 priv->bCfgScanning = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900712 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
713 /* max_scan_ssids */
714 for (i = 0; i < request->n_channels; i++) {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900715 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900716 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
717 }
718
719 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530720 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900721
722 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
723
724 if (request->n_ssids >= 1) {
725
726
Leo Kim607db442015-10-05 15:25:37 +0900727 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900728 strHiddenNetwork.u8ssidnum = request->n_ssids;
729
730
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 for (i = 0; i < request->n_ssids; i++) {
732
733 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
Glen Leef3052582015-09-10 12:03:04 +0900734 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900735 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900736 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
737 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530738 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900739 strHiddenNetwork.u8ssidnum -= 1;
740 }
741 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530742 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900743 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
744 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900745 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900746 CfgScanResult, (void *)priv, &strHiddenNetwork);
747 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530748 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
750 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900751 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900752 CfgScanResult, (void *)priv, NULL);
753 }
754
755 } else {
756 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530757 " channels\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900758 }
759
Leo Kime6e12662015-09-16 18:36:03 +0900760 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900761 s32Error = -EBUSY;
762 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
763 }
764
765 return s32Error;
766}
767
768/**
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900769 * @brief connect
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900770 * @details Connect to the ESS with the specified parameters. When connected,
771 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
772 * If the connection fails for some reason, call cfg80211_connect_result()
773 * with the status from the AP.
774 * @param[in]
775 * @return int : Return 0 on Success
776 * @author mabubakr
777 * @date 01 MAR 2012
778 * @version 1.0
779 */
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900780static int connect(struct wiphy *wiphy, struct net_device *dev,
781 struct cfg80211_connect_params *sme)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900782{
Leo Kime6e12662015-09-16 18:36:03 +0900783 s32 s32Error = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900784 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900785 u8 u8security = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +0900786 enum AUTHTYPE tenuAuth_type = ANY;
Dean Lee576917a2015-06-15 11:58:57 +0900787 char *pcgroup_encrypt_val = NULL;
788 char *pccipher_group = NULL;
789 char *pcwpa_version = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900790
Chaehyun Lim27268872015-09-15 14:06:13 +0900791 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +0900792 struct host_if_drv *pstrWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900793 tstrNetworkInfo *pstrNetworkInfo = NULL;
794
795
796 connecting = 1;
797 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +0900798 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900799
Johnny Kim218dc402015-08-13 13:41:19 +0900800 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900801
Johnny Kim8a143302015-06-10 17:06:46 +0900802 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 +0900803 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900804 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
Leo Kimab16ec02015-10-29 12:05:40 +0900805 pstrWFIDrv->p2p_connect = 1;
806 } else {
807 pstrWFIDrv->p2p_connect = 0;
808 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530809 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900810
811 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
812 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900813 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900814 sme->ssid,
815 sme->ssid_len) == 0) {
816 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
817 if (sme->bssid == NULL) {
818 /* BSSID is not passed from the user, so decision of matching
819 * is done by SSID only */
820 PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n");
821 break;
822 } else {
823 /* BSSID is also passed from the user, so decision of matching
824 * should consider also this passed BSSID */
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900825 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900826 sme->bssid,
827 ETH_ALEN) == 0) {
828 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
829 break;
830 }
831 }
832 }
833 }
834
835 if (i < u32LastScannedNtwrksCountShadow) {
836 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
837
838 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
839
840 PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n",
841 pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1],
842 pstrNetworkInfo->au8bssid[2], pstrNetworkInfo->au8bssid[3],
843 pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]);
844 } else {
845 s32Error = -ENOENT;
846 if (u32LastScannedNtwrksCountShadow == 0)
847 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
848 else
849 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
850
851 goto done;
852 }
853
854 priv->WILC_WFI_wep_default = 0;
Chaehyun Lim2cc46832015-08-07 09:02:01 +0900855 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
856 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900857
858 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
859 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
860
861 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
862
863 if (INFO) {
864 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
865 PRINT_D(CORECONFIG_DBG, "sme->crypto.ciphers_pairwise[%d]=%x\n", i, sme->crypto.ciphers_pairwise[i]);
866 }
867
868 if (sme->crypto.cipher_group != NO_ENCRYPT) {
869 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
870 * we will add to it the pairwise cipher suite(s) */
871 pcwpa_version = "Default";
872 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900873 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900874 u8security = ENCRYPT_ENABLED | WEP;
875 pcgroup_encrypt_val = "WEP40";
876 pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
877 PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
878
879 if (INFO) {
880 for (i = 0; i < sme->key_len; i++)
881 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
882 }
883 priv->WILC_WFI_wep_default = sme->key_idx;
884 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900885 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900886
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900887 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900888 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900889 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
890 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900891 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900892
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900893 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
895 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900896 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
897 pcgroup_encrypt_val = "WEP104";
898 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
899
900 priv->WILC_WFI_wep_default = sme->key_idx;
901 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900902 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900903
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900904 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900905 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900906 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
907 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900908 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900909
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900910 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900911 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
912 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900913 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900914 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
915 pcgroup_encrypt_val = "WPA2_TKIP";
916 pccipher_group = "TKIP";
917 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
918 /* tenuSecurity_t = WPA2_AES; */
919 u8security = ENCRYPT_ENABLED | WPA2 | AES;
920 pcgroup_encrypt_val = "WPA2_AES";
921 pccipher_group = "AES";
922 }
923 pcwpa_version = "WPA_VERSION_2";
924 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
925 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900926 u8security = ENCRYPT_ENABLED | WPA | TKIP;
927 pcgroup_encrypt_val = "WPA_TKIP";
928 pccipher_group = "TKIP";
929 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
930 /* tenuSecurity_t = WPA_AES; */
931 u8security = ENCRYPT_ENABLED | WPA | AES;
932 pcgroup_encrypt_val = "WPA_AES";
933 pccipher_group = "AES";
934
935 }
936 pcwpa_version = "WPA_VERSION_1";
937
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900938 } else {
939 s32Error = -ENOTSUPP;
940 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
941
942 goto done;
943 }
944
945 }
946
947 /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will
948 * add to it the pairwise cipher suite(s) */
949 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
950 || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
951 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
952 if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) {
953 u8security = u8security | TKIP;
954 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
955 u8security = u8security | AES;
956 }
957 }
958 }
959
960 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
961
962 PRINT_D(CFG80211_DBG, "Authentication Type = %d\n", sme->auth_type);
963 switch (sme->auth_type) {
964 case NL80211_AUTHTYPE_OPEN_SYSTEM:
965 PRINT_D(CFG80211_DBG, "In OPEN SYSTEM\n");
966 tenuAuth_type = OPEN_SYSTEM;
967 break;
968
969 case NL80211_AUTHTYPE_SHARED_KEY:
970 tenuAuth_type = SHARED_KEY;
971 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
972 break;
973
974 default:
975 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
976 }
977
978
979 /* ai: key_mgmt: enterprise case */
980 if (sme->crypto.n_akm_suites) {
981 switch (sme->crypto.akm_suites[0]) {
982 case WLAN_AKM_SUITE_8021X:
983 tenuAuth_type = IEEE8021;
984 break;
985
986 default:
987 break;
988 }
989 }
990
991
992 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
993
994 PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
995 pcgroup_encrypt_val, pccipher_group, pcwpa_version);
996
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900997 curr_channel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900998
Leo Kimab16ec02015-10-29 12:05:40 +0900999 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001000 u8WLANChannel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001001
1002 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1003
1004 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1005 sme->ssid_len, sme->ie, sme->ie_len,
1006 CfgConnectResult, (void *)priv, u8security,
1007 tenuAuth_type, pstrNetworkInfo->u8channel,
1008 pstrNetworkInfo->pJoinParams);
Leo Kime6e12662015-09-16 18:36:03 +09001009 if (s32Error != 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301010 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001011 s32Error = -ENOENT;
1012 goto done;
1013 }
1014
1015done:
1016
1017 return s32Error;
1018}
1019
1020
1021/**
Chaehyun Limb027cde2015-09-14 12:24:04 +09001022 * @brief disconnect
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001023 * @details Disconnect from the BSS/ESS.
1024 * @param[in]
1025 * @return int : Return 0 on Success
1026 * @author mdaftedar
1027 * @date 01 MAR 2012
1028 * @version 1.0
1029 */
Chaehyun Limb027cde2015-09-14 12:24:04 +09001030static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001031{
Leo Kime6e12662015-09-16 18:36:03 +09001032 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001033 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09001034 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001035 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001036
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001037 connecting = 0;
1038 priv = wiphy_priv(wiphy);
1039
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001040 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kim441dc602015-10-12 16:55:35 +09001041 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Leo Kimab16ec02015-10-29 12:05:40 +09001042 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001043 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001044 linux_wlan_set_bssid(priv->dev, NullBssid);
1045
1046 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1047
1048 u8P2Plocalrandom = 0x01;
1049 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +09001050 bWilc_ie = false;
Leo Kim1229b1a2015-10-29 12:05:39 +09001051 pstrWFIDrv->p2p_timeout = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001052
1053 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
Leo Kime6e12662015-09-16 18:36:03 +09001054 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1056 s32Error = -EINVAL;
1057 }
1058
1059 return s32Error;
1060}
1061
1062/**
Chaehyun Lim953d4172015-09-14 12:24:05 +09001063 * @brief add_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001064 * @details Add a key with the given parameters. @mac_addr will be %NULL
1065 * when adding a group key.
1066 * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1067 * @return int : Return 0 on Success
1068 * @author mdaftedar
1069 * @date 01 MAR 2012
1070 * @version 1.0
1071 */
Chaehyun Lim953d4172015-09-14 12:24:05 +09001072static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1073 bool pairwise,
1074 const u8 *mac_addr, struct key_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001075
1076{
Leo Kime6e12662015-09-16 18:36:03 +09001077 s32 s32Error = 0, KeyLen = params->key_len;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001078 u32 i;
Chaehyun Lim27268872015-09-15 14:06:13 +09001079 struct wilc_priv *priv;
Arnd Bergmann057d1e92015-06-01 21:06:44 +02001080 const u8 *pu8RxMic = NULL;
1081 const u8 *pu8TxMic = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001082 u8 u8mode = NO_ENCRYPT;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001083 u8 u8gmode = NO_ENCRYPT;
1084 u8 u8pmode = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +09001085 enum AUTHTYPE tenuAuth_type = ANY;
Glen Lee76469202015-10-20 17:13:59 +09001086 struct wilc *wl;
1087 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001088
1089 priv = wiphy_priv(wiphy);
Glen Lee76469202015-10-20 17:13:59 +09001090 nic = netdev_priv(netdev);
1091 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001092
1093 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1094
Johnny Kim8a143302015-06-10 17:06:46 +09001095 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001096
1097 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1098 params->key[1],
1099 params->key[2]);
1100
1101
1102 switch (params->cipher) {
1103 case WLAN_CIPHER_SUITE_WEP40:
1104 case WLAN_CIPHER_SUITE_WEP104:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001105 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1106
1107 priv->WILC_WFI_wep_default = key_index;
1108 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001109 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001110
1111 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1112 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1113
1114 for (i = 0; i < params->key_len; i++)
1115 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1116
1117 tenuAuth_type = OPEN_SYSTEM;
1118
1119 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1120 u8mode = ENCRYPT_ENABLED | WEP;
1121 else
1122 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1123
1124 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1125 break;
1126 }
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001127 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001128 priv->WILC_WFI_wep_default = key_index;
1129 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001130 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001131
1132 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1133 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1134 if (INFO) {
1135 for (i = 0; i < params->key_len; i++)
1136 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1137 }
1138 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1139 }
1140
1141 break;
1142
1143 case WLAN_CIPHER_SUITE_TKIP:
1144 case WLAN_CIPHER_SUITE_CCMP:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001145 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1146
1147 if (priv->wilc_gtk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001148 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001149 priv->wilc_gtk[key_index]->key = NULL;
1150 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001151
1152 }
1153 if (priv->wilc_ptk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001154 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001155 priv->wilc_ptk[key_index]->key = NULL;
1156 priv->wilc_ptk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001157 }
1158
1159
1160
Daniel Machon19132212015-08-05 08:18:31 +02001161 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001162 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1163 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1164 else
1165 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1166
1167 priv->wilc_groupkey = u8gmode;
1168
1169 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1170
1171 pu8TxMic = params->key + 24;
1172 pu8RxMic = params->key + 16;
1173 KeyLen = params->key_len - 16;
1174 }
1175 /* 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 +05301176 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001177
Glen Leef3052582015-09-10 12:03:04 +09001178 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001179 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001180
1181 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301182 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001183
1184 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001185 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001186 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001187 }
1188
1189 priv->wilc_gtk[key_index]->cipher = params->cipher;
1190 priv->wilc_gtk[key_index]->key_len = params->key_len;
1191 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1192
1193 if (INFO) {
1194 for (i = 0; i < params->key_len; i++)
1195 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1196 for (i = 0; i < params->seq_len; i++)
1197 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1198 }
1199
1200
1201 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1202 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1203
1204 } else {
1205 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]);
1206
1207 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1208 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1209 else
1210 u8pmode = priv->wilc_groupkey | AES;
1211
1212
1213 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1214
1215 pu8TxMic = params->key + 24;
1216 pu8RxMic = params->key + 16;
1217 KeyLen = params->key_len - 16;
1218 }
1219
Shraddha Barkecccfc392015-10-12 20:49:19 +05301220 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001221
Glen Leef3052582015-09-10 12:03:04 +09001222 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223
Shraddha Barkecccfc392015-10-12 20:49:19 +05301224 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001225
1226 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001227 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001228
1229 if (INFO) {
1230 for (i = 0; i < params->key_len; i++)
1231 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1232
1233 for (i = 0; i < params->seq_len; i++)
1234 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1235 }
1236
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001237 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001238
1239 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001240 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001241
1242 priv->wilc_ptk[key_index]->cipher = params->cipher;
1243 priv->wilc_ptk[key_index]->key_len = params->key_len;
1244 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1245
1246 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1247 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1248 }
1249 break;
1250 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001251
1252 {
1253 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001254 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001255 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1256 /* swap the tx mic by rx mic */
1257 pu8RxMic = params->key + 24;
1258 pu8TxMic = params->key + 16;
1259 KeyLen = params->key_len - 16;
1260 }
1261
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001262 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001263 if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001265 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001266 if (!mac_addr) {
1267 g_add_gtk_key_params.mac_addr = NULL;
1268 } else {
Glen Leef3052582015-09-10 12:03:04 +09001269 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001270 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1271 }
1272 g_key_gtk_params.key_len = params->key_len;
1273 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001274 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001275 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1276 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001277 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001278 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1279 }
1280 g_key_gtk_params.cipher = params->cipher;
1281
1282 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1283 g_key_gtk_params.key[1],
1284 g_key_gtk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001285 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001286 }
1287
1288 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1289 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001290 } else {
1291 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1292 /* swap the tx mic by rx mic */
1293 pu8RxMic = params->key + 24;
1294 pu8TxMic = params->key + 16;
1295 KeyLen = params->key_len - 16;
1296 }
1297
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001298 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001299 if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001300 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001302 if (!mac_addr) {
1303 g_add_ptk_key_params.mac_addr = NULL;
1304 } else {
Glen Leef3052582015-09-10 12:03:04 +09001305 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001306 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1307 }
1308 g_key_ptk_params.key_len = params->key_len;
1309 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001310 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001311 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1312 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001313 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001314 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1315 }
1316 g_key_ptk_params.cipher = params->cipher;
1317
1318 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1319 g_key_ptk_params.key[1],
1320 g_key_ptk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001321 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001322 }
1323
1324 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1325 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1326 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1327 if (INFO) {
1328 for (i = 0; i < params->key_len; i++)
1329 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1330 }
1331 }
1332 }
1333 break;
1334
1335 default:
1336 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1337 s32Error = -ENOTSUPP;
1338
1339 }
1340
1341 return s32Error;
1342}
1343
1344/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001345 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001346 * @details Remove a key given the @mac_addr (%NULL for a group key)
1347 * and @key_index, return -ENOENT if the key doesn't exist.
1348 * @param[in]
1349 * @return int : Return 0 on Success
1350 * @author mdaftedar
1351 * @date 01 MAR 2012
1352 * @version 1.0
1353 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001354static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1355 u8 key_index,
1356 bool pairwise,
1357 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001358{
Chaehyun Lim27268872015-09-15 14:06:13 +09001359 struct wilc_priv *priv;
Glen Lee692e2ac2015-10-20 17:14:00 +09001360 struct wilc *wl;
1361 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001362
1363 priv = wiphy_priv(wiphy);
Glen Lee692e2ac2015-10-20 17:14:00 +09001364 nic = netdev_priv(netdev);
1365 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001366
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367 /*delete saved keys, if any*/
Glen Lee692e2ac2015-10-20 17:14:00 +09001368 if (netdev == wl->vif[0].ndev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001369 g_ptk_keys_saved = false;
1370 g_gtk_keys_saved = false;
1371 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001372
1373 /*Delete saved WEP keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301374 kfree(g_key_wep_params.key);
1375 g_key_wep_params.key = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001376
1377 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1378
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001379 if ((priv->wilc_gtk[key_index]) != NULL) {
1380
Shraddha Barkecccfc392015-10-12 20:49:19 +05301381 kfree(priv->wilc_gtk[key_index]->key);
1382 priv->wilc_gtk[key_index]->key = NULL;
1383 kfree(priv->wilc_gtk[key_index]->seq);
1384 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001385
Chaehyun Lim49188af2015-08-11 10:32:41 +09001386 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001387 priv->wilc_gtk[key_index] = NULL;
1388
1389 }
1390
1391 if ((priv->wilc_ptk[key_index]) != NULL) {
1392
Shraddha Barkecccfc392015-10-12 20:49:19 +05301393 kfree(priv->wilc_ptk[key_index]->key);
1394 priv->wilc_ptk[key_index]->key = NULL;
1395 kfree(priv->wilc_ptk[key_index]->seq);
1396 priv->wilc_ptk[key_index]->seq = NULL;
Chaehyun Lim49188af2015-08-11 10:32:41 +09001397 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001398 priv->wilc_ptk[key_index] = NULL;
1399 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001400
1401 /*Delete saved PTK and GTK keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301402 kfree(g_key_ptk_params.key);
1403 g_key_ptk_params.key = NULL;
1404 kfree(g_key_ptk_params.seq);
1405 g_key_ptk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001406
Shraddha Barkecccfc392015-10-12 20:49:19 +05301407 kfree(g_key_gtk_params.key);
1408 g_key_gtk_params.key = NULL;
1409 kfree(g_key_gtk_params.seq);
1410 g_key_gtk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001411
1412 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee178c3832015-10-27 18:27:58 +09001413 Set_machw_change_vir_if(netdev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001414 }
1415
1416 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001417 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001418 priv->WILC_WFI_wep_key_len[key_index] = 0;
1419
1420 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1421 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1422 } else {
1423 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1424 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1425 }
1426
Leo Kimaaed3292015-10-12 16:55:38 +09001427 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001428}
1429
1430/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001431 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001432 * @details Get information about the key with the given parameters.
1433 * @mac_addr will be %NULL when requesting information for a group
1434 * key. All pointers given to the @callback function need not be valid
1435 * after it returns. This function should return an error if it is
1436 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1437 * @param[in]
1438 * @return int : Return 0 on Success
1439 * @author mdaftedar
1440 * @date 01 MAR 2012
1441 * @version 1.0
1442 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001443static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1444 bool pairwise,
1445 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446{
Chaehyun Lim27268872015-09-15 14:06:13 +09001447 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001448 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001449 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001450
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001451 priv = wiphy_priv(wiphy);
1452
1453
Alison Schofield3604af52015-10-12 13:22:44 -07001454 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001455 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1456
1457 key_params.key = priv->wilc_gtk[key_index]->key;
1458 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1459 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1460 key_params.seq = priv->wilc_gtk[key_index]->seq;
1461 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1462 if (INFO) {
1463 for (i = 0; i < key_params.key_len; i++)
1464 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1465 }
1466 } else {
1467 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1468
1469 key_params.key = priv->wilc_ptk[key_index]->key;
1470 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1471 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1472 key_params.seq = priv->wilc_ptk[key_index]->seq;
1473 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1474 }
1475
1476 callback(cookie, &key_params);
1477
Leo Kimaaed3292015-10-12 16:55:38 +09001478 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001479}
1480
1481/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001482 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001483 * @details Set the default management frame key on an interface
1484 * @param[in]
1485 * @return int : Return 0 on Success.
1486 * @author mdaftedar
1487 * @date 01 MAR 2012
1488 * @version 1.0
1489 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001490static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1491 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001492{
Chaehyun Lim27268872015-09-15 14:06:13 +09001493 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494
1495
1496 priv = wiphy_priv(wiphy);
1497
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301498 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001499
1500 if (key_index != priv->WILC_WFI_wep_default) {
1501
Chaehyun Limdf8b4832015-10-26 09:44:45 +09001502 host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001503 }
1504
Leo Kimaaed3292015-10-12 16:55:38 +09001505 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001506}
1507
1508/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001509 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001510 * @details Get station information for the station identified by @mac
1511 * @param[in] NONE
1512 * @return int : Return 0 on Success.
1513 * @author mdaftedar
1514 * @date 01 MAR 2012
1515 * @version 1.0
1516 */
1517
Chaehyun Limf06f5622015-09-14 12:24:18 +09001518static int get_station(struct wiphy *wiphy, struct net_device *dev,
1519 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001520{
Chaehyun Lim27268872015-09-15 14:06:13 +09001521 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001522 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001523 u32 i = 0;
1524 u32 associatedsta = 0;
1525 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001526 priv = wiphy_priv(wiphy);
1527 nic = netdev_priv(dev);
1528
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001529 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1530 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1531
1532 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1533
1534 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1535
1536 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1537 associatedsta = i;
1538 break;
1539 }
1540
1541 }
1542
1543 if (associatedsta == -1) {
Leo Kimaaed3292015-10-12 16:55:38 +09001544 PRINT_ER("Station required is not associated\n");
1545 return -ENOENT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001546 }
1547
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001548 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001549
1550 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1551 sinfo->inactive_time = 1000 * inactive_time;
1552 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1553
1554 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001555
1556 if (nic->iftype == STATION_MODE) {
Leo Kim03e7b9c2015-10-12 16:55:58 +09001557 struct rf_info strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001558
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001559 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1560
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301562 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001563 BIT(NL80211_STA_INFO_TX_PACKETS) |
1564 BIT(NL80211_STA_INFO_TX_FAILED) |
1565 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001566
Leo Kim00c8dfc2015-10-29 12:05:30 +09001567 sinfo->signal = strStatistics.rssi;
Leo Kim9b992742015-10-29 12:05:32 +09001568 sinfo->rx_packets = strStatistics.rx_cnt;
Leo Kim54160372015-10-29 12:05:33 +09001569 sinfo->tx_packets = strStatistics.tx_cnt + strStatistics.tx_fail_cnt;
1570 sinfo->tx_failed = strStatistics.tx_fail_cnt;
Leo Kim5babeec2015-10-29 12:05:29 +09001571 sinfo->txrate.legacy = strStatistics.link_speed * 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001572
Leo Kim5babeec2015-10-29 12:05:29 +09001573 if ((strStatistics.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH) &&
1574 (strStatistics.link_speed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001575 Enable_TCP_ACK_Filter(true);
Leo Kim5babeec2015-10-29 12:05:29 +09001576 else if (strStatistics.link_speed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001577 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001578
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001579 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1580 sinfo->tx_failed, sinfo->txrate.legacy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001581 }
Leo Kimaaed3292015-10-12 16:55:38 +09001582 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001583}
1584
1585
1586/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001587 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001588 * @details Modify parameters for a given BSS.
1589 * @param[in]
1590 * -use_cts_prot: Whether to use CTS protection
1591 * (0 = no, 1 = yes, -1 = do not change)
1592 * -use_short_preamble: Whether the use of short preambles is allowed
1593 * (0 = no, 1 = yes, -1 = do not change)
1594 * -use_short_slot_time: Whether the use of short slot time is allowed
1595 * (0 = no, 1 = yes, -1 = do not change)
1596 * -basic_rates: basic rates in IEEE 802.11 format
1597 * (or NULL for no change)
1598 * -basic_rates_len: number of basic rates
1599 * -ap_isolate: do not forward packets between connected stations
1600 * -ht_opmode: HT Operation mode
1601 * (u16 = opmode, -1 = do not change)
1602 * @return int : Return 0 on Success.
1603 * @author mdaftedar
1604 * @date 01 MAR 2012
1605 * @version 1.0
1606 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001607static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1608 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001609{
1610 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1611 return 0;
1612}
1613
1614/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001615 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001616 * @details Notify that wiphy parameters have changed;
1617 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1618 * have changed.
1619 * @return int : Return 0 on Success
1620 * @author mdaftedar
1621 * @date 01 MAR 2012
1622 * @version 1.0
1623 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001624static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001625{
Leo Kime6e12662015-09-16 18:36:03 +09001626 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001627 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001628 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001629
1630 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001631
Tony Cho87c05b22015-10-12 16:56:07 +09001632 pstrCfgParamVal.flag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301633 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001634
1635 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1636 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1637 priv->dev->ieee80211_ptr->wiphy->retry_short);
Tony Cho87c05b22015-10-12 16:56:07 +09001638 pstrCfgParamVal.flag |= RETRY_SHORT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001639 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1640 }
1641 if (changed & WIPHY_PARAM_RETRY_LONG) {
1642
1643 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 +09001644 pstrCfgParamVal.flag |= RETRY_LONG;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001645 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1646
1647 }
1648 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1649 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 +09001650 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001651 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1652
1653 }
1654
1655 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1656 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1657
Tony Cho87c05b22015-10-12 16:56:07 +09001658 pstrCfgParamVal.flag |= RTS_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001659 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1660
1661 }
1662
1663 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1664 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1665 if (s32Error)
1666 PRINT_ER("Error in setting WIPHY PARAMS\n");
1667
1668
1669 return s32Error;
1670}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001671
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001672/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001673 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001674 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1675 * devices running firmwares capable of generating the (re) association
1676 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1677 * @param[in]
1678 * @return int : Return 0 on Success
1679 * @author mdaftedar
1680 * @date 01 MAR 2012
1681 * @version 1.0
1682 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001683static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1684 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001685{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001686 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001687 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001688 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001689
Chaehyun Lim27268872015-09-15 14:06:13 +09001690 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691
1692 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1693
1694
1695 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001696 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001697 ETH_ALEN)) {
1698 /*If bssid already exists and pmkid value needs to reset*/
1699 flag = PMKID_FOUND;
1700 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1701 break;
1702 }
1703 }
1704 if (i < WILC_MAX_NUM_PMKIDS) {
1705 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001706 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001707 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001708 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001709 PMKID_LEN);
1710 if (!(flag == PMKID_FOUND))
1711 priv->pmkid_list.numpmkid++;
1712 } else {
1713 PRINT_ER("Invalid PMKID index\n");
1714 s32Error = -EINVAL;
1715 }
1716
1717 if (!s32Error) {
1718 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1719 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1720 }
1721 return s32Error;
1722}
1723
1724/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001725 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001726 * @details Delete a cached PMKID.
1727 * @param[in]
1728 * @return int : Return 0 on Success
1729 * @author mdaftedar
1730 * @date 01 MAR 2012
1731 * @version 1.0
1732 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001733static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1734 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001735{
1736
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001737 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001738 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001739
Chaehyun Lim27268872015-09-15 14:06:13 +09001740 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741
1742 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1743
1744 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001745 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001746 ETH_ALEN)) {
1747 /*If bssid is found, reset the values*/
1748 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001749 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001750 break;
1751 }
1752 }
1753
1754 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1755 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001756 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001757 priv->pmkid_list.pmkidlist[i + 1].bssid,
1758 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001759 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001760 priv->pmkid_list.pmkidlist[i].pmkid,
1761 PMKID_LEN);
1762 }
1763 priv->pmkid_list.numpmkid--;
1764 } else {
1765 s32Error = -EINVAL;
1766 }
1767
1768 return s32Error;
1769}
1770
1771/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001772 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001773 * @details Flush all cached PMKIDs.
1774 * @param[in]
1775 * @return int : Return 0 on Success
1776 * @author mdaftedar
1777 * @date 01 MAR 2012
1778 * @version 1.0
1779 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001780static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001781{
Chaehyun Lim27268872015-09-15 14:06:13 +09001782 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001783
1784 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1785
1786 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001787 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001788
1789 return 0;
1790}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001791
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001792
1793/**
1794 * @brief WILC_WFI_CfgParseRxAction
1795 * @details Function parses the received frames and modifies the following attributes:
1796 * -GO Intent
1797 * -Channel list
1798 * -Operating Channel
1799 *
1800 * @param[in] u8* Buffer, u32 length
1801 * @return NONE.
1802 * @author mdaftedar
1803 * @date 12 DEC 2012
1804 * @version
1805 */
1806
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001807void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001809 u32 index = 0;
1810 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001812 u8 op_channel_attr_index = 0;
1813 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001814
1815 while (index < len) {
1816 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001817 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001818 }
1819
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301820 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001821 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301822 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001823 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001824 index += buf[index + 1] + 3; /* ID,Length byte */
1825 }
Alison Schofield3604af52015-10-12 13:22:44 -07001826 if (u8WLANChannel != INVALID_CHANNEL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001827
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001828 /*Modify channel list attribute*/
1829 if (channel_list_attr_index) {
1830 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1831 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1832 if (buf[i] == 0x51) {
1833 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1834 buf[j] = u8WLANChannel;
1835 }
1836 break;
1837 }
1838 }
1839 }
1840 /*Modify operating channel attribute*/
1841 if (op_channel_attr_index) {
1842 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1843 buf[op_channel_attr_index + 6] = 0x51;
1844 buf[op_channel_attr_index + 7] = u8WLANChannel;
1845 }
1846 }
1847}
1848
1849/**
1850 * @brief WILC_WFI_CfgParseTxAction
1851 * @details Function parses the transmitted action frames and modifies the
1852 * GO Intent attribute
1853 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1854 * @return NONE.
1855 * @author mdaftedar
1856 * @date 12 DEC 2012
1857 * @version
1858 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001859void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001861 u32 index = 0;
1862 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001864 u8 op_channel_attr_index = 0;
1865 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001866
1867 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001868 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001869 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001870
1871 break;
1872 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001873
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301874 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001875 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301876 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001878 index += buf[index + 1] + 3; /* ID,Length byte */
1879 }
Alison Schofield3604af52015-10-12 13:22:44 -07001880 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001881
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001882 /*Modify channel list attribute*/
1883 if (channel_list_attr_index) {
1884 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1885 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1886 if (buf[i] == 0x51) {
1887 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1888 buf[j] = u8WLANChannel;
1889 }
1890 break;
1891 }
1892 }
1893 }
1894 /*Modify operating channel attribute*/
1895 if (op_channel_attr_index) {
1896 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1897 buf[op_channel_attr_index + 6] = 0x51;
1898 buf[op_channel_attr_index + 7] = u8WLANChannel;
1899 }
1900 }
1901}
1902
1903/* @brief WILC_WFI_p2p_rx
1904 * @details
1905 * @param[in]
1906 *
1907 * @return None
1908 * @author Mai Daftedar
1909 * @date 2 JUN 2013
1910 * @version 1.0
1911 */
1912
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001913void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001914{
1915
Chaehyun Lim27268872015-09-15 14:06:13 +09001916 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001917 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001918 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001919 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001920 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001921
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001922 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001923 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001924
1925 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001926 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001927
1928 /* The packet offset field conain info about what type of managment frame */
1929 /* we are dealing with and ack status */
1930 pkt_offset = GET_PKT_OFFSET(header);
1931
1932 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1933 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1934 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001935 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001936 return;
1937 } else {
1938 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1939 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],
1940 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001941 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001942 } else {
1943 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],
1944 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001945 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001946 }
1947 return;
1948 }
1949 } else {
1950
1951 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1952
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001953 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001954 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001955
1956 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1957 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1958
Leo Kim1229b1a2015-10-29 12:05:39 +09001959 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->p2p_timeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001960 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1961 return;
1962 }
1963 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1964
1965 switch (buff[ACTION_SUBTYPE_ID]) {
1966 case GAS_INTIAL_REQ:
1967 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
1968 break;
1969
1970 case GAS_INTIAL_RSP:
1971 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1972 break;
1973
1974 case PUBLIC_ACT_VENDORSPEC:
1975 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1976 * 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 +09001977 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001978 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1979 if (!bWilc_ie) {
1980 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001981 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001982 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09001983 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001984 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1985 break;
1986 }
1987 }
1988 }
1989 }
1990 if (u8P2Plocalrandom > u8P2Precvrandom) {
1991 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1992 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1993 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001994 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001995 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1996 break;
1997 }
1998 }
1999 }
2000 } else
2001 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2002 }
2003
2004
2005 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2006 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2007 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002008 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002009 return;
2010 }
2011 break;
2012
2013 default:
2014 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2015 break;
2016 }
2017 }
2018 }
2019
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002020 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002021 }
2022}
2023
2024/**
2025 * @brief WILC_WFI_mgmt_tx_complete
2026 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2027 * @param[in] priv
2028 * transmitting status
2029 * @return None
2030 * @author Amr Abdelmoghny
2031 * @date 20 MAY 2013
2032 * @version 1.0
2033 */
2034static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2035{
2036 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2037
2038
2039 kfree(pv_data->buff);
2040 kfree(pv_data);
2041}
2042
2043/**
2044 * @brief WILC_WFI_RemainOnChannelReady
2045 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2046 * @param
2047 * @return none
2048 * @author Amr abdelmoghny
2049 * @date 9 JUNE 2013
2050 * @version
2051 */
2052
2053static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2054{
Chaehyun Lim27268872015-09-15 14:06:13 +09002055 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002056
Chaehyun Lim27268872015-09-15 14:06:13 +09002057 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302059 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060
Dean Lee72ed4dc2015-06-12 14:11:44 +09002061 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002062
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002063 cfg80211_ready_on_channel(priv->wdev,
2064 priv->strRemainOnChanParams.u64ListenCookie,
2065 priv->strRemainOnChanParams.pstrListenChan,
2066 priv->strRemainOnChanParams.u32ListenDuration,
2067 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002068}
2069
2070/**
2071 * @brief WILC_WFI_RemainOnChannelExpired
2072 * @details Callback function, called on expiration of remain-on-channel duration
2073 * @param
2074 * @return none
2075 * @author Amr abdelmoghny
2076 * @date 15 MAY 2013
2077 * @version
2078 */
2079
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002080static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002081{
Chaehyun Lim27268872015-09-15 14:06:13 +09002082 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002083
Chaehyun Lim27268872015-09-15 14:06:13 +09002084 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002085
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002086 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302087 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002088
Dean Lee72ed4dc2015-06-12 14:11:44 +09002089 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002090
2091 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002092 cfg80211_remain_on_channel_expired(priv->wdev,
2093 priv->strRemainOnChanParams.u64ListenCookie,
2094 priv->strRemainOnChanParams.pstrListenChan,
2095 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002096 } else {
2097 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2098 , priv->strRemainOnChanParams.u32ListenSessionID);
2099 }
2100}
2101
2102
2103/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002104 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002105 * @details Request the driver to remain awake on the specified
2106 * channel for the specified duration to complete an off-channel
2107 * operation (e.g., public action frame exchange). When the driver is
2108 * ready on the requested channel, it must indicate this with an event
2109 * notification by calling cfg80211_ready_on_channel().
2110 * @param[in]
2111 * @return int : Return 0 on Success
2112 * @author mdaftedar
2113 * @date 01 MAR 2012
2114 * @version 1.0
2115 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002116static int remain_on_channel(struct wiphy *wiphy,
2117 struct wireless_dev *wdev,
2118 struct ieee80211_channel *chan,
2119 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002120{
Leo Kime6e12662015-09-16 18:36:03 +09002121 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002122 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002123
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002124 priv = wiphy_priv(wiphy);
2125
2126 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2127
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002128
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002129 if (wdev->iftype == NL80211_IFTYPE_AP) {
2130 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2131 return s32Error;
2132 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002133
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002134 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002135
2136 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2137 priv->strRemainOnChanParams.pstrListenChan = chan;
2138 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002139 priv->strRemainOnChanParams.u32ListenDuration = duration;
2140 priv->strRemainOnChanParams.u32ListenSessionID++;
2141
2142 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2143 , priv->strRemainOnChanParams.u32ListenSessionID
2144 , duration
2145 , chan->hw_value
2146 , WILC_WFI_RemainOnChannelExpired
2147 , WILC_WFI_RemainOnChannelReady
2148 , (void *)priv);
2149
2150 return s32Error;
2151}
2152
2153/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002154 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002155 * @details Cancel an on-going remain-on-channel operation.
2156 * This allows the operation to be terminated prior to timeout based on
2157 * the duration value.
2158 * @param[in] struct wiphy *wiphy,
2159 * @param[in] struct net_device *dev
2160 * @param[in] u64 cookie,
2161 * @return int : Return 0 on Success
2162 * @author mdaftedar
2163 * @date 01 MAR 2012
2164 * @version 1.0
2165 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002166static int cancel_remain_on_channel(struct wiphy *wiphy,
2167 struct wireless_dev *wdev,
2168 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002169{
Leo Kime6e12662015-09-16 18:36:03 +09002170 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002171 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002172
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002173 priv = wiphy_priv(wiphy);
2174
2175 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2176
2177 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2178 return s32Error;
2179}
2180/**
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002181 * @brief WILC_WFI_mgmt_tx_frame
2182 * @details
2183 *
2184 * @param[in]
2185 * @return NONE.
2186 * @author mdaftedar
2187 * @date 01 JUL 2012
2188 * @version
2189 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09002190extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002191static int mgmt_tx(struct wiphy *wiphy,
2192 struct wireless_dev *wdev,
2193 struct cfg80211_mgmt_tx_params *params,
2194 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002195{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002196 struct ieee80211_channel *chan = params->chan;
2197 unsigned int wait = params->wait;
2198 const u8 *buf = params->buf;
2199 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002200 const struct ieee80211_mgmt *mgmt;
2201 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002202 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002203 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002204 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002205 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002206 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002207
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002208 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002209 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002210 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002211
2212 *cookie = (unsigned long)buf;
2213 priv->u64tx_cookie = *cookie;
2214 mgmt = (const struct ieee80211_mgmt *) buf;
2215
2216 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2217
2218 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002219 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002220 if (mgmt_tx == NULL) {
2221 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002222 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002223 }
Glen Leef3052582015-09-10 12:03:04 +09002224 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002225 if (mgmt_tx->buff == NULL) {
2226 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002227 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002228 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002229 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002230 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002231 mgmt_tx->size = len;
2232
2233
2234 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2235 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2236 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2237 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2238 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002239 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002240 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002241 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002242
2243
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002244 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002245 /*Only set the channel, if not a negotiation confirmation frame
2246 * (If Negotiation confirmation frame, force it
2247 * to be transmitted on the same negotiation channel)*/
2248
2249 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2250 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2251 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2252 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2253 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002254 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002255 }
2256 switch (buf[ACTION_SUBTYPE_ID]) {
2257 case GAS_INTIAL_REQ:
2258 {
2259 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2260 break;
2261 }
2262
2263 case GAS_INTIAL_RSP:
2264 {
2265 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2266 break;
2267 }
2268
2269 case PUBLIC_ACT_VENDORSPEC:
2270 {
2271 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2272 * 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 +09002273 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002274 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2275 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2276 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2277 get_random_bytes(&u8P2Plocalrandom, 1);
2278 /*Increment the number to prevent if its 0*/
2279 u8P2Plocalrandom++;
2280 }
2281 }
2282
2283 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2284 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2285 if (u8P2Plocalrandom > u8P2Precvrandom) {
2286 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2287
2288 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2289 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002290 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002291 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002292 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002293
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002294 /*If using supplicant go intent, no need at all*/
2295 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002296 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002297 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002298 break;
2299 }
2300 }
2301
2302 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
Shivani Bhardwajd8060fc2015-10-29 00:30:01 +05302303 /*
2304 * Adding WILC information element to allow two WILC devices to
2305 * identify each other and connect
2306 */
2307 memcpy(&mgmt_tx->buff[len], u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002308 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2309 mgmt_tx->size = buf_len;
2310 }
2311 } else
2312 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2313 }
2314
2315 } else {
2316 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2317 }
2318
2319 break;
2320 }
2321
2322 default:
2323 {
2324 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2325 break;
2326 }
2327 }
2328
2329 }
2330
2331 PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value);
Leo Kim1229b1a2015-10-29 12:05:39 +09002332 pstrWFIDrv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002333
Leo Kim1229b1a2015-10-29 12:05:39 +09002334 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n",
2335 jiffies, pstrWFIDrv->p2p_timeout);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002336 }
2337
Glen Lee829c4772015-10-29 12:18:44 +09002338 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
2339 mgmt_tx->buff, mgmt_tx->size,
Glen Leec9d48342015-10-01 16:03:43 +09002340 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002341 } else {
2342 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2343 }
Leo Kimaaed3292015-10-12 16:55:38 +09002344 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002345}
2346
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002347static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2348 struct wireless_dev *wdev,
2349 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002350{
Chaehyun Lim27268872015-09-15 14:06:13 +09002351 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002352 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002353
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002354 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002355 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002356
2357
2358 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
Leo Kim1229b1a2015-10-29 12:05:39 +09002359 pstrWFIDrv->p2p_timeout = jiffies;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002360
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01002361 if (!priv->bInP2PlistenState) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002362 cfg80211_remain_on_channel_expired(priv->wdev,
2363 priv->strRemainOnChanParams.u64ListenCookie,
2364 priv->strRemainOnChanParams.pstrListenChan,
2365 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002366 }
2367
2368 return 0;
2369}
2370
2371/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002372 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002373 * @details Notify driver that a management frame type was
2374 * registered. Note that this callback may not sleep, and cannot run
2375 * concurrently with itself.
2376 * @param[in]
2377 * @return NONE.
2378 * @author mdaftedar
2379 * @date 01 JUL 2012
2380 * @version
2381 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002382void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2383 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002384{
2385
Chaehyun Lim27268872015-09-15 14:06:13 +09002386 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002387 perInterface_wlan_t *nic;
Glen Lee1b869352015-10-20 17:14:01 +09002388 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002389
2390 priv = wiphy_priv(wiphy);
2391 nic = netdev_priv(priv->wdev->netdev);
Glen Lee1b869352015-10-20 17:14:01 +09002392 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002393
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002394 if (!frame_type)
2395 return;
2396
2397 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2398 switch (frame_type) {
2399 case PROBE_REQ:
2400 {
2401 nic->g_struct_frame_reg[0].frame_type = frame_type;
2402 nic->g_struct_frame_reg[0].reg = reg;
2403 }
2404 break;
2405
2406 case ACTION:
2407 {
2408 nic->g_struct_frame_reg[1].frame_type = frame_type;
2409 nic->g_struct_frame_reg[1].reg = reg;
2410 }
2411 break;
2412
2413 default:
2414 {
2415 break;
2416 }
2417
2418 }
2419 /*If mac is closed, then return*/
Glen Lee1b869352015-10-20 17:14:01 +09002420 if (!wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002421 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2422 return;
2423 }
2424 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2425
2426
2427}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002428
2429/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002430 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002431 * @details Configure connection quality monitor RSSI threshold.
2432 * @param[in] struct wiphy *wiphy:
2433 * @param[in] struct net_device *dev:
2434 * @param[in] s32 rssi_thold:
2435 * @param[in] u32 rssi_hyst:
2436 * @return int : Return 0 on Success
2437 * @author mdaftedar
2438 * @date 01 MAR 2012
2439 * @version 1.0
2440 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002441static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2442 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002443{
2444 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2445 return 0;
2446
2447}
2448/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002449 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002450 * @details Configure connection quality monitor RSSI threshold.
2451 * @param[in] struct wiphy *wiphy:
2452 * @param[in] struct net_device *dev
2453 * @param[in] int idx
2454 * @param[in] u8 *mac
2455 * @param[in] struct station_info *sinfo
2456 * @return int : Return 0 on Success
2457 * @author mdaftedar
2458 * @date 01 MAR 2012
2459 * @version 1.0
2460 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002461static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2462 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002463{
Chaehyun Lim27268872015-09-15 14:06:13 +09002464 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002465
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002466 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2467
2468 if (idx != 0)
2469 return -ENOENT;
2470
2471 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002472
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002473 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002474
2475 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2476
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002477 return 0;
2478
2479}
2480
2481
2482/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002483 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002484 * @details
2485 * @param[in]
2486 * @return int : Return 0 on Success.
2487 * @author mdaftedar
2488 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002489 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002490 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002491static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2492 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002493{
Chaehyun Lim27268872015-09-15 14:06:13 +09002494 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002495
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002496 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2497
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002498 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002499 return -ENOENT;
2500
2501 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002502 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002503 PRINT_ER("Driver is NULL\n");
2504 return -EIO;
2505 }
2506
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002507 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002508 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2509
2510
Leo Kime6e12662015-09-16 18:36:03 +09002511 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002512
2513}
Glen Lee108b3432015-09-16 18:53:20 +09002514
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002515/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002516 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002517 * @details Change type/configuration of virtual interface,
2518 * keep the struct wireless_dev's iftype updated.
2519 * @param[in] NONE
2520 * @return int : Return 0 on Success.
2521 * @author mdaftedar
2522 * @date 01 MAR 2012
2523 * @version 1.0
2524 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002525int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2526
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002527static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2528 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002529{
Chaehyun Lim27268872015-09-15 14:06:13 +09002530 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002531 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002532 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002533 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002534 u8 i;
Glen Lee299382c2015-10-20 17:13:56 +09002535 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002536
2537 nic = netdev_priv(dev);
2538 priv = wiphy_priv(wiphy);
Glen Lee299382c2015-10-20 17:13:56 +09002539 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002540
2541 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2542 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2543 u8P2Plocalrandom = 0x01;
2544 u8P2Precvrandom = 0x00;
2545
Dean Lee72ed4dc2015-06-12 14:11:44 +09002546 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002547
Dean Lee72ed4dc2015-06-12 14:11:44 +09002548 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002549 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002550 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002551 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2552 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Glen Lee178c3832015-10-27 18:27:58 +09002553 Set_machw_change_vir_if(dev, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002554 }
2555
2556 switch (type) {
2557 case NL80211_IFTYPE_STATION:
2558 connecting = 0;
2559 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002560
2561 /* send delba over wlan interface */
2562
2563
2564 dev->ieee80211_ptr->iftype = type;
2565 priv->wdev->iftype = type;
2566 nic->monitor_flag = 0;
2567 nic->iftype = STATION_MODE;
2568
2569 /*Remove the enteries of the previously connected clients*/
2570 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002571 interface_type = nic->iftype;
2572 nic->iftype = STATION_MODE;
2573
Glen Lee299382c2015-10-20 17:13:56 +09002574 if (wl->initialized) {
2575 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2576 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002577 /* ensure that the message Q is empty */
2578 host_int_wait_msg_queue_idle();
2579
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002580 /*Eliminate host interface blocking state*/
Glen Lee299382c2015-10-20 17:13:56 +09002581 up(&wl->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002582
Glen Lee53dc0cf2015-10-20 17:13:57 +09002583 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002584 wilc1000_wlan_init(dev, nic);
2585 g_wilc_initialized = 1;
2586 nic->iftype = interface_type;
2587
2588 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002589 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2590 host_int_set_MacAddress(wl->vif[0].hif_drv,
2591 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002592 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2593
2594 /*Add saved WEP keys, if any*/
2595 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002596 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002597 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002598 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002599 g_key_wep_params.key,
2600 g_key_wep_params.key_len,
2601 g_key_wep_params.key_idx);
2602 }
2603
2604 /*No matter the driver handler passed here, it will be overwriiten*/
2605 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2606 host_int_flush_join_req(priv->hWILCWFIDrv);
2607
2608 /*Add saved PTK and GTK keys, if any*/
2609 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2610 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2611 g_key_ptk_params.key[1],
2612 g_key_ptk_params.key[2]);
2613 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2614 g_key_gtk_params.key[1],
2615 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002616 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2617 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002618 g_add_ptk_key_params.key_idx,
2619 g_add_ptk_key_params.pairwise,
2620 g_add_ptk_key_params.mac_addr,
2621 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002622
Glen Lee299382c2015-10-20 17:13:56 +09002623 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2624 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002625 g_add_gtk_key_params.key_idx,
2626 g_add_gtk_key_params.pairwise,
2627 g_add_gtk_key_params.mac_addr,
2628 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002629 }
2630
Glen Lee299382c2015-10-20 17:13:56 +09002631 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002632 for (i = 0; i < num_reg_frame; i++) {
2633 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2634 nic->g_struct_frame_reg[i].reg);
2635 host_int_frame_register(priv->hWILCWFIDrv,
2636 nic->g_struct_frame_reg[i].frame_type,
2637 nic->g_struct_frame_reg[i].reg);
2638 }
2639 }
2640
Dean Lee72ed4dc2015-06-12 14:11:44 +09002641 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002642 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2643 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002644 break;
2645
2646 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002647 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002648 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2649 connecting = 0;
2650 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002651
Glen Lee299382c2015-10-20 17:13:56 +09002652 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2653 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002654
2655 dev->ieee80211_ptr->iftype = type;
2656 priv->wdev->iftype = type;
2657 nic->monitor_flag = 0;
2658
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002659 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2660 nic->iftype = CLIENT_MODE;
2661
2662
Glen Lee299382c2015-10-20 17:13:56 +09002663 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002664 /* ensure that the message Q is empty */
2665 host_int_wait_msg_queue_idle();
2666
Glen Lee53dc0cf2015-10-20 17:13:57 +09002667 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002668 wilc1000_wlan_init(dev, nic);
2669 g_wilc_initialized = 1;
2670
Glen Lee299382c2015-10-20 17:13:56 +09002671 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2672 host_int_set_MacAddress(wl->vif[0].hif_drv,
2673 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002674 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2675
2676 /*Add saved WEP keys, if any*/
2677 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002678 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002679 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002680 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002681 g_key_wep_params.key,
2682 g_key_wep_params.key_len,
2683 g_key_wep_params.key_idx);
2684 }
2685
2686 /*No matter the driver handler passed here, it will be overwriiten*/
2687 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2688 host_int_flush_join_req(priv->hWILCWFIDrv);
2689
2690 /*Add saved PTK and GTK keys, if any*/
2691 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2692 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2693 g_key_ptk_params.key[1],
2694 g_key_ptk_params.key[2]);
2695 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2696 g_key_gtk_params.key[1],
2697 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002698 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2699 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002700 g_add_ptk_key_params.key_idx,
2701 g_add_ptk_key_params.pairwise,
2702 g_add_ptk_key_params.mac_addr,
2703 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002704
Glen Lee299382c2015-10-20 17:13:56 +09002705 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2706 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002707 g_add_gtk_key_params.key_idx,
2708 g_add_gtk_key_params.pairwise,
2709 g_add_gtk_key_params.mac_addr,
2710 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002711 }
2712
2713 /*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 +09002714 refresh_scan(priv, 1, true);
Glen Lee178c3832015-10-27 18:27:58 +09002715 Set_machw_change_vir_if(dev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002716
Glen Lee299382c2015-10-20 17:13:56 +09002717 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002718 for (i = 0; i < num_reg_frame; i++) {
2719 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2720 nic->g_struct_frame_reg[i].reg);
2721 host_int_frame_register(priv->hWILCWFIDrv,
2722 nic->g_struct_frame_reg[i].frame_type,
2723 nic->g_struct_frame_reg[i].reg);
2724 }
2725 }
2726 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002727 break;
2728
2729 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002730 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002731 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002732 dev->ieee80211_ptr->iftype = type;
2733 priv->wdev->iftype = type;
2734 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002735 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002736
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002737 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
Glen Lee65c8adc2015-10-29 12:18:49 +09002738 linux_wlan_get_firmware(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002739 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
Glen Lee299382c2015-10-20 17:13:56 +09002740 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002741 nic->iftype = AP_MODE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002742 mac_close(dev);
2743 mac_open(dev);
2744
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002745 for (i = 0; i < num_reg_frame; i++) {
2746 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2747 nic->g_struct_frame_reg[i].reg);
2748 host_int_frame_register(priv->hWILCWFIDrv,
2749 nic->g_struct_frame_reg[i].frame_type,
2750 nic->g_struct_frame_reg[i].reg);
2751 }
2752 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002753 break;
2754
2755 case NL80211_IFTYPE_P2P_GO:
2756 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2757
Dean Lee72ed4dc2015-06-12 14:11:44 +09002758 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002759 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002760 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002761 /*Delete block ack has to be the latest config packet*/
2762 /*sent before downloading new FW. This is because it blocks on*/
2763 /*hWaitResponse semaphore, which allows previous config*/
2764 /*packets to actually take action on old FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002765 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2766 wl->vif[0].bssid, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002767 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002768 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002769 dev->ieee80211_ptr->iftype = type;
2770 priv->wdev->iftype = type;
2771
Johnny Kim8a143302015-06-10 17:06:46 +09002772 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002773
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002774 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2775
2776
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002777 nic->iftype = GO_MODE;
2778
2779 /* ensure that the message Q is empty */
2780 host_int_wait_msg_queue_idle();
Glen Lee53dc0cf2015-10-20 17:13:57 +09002781 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002782 wilc1000_wlan_init(dev, nic);
2783 g_wilc_initialized = 1;
2784
2785
2786 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002787 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2788 host_int_set_MacAddress(wl->vif[0].hif_drv,
2789 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002790 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2791
2792 /*Add saved WEP keys, if any*/
2793 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002794 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002795 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002796 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002797 g_key_wep_params.key,
2798 g_key_wep_params.key_len,
2799 g_key_wep_params.key_idx);
2800 }
2801
2802 /*No matter the driver handler passed here, it will be overwriiten*/
2803 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2804 host_int_flush_join_req(priv->hWILCWFIDrv);
2805
2806 /*Add saved PTK and GTK keys, if any*/
2807 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2808 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2809 g_key_ptk_params.key[1],
2810 g_key_ptk_params.key[2],
2811 g_key_ptk_params.cipher);
2812 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2813 g_key_gtk_params.key[1],
2814 g_key_gtk_params.key[2],
2815 g_key_gtk_params.cipher);
Glen Lee299382c2015-10-20 17:13:56 +09002816 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2817 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002818 g_add_ptk_key_params.key_idx,
2819 g_add_ptk_key_params.pairwise,
2820 g_add_ptk_key_params.mac_addr,
2821 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002822
Glen Lee299382c2015-10-20 17:13:56 +09002823 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2824 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002825 g_add_gtk_key_params.key_idx,
2826 g_add_gtk_key_params.pairwise,
2827 g_add_gtk_key_params.mac_addr,
2828 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002829 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002830
Glen Lee299382c2015-10-20 17:13:56 +09002831 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002832 for (i = 0; i < num_reg_frame; i++) {
2833 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2834 nic->g_struct_frame_reg[i].reg);
2835 host_int_frame_register(priv->hWILCWFIDrv,
2836 nic->g_struct_frame_reg[i].frame_type,
2837 nic->g_struct_frame_reg[i].reg);
2838 }
2839 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002840 break;
2841
2842 default:
2843 PRINT_ER("Unknown interface type= %d\n", type);
Leo Kimaaed3292015-10-12 16:55:38 +09002844 return -EINVAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002845 }
2846
Leo Kimaaed3292015-10-12 16:55:38 +09002847 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002848}
2849
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002850/* (austin.2013-07-23)
2851 *
2852 * To support revised cfg80211_ops
2853 *
2854 * add_beacon --> start_ap
2855 * set_beacon --> change_beacon
2856 * del_beacon --> stop_ap
2857 *
2858 * beacon_parameters --> cfg80211_ap_settings
2859 * cfg80211_beacon_data
2860 *
2861 * applicable for linux kernel 3.4+
2862 */
2863
2864/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002865 * @brief start_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002866 * @details Add a beacon with given parameters, @head, @interval
2867 * and @dtim_period will be valid, @tail is optional.
2868 * @param[in] wiphy
2869 * @param[in] dev The net device structure
2870 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2871 * @return int : Return 0 on Success.
2872 * @author austin
2873 * @date 23 JUL 2013
2874 * @version 1.0
2875 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002876static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2877 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002878{
2879 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002880 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002881 s32 s32Error = 0;
Glen Lee684dc182015-10-20 17:14:02 +09002882 struct wilc *wl;
2883 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002884
2885 priv = wiphy_priv(wiphy);
Glen Lee684dc182015-10-20 17:14:02 +09002886 nic = netdev_priv(dev);
2887 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002888 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2889
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302890 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 +09002891 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2892
Chaehyun Lim80785a92015-09-14 12:24:01 +09002893 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002894
Leo Kime6e12662015-09-16 18:36:03 +09002895 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002896 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002897
Glen Lee684dc182015-10-20 17:14:02 +09002898 linux_wlan_set_bssid(dev, wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002899
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002900 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2901 settings->beacon_interval,
2902 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002903 beacon->head_len, (u8 *)beacon->head,
2904 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002905
2906 return s32Error;
2907}
2908
2909/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002910 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002911 * @details Add a beacon with given parameters, @head, @interval
2912 * and @dtim_period will be valid, @tail is optional.
2913 * @param[in] wiphy
2914 * @param[in] dev The net device structure
2915 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2916 * @return int : Return 0 on Success.
2917 * @author austin
2918 * @date 23 JUL 2013
2919 * @version 1.0
2920 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002921static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2922 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002923{
Chaehyun Lim27268872015-09-15 14:06:13 +09002924 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002925 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002926
2927 priv = wiphy_priv(wiphy);
2928 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2929
2930
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002931 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2932 0,
2933 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002934 beacon->head_len, (u8 *)beacon->head,
2935 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002936
2937 return s32Error;
2938}
2939
2940/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002941 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002942 * @details Remove beacon configuration and stop sending the beacon.
2943 * @param[in]
2944 * @return int : Return 0 on Success.
2945 * @author austin
2946 * @date 23 JUL 2013
2947 * @version 1.0
2948 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002949static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002950{
Leo Kime6e12662015-09-16 18:36:03 +09002951 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002952 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002953 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002954
Leo Kim7ae43362015-09-16 18:35:59 +09002955 if (!wiphy)
2956 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002957
2958 priv = wiphy_priv(wiphy);
2959
2960 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2961
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002962 linux_wlan_set_bssid(dev, NullBssid);
2963
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002964 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002965
Leo Kim7dc1d0c2015-09-16 18:36:00 +09002966 if (s32Error)
2967 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002968
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002969 return s32Error;
2970}
2971
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002972/**
Chaehyun Limed269552015-09-14 12:24:15 +09002973 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002974 * @details Add a new station.
2975 * @param[in]
2976 * @return int : Return 0 on Success.
2977 * @author mdaftedar
2978 * @date 01 MAR 2012
2979 * @version 1.0
2980 */
Chaehyun Limed269552015-09-14 12:24:15 +09002981static int add_station(struct wiphy *wiphy, struct net_device *dev,
2982 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002983{
Leo Kime6e12662015-09-16 18:36:03 +09002984 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002985 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09002986 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002987 perInterface_wlan_t *nic;
2988
Leo Kim7ae43362015-09-16 18:35:59 +09002989 if (!wiphy)
2990 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002991
2992 priv = wiphy_priv(wiphy);
2993 nic = netdev_priv(dev);
2994
2995 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09002996 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002997 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09002998 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09002999 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09003000 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003001
3002 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3003
3004 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],
3005 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003006 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003007 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3008 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003009
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003010 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003011 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003012 } else {
Leo Kim22520122015-10-29 12:05:45 +09003013 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003014 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003015 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003016 memcpy(strStaParams.ht_supp_mcs_set,
3017 &params->ht_capa->mcs,
3018 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003019 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003020 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003021 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003022 }
3023
Leo Kimf676e172015-10-29 12:05:52 +09003024 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003025 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003026
Leo Kim22520122015-10-29 12:05:45 +09003027 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3028 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003029 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3030 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003031 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3032 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003033 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3034 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003035 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3036 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003037 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3038 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003039 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3040 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003041 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3042 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003043
3044 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003045 if (s32Error)
3046 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003047 }
3048
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003049 return s32Error;
3050}
3051
3052/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003053 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003054 * @details Remove a station; @mac may be NULL to remove all stations.
3055 * @param[in]
3056 * @return int : Return 0 on Success.
3057 * @author mdaftedar
3058 * @date 01 MAR 2012
3059 * @version 1.0
3060 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003061static int del_station(struct wiphy *wiphy, struct net_device *dev,
3062 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003063{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003064 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003065 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003066 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003067 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003068
Leo Kim7ae43362015-09-16 18:35:59 +09003069 if (!wiphy)
3070 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003071
3072 priv = wiphy_priv(wiphy);
3073 nic = netdev_priv(dev);
3074
3075 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3076 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3077
3078
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003079 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303080 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003081 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3082 } else {
3083 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]);
3084 }
3085
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003086 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003087
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003088 if (s32Error)
3089 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003090 }
3091 return s32Error;
3092}
3093
3094/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003095 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003096 * @details Modify a given station.
3097 * @param[in]
3098 * @return int : Return 0 on Success.
3099 * @author mdaftedar
3100 * @date 01 MAR 2012
3101 * @version 1.0
3102 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003103static int change_station(struct wiphy *wiphy, struct net_device *dev,
3104 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003105{
Leo Kime6e12662015-09-16 18:36:03 +09003106 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003107 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003108 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003109 perInterface_wlan_t *nic;
3110
3111
3112 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3113
Leo Kim7ae43362015-09-16 18:35:59 +09003114 if (!wiphy)
3115 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003116
3117 priv = wiphy_priv(wiphy);
3118 nic = netdev_priv(dev);
3119
3120 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09003121 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09003122 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09003123 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09003124 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003125
Leo Kim2353c382015-10-29 12:05:41 +09003126 PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n",
3127 strStaParams.bssid[0], strStaParams.bssid[1],
3128 strStaParams.bssid[2], strStaParams.bssid[3],
3129 strStaParams.bssid[4], strStaParams.bssid[5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003130 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003131 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3132 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003133
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003134 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003135 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003136 } else {
Leo Kim22520122015-10-29 12:05:45 +09003137 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003138 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003139 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003140 memcpy(strStaParams.ht_supp_mcs_set,
3141 &params->ht_capa->mcs,
3142 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003143 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003144 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003145 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003146 }
3147
Leo Kimf676e172015-10-29 12:05:52 +09003148 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003149 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003150
Leo Kim22520122015-10-29 12:05:45 +09003151 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3152 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003153 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3154 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003155 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3156 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003157 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3158 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003159 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3160 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003161 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3162 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003163 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3164 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003165 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3166 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003167
3168 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003169 if (s32Error)
3170 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003171 }
3172 return s32Error;
3173}
3174
3175
3176/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003177 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003178 * @details
3179 * @param[in]
3180 * @return int : Return 0 on Success.
3181 * @author mdaftedar
3182 * @date 01 JUL 2012
3183 * @version 1.0
3184 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003185static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3186 const char *name,
3187 unsigned char name_assign_type,
3188 enum nl80211_iftype type,
3189 u32 *flags,
3190 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003191{
3192 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003193 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003194 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003195
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003196 priv = wiphy_priv(wiphy);
3197
3198
3199
3200 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3201
3202 nic = netdev_priv(priv->wdev->netdev);
3203
3204
3205 if (type == NL80211_IFTYPE_MONITOR) {
3206 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3207 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3208 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3209 if (new_ifc != NULL) {
3210 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003211 nic = netdev_priv(priv->wdev->netdev);
3212 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003213 } else
3214 PRINT_ER("Error in initializing monitor interface\n ");
3215 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003216 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003217}
3218
3219/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003220 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003221 * @details
3222 * @param[in]
3223 * @return int : Return 0 on Success.
3224 * @author mdaftedar
3225 * @date 01 JUL 2012
3226 * @version 1.0
3227 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003228static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003229{
3230 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003231 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003232}
3233
Chaehyun Lim08241922015-09-15 14:06:12 +09003234static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003235
Chaehyun Lim80785a92015-09-14 12:24:01 +09003236 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003237 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003238 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003239 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003240 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003241 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003242 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003243 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003244 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003245 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003246 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003247
Chaehyun Lima13168d2015-09-14 12:24:12 +09003248 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003249 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003250 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003251 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003252 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003253 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003254 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003255 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003256 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003257 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003258
Chaehyun Lim4d466572015-09-14 12:24:22 +09003259 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003260 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003261 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003262 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003263 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003264 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003265 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003266 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003267 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003268 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003269
3270};
3271
3272
3273
3274
3275
3276/**
3277 * @brief WILC_WFI_update_stats
3278 * @details Modify parameters for a given BSS.
3279 * @param[in]
3280 * @return int : Return 0 on Success.
3281 * @author mdaftedar
3282 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003283 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003284 */
3285int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3286{
3287
Chaehyun Lim27268872015-09-15 14:06:13 +09003288 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003289
3290 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003291 switch (changed) {
3292
3293 case WILC_WFI_RX_PKT:
3294 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003295 priv->netstats.rx_packets++;
3296 priv->netstats.rx_bytes += pktlen;
3297 priv->netstats.rx_time = get_jiffies_64();
3298 }
3299 break;
3300
3301 case WILC_WFI_TX_PKT:
3302 {
3303 priv->netstats.tx_packets++;
3304 priv->netstats.tx_bytes += pktlen;
3305 priv->netstats.tx_time = get_jiffies_64();
3306
3307 }
3308 break;
3309
3310 default:
3311 break;
3312 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003313 return 0;
3314}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003315
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003316/**
3317 * @brief WILC_WFI_CfgAlloc
3318 * @details Allocation of the wireless device structure and assigning it
3319 * to the cfg80211 operations structure.
3320 * @param[in] NONE
3321 * @return wireless_dev : Returns pointer to wireless_dev structure.
3322 * @author mdaftedar
3323 * @date 01 MAR 2012
3324 * @version 1.0
3325 */
3326struct wireless_dev *WILC_WFI_CfgAlloc(void)
3327{
3328
3329 struct wireless_dev *wdev;
3330
3331
3332 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3333 /*Allocating the wireless device structure*/
3334 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3335 if (!wdev) {
3336 PRINT_ER("Cannot allocate wireless device\n");
3337 goto _fail_;
3338 }
3339
3340 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003341 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003342 if (!wdev->wiphy) {
3343 PRINT_ER("Cannot allocate wiphy\n");
3344 goto _fail_mem_;
3345
3346 }
3347
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003348 /* enable 802.11n HT */
3349 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3350 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3351 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3352 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3353 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003354
3355 /*wiphy bands*/
3356 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3357
3358 return wdev;
3359
3360_fail_mem_:
3361 kfree(wdev);
3362_fail_:
3363 return NULL;
3364
3365}
3366/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003367 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003368 * @details Registering of the wiphy structure and interface modes
3369 * @param[in] NONE
3370 * @return NONE
3371 * @author mdaftedar
3372 * @date 01 MAR 2012
3373 * @version 1.0
3374 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003375struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003376{
Chaehyun Lim27268872015-09-15 14:06:13 +09003377 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003378 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003379 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003380
3381 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3382
3383 wdev = WILC_WFI_CfgAlloc();
3384 if (wdev == NULL) {
3385 PRINT_ER("CfgAlloc Failed\n");
3386 return NULL;
3387 }
3388
3389
3390 /*Return hardware description structure (wiphy)'s priv*/
3391 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003392 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003393
3394 /*Link the wiphy with wireless structure*/
3395 priv->wdev = wdev;
3396
3397 /*Maximum number of probed ssid to be added by user for the scan request*/
3398 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003399 /*Maximum number of pmkids to be cashed*/
3400 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3401 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003402
3403 wdev->wiphy->max_scan_ie_len = 1000;
3404
3405 /*signal strength in mBm (100*dBm) */
3406 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3407
3408 /*Set the availaible cipher suites*/
3409 wdev->wiphy->cipher_suites = cipher_suites;
3410 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003411 /*Setting default managment types: for register action frame: */
3412 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003413
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003414 wdev->wiphy->max_remain_on_channel_duration = 500;
3415 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3416 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3417 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003418 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003419 wdev->iftype = NL80211_IFTYPE_STATION;
3420
3421
3422
3423 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3424 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3425 wdev->wiphy->interface_modes, wdev->iftype);
3426
3427 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003428 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003429 #endif
3430
3431 /*Register wiphy structure*/
3432 s32Error = wiphy_register(wdev->wiphy);
3433 if (s32Error) {
3434 PRINT_ER("Cannot register wiphy device\n");
3435 /*should define what action to be taken in such failure*/
3436 } else {
3437 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3438 }
3439
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003440 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003441 return wdev;
3442
3443
3444}
3445/**
3446 * @brief WILC_WFI_WiphyFree
3447 * @details Freeing allocation of the wireless device structure
3448 * @param[in] NONE
3449 * @return NONE
3450 * @author mdaftedar
3451 * @date 01 MAR 2012
3452 * @version 1.0
3453 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003454int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003455{
3456
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003457 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003458
Chaehyun Lim27268872015-09-15 14:06:13 +09003459 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003460
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003461 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3462 priv = wdev_priv(net->ieee80211_ptr);
3463 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003464 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003465 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003466 }
3467 op_ifcs++;
3468 if (s32Error < 0) {
3469 PRINT_ER("Failed to creat refresh Timer\n");
3470 return s32Error;
3471 }
3472
Dean Lee72ed4dc2015-06-12 14:11:44 +09003473 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003474
Dean Lee72ed4dc2015-06-12 14:11:44 +09003475 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003476
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003477 sema_init(&(priv->hSemScanReq), 1);
Glen Leed53822192015-10-27 18:27:49 +09003478 s32Error = host_int_init(net, &priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003479 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003480 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003481
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003482 return s32Error;
3483}
3484
3485/**
3486 * @brief WILC_WFI_WiphyFree
3487 * @details Freeing allocation of the wireless device structure
3488 * @param[in] NONE
3489 * @return NONE
3490 * @author mdaftedar
3491 * @date 01 MAR 2012
3492 * @version 1.0
3493 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003494int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003495{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003496 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003497
Chaehyun Lim27268872015-09-15 14:06:13 +09003498 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003499
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003500 priv = wdev_priv(net->ieee80211_ptr);
3501
Dean Lee72ed4dc2015-06-12 14:11:44 +09003502 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003503
Dean Lee72ed4dc2015-06-12 14:11:44 +09003504 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003505
3506 op_ifcs--;
3507
3508 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003509
3510 /* Clear the Shadow scan */
3511 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003512 if (op_ifcs == 0) {
3513 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003514 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003515 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003516
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003517 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003518 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003519
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003520 return s32Error;
3521}
3522
3523
3524/**
3525 * @brief WILC_WFI_WiphyFree
3526 * @details Freeing allocation of the wireless device structure
3527 * @param[in] NONE
3528 * @return NONE
3529 * @author mdaftedar
3530 * @date 01 MAR 2012
3531 * @version 1.0
3532 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003533void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003534{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003535 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3536
Chaehyun Lim619837a2015-09-20 15:51:10 +09003537 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003538 PRINT_D(INIT_DBG, "net_device is NULL\n");
3539 return;
3540 }
3541
Chaehyun Lim619837a2015-09-20 15:51:10 +09003542 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003543 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3544 return;
3545 }
3546
Chaehyun Lim619837a2015-09-20 15:51:10 +09003547 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003548 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3549 return;
3550 }
3551
3552 wiphy_unregister(net->ieee80211_ptr->wiphy);
3553
3554 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3555 wiphy_free(net->ieee80211_ptr->wiphy);
3556 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003557}