blob: 5291868b70773fdf11fdfa8e75bbfa133e0c14eb [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}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900508
509/**
510 * @brief CfgConnectResult
511 * @details
512 * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either
513 * connection response or disconnection notification.
514 * tstrConnectInfo* pstrConnectInfo: COnnection information.
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900515 * u8 u8MacStatus: Mac Status from firmware
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900516 * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification
517 * void* pUserVoid: Private data associated with wireless interface
518 * @return NONE
519 * @author mabubakr
520 * @date 01 MAR 2012
521 * @version 1.0
522 */
523int connecting;
524
Leo Kimed3f0372015-10-12 16:56:01 +0900525static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900526 tstrConnectInfo *pstrConnectInfo,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900527 u8 u8MacStatus,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900528 tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
529 void *pUserVoid)
530{
Chaehyun Lim27268872015-09-15 14:06:13 +0900531 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900532 struct net_device *dev;
Leo Kim441dc602015-10-12 16:55:35 +0900533 struct host_if_drv *pstrWFIDrv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900534 u8 NullBssid[ETH_ALEN] = {0};
Glen Leec1ec2c12015-10-20 17:13:58 +0900535 struct wilc *wl;
536 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900537
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900538 connecting = 0;
539
Chaehyun Lim27268872015-09-15 14:06:13 +0900540 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541 dev = priv->dev;
Glen Leec1ec2c12015-10-20 17:13:58 +0900542 nic = netdev_priv(dev);
543 wl = nic->wilc;
Leo Kim441dc602015-10-12 16:55:35 +0900544 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545
546 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
547 /*Initialization*/
Amitoj Kaur Chawlababa7c72015-10-15 13:48:29 +0530548 u16 u16ConnectStatus;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900549
550 u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
551
552 PRINT_D(CFG80211_DBG, " Connection response received = %d\n", u8MacStatus);
553
554 if ((u8MacStatus == MAC_DISCONNECTED) &&
555 (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
556 /* The case here is that our station was waiting for association response frame and has just received it containing status code
557 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
558 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
559 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530560 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900561
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900562 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900563 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900565
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530566 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900567 }
568
569 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900570 bool bNeedScanRefresh = false;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900571 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900572
573 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
574 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900575 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900576
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577
578 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900579 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
581 unsigned long now = jiffies;
582
583 if (time_after(now,
584 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900585 bNeedScanRefresh = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586 }
587
588 break;
589 }
590 }
591
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000592 if (bNeedScanRefresh) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593 /*Also, refrsh DIRECT- results if */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900594 refresh_scan(priv, 1, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595
596 }
597
598 }
599
600
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530601 PRINT_D(CFG80211_DBG, "Association request info elements length = %zu\n", pstrConnectInfo->ReqIEsLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900602
603 PRINT_D(CFG80211_DBG, "Association response info elements length = %d\n", pstrConnectInfo->u16RespIEsLen);
604
605 cfg80211_connect_result(dev, pstrConnectInfo->au8bssid,
606 pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen,
607 pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen,
608 u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */
609 /* be replaced by pstrConnectInfo->u16ConnectStatus */
610 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
Dean Lee72ed4dc2015-06-12 14:11:44 +0900611 g_obtainingIP = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612 PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
613 pstrDisconnectNotifInfo->u16reason, priv->dev);
614 u8P2Plocalrandom = 0x01;
615 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900616 bWilc_ie = false;
Shraddha Barkebcf02652015-10-05 17:00:32 +0530617 eth_zero_addr(priv->au8AssociatedBss);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900618 linux_wlan_set_bssid(priv->dev, NullBssid);
Shraddha Barkebcf02652015-10-05 17:00:32 +0530619 eth_zero_addr(u8ConnectedSSID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900620
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900621 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kimab16ec02015-10-29 12:05:40 +0900622 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900624 /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
625 * virtual interface to station*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900626 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 pstrDisconnectNotifInfo->u16reason = 3;
628 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900629 /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
630 * to scan again and retry the connection*/
Glen Leec1ec2c12015-10-20 17:13:58 +0900631 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900632 pstrDisconnectNotifInfo->u16reason = 1;
633 }
634 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
Sudip Mukherjeee26bb712015-06-30 13:51:51 +0530635 pstrDisconnectNotifInfo->ie_len, false,
636 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900637
638 }
639
640}
641
642
643/**
Chaehyun Lim80785a92015-09-14 12:24:01 +0900644 * @brief set_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900645 * @details Set channel for a given wireless interface. Some devices
646 * may support multi-channel operation (by channel hopping) so cfg80211
647 * doesn't verify much. Note, however, that the passed netdev may be
648 * %NULL as well if the user requested changing the channel for the
649 * device itself, or for a monitor interface.
650 * @param[in]
651 * @return int : Return 0 on Success
652 * @author mdaftedar
653 * @date 01 MAR 2012
654 * @version 1.0
655 */
Chaehyun Lim80785a92015-09-14 12:24:01 +0900656static int set_channel(struct wiphy *wiphy,
657 struct cfg80211_chan_def *chandef)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900659 u32 channelnum = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +0900660 struct wilc_priv *priv;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900661 int result = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900662
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900663 priv = wiphy_priv(wiphy);
664
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900665 channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
666 PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900667
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900668 curr_channel = channelnum;
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900669 result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900670
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900671 if (result != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900672 PRINT_ER("Error in setting channel %d\n", channelnum);
673
Chaehyun Limdd739ea2015-10-02 16:41:20 +0900674 return result;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900675}
676
677/**
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900678 * @brief scan
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679 * @details Request to do a scan. If returning zero, the scan request is given
680 * the driver, and will be valid until passed to cfg80211_scan_done().
681 * For scan results, call cfg80211_inform_bss(); you can call this outside
682 * the scan/scan_done bracket too.
683 * @param[in]
684 * @return int : Return 0 on Success
685 * @author mabubakr
686 * @date 01 MAR 2012
687 * @version 1.0
688 */
689
Chaehyun Lim0e30d062015-09-14 12:24:02 +0900690static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900691{
Chaehyun Lim27268872015-09-15 14:06:13 +0900692 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900693 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +0900694 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900695 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
Leo Kim607db442015-10-05 15:25:37 +0900696 struct hidden_network strHiddenNetwork;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900697
698 priv = wiphy_priv(wiphy);
699
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900700 priv->pstrScanReq = request;
701
702 priv->u32RcvdChCount = 0;
703
Johnny Kim218dc402015-08-13 13:41:19 +0900704 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900705
706
707 reset_shadow_found(priv);
708
Dean Lee72ed4dc2015-06-12 14:11:44 +0900709 priv->bCfgScanning = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900710 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
711 /* max_scan_ssids */
712 for (i = 0; i < request->n_channels; i++) {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900713 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900714 PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]);
715 }
716
717 PRINT_D(CFG80211_DBG, "Requested num of scan channel %d\n", request->n_channels);
Sudip Mukherjee52db75202015-06-02 14:28:17 +0530718 PRINT_D(CFG80211_DBG, "Scan Request IE len = %zu\n", request->ie_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900719
720 PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids);
721
722 if (request->n_ssids >= 1) {
723
724
Leo Kim607db442015-10-05 15:25:37 +0900725 strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900726 strHiddenNetwork.u8ssidnum = request->n_ssids;
727
728
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900729 for (i = 0; i < request->n_ssids; i++) {
730
731 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
Glen Leef3052582015-09-10 12:03:04 +0900732 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900733 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900734 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
735 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530736 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900737 strHiddenNetwork.u8ssidnum -= 1;
738 }
739 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530740 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900741 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
742 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900743 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900744 CfgScanResult, (void *)priv, &strHiddenNetwork);
745 } else {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530746 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900747 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
748 au8ScanChanList, request->n_channels,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900749 (const u8 *)request->ie, request->ie_len,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900750 CfgScanResult, (void *)priv, NULL);
751 }
752
753 } else {
754 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530755 " channels\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900756 }
757
Leo Kime6e12662015-09-16 18:36:03 +0900758 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900759 s32Error = -EBUSY;
760 PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
761 }
762
763 return s32Error;
764}
765
766/**
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900767 * @brief connect
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900768 * @details Connect to the ESS with the specified parameters. When connected,
769 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
770 * If the connection fails for some reason, call cfg80211_connect_result()
771 * with the status from the AP.
772 * @param[in]
773 * @return int : Return 0 on Success
774 * @author mabubakr
775 * @date 01 MAR 2012
776 * @version 1.0
777 */
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +0900778static int connect(struct wiphy *wiphy, struct net_device *dev,
779 struct cfg80211_connect_params *sme)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900780{
Leo Kime6e12662015-09-16 18:36:03 +0900781 s32 s32Error = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900782 u32 i;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900783 u8 u8security = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +0900784 enum AUTHTYPE tenuAuth_type = ANY;
Dean Lee576917a2015-06-15 11:58:57 +0900785 char *pcgroup_encrypt_val = NULL;
786 char *pccipher_group = NULL;
787 char *pcwpa_version = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788
Chaehyun Lim27268872015-09-15 14:06:13 +0900789 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +0900790 struct host_if_drv *pstrWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900791 tstrNetworkInfo *pstrNetworkInfo = NULL;
792
793
794 connecting = 1;
795 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +0900796 pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900797
Johnny Kim218dc402015-08-13 13:41:19 +0900798 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900799
Johnny Kim8a143302015-06-10 17:06:46 +0900800 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 +0900801 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900802 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
Leo Kimab16ec02015-10-29 12:05:40 +0900803 pstrWFIDrv->p2p_connect = 1;
804 } else {
805 pstrWFIDrv->p2p_connect = 0;
806 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530807 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900808
809 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
810 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900811 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900812 sme->ssid,
813 sme->ssid_len) == 0) {
814 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
815 if (sme->bssid == NULL) {
816 /* BSSID is not passed from the user, so decision of matching
817 * is done by SSID only */
818 PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n");
819 break;
820 } else {
821 /* BSSID is also passed from the user, so decision of matching
822 * should consider also this passed BSSID */
Chaehyun Lim1a646e72015-08-07 09:02:03 +0900823 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900824 sme->bssid,
825 ETH_ALEN) == 0) {
826 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
827 break;
828 }
829 }
830 }
831 }
832
833 if (i < u32LastScannedNtwrksCountShadow) {
834 PRINT_D(CFG80211_DBG, "Required bss is in scan results\n");
835
836 pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
837
838 PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n",
839 pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1],
840 pstrNetworkInfo->au8bssid[2], pstrNetworkInfo->au8bssid[3],
841 pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]);
842 } else {
843 s32Error = -ENOENT;
844 if (u32LastScannedNtwrksCountShadow == 0)
845 PRINT_D(CFG80211_DBG, "No Scan results yet\n");
846 else
847 PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
848
849 goto done;
850 }
851
852 priv->WILC_WFI_wep_default = 0;
Chaehyun Lim2cc46832015-08-07 09:02:01 +0900853 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
854 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900855
856 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
857 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
858
859 PRINT_INFO(CFG80211_DBG, "sme->crypto.n_ciphers_pairwise=%d\n", sme->crypto.n_ciphers_pairwise);
860
861 if (INFO) {
862 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
863 PRINT_D(CORECONFIG_DBG, "sme->crypto.ciphers_pairwise[%d]=%x\n", i, sme->crypto.ciphers_pairwise[i]);
864 }
865
866 if (sme->crypto.cipher_group != NO_ENCRYPT) {
867 /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2}
868 * we will add to it the pairwise cipher suite(s) */
869 pcwpa_version = "Default";
870 PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900871 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900872 u8security = ENCRYPT_ENABLED | WEP;
873 pcgroup_encrypt_val = "WEP40";
874 pccipher_group = "WLAN_CIPHER_SUITE_WEP40";
875 PRINT_INFO(CFG80211_DBG, "WEP Default Key Idx = %d\n", sme->key_idx);
876
877 if (INFO) {
878 for (i = 0; i < sme->key_len; i++)
879 PRINT_D(CORECONFIG_DBG, "WEP Key Value[%d] = %d\n", i, sme->key[i]);
880 }
881 priv->WILC_WFI_wep_default = sme->key_idx;
882 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900883 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900884
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900885 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900886 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900887 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
888 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900889 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900890
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900891 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900892 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
893 } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894 u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
895 pcgroup_encrypt_val = "WEP104";
896 pccipher_group = "WLAN_CIPHER_SUITE_WEP104";
897
898 priv->WILC_WFI_wep_default = sme->key_idx;
899 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +0900900 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900901
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900902 g_key_wep_params.key_len = sme->key_len;
Glen Leef3052582015-09-10 12:03:04 +0900903 g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900904 memcpy(g_key_wep_params.key, sme->key, sme->key_len);
905 g_key_wep_params.key_idx = sme->key_idx;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900906 g_wep_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900907
Chaehyun Limdf8b4832015-10-26 09:44:45 +0900908 host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900909 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
910 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900911 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900912 u8security = ENCRYPT_ENABLED | WPA2 | TKIP;
913 pcgroup_encrypt_val = "WPA2_TKIP";
914 pccipher_group = "TKIP";
915 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
916 /* tenuSecurity_t = WPA2_AES; */
917 u8security = ENCRYPT_ENABLED | WPA2 | AES;
918 pcgroup_encrypt_val = "WPA2_AES";
919 pccipher_group = "AES";
920 }
921 pcwpa_version = "WPA_VERSION_2";
922 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
923 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900924 u8security = ENCRYPT_ENABLED | WPA | TKIP;
925 pcgroup_encrypt_val = "WPA_TKIP";
926 pccipher_group = "TKIP";
927 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
928 /* tenuSecurity_t = WPA_AES; */
929 u8security = ENCRYPT_ENABLED | WPA | AES;
930 pcgroup_encrypt_val = "WPA_AES";
931 pccipher_group = "AES";
932
933 }
934 pcwpa_version = "WPA_VERSION_1";
935
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900936 } else {
937 s32Error = -ENOTSUPP;
938 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
939
940 goto done;
941 }
942
943 }
944
945 /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will
946 * add to it the pairwise cipher suite(s) */
947 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
948 || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
949 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
950 if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) {
951 u8security = u8security | TKIP;
952 } else { /* TODO: mostafa: here we assume that any other encryption type is AES */
953 u8security = u8security | AES;
954 }
955 }
956 }
957
958 PRINT_D(CFG80211_DBG, "Adding key with cipher group = %x\n", sme->crypto.cipher_group);
959
960 PRINT_D(CFG80211_DBG, "Authentication Type = %d\n", sme->auth_type);
961 switch (sme->auth_type) {
962 case NL80211_AUTHTYPE_OPEN_SYSTEM:
963 PRINT_D(CFG80211_DBG, "In OPEN SYSTEM\n");
964 tenuAuth_type = OPEN_SYSTEM;
965 break;
966
967 case NL80211_AUTHTYPE_SHARED_KEY:
968 tenuAuth_type = SHARED_KEY;
969 PRINT_D(CFG80211_DBG, "In SHARED KEY\n");
970 break;
971
972 default:
973 PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type);
974 }
975
976
977 /* ai: key_mgmt: enterprise case */
978 if (sme->crypto.n_akm_suites) {
979 switch (sme->crypto.akm_suites[0]) {
980 case WLAN_AKM_SUITE_8021X:
981 tenuAuth_type = IEEE8021;
982 break;
983
984 default:
985 break;
986 }
987 }
988
989
990 PRINT_INFO(CFG80211_DBG, "Required Channel = %d\n", pstrNetworkInfo->u8channel);
991
992 PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
993 pcgroup_encrypt_val, pccipher_group, pcwpa_version);
994
Chaehyun Lim866a2c22015-10-02 16:41:21 +0900995 curr_channel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900996
Leo Kimab16ec02015-10-29 12:05:40 +0900997 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900998 u8WLANChannel = pstrNetworkInfo->u8channel;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900999
1000 linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
1001
1002 s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid,
1003 sme->ssid_len, sme->ie, sme->ie_len,
1004 CfgConnectResult, (void *)priv, u8security,
1005 tenuAuth_type, pstrNetworkInfo->u8channel,
1006 pstrNetworkInfo->pJoinParams);
Leo Kime6e12662015-09-16 18:36:03 +09001007 if (s32Error != 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301008 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001009 s32Error = -ENOENT;
1010 goto done;
1011 }
1012
1013done:
1014
1015 return s32Error;
1016}
1017
1018
1019/**
Chaehyun Limb027cde2015-09-14 12:24:04 +09001020 * @brief disconnect
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001021 * @details Disconnect from the BSS/ESS.
1022 * @param[in]
1023 * @return int : Return 0 on Success
1024 * @author mdaftedar
1025 * @date 01 MAR 2012
1026 * @version 1.0
1027 */
Chaehyun Limb027cde2015-09-14 12:24:04 +09001028static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001029{
Leo Kime6e12662015-09-16 18:36:03 +09001030 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09001031 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09001032 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001033 u8 NullBssid[ETH_ALEN] = {0};
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001034
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001035 connecting = 0;
1036 priv = wiphy_priv(wiphy);
1037
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001038 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
Leo Kim441dc602015-10-12 16:55:35 +09001039 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Leo Kimab16ec02015-10-29 12:05:40 +09001040 if (!pstrWFIDrv->p2p_connect)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001041 u8WLANChannel = INVALID_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001042 linux_wlan_set_bssid(priv->dev, NullBssid);
1043
1044 PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
1045
1046 u8P2Plocalrandom = 0x01;
1047 u8P2Precvrandom = 0x00;
Dean Lee72ed4dc2015-06-12 14:11:44 +09001048 bWilc_ie = false;
Leo Kim1229b1a2015-10-29 12:05:39 +09001049 pstrWFIDrv->p2p_timeout = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001050
1051 s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
Leo Kime6e12662015-09-16 18:36:03 +09001052 if (s32Error != 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001053 PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
1054 s32Error = -EINVAL;
1055 }
1056
1057 return s32Error;
1058}
1059
1060/**
Chaehyun Lim953d4172015-09-14 12:24:05 +09001061 * @brief add_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001062 * @details Add a key with the given parameters. @mac_addr will be %NULL
1063 * when adding a group key.
1064 * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
1065 * @return int : Return 0 on Success
1066 * @author mdaftedar
1067 * @date 01 MAR 2012
1068 * @version 1.0
1069 */
Chaehyun Lim953d4172015-09-14 12:24:05 +09001070static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1071 bool pairwise,
1072 const u8 *mac_addr, struct key_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001073
1074{
Leo Kime6e12662015-09-16 18:36:03 +09001075 s32 s32Error = 0, KeyLen = params->key_len;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001076 u32 i;
Chaehyun Lim27268872015-09-15 14:06:13 +09001077 struct wilc_priv *priv;
Arnd Bergmann057d1e92015-06-01 21:06:44 +02001078 const u8 *pu8RxMic = NULL;
1079 const u8 *pu8TxMic = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001080 u8 u8mode = NO_ENCRYPT;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001081 u8 u8gmode = NO_ENCRYPT;
1082 u8 u8pmode = NO_ENCRYPT;
Leo Kim841dfc42015-10-05 15:25:39 +09001083 enum AUTHTYPE tenuAuth_type = ANY;
Glen Lee76469202015-10-20 17:13:59 +09001084 struct wilc *wl;
1085 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001086
1087 priv = wiphy_priv(wiphy);
Glen Lee76469202015-10-20 17:13:59 +09001088 nic = netdev_priv(netdev);
1089 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001090
1091 PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
1092
Johnny Kim8a143302015-06-10 17:06:46 +09001093 PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001094
1095 PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
1096 params->key[1],
1097 params->key[2]);
1098
1099
1100 switch (params->cipher) {
1101 case WLAN_CIPHER_SUITE_WEP40:
1102 case WLAN_CIPHER_SUITE_WEP104:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001103 if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
1104
1105 priv->WILC_WFI_wep_default = key_index;
1106 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001107 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001108
1109 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1110 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
1111
1112 for (i = 0; i < params->key_len; i++)
1113 PRINT_D(CFG80211_DBG, "WEP AP key val[%d] = %x\n", i, params->key[i]);
1114
1115 tenuAuth_type = OPEN_SYSTEM;
1116
1117 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
1118 u8mode = ENCRYPT_ENABLED | WEP;
1119 else
1120 u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
1121
1122 host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
1123 break;
1124 }
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001125 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001126 priv->WILC_WFI_wep_default = key_index;
1127 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001128 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001129
1130 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1131 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
1132 if (INFO) {
1133 for (i = 0; i < params->key_len; i++)
1134 PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]);
1135 }
1136 host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index);
1137 }
1138
1139 break;
1140
1141 case WLAN_CIPHER_SUITE_TKIP:
1142 case WLAN_CIPHER_SUITE_CCMP:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001143 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1144
1145 if (priv->wilc_gtk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001146 priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001147 priv->wilc_gtk[key_index]->key = NULL;
1148 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001149
1150 }
1151 if (priv->wilc_ptk[key_index] == NULL) {
Glen Leef3052582015-09-10 12:03:04 +09001152 priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001153 priv->wilc_ptk[key_index]->key = NULL;
1154 priv->wilc_ptk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001155 }
1156
1157
1158
Daniel Machon19132212015-08-05 08:18:31 +02001159 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001160 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1161 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1162 else
1163 u8gmode = ENCRYPT_ENABLED | WPA2 | AES;
1164
1165 priv->wilc_groupkey = u8gmode;
1166
1167 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1168
1169 pu8TxMic = params->key + 24;
1170 pu8RxMic = params->key + 16;
1171 KeyLen = params->key_len - 16;
1172 }
1173 /* 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 +05301174 kfree(priv->wilc_gtk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001175
Glen Leef3052582015-09-10 12:03:04 +09001176 priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001177 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001178
1179 /* 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 +05301180 kfree(priv->wilc_gtk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001181
1182 if ((params->seq_len) > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001183 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001184 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001185 }
1186
1187 priv->wilc_gtk[key_index]->cipher = params->cipher;
1188 priv->wilc_gtk[key_index]->key_len = params->key_len;
1189 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
1190
1191 if (INFO) {
1192 for (i = 0; i < params->key_len; i++)
1193 PRINT_INFO(CFG80211_DBG, "Adding group key value[%d] = %x\n", i, params->key[i]);
1194 for (i = 0; i < params->seq_len; i++)
1195 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1196 }
1197
1198
1199 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1200 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode);
1201
1202 } else {
1203 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]);
1204
1205 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1206 u8pmode = ENCRYPT_ENABLED | WPA | TKIP;
1207 else
1208 u8pmode = priv->wilc_groupkey | AES;
1209
1210
1211 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1212
1213 pu8TxMic = params->key + 24;
1214 pu8RxMic = params->key + 16;
1215 KeyLen = params->key_len - 16;
1216 }
1217
Shraddha Barkecccfc392015-10-12 20:49:19 +05301218 kfree(priv->wilc_ptk[key_index]->key);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001219
Glen Leef3052582015-09-10 12:03:04 +09001220 priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001221
Shraddha Barkecccfc392015-10-12 20:49:19 +05301222 kfree(priv->wilc_ptk[key_index]->seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223
1224 if ((params->seq_len) > 0)
Glen Leef3052582015-09-10 12:03:04 +09001225 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001226
1227 if (INFO) {
1228 for (i = 0; i < params->key_len; i++)
1229 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %x\n", i, params->key[i]);
1230
1231 for (i = 0; i < params->seq_len; i++)
1232 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1233 }
1234
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001235 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001236
1237 if ((params->seq_len) > 0)
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001238 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001239
1240 priv->wilc_ptk[key_index]->cipher = params->cipher;
1241 priv->wilc_ptk[key_index]->key_len = params->key_len;
1242 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
1243
1244 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1245 pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index);
1246 }
1247 break;
1248 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001249
1250 {
1251 u8mode = 0;
Daniel Machon19132212015-08-05 08:18:31 +02001252 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001253 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1254 /* swap the tx mic by rx mic */
1255 pu8RxMic = params->key + 24;
1256 pu8TxMic = params->key + 16;
1257 KeyLen = params->key_len - 16;
1258 }
1259
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001260 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001261 if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001262 g_add_gtk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001263 g_add_gtk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 if (!mac_addr) {
1265 g_add_gtk_key_params.mac_addr = NULL;
1266 } else {
Glen Leef3052582015-09-10 12:03:04 +09001267 g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001268 memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
1269 }
1270 g_key_gtk_params.key_len = params->key_len;
1271 g_key_gtk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001272 g_key_gtk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001273 memcpy(g_key_gtk_params.key, params->key, params->key_len);
1274 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001275 g_key_gtk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001276 memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
1277 }
1278 g_key_gtk_params.cipher = params->cipher;
1279
1280 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_gtk_params.key[0],
1281 g_key_gtk_params.key[1],
1282 g_key_gtk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001283 g_gtk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001284 }
1285
1286 host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen,
1287 key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001288 } else {
1289 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1290 /* swap the tx mic by rx mic */
1291 pu8RxMic = params->key + 24;
1292 pu8TxMic = params->key + 16;
1293 KeyLen = params->key_len - 16;
1294 }
1295
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001296 /*save keys only on interface 0 (wifi interface)*/
Glen Lee76469202015-10-20 17:13:59 +09001297 if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001298 g_add_ptk_key_params.key_idx = key_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001299 g_add_ptk_key_params.pairwise = pairwise;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001300 if (!mac_addr) {
1301 g_add_ptk_key_params.mac_addr = NULL;
1302 } else {
Glen Leef3052582015-09-10 12:03:04 +09001303 g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
1305 }
1306 g_key_ptk_params.key_len = params->key_len;
1307 g_key_ptk_params.seq_len = params->seq_len;
Glen Leef3052582015-09-10 12:03:04 +09001308 g_key_ptk_params.key = kmalloc(params->key_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001309 memcpy(g_key_ptk_params.key, params->key, params->key_len);
1310 if (params->seq_len > 0) {
Glen Leef3052582015-09-10 12:03:04 +09001311 g_key_ptk_params.seq = kmalloc(params->seq_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001312 memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
1313 }
1314 g_key_ptk_params.cipher = params->cipher;
1315
1316 PRINT_D(CFG80211_DBG, "key %x %x %x\n", g_key_ptk_params.key[0],
1317 g_key_ptk_params.key[1],
1318 g_key_ptk_params.key[2]);
Dean Lee72ed4dc2015-06-12 14:11:44 +09001319 g_ptk_keys_saved = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001320 }
1321
1322 host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr,
1323 pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index);
1324 PRINT_D(CFG80211_DBG, "Adding pairwise key\n");
1325 if (INFO) {
1326 for (i = 0; i < params->key_len; i++)
1327 PRINT_INFO(CFG80211_DBG, "Adding pairwise key value[%d] = %d\n", i, params->key[i]);
1328 }
1329 }
1330 }
1331 break;
1332
1333 default:
1334 PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
1335 s32Error = -ENOTSUPP;
1336
1337 }
1338
1339 return s32Error;
1340}
1341
1342/**
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001343 * @brief del_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001344 * @details Remove a key given the @mac_addr (%NULL for a group key)
1345 * and @key_index, return -ENOENT if the key doesn't exist.
1346 * @param[in]
1347 * @return int : Return 0 on Success
1348 * @author mdaftedar
1349 * @date 01 MAR 2012
1350 * @version 1.0
1351 */
Chaehyun Lim3044ba72015-09-14 12:24:06 +09001352static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1353 u8 key_index,
1354 bool pairwise,
1355 const u8 *mac_addr)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001356{
Chaehyun Lim27268872015-09-15 14:06:13 +09001357 struct wilc_priv *priv;
Glen Lee692e2ac2015-10-20 17:14:00 +09001358 struct wilc *wl;
1359 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001360
1361 priv = wiphy_priv(wiphy);
Glen Lee692e2ac2015-10-20 17:14:00 +09001362 nic = netdev_priv(netdev);
1363 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001365 /*delete saved keys, if any*/
Glen Lee692e2ac2015-10-20 17:14:00 +09001366 if (netdev == wl->vif[0].ndev) {
Dean Lee72ed4dc2015-06-12 14:11:44 +09001367 g_ptk_keys_saved = false;
1368 g_gtk_keys_saved = false;
1369 g_wep_keys_saved = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001370
1371 /*Delete saved WEP keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301372 kfree(g_key_wep_params.key);
1373 g_key_wep_params.key = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374
1375 /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
1376
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001377 if ((priv->wilc_gtk[key_index]) != NULL) {
1378
Shraddha Barkecccfc392015-10-12 20:49:19 +05301379 kfree(priv->wilc_gtk[key_index]->key);
1380 priv->wilc_gtk[key_index]->key = NULL;
1381 kfree(priv->wilc_gtk[key_index]->seq);
1382 priv->wilc_gtk[key_index]->seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001383
Chaehyun Lim49188af2015-08-11 10:32:41 +09001384 kfree(priv->wilc_gtk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001385 priv->wilc_gtk[key_index] = NULL;
1386
1387 }
1388
1389 if ((priv->wilc_ptk[key_index]) != NULL) {
1390
Shraddha Barkecccfc392015-10-12 20:49:19 +05301391 kfree(priv->wilc_ptk[key_index]->key);
1392 priv->wilc_ptk[key_index]->key = NULL;
1393 kfree(priv->wilc_ptk[key_index]->seq);
1394 priv->wilc_ptk[key_index]->seq = NULL;
Chaehyun Lim49188af2015-08-11 10:32:41 +09001395 kfree(priv->wilc_ptk[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001396 priv->wilc_ptk[key_index] = NULL;
1397 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001398
1399 /*Delete saved PTK and GTK keys params, if any*/
Shraddha Barkecccfc392015-10-12 20:49:19 +05301400 kfree(g_key_ptk_params.key);
1401 g_key_ptk_params.key = NULL;
1402 kfree(g_key_ptk_params.seq);
1403 g_key_ptk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001404
Shraddha Barkecccfc392015-10-12 20:49:19 +05301405 kfree(g_key_gtk_params.key);
1406 g_key_gtk_params.key = NULL;
1407 kfree(g_key_gtk_params.seq);
1408 g_key_gtk_params.seq = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409
1410 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Leo Kim2ad8c472015-11-05 14:36:35 +09001411 set_machw_change_vir_if(netdev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412 }
1413
1414 if (key_index >= 0 && key_index <= 3) {
Chaehyun Lim2cc46832015-08-07 09:02:01 +09001415 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001416 priv->WILC_WFI_wep_key_len[key_index] = 0;
1417
1418 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
1419 host_int_remove_wep_key(priv->hWILCWFIDrv, key_index);
1420 } else {
1421 PRINT_D(CFG80211_DBG, "Removing all installed keys\n");
1422 host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
1423 }
1424
Leo Kimaaed3292015-10-12 16:55:38 +09001425 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001426}
1427
1428/**
Chaehyun Limf4893df2015-09-14 12:24:07 +09001429 * @brief get_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001430 * @details Get information about the key with the given parameters.
1431 * @mac_addr will be %NULL when requesting information for a group
1432 * key. All pointers given to the @callback function need not be valid
1433 * after it returns. This function should return an error if it is
1434 * not possible to retrieve the key, -ENOENT if it doesn't exist.
1435 * @param[in]
1436 * @return int : Return 0 on Success
1437 * @author mdaftedar
1438 * @date 01 MAR 2012
1439 * @version 1.0
1440 */
Chaehyun Limf4893df2015-09-14 12:24:07 +09001441static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1442 bool pairwise,
1443 const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001444{
Chaehyun Lim27268872015-09-15 14:06:13 +09001445 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446 struct key_params key_params;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001447 u32 i;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001448
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001449 priv = wiphy_priv(wiphy);
1450
1451
Alison Schofield3604af52015-10-12 13:22:44 -07001452 if (!pairwise) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001453 PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
1454
1455 key_params.key = priv->wilc_gtk[key_index]->key;
1456 key_params.cipher = priv->wilc_gtk[key_index]->cipher;
1457 key_params.key_len = priv->wilc_gtk[key_index]->key_len;
1458 key_params.seq = priv->wilc_gtk[key_index]->seq;
1459 key_params.seq_len = priv->wilc_gtk[key_index]->seq_len;
1460 if (INFO) {
1461 for (i = 0; i < key_params.key_len; i++)
1462 PRINT_INFO(CFG80211_DBG, "Retrieved key value %x\n", key_params.key[i]);
1463 }
1464 } else {
1465 PRINT_D(CFG80211_DBG, "Getting pairwise key\n");
1466
1467 key_params.key = priv->wilc_ptk[key_index]->key;
1468 key_params.cipher = priv->wilc_ptk[key_index]->cipher;
1469 key_params.key_len = priv->wilc_ptk[key_index]->key_len;
1470 key_params.seq = priv->wilc_ptk[key_index]->seq;
1471 key_params.seq_len = priv->wilc_ptk[key_index]->seq_len;
1472 }
1473
1474 callback(cookie, &key_params);
1475
Leo Kimaaed3292015-10-12 16:55:38 +09001476 return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001477}
1478
1479/**
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001480 * @brief set_default_key
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001481 * @details Set the default management frame key on an interface
1482 * @param[in]
1483 * @return int : Return 0 on Success.
1484 * @author mdaftedar
1485 * @date 01 MAR 2012
1486 * @version 1.0
1487 */
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09001488static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1489 bool unicast, bool multicast)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001490{
Chaehyun Lim27268872015-09-15 14:06:13 +09001491 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001492
1493
1494 priv = wiphy_priv(wiphy);
1495
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301496 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001497
1498 if (key_index != priv->WILC_WFI_wep_default) {
1499
Chaehyun Limdf8b4832015-10-26 09:44:45 +09001500 host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001501 }
1502
Leo Kimaaed3292015-10-12 16:55:38 +09001503 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001504}
1505
1506/**
Chaehyun Limf06f5622015-09-14 12:24:18 +09001507 * @brief get_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001508 * @details Get station information for the station identified by @mac
1509 * @param[in] NONE
1510 * @return int : Return 0 on Success.
1511 * @author mdaftedar
1512 * @date 01 MAR 2012
1513 * @version 1.0
1514 */
1515
Chaehyun Limf06f5622015-09-14 12:24:18 +09001516static int get_station(struct wiphy *wiphy, struct net_device *dev,
1517 const u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001518{
Chaehyun Lim27268872015-09-15 14:06:13 +09001519 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001520 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001521 u32 i = 0;
1522 u32 associatedsta = 0;
1523 u32 inactive_time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524 priv = wiphy_priv(wiphy);
1525 nic = netdev_priv(dev);
1526
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001527 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
1528 PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
1529
1530 PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]);
1531
1532 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1533
1534 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) {
1535 associatedsta = i;
1536 break;
1537 }
1538
1539 }
1540
1541 if (associatedsta == -1) {
Leo Kimaaed3292015-10-12 16:55:38 +09001542 PRINT_ER("Station required is not associated\n");
1543 return -ENOENT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001544 }
1545
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001546 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001547
1548 host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time));
1549 sinfo->inactive_time = 1000 * inactive_time;
1550 PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
1551
1552 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001553
1554 if (nic->iftype == STATION_MODE) {
Leo Kim03e7b9c2015-10-12 16:55:58 +09001555 struct rf_info strStatistics;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001556
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001557 host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
1558
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001559 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
Chandra S Gorentla62129902015-08-05 22:11:57 +05301560 BIT(NL80211_STA_INFO_RX_PACKETS) |
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561 BIT(NL80211_STA_INFO_TX_PACKETS) |
1562 BIT(NL80211_STA_INFO_TX_FAILED) |
1563 BIT(NL80211_STA_INFO_TX_BITRATE);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001564
Leo Kim00c8dfc2015-10-29 12:05:30 +09001565 sinfo->signal = strStatistics.rssi;
Leo Kim9b992742015-10-29 12:05:32 +09001566 sinfo->rx_packets = strStatistics.rx_cnt;
Leo Kim54160372015-10-29 12:05:33 +09001567 sinfo->tx_packets = strStatistics.tx_cnt + strStatistics.tx_fail_cnt;
1568 sinfo->tx_failed = strStatistics.tx_fail_cnt;
Leo Kim5babeec2015-10-29 12:05:29 +09001569 sinfo->txrate.legacy = strStatistics.link_speed * 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001570
Leo Kim5babeec2015-10-29 12:05:29 +09001571 if ((strStatistics.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH) &&
1572 (strStatistics.link_speed != DEFAULT_LINK_SPEED))
Dean Lee72ed4dc2015-06-12 14:11:44 +09001573 Enable_TCP_ACK_Filter(true);
Leo Kim5babeec2015-10-29 12:05:29 +09001574 else if (strStatistics.link_speed != DEFAULT_LINK_SPEED)
Dean Lee72ed4dc2015-06-12 14:11:44 +09001575 Enable_TCP_ACK_Filter(false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001576
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001577 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
1578 sinfo->tx_failed, sinfo->txrate.legacy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001579 }
Leo Kimaaed3292015-10-12 16:55:38 +09001580 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001581}
1582
1583
1584/**
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001585 * @brief change_bss
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001586 * @details Modify parameters for a given BSS.
1587 * @param[in]
1588 * -use_cts_prot: Whether to use CTS protection
1589 * (0 = no, 1 = yes, -1 = do not change)
1590 * -use_short_preamble: Whether the use of short preambles is allowed
1591 * (0 = no, 1 = yes, -1 = do not change)
1592 * -use_short_slot_time: Whether the use of short slot time is allowed
1593 * (0 = no, 1 = yes, -1 = do not change)
1594 * -basic_rates: basic rates in IEEE 802.11 format
1595 * (or NULL for no change)
1596 * -basic_rates_len: number of basic rates
1597 * -ap_isolate: do not forward packets between connected stations
1598 * -ht_opmode: HT Operation mode
1599 * (u16 = opmode, -1 = do not change)
1600 * @return int : Return 0 on Success.
1601 * @author mdaftedar
1602 * @date 01 MAR 2012
1603 * @version 1.0
1604 */
Chaehyun Lima5f7db62015-09-14 12:24:20 +09001605static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1606 struct bss_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001607{
1608 PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
1609 return 0;
1610}
1611
1612/**
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001613 * @brief set_wiphy_params
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001614 * @details Notify that wiphy parameters have changed;
1615 * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values
1616 * have changed.
1617 * @return int : Return 0 on Success
1618 * @author mdaftedar
1619 * @date 01 MAR 2012
1620 * @version 1.0
1621 */
Chaehyun Lima76b63e2015-09-14 12:24:21 +09001622static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001623{
Leo Kime6e12662015-09-16 18:36:03 +09001624 s32 s32Error = 0;
Leo Kim95296502015-10-05 15:25:46 +09001625 struct cfg_param_val pstrCfgParamVal;
Chaehyun Lim27268872015-09-15 14:06:13 +09001626 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001627
1628 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001629
Tony Cho87c05b22015-10-12 16:56:07 +09001630 pstrCfgParamVal.flag = 0;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301631 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001632
1633 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1634 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
1635 priv->dev->ieee80211_ptr->wiphy->retry_short);
Tony Cho87c05b22015-10-12 16:56:07 +09001636 pstrCfgParamVal.flag |= RETRY_SHORT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001637 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1638 }
1639 if (changed & WIPHY_PARAM_RETRY_LONG) {
1640
1641 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 +09001642 pstrCfgParamVal.flag |= RETRY_LONG;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001643 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1644
1645 }
1646 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1647 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 +09001648 pstrCfgParamVal.flag |= FRAG_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001649 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1650
1651 }
1652
1653 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1654 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
1655
Tony Cho87c05b22015-10-12 16:56:07 +09001656 pstrCfgParamVal.flag |= RTS_THRESHOLD;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001657 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1658
1659 }
1660
1661 PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n");
1662 s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal);
1663 if (s32Error)
1664 PRINT_ER("Error in setting WIPHY PARAMS\n");
1665
1666
1667 return s32Error;
1668}
Arnd Bergmanne5af0562015-05-29 22:52:12 +02001669
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001670/**
Chaehyun Lim4d466572015-09-14 12:24:22 +09001671 * @brief set_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001672 * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac
1673 * devices running firmwares capable of generating the (re) association
1674 * RSN IE. It allows for faster roaming between WPA2 BSSIDs.
1675 * @param[in]
1676 * @return int : Return 0 on Success
1677 * @author mdaftedar
1678 * @date 01 MAR 2012
1679 * @version 1.0
1680 */
Chaehyun Lim4d466572015-09-14 12:24:22 +09001681static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1682 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001683{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001684 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001685 s32 s32Error = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001686 u8 flag = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001687
Chaehyun Lim27268872015-09-15 14:06:13 +09001688 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001689
1690 PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
1691
1692
1693 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001694 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001695 ETH_ALEN)) {
1696 /*If bssid already exists and pmkid value needs to reset*/
1697 flag = PMKID_FOUND;
1698 PRINT_D(CFG80211_DBG, "PMKID already exists\n");
1699 break;
1700 }
1701 }
1702 if (i < WILC_MAX_NUM_PMKIDS) {
1703 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001704 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001705 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001706 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001707 PMKID_LEN);
1708 if (!(flag == PMKID_FOUND))
1709 priv->pmkid_list.numpmkid++;
1710 } else {
1711 PRINT_ER("Invalid PMKID index\n");
1712 s32Error = -EINVAL;
1713 }
1714
1715 if (!s32Error) {
1716 PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n");
1717 s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
1718 }
1719 return s32Error;
1720}
1721
1722/**
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001723 * @brief del_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001724 * @details Delete a cached PMKID.
1725 * @param[in]
1726 * @return int : Return 0 on Success
1727 * @author mdaftedar
1728 * @date 01 MAR 2012
1729 * @version 1.0
1730 */
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09001731static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1732 struct cfg80211_pmksa *pmksa)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001733{
1734
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001735 u32 i;
Leo Kime6e12662015-09-16 18:36:03 +09001736 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001737
Chaehyun Lim27268872015-09-15 14:06:13 +09001738 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001739
1740 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1741
1742 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001743 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001744 ETH_ALEN)) {
1745 /*If bssid is found, reset the values*/
1746 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
Leo Kimcd1e6cb2015-10-05 15:25:45 +09001747 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001748 break;
1749 }
1750 }
1751
1752 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1753 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001754 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001755 priv->pmkid_list.pmkidlist[i + 1].bssid,
1756 ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001757 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001758 priv->pmkid_list.pmkidlist[i].pmkid,
1759 PMKID_LEN);
1760 }
1761 priv->pmkid_list.numpmkid--;
1762 } else {
1763 s32Error = -EINVAL;
1764 }
1765
1766 return s32Error;
1767}
1768
1769/**
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001770 * @brief flush_pmksa
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001771 * @details Flush all cached PMKIDs.
1772 * @param[in]
1773 * @return int : Return 0 on Success
1774 * @author mdaftedar
1775 * @date 01 MAR 2012
1776 * @version 1.0
1777 */
Chaehyun Limb33c39b2015-09-14 12:24:24 +09001778static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001779{
Chaehyun Lim27268872015-09-15 14:06:13 +09001780 struct wilc_priv *priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001781
1782 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
1783
1784 /*Get cashed Pmkids and set all with zeros*/
Leo Kima949f902015-10-05 15:25:44 +09001785 memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001786
1787 return 0;
1788}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001789
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001790
1791/**
1792 * @brief WILC_WFI_CfgParseRxAction
1793 * @details Function parses the received frames and modifies the following attributes:
1794 * -GO Intent
1795 * -Channel list
1796 * -Operating Channel
1797 *
1798 * @param[in] u8* Buffer, u32 length
1799 * @return NONE.
1800 * @author mdaftedar
1801 * @date 12 DEC 2012
1802 * @version
1803 */
1804
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001805void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001806{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001807 u32 index = 0;
1808 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001809
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001810 u8 op_channel_attr_index = 0;
1811 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001812
1813 while (index < len) {
1814 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001815 buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001816 }
1817
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301818 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001819 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301820 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001821 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001822 index += buf[index + 1] + 3; /* ID,Length byte */
1823 }
Alison Schofield3604af52015-10-12 13:22:44 -07001824 if (u8WLANChannel != INVALID_CHANNEL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001825
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001826 /*Modify channel list attribute*/
1827 if (channel_list_attr_index) {
1828 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1829 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1830 if (buf[i] == 0x51) {
1831 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1832 buf[j] = u8WLANChannel;
1833 }
1834 break;
1835 }
1836 }
1837 }
1838 /*Modify operating channel attribute*/
1839 if (op_channel_attr_index) {
1840 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1841 buf[op_channel_attr_index + 6] = 0x51;
1842 buf[op_channel_attr_index + 7] = u8WLANChannel;
1843 }
1844 }
1845}
1846
1847/**
1848 * @brief WILC_WFI_CfgParseTxAction
1849 * @details Function parses the transmitted action frames and modifies the
1850 * GO Intent attribute
1851 * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype
1852 * @return NONE.
1853 * @author mdaftedar
1854 * @date 12 DEC 2012
1855 * @version
1856 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001857void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001858{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001859 u32 index = 0;
1860 u32 i = 0, j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001861
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09001862 u8 op_channel_attr_index = 0;
1863 u8 channel_list_attr_index = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001864
1865 while (index < len) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001866 if (buf[index] == GO_INTENT_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001867 buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001868
1869 break;
1870 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001871
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301872 if (buf[index] == CHANLIST_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001873 channel_list_attr_index = index;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301874 else if (buf[index] == OPERCHAN_ATTR_ID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001875 op_channel_attr_index = index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001876 index += buf[index + 1] + 3; /* ID,Length byte */
1877 }
Alison Schofield3604af52015-10-12 13:22:44 -07001878 if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001879
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001880 /*Modify channel list attribute*/
1881 if (channel_list_attr_index) {
1882 PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
1883 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1884 if (buf[i] == 0x51) {
1885 for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) {
1886 buf[j] = u8WLANChannel;
1887 }
1888 break;
1889 }
1890 }
1891 }
1892 /*Modify operating channel attribute*/
1893 if (op_channel_attr_index) {
1894 PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n");
1895 buf[op_channel_attr_index + 6] = 0x51;
1896 buf[op_channel_attr_index + 7] = u8WLANChannel;
1897 }
1898 }
1899}
1900
1901/* @brief WILC_WFI_p2p_rx
1902 * @details
1903 * @param[in]
1904 *
1905 * @return None
1906 * @author Mai Daftedar
1907 * @date 2 JUN 2013
1908 * @version 1.0
1909 */
1910
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001911void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001912{
1913
Chaehyun Lim27268872015-09-15 14:06:13 +09001914 struct wilc_priv *priv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001915 u32 header, pkt_offset;
Leo Kim441dc602015-10-12 16:55:35 +09001916 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001917 u32 i = 0;
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +09001918 s32 s32Freq;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001919
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001920 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09001921 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001922
1923 /* Get WILC header */
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09001924 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001925
1926 /* The packet offset field conain info about what type of managment frame */
1927 /* we are dealing with and ack status */
1928 pkt_offset = GET_PKT_OFFSET(header);
1929
1930 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1931 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1932 PRINT_D(GENERIC_DBG, "Probe response ACK\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001933 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001934 return;
1935 } else {
1936 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
1937 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],
1938 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001939 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001940 } else {
1941 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],
1942 buff[ACTION_SUBTYPE_ID + 1], buff[P2P_PUB_ACTION_SUBTYPE + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001943 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001944 }
1945 return;
1946 }
1947 } else {
1948
1949 PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
1950
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001951 /*Upper layer is informed that the frame is received on this freq*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09001952 s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001953
1954 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1955 PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
1956
Leo Kim1229b1a2015-10-29 12:05:39 +09001957 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->p2p_timeout)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001958 PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
1959 return;
1960 }
1961 if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
1962
1963 switch (buff[ACTION_SUBTYPE_ID]) {
1964 case GAS_INTIAL_REQ:
1965 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]);
1966 break;
1967
1968 case GAS_INTIAL_RSP:
1969 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buff[ACTION_SUBTYPE_ID]);
1970 break;
1971
1972 case PUBLIC_ACT_VENDORSPEC:
1973 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
1974 * 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 +09001975 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001976 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
1977 if (!bWilc_ie) {
1978 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001979 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001980 u8P2Precvrandom = buff[i + 6];
Dean Lee72ed4dc2015-06-12 14:11:44 +09001981 bWilc_ie = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001982 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
1983 break;
1984 }
1985 }
1986 }
1987 }
1988 if (u8P2Plocalrandom > u8P2Precvrandom) {
1989 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
1990 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1991 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09001992 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001993 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
1994 break;
1995 }
1996 }
1997 }
1998 } else
1999 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2000 }
2001
2002
2003 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) {
2004 PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n");
2005 /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002006 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002007 return;
2008 }
2009 break;
2010
2011 default:
2012 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buff[ACTION_SUBTYPE_ID]);
2013 break;
2014 }
2015 }
2016 }
2017
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002018 cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002019 }
2020}
2021
2022/**
2023 * @brief WILC_WFI_mgmt_tx_complete
2024 * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here)
2025 * @param[in] priv
2026 * transmitting status
2027 * @return None
2028 * @author Amr Abdelmoghny
2029 * @date 20 MAY 2013
2030 * @version 1.0
2031 */
2032static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
2033{
2034 struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv;
2035
2036
2037 kfree(pv_data->buff);
2038 kfree(pv_data);
2039}
2040
2041/**
2042 * @brief WILC_WFI_RemainOnChannelReady
2043 * @details Callback function, called from handle_remain_on_channel on being ready on channel
2044 * @param
2045 * @return none
2046 * @author Amr abdelmoghny
2047 * @date 9 JUNE 2013
2048 * @version
2049 */
2050
2051static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2052{
Chaehyun Lim27268872015-09-15 14:06:13 +09002053 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002054
Chaehyun Lim27268872015-09-15 14:06:13 +09002055 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302057 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058
Dean Lee72ed4dc2015-06-12 14:11:44 +09002059 priv->bInP2PlistenState = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002061 cfg80211_ready_on_channel(priv->wdev,
2062 priv->strRemainOnChanParams.u64ListenCookie,
2063 priv->strRemainOnChanParams.pstrListenChan,
2064 priv->strRemainOnChanParams.u32ListenDuration,
2065 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002066}
2067
2068/**
2069 * @brief WILC_WFI_RemainOnChannelExpired
2070 * @details Callback function, called on expiration of remain-on-channel duration
2071 * @param
2072 * @return none
2073 * @author Amr abdelmoghny
2074 * @date 15 MAY 2013
2075 * @version
2076 */
2077
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002078static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002079{
Chaehyun Lim27268872015-09-15 14:06:13 +09002080 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002081
Chaehyun Lim27268872015-09-15 14:06:13 +09002082 priv = (struct wilc_priv *)pUserVoid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002083
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002084 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302085 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002086
Dean Lee72ed4dc2015-06-12 14:11:44 +09002087 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002088
2089 /*Inform wpas of remain-on-channel expiration*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002090 cfg80211_remain_on_channel_expired(priv->wdev,
2091 priv->strRemainOnChanParams.u64ListenCookie,
2092 priv->strRemainOnChanParams.pstrListenChan,
2093 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002094 } else {
2095 PRINT_D(GENERIC_DBG, "Received ID 0x%x Expected ID 0x%x (No match)\n", u32SessionID
2096 , priv->strRemainOnChanParams.u32ListenSessionID);
2097 }
2098}
2099
2100
2101/**
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002102 * @brief remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002103 * @details Request the driver to remain awake on the specified
2104 * channel for the specified duration to complete an off-channel
2105 * operation (e.g., public action frame exchange). When the driver is
2106 * ready on the requested channel, it must indicate this with an event
2107 * notification by calling cfg80211_ready_on_channel().
2108 * @param[in]
2109 * @return int : Return 0 on Success
2110 * @author mdaftedar
2111 * @date 01 MAR 2012
2112 * @version 1.0
2113 */
Chaehyun Lim6d19d692015-09-14 12:24:25 +09002114static int remain_on_channel(struct wiphy *wiphy,
2115 struct wireless_dev *wdev,
2116 struct ieee80211_channel *chan,
2117 unsigned int duration, u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002118{
Leo Kime6e12662015-09-16 18:36:03 +09002119 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002120 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002121
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002122 priv = wiphy_priv(wiphy);
2123
2124 PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
2125
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002126
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002127 if (wdev->iftype == NL80211_IFTYPE_AP) {
2128 PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
2129 return s32Error;
2130 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002131
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002132 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002133
2134 /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
2135 priv->strRemainOnChanParams.pstrListenChan = chan;
2136 priv->strRemainOnChanParams.u64ListenCookie = *cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002137 priv->strRemainOnChanParams.u32ListenDuration = duration;
2138 priv->strRemainOnChanParams.u32ListenSessionID++;
2139
2140 s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv
2141 , priv->strRemainOnChanParams.u32ListenSessionID
2142 , duration
2143 , chan->hw_value
2144 , WILC_WFI_RemainOnChannelExpired
2145 , WILC_WFI_RemainOnChannelReady
2146 , (void *)priv);
2147
2148 return s32Error;
2149}
2150
2151/**
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002152 * @brief cancel_remain_on_channel
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002153 * @details Cancel an on-going remain-on-channel operation.
2154 * This allows the operation to be terminated prior to timeout based on
2155 * the duration value.
2156 * @param[in] struct wiphy *wiphy,
2157 * @param[in] struct net_device *dev
2158 * @param[in] u64 cookie,
2159 * @return int : Return 0 on Success
2160 * @author mdaftedar
2161 * @date 01 MAR 2012
2162 * @version 1.0
2163 */
Chaehyun Lim1dd54402015-09-14 12:24:26 +09002164static int cancel_remain_on_channel(struct wiphy *wiphy,
2165 struct wireless_dev *wdev,
2166 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002167{
Leo Kime6e12662015-09-16 18:36:03 +09002168 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002169 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002170
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002171 priv = wiphy_priv(wiphy);
2172
2173 PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
2174
2175 s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
2176 return s32Error;
2177}
2178/**
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002179 * @brief WILC_WFI_mgmt_tx_frame
2180 * @details
2181 *
2182 * @param[in]
2183 * @return NONE.
2184 * @author mdaftedar
2185 * @date 01 JUL 2012
2186 * @version
2187 */
Dean Lee72ed4dc2015-06-12 14:11:44 +09002188extern bool bEnablePS;
Chaehyun Limc1560322015-09-22 18:34:51 +09002189static int mgmt_tx(struct wiphy *wiphy,
2190 struct wireless_dev *wdev,
2191 struct cfg80211_mgmt_tx_params *params,
2192 u64 *cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002193{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002194 struct ieee80211_channel *chan = params->chan;
2195 unsigned int wait = params->wait;
2196 const u8 *buf = params->buf;
2197 size_t len = params->len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002198 const struct ieee80211_mgmt *mgmt;
2199 struct p2p_mgmt_data *mgmt_tx;
Chaehyun Lim27268872015-09-15 14:06:13 +09002200 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002201 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002202 u32 i;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002203 perInterface_wlan_t *nic;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002204 u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002205
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002206 nic = netdev_priv(wdev->netdev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002207 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002208 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002209
2210 *cookie = (unsigned long)buf;
2211 priv->u64tx_cookie = *cookie;
2212 mgmt = (const struct ieee80211_mgmt *) buf;
2213
2214 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2215
2216 /*mgmt frame allocation*/
Glen Leef3052582015-09-10 12:03:04 +09002217 mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002218 if (mgmt_tx == NULL) {
2219 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
Leo Kime6e12662015-09-16 18:36:03 +09002220 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002221 }
Glen Leef3052582015-09-10 12:03:04 +09002222 mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002223 if (mgmt_tx->buff == NULL) {
2224 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
Tony Chof638dd32015-09-07 19:09:31 +09002225 kfree(mgmt_tx);
Leo Kime6e12662015-09-16 18:36:03 +09002226 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002227 }
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002228 memcpy(mgmt_tx->buff, buf, len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002229 mgmt_tx->size = len;
2230
2231
2232 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2233 PRINT_D(GENERIC_DBG, "TX: Probe Response\n");
2234 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2235 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2236 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002237 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002238 } else if (ieee80211_is_action(mgmt->frame_control)) {
Chaehyun Limd85f5322015-06-11 14:35:54 +09002239 PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002240
2241
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002242 if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002243 /*Only set the channel, if not a negotiation confirmation frame
2244 * (If Negotiation confirmation frame, force it
2245 * to be transmitted on the same negotiation channel)*/
2246
2247 if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
2248 buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
2249 PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
2250 host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
2251 /*Save the current channel after we tune to it*/
Chaehyun Lim866a2c22015-10-02 16:41:21 +09002252 curr_channel = chan->hw_value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002253 }
2254 switch (buf[ACTION_SUBTYPE_ID]) {
2255 case GAS_INTIAL_REQ:
2256 {
2257 PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buf[ACTION_SUBTYPE_ID]);
2258 break;
2259 }
2260
2261 case GAS_INTIAL_RSP:
2262 {
2263 PRINT_D(GENERIC_DBG, "GAS INITIAL RSP %x\n", buf[ACTION_SUBTYPE_ID]);
2264 break;
2265 }
2266
2267 case PUBLIC_ACT_VENDORSPEC:
2268 {
2269 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2270 * 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 +09002271 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002272 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2273 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2274 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
2275 get_random_bytes(&u8P2Plocalrandom, 1);
2276 /*Increment the number to prevent if its 0*/
2277 u8P2Plocalrandom++;
2278 }
2279 }
2280
2281 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2282 || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2283 if (u8P2Plocalrandom > u8P2Precvrandom) {
2284 PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2285
2286 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2287 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
Chaehyun Lim1a646e72015-08-07 09:02:03 +09002288 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002289 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002290 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002291
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002292 /*If using supplicant go intent, no need at all*/
2293 /*to parse transmitted negotiation frames*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002294 else
Dean Lee72ed4dc2015-06-12 14:11:44 +09002295 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002296 break;
2297 }
2298 }
2299
2300 if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
Shivani Bhardwajd8060fc2015-10-29 00:30:01 +05302301 /*
2302 * Adding WILC information element to allow two WILC devices to
2303 * identify each other and connect
2304 */
2305 memcpy(&mgmt_tx->buff[len], u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002306 mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
2307 mgmt_tx->size = buf_len;
2308 }
2309 } else
2310 PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom);
2311 }
2312
2313 } else {
2314 PRINT_D(GENERIC_DBG, "Not a P2P public action frame\n");
2315 }
2316
2317 break;
2318 }
2319
2320 default:
2321 {
2322 PRINT_D(GENERIC_DBG, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
2323 break;
2324 }
2325 }
2326
2327 }
2328
2329 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 +09002330 pstrWFIDrv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002331
Leo Kim1229b1a2015-10-29 12:05:39 +09002332 PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n",
2333 jiffies, pstrWFIDrv->p2p_timeout);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002334 }
2335
Glen Lee829c4772015-10-29 12:18:44 +09002336 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
2337 mgmt_tx->buff, mgmt_tx->size,
Glen Leec9d48342015-10-01 16:03:43 +09002338 WILC_WFI_mgmt_tx_complete);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002339 } else {
2340 PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
2341 }
Leo Kimaaed3292015-10-12 16:55:38 +09002342 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002343}
2344
Chaehyun Lim85c587a2015-09-22 18:34:50 +09002345static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
2346 struct wireless_dev *wdev,
2347 u64 cookie)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002348{
Chaehyun Lim27268872015-09-15 14:06:13 +09002349 struct wilc_priv *priv;
Leo Kim441dc602015-10-12 16:55:35 +09002350 struct host_if_drv *pstrWFIDrv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002351
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002352 priv = wiphy_priv(wiphy);
Leo Kim441dc602015-10-12 16:55:35 +09002353 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002354
2355
2356 PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
Leo Kim1229b1a2015-10-29 12:05:39 +09002357 pstrWFIDrv->p2p_timeout = jiffies;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002358
Luis de Bethencourt7e4e87d2015-10-16 16:32:26 +01002359 if (!priv->bInP2PlistenState) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002360 cfg80211_remain_on_channel_expired(priv->wdev,
2361 priv->strRemainOnChanParams.u64ListenCookie,
2362 priv->strRemainOnChanParams.pstrListenChan,
2363 GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002364 }
2365
2366 return 0;
2367}
2368
2369/**
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002370 * @brief wilc_mgmt_frame_register
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002371 * @details Notify driver that a management frame type was
2372 * registered. Note that this callback may not sleep, and cannot run
2373 * concurrently with itself.
2374 * @param[in]
2375 * @return NONE.
2376 * @author mdaftedar
2377 * @date 01 JUL 2012
2378 * @version
2379 */
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09002380void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
2381 u16 frame_type, bool reg)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002382{
2383
Chaehyun Lim27268872015-09-15 14:06:13 +09002384 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002385 perInterface_wlan_t *nic;
Glen Lee1b869352015-10-20 17:14:01 +09002386 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002387
2388 priv = wiphy_priv(wiphy);
2389 nic = netdev_priv(priv->wdev->netdev);
Glen Lee1b869352015-10-20 17:14:01 +09002390 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002391
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002392 if (!frame_type)
2393 return;
2394
2395 PRINT_D(GENERIC_DBG, "Frame registering Frame Type: %x: Boolean: %d\n", frame_type, reg);
2396 switch (frame_type) {
2397 case PROBE_REQ:
2398 {
2399 nic->g_struct_frame_reg[0].frame_type = frame_type;
2400 nic->g_struct_frame_reg[0].reg = reg;
2401 }
2402 break;
2403
2404 case ACTION:
2405 {
2406 nic->g_struct_frame_reg[1].frame_type = frame_type;
2407 nic->g_struct_frame_reg[1].reg = reg;
2408 }
2409 break;
2410
2411 default:
2412 {
2413 break;
2414 }
2415
2416 }
2417 /*If mac is closed, then return*/
Glen Lee1b869352015-10-20 17:14:01 +09002418 if (!wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002419 PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
2420 return;
2421 }
2422 host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg);
2423
2424
2425}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002426
2427/**
Chaehyun Lima8047e22015-09-22 18:34:48 +09002428 * @brief set_cqm_rssi_config
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002429 * @details Configure connection quality monitor RSSI threshold.
2430 * @param[in] struct wiphy *wiphy:
2431 * @param[in] struct net_device *dev:
2432 * @param[in] s32 rssi_thold:
2433 * @param[in] u32 rssi_hyst:
2434 * @return int : Return 0 on Success
2435 * @author mdaftedar
2436 * @date 01 MAR 2012
2437 * @version 1.0
2438 */
Chaehyun Lima8047e22015-09-22 18:34:48 +09002439static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
2440 s32 rssi_thold, u32 rssi_hyst)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002441{
2442 PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
2443 return 0;
2444
2445}
2446/**
Chaehyun Limbdb63382015-09-14 12:24:19 +09002447 * @brief dump_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002448 * @details Configure connection quality monitor RSSI threshold.
2449 * @param[in] struct wiphy *wiphy:
2450 * @param[in] struct net_device *dev
2451 * @param[in] int idx
2452 * @param[in] u8 *mac
2453 * @param[in] struct station_info *sinfo
2454 * @return int : Return 0 on Success
2455 * @author mdaftedar
2456 * @date 01 MAR 2012
2457 * @version 1.0
2458 */
Chaehyun Limbdb63382015-09-14 12:24:19 +09002459static int dump_station(struct wiphy *wiphy, struct net_device *dev,
2460 int idx, u8 *mac, struct station_info *sinfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002461{
Chaehyun Lim27268872015-09-15 14:06:13 +09002462 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002463
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002464 PRINT_D(CFG80211_DBG, "Dumping station information\n");
2465
2466 if (idx != 0)
2467 return -ENOENT;
2468
2469 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002470
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002471 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002472
2473 host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal));
2474
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002475 return 0;
2476
2477}
2478
2479
2480/**
Chaehyun Lim46530672015-09-22 18:34:46 +09002481 * @brief set_power_mgmt
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002482 * @details
2483 * @param[in]
2484 * @return int : Return 0 on Success.
2485 * @author mdaftedar
2486 * @date 01 JUL 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09002487 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002488 */
Chaehyun Lim46530672015-09-22 18:34:46 +09002489static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2490 bool enabled, int timeout)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002491{
Chaehyun Lim27268872015-09-15 14:06:13 +09002492 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09002493
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002494 PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
2495
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002496 if (wiphy == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002497 return -ENOENT;
2498
2499 priv = wiphy_priv(wiphy);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002500 if (priv->hWILCWFIDrv == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002501 PRINT_ER("Driver is NULL\n");
2502 return -EIO;
2503 }
2504
Abdul Hussain5a66bf22015-06-16 09:44:06 +00002505 if (bEnablePS)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002506 host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
2507
2508
Leo Kime6e12662015-09-16 18:36:03 +09002509 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002510
2511}
Glen Lee108b3432015-09-16 18:53:20 +09002512
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002513/**
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002514 * @brief change_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002515 * @details Change type/configuration of virtual interface,
2516 * keep the struct wireless_dev's iftype updated.
2517 * @param[in] NONE
2518 * @return int : Return 0 on Success.
2519 * @author mdaftedar
2520 * @date 01 MAR 2012
2521 * @version 1.0
2522 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002523int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
2524
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09002525static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
2526 enum nl80211_iftype type, u32 *flags, struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002527{
Chaehyun Lim27268872015-09-15 14:06:13 +09002528 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002529 perInterface_wlan_t *nic;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002530 u8 interface_type;
Chaehyun Limd85f5322015-06-11 14:35:54 +09002531 u16 TID = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002532 u8 i;
Glen Lee299382c2015-10-20 17:13:56 +09002533 struct wilc *wl;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002534
2535 nic = netdev_priv(dev);
2536 priv = wiphy_priv(wiphy);
Glen Lee299382c2015-10-20 17:13:56 +09002537 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002538
2539 PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
2540 PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
2541 u8P2Plocalrandom = 0x01;
2542 u8P2Precvrandom = 0x00;
2543
Dean Lee72ed4dc2015-06-12 14:11:44 +09002544 bWilc_ie = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002545
Dean Lee72ed4dc2015-06-12 14:11:44 +09002546 g_obtainingIP = false;
Greg Kroah-Hartman8972d0f2015-08-14 20:04:13 -07002547 del_timer(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002548 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002549 /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
2550 if (g_ptk_keys_saved && g_gtk_keys_saved) {
Leo Kim2ad8c472015-11-05 14:36:35 +09002551 set_machw_change_vir_if(dev, true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002552 }
2553
2554 switch (type) {
2555 case NL80211_IFTYPE_STATION:
2556 connecting = 0;
2557 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002558
2559 /* send delba over wlan interface */
2560
2561
2562 dev->ieee80211_ptr->iftype = type;
2563 priv->wdev->iftype = type;
2564 nic->monitor_flag = 0;
2565 nic->iftype = STATION_MODE;
2566
2567 /*Remove the enteries of the previously connected clients*/
2568 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002569 interface_type = nic->iftype;
2570 nic->iftype = STATION_MODE;
2571
Glen Lee299382c2015-10-20 17:13:56 +09002572 if (wl->initialized) {
2573 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2574 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002575 /* ensure that the message Q is empty */
2576 host_int_wait_msg_queue_idle();
2577
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002578 /*Eliminate host interface blocking state*/
Glen Lee299382c2015-10-20 17:13:56 +09002579 up(&wl->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002580
Glen Lee53dc0cf2015-10-20 17:13:57 +09002581 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002582 wilc1000_wlan_init(dev, nic);
2583 g_wilc_initialized = 1;
2584 nic->iftype = interface_type;
2585
2586 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002587 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2588 host_int_set_MacAddress(wl->vif[0].hif_drv,
2589 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002590 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2591
2592 /*Add saved WEP keys, if any*/
2593 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002594 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002595 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002596 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002597 g_key_wep_params.key,
2598 g_key_wep_params.key_len,
2599 g_key_wep_params.key_idx);
2600 }
2601
2602 /*No matter the driver handler passed here, it will be overwriiten*/
2603 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2604 host_int_flush_join_req(priv->hWILCWFIDrv);
2605
2606 /*Add saved PTK and GTK keys, if any*/
2607 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2608 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2609 g_key_ptk_params.key[1],
2610 g_key_ptk_params.key[2]);
2611 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2612 g_key_gtk_params.key[1],
2613 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002614 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2615 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002616 g_add_ptk_key_params.key_idx,
2617 g_add_ptk_key_params.pairwise,
2618 g_add_ptk_key_params.mac_addr,
2619 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002620
Glen Lee299382c2015-10-20 17:13:56 +09002621 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2622 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002623 g_add_gtk_key_params.key_idx,
2624 g_add_gtk_key_params.pairwise,
2625 g_add_gtk_key_params.mac_addr,
2626 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002627 }
2628
Glen Lee299382c2015-10-20 17:13:56 +09002629 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002630 for (i = 0; i < num_reg_frame; i++) {
2631 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2632 nic->g_struct_frame_reg[i].reg);
2633 host_int_frame_register(priv->hWILCWFIDrv,
2634 nic->g_struct_frame_reg[i].frame_type,
2635 nic->g_struct_frame_reg[i].reg);
2636 }
2637 }
2638
Dean Lee72ed4dc2015-06-12 14:11:44 +09002639 bEnablePS = true;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002640 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2641 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002642 break;
2643
2644 case NL80211_IFTYPE_P2P_CLIENT:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002645 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002646 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
2647 connecting = 0;
2648 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002649
Glen Lee299382c2015-10-20 17:13:56 +09002650 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2651 wl->vif[0].bssid, TID);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002652
2653 dev->ieee80211_ptr->iftype = type;
2654 priv->wdev->iftype = type;
2655 nic->monitor_flag = 0;
2656
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002657 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2658 nic->iftype = CLIENT_MODE;
2659
2660
Glen Lee299382c2015-10-20 17:13:56 +09002661 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002662 /* ensure that the message Q is empty */
2663 host_int_wait_msg_queue_idle();
2664
Glen Lee53dc0cf2015-10-20 17:13:57 +09002665 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002666 wilc1000_wlan_init(dev, nic);
2667 g_wilc_initialized = 1;
2668
Glen Lee299382c2015-10-20 17:13:56 +09002669 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2670 host_int_set_MacAddress(wl->vif[0].hif_drv,
2671 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002672 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2673
2674 /*Add saved WEP keys, if any*/
2675 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002676 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002677 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002678 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002679 g_key_wep_params.key,
2680 g_key_wep_params.key_len,
2681 g_key_wep_params.key_idx);
2682 }
2683
2684 /*No matter the driver handler passed here, it will be overwriiten*/
2685 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2686 host_int_flush_join_req(priv->hWILCWFIDrv);
2687
2688 /*Add saved PTK and GTK keys, if any*/
2689 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2690 PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
2691 g_key_ptk_params.key[1],
2692 g_key_ptk_params.key[2]);
2693 PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
2694 g_key_gtk_params.key[1],
2695 g_key_gtk_params.key[2]);
Glen Lee299382c2015-10-20 17:13:56 +09002696 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2697 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002698 g_add_ptk_key_params.key_idx,
2699 g_add_ptk_key_params.pairwise,
2700 g_add_ptk_key_params.mac_addr,
2701 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002702
Glen Lee299382c2015-10-20 17:13:56 +09002703 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2704 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002705 g_add_gtk_key_params.key_idx,
2706 g_add_gtk_key_params.pairwise,
2707 g_add_gtk_key_params.mac_addr,
2708 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002709 }
2710
2711 /*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 +09002712 refresh_scan(priv, 1, true);
Leo Kim2ad8c472015-11-05 14:36:35 +09002713 set_machw_change_vir_if(dev, false);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002714
Glen Lee299382c2015-10-20 17:13:56 +09002715 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002716 for (i = 0; i < num_reg_frame; i++) {
2717 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2718 nic->g_struct_frame_reg[i].reg);
2719 host_int_frame_register(priv->hWILCWFIDrv,
2720 nic->g_struct_frame_reg[i].frame_type,
2721 nic->g_struct_frame_reg[i].reg);
2722 }
2723 }
2724 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002725 break;
2726
2727 case NL80211_IFTYPE_AP:
Dean Lee72ed4dc2015-06-12 14:11:44 +09002728 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002729 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002730 dev->ieee80211_ptr->iftype = type;
2731 priv->wdev->iftype = type;
2732 nic->iftype = AP_MODE;
Johnny Kim8a143302015-06-10 17:06:46 +09002733 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002734
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002735 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
Glen Lee65c8adc2015-10-29 12:18:49 +09002736 linux_wlan_get_firmware(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002737 /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
Glen Lee299382c2015-10-20 17:13:56 +09002738 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002739 nic->iftype = AP_MODE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002740 mac_close(dev);
2741 mac_open(dev);
2742
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002743 for (i = 0; i < num_reg_frame; i++) {
2744 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2745 nic->g_struct_frame_reg[i].reg);
2746 host_int_frame_register(priv->hWILCWFIDrv,
2747 nic->g_struct_frame_reg[i].frame_type,
2748 nic->g_struct_frame_reg[i].reg);
2749 }
2750 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002751 break;
2752
2753 case NL80211_IFTYPE_P2P_GO:
2754 PRINT_D(GENERIC_DBG, "start duringIP timer\n");
2755
Dean Lee72ed4dc2015-06-12 14:11:44 +09002756 g_obtainingIP = true;
Greg Kroah-Hartman9eb06642015-08-17 11:10:55 -07002757 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002758 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002759 /*Delete block ack has to be the latest config packet*/
2760 /*sent before downloading new FW. This is because it blocks on*/
2761 /*hWaitResponse semaphore, which allows previous config*/
2762 /*packets to actually take action on old FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002763 host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
2764 wl->vif[0].bssid, TID);
Dean Lee72ed4dc2015-06-12 14:11:44 +09002765 bEnablePS = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002766 PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002767 dev->ieee80211_ptr->iftype = type;
2768 priv->wdev->iftype = type;
2769
Johnny Kim8a143302015-06-10 17:06:46 +09002770 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002771
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002772 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
2773
2774
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002775 nic->iftype = GO_MODE;
2776
2777 /* ensure that the message Q is empty */
2778 host_int_wait_msg_queue_idle();
Glen Lee53dc0cf2015-10-20 17:13:57 +09002779 wilc1000_wlan_deinit(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002780 wilc1000_wlan_init(dev, nic);
2781 g_wilc_initialized = 1;
2782
2783
2784 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
Glen Lee299382c2015-10-20 17:13:56 +09002785 host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
2786 host_int_set_MacAddress(wl->vif[0].hif_drv,
2787 wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002788 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
2789
2790 /*Add saved WEP keys, if any*/
2791 if (g_wep_keys_saved) {
Chaehyun Limdf8b4832015-10-26 09:44:45 +09002792 host_int_set_wep_default_key(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002793 g_key_wep_params.key_idx);
Glen Lee299382c2015-10-20 17:13:56 +09002794 host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002795 g_key_wep_params.key,
2796 g_key_wep_params.key_len,
2797 g_key_wep_params.key_idx);
2798 }
2799
2800 /*No matter the driver handler passed here, it will be overwriiten*/
2801 /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/
2802 host_int_flush_join_req(priv->hWILCWFIDrv);
2803
2804 /*Add saved PTK and GTK keys, if any*/
2805 if (g_ptk_keys_saved && g_gtk_keys_saved) {
2806 PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
2807 g_key_ptk_params.key[1],
2808 g_key_ptk_params.key[2],
2809 g_key_ptk_params.cipher);
2810 PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
2811 g_key_gtk_params.key[1],
2812 g_key_gtk_params.key[2],
2813 g_key_gtk_params.cipher);
Glen Lee299382c2015-10-20 17:13:56 +09002814 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2815 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002816 g_add_ptk_key_params.key_idx,
2817 g_add_ptk_key_params.pairwise,
2818 g_add_ptk_key_params.mac_addr,
2819 (struct key_params *)(&g_key_ptk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002820
Glen Lee299382c2015-10-20 17:13:56 +09002821 add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
2822 wl->vif[0].ndev,
Chaehyun Lim953d4172015-09-14 12:24:05 +09002823 g_add_gtk_key_params.key_idx,
2824 g_add_gtk_key_params.pairwise,
2825 g_add_gtk_key_params.mac_addr,
2826 (struct key_params *)(&g_key_gtk_params));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002827 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002828
Glen Lee299382c2015-10-20 17:13:56 +09002829 if (wl->initialized) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002830 for (i = 0; i < num_reg_frame; i++) {
2831 PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
2832 nic->g_struct_frame_reg[i].reg);
2833 host_int_frame_register(priv->hWILCWFIDrv,
2834 nic->g_struct_frame_reg[i].frame_type,
2835 nic->g_struct_frame_reg[i].reg);
2836 }
2837 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002838 break;
2839
2840 default:
2841 PRINT_ER("Unknown interface type= %d\n", type);
Leo Kimaaed3292015-10-12 16:55:38 +09002842 return -EINVAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002843 }
2844
Leo Kimaaed3292015-10-12 16:55:38 +09002845 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002846}
2847
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002848/* (austin.2013-07-23)
2849 *
2850 * To support revised cfg80211_ops
2851 *
2852 * add_beacon --> start_ap
2853 * set_beacon --> change_beacon
2854 * del_beacon --> stop_ap
2855 *
2856 * beacon_parameters --> cfg80211_ap_settings
2857 * cfg80211_beacon_data
2858 *
2859 * applicable for linux kernel 3.4+
2860 */
2861
2862/**
Chaehyun Lima13168d2015-09-14 12:24:12 +09002863 * @brief start_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002864 * @details Add a beacon with given parameters, @head, @interval
2865 * and @dtim_period will be valid, @tail is optional.
2866 * @param[in] wiphy
2867 * @param[in] dev The net device structure
2868 * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added
2869 * @return int : Return 0 on Success.
2870 * @author austin
2871 * @date 23 JUL 2013
2872 * @version 1.0
2873 */
Chaehyun Lima13168d2015-09-14 12:24:12 +09002874static int start_ap(struct wiphy *wiphy, struct net_device *dev,
2875 struct cfg80211_ap_settings *settings)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002876{
2877 struct cfg80211_beacon_data *beacon = &(settings->beacon);
Chaehyun Lim27268872015-09-15 14:06:13 +09002878 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002879 s32 s32Error = 0;
Glen Lee684dc182015-10-20 17:14:02 +09002880 struct wilc *wl;
2881 perInterface_wlan_t *nic;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002882
2883 priv = wiphy_priv(wiphy);
Glen Lee684dc182015-10-20 17:14:02 +09002884 nic = netdev_priv(dev);
2885 wl = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002886 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
2887
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05302888 PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002889 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
2890
Chaehyun Lim80785a92015-09-14 12:24:01 +09002891 s32Error = set_channel(wiphy, &settings->chandef);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002892
Leo Kime6e12662015-09-16 18:36:03 +09002893 if (s32Error != 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002894 PRINT_ER("Error in setting channel\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002895
Glen Lee684dc182015-10-20 17:14:02 +09002896 linux_wlan_set_bssid(dev, wl->vif[0].src_addr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002897
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002898 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2899 settings->beacon_interval,
2900 settings->dtim_period,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002901 beacon->head_len, (u8 *)beacon->head,
2902 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002903
2904 return s32Error;
2905}
2906
2907/**
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002908 * @brief change_beacon
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002909 * @details Add a beacon with given parameters, @head, @interval
2910 * and @dtim_period will be valid, @tail is optional.
2911 * @param[in] wiphy
2912 * @param[in] dev The net device structure
2913 * @param[in] beacon cfg80211_beacon_data for the beacon to be changed
2914 * @return int : Return 0 on Success.
2915 * @author austin
2916 * @date 23 JUL 2013
2917 * @version 1.0
2918 */
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09002919static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
2920 struct cfg80211_beacon_data *beacon)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002921{
Chaehyun Lim27268872015-09-15 14:06:13 +09002922 struct wilc_priv *priv;
Leo Kime6e12662015-09-16 18:36:03 +09002923 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002924
2925 priv = wiphy_priv(wiphy);
2926 PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
2927
2928
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002929 s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
2930 0,
2931 0,
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002932 beacon->head_len, (u8 *)beacon->head,
2933 beacon->tail_len, (u8 *)beacon->tail);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002934
2935 return s32Error;
2936}
2937
2938/**
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002939 * @brief stop_ap
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002940 * @details Remove beacon configuration and stop sending the beacon.
2941 * @param[in]
2942 * @return int : Return 0 on Success.
2943 * @author austin
2944 * @date 23 JUL 2013
2945 * @version 1.0
2946 */
Chaehyun Limc8cddd72015-09-14 12:24:14 +09002947static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002948{
Leo Kime6e12662015-09-16 18:36:03 +09002949 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002950 struct wilc_priv *priv;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +09002951 u8 NullBssid[ETH_ALEN] = {0};
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002952
Leo Kim7ae43362015-09-16 18:35:59 +09002953 if (!wiphy)
2954 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002955
2956 priv = wiphy_priv(wiphy);
2957
2958 PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
2959
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002960 linux_wlan_set_bssid(dev, NullBssid);
2961
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002962 s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002963
Leo Kim7dc1d0c2015-09-16 18:36:00 +09002964 if (s32Error)
2965 PRINT_ER("Host delete beacon fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002966
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002967 return s32Error;
2968}
2969
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002970/**
Chaehyun Limed269552015-09-14 12:24:15 +09002971 * @brief add_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002972 * @details Add a new station.
2973 * @param[in]
2974 * @return int : Return 0 on Success.
2975 * @author mdaftedar
2976 * @date 01 MAR 2012
2977 * @version 1.0
2978 */
Chaehyun Limed269552015-09-14 12:24:15 +09002979static int add_station(struct wiphy *wiphy, struct net_device *dev,
2980 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002981{
Leo Kime6e12662015-09-16 18:36:03 +09002982 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09002983 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09002984 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002985 perInterface_wlan_t *nic;
2986
Leo Kim7ae43362015-09-16 18:35:59 +09002987 if (!wiphy)
2988 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002989
2990 priv = wiphy_priv(wiphy);
2991 nic = netdev_priv(dev);
2992
2993 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09002994 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Chaehyun Limd00d2ba2015-08-10 11:33:19 +09002995 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09002996 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09002997 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09002998 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002999
3000 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3001
3002 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4],
3003 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003004 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003005 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3006 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003007
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003008 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003009 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003010 } else {
Leo Kim22520122015-10-29 12:05:45 +09003011 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003012 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003013 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003014 memcpy(strStaParams.ht_supp_mcs_set,
3015 &params->ht_capa->mcs,
3016 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003017 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003018 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003019 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003020 }
3021
Leo Kimf676e172015-10-29 12:05:52 +09003022 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003023 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003024
Leo Kim22520122015-10-29 12:05:45 +09003025 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3026 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003027 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3028 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003029 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3030 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003031 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3032 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003033 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3034 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003035 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3036 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003037 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3038 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003039 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3040 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003041
3042 s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003043 if (s32Error)
3044 PRINT_ER("Host add station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003045 }
3046
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003047 return s32Error;
3048}
3049
3050/**
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003051 * @brief del_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003052 * @details Remove a station; @mac may be NULL to remove all stations.
3053 * @param[in]
3054 * @return int : Return 0 on Success.
3055 * @author mdaftedar
3056 * @date 01 MAR 2012
3057 * @version 1.0
3058 */
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003059static int del_station(struct wiphy *wiphy, struct net_device *dev,
3060 struct station_del_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003061{
Arnd Bergmann057d1e92015-06-01 21:06:44 +02003062 const u8 *mac = params->mac;
Leo Kime6e12662015-09-16 18:36:03 +09003063 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003064 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003065 perInterface_wlan_t *nic;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003066
Leo Kim7ae43362015-09-16 18:35:59 +09003067 if (!wiphy)
3068 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003069
3070 priv = wiphy_priv(wiphy);
3071 nic = netdev_priv(dev);
3072
3073 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3074 PRINT_D(HOSTAPD_DBG, "Deleting station\n");
3075
3076
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003077 if (mac == NULL) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05303078 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003079 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3080 } else {
3081 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]);
3082 }
3083
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003084 s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003085
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003086 if (s32Error)
3087 PRINT_ER("Host delete station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003088 }
3089 return s32Error;
3090}
3091
3092/**
Chaehyun Lim14b42082015-09-14 12:24:17 +09003093 * @brief change_station
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003094 * @details Modify a given station.
3095 * @param[in]
3096 * @return int : Return 0 on Success.
3097 * @author mdaftedar
3098 * @date 01 MAR 2012
3099 * @version 1.0
3100 */
Chaehyun Lim14b42082015-09-14 12:24:17 +09003101static int change_station(struct wiphy *wiphy, struct net_device *dev,
3102 const u8 *mac, struct station_parameters *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003103{
Leo Kime6e12662015-09-16 18:36:03 +09003104 s32 s32Error = 0;
Chaehyun Lim27268872015-09-15 14:06:13 +09003105 struct wilc_priv *priv;
Tony Cho6a89ba92015-09-21 12:16:46 +09003106 struct add_sta_param strStaParams = { {0} };
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003107 perInterface_wlan_t *nic;
3108
3109
3110 PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
3111
Leo Kim7ae43362015-09-16 18:35:59 +09003112 if (!wiphy)
3113 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003114
3115 priv = wiphy_priv(wiphy);
3116 nic = netdev_priv(dev);
3117
3118 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
Leo Kim2353c382015-10-29 12:05:41 +09003119 memcpy(strStaParams.bssid, mac, ETH_ALEN);
Leo Kim4101eb82015-10-29 12:05:42 +09003120 strStaParams.aid = params->aid;
Leo Kime7342232015-10-29 12:05:43 +09003121 strStaParams.rates_len = params->supported_rates_len;
Leo Kima622e012015-10-29 12:05:44 +09003122 strStaParams.rates = params->supported_rates;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003123
Leo Kim2353c382015-10-29 12:05:41 +09003124 PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n",
3125 strStaParams.bssid[0], strStaParams.bssid[1],
3126 strStaParams.bssid[2], strStaParams.bssid[3],
3127 strStaParams.bssid[4], strStaParams.bssid[5]);
Leo Kim4101eb82015-10-29 12:05:42 +09003128 PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid);
Leo Kime7342232015-10-29 12:05:43 +09003129 PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n",
3130 strStaParams.rates_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003131
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09003132 if (params->ht_capa == NULL) {
Leo Kim22520122015-10-29 12:05:45 +09003133 strStaParams.ht_supported = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003134 } else {
Leo Kim22520122015-10-29 12:05:45 +09003135 strStaParams.ht_supported = true;
Leo Kim0d073f62015-10-29 12:05:46 +09003136 strStaParams.ht_capa_info = params->ht_capa->cap_info;
Leo Kimfba1f2d2015-10-29 12:05:47 +09003137 strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info;
Leo Kim5ebbf4f2015-10-29 12:05:48 +09003138 memcpy(strStaParams.ht_supp_mcs_set,
3139 &params->ht_capa->mcs,
3140 WILC_SUPP_MCS_SET_SIZE);
Leo Kim223741d2015-10-29 12:05:49 +09003141 strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info;
Leo Kim74fe73c2015-10-29 12:05:50 +09003142 strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info;
Leo Kima486baf2015-10-29 12:05:51 +09003143 strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003144 }
3145
Leo Kimf676e172015-10-29 12:05:52 +09003146 strStaParams.flags_mask = params->sta_flags_mask;
Leo Kim67ab64e2015-10-29 12:05:53 +09003147 strStaParams.flags_set = params->sta_flags_set;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003148
Leo Kim22520122015-10-29 12:05:45 +09003149 PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n",
3150 strStaParams.ht_supported);
Leo Kim0d073f62015-10-29 12:05:46 +09003151 PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n",
3152 strStaParams.ht_capa_info);
Leo Kimfba1f2d2015-10-29 12:05:47 +09003153 PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n",
3154 strStaParams.ht_ampdu_params);
Leo Kim223741d2015-10-29 12:05:49 +09003155 PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n",
3156 strStaParams.ht_ext_params);
Leo Kim74fe73c2015-10-29 12:05:50 +09003157 PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n",
3158 strStaParams.ht_tx_bf_cap);
Leo Kima486baf2015-10-29 12:05:51 +09003159 PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n",
3160 strStaParams.ht_ante_sel);
Leo Kimf676e172015-10-29 12:05:52 +09003161 PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n",
3162 strStaParams.flags_mask);
Leo Kim67ab64e2015-10-29 12:05:53 +09003163 PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n",
3164 strStaParams.flags_set);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003165
3166 s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
Leo Kim7dc1d0c2015-09-16 18:36:00 +09003167 if (s32Error)
3168 PRINT_ER("Host edit station fail\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003169 }
3170 return s32Error;
3171}
3172
3173
3174/**
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003175 * @brief add_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003176 * @details
3177 * @param[in]
3178 * @return int : Return 0 on Success.
3179 * @author mdaftedar
3180 * @date 01 JUL 2012
3181 * @version 1.0
3182 */
Chaehyun Lim37316e82015-09-22 18:34:52 +09003183static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
3184 const char *name,
3185 unsigned char name_assign_type,
3186 enum nl80211_iftype type,
3187 u32 *flags,
3188 struct vif_params *params)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003189{
3190 perInterface_wlan_t *nic;
Chaehyun Lim27268872015-09-15 14:06:13 +09003191 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003192 struct net_device *new_ifc = NULL;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003193
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003194 priv = wiphy_priv(wiphy);
3195
3196
3197
3198 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev);
3199
3200 nic = netdev_priv(priv->wdev->netdev);
3201
3202
3203 if (type == NL80211_IFTYPE_MONITOR) {
3204 PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n");
3205 PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev);
3206 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3207 if (new_ifc != NULL) {
3208 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003209 nic = netdev_priv(priv->wdev->netdev);
3210 nic->monitor_flag = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003211 } else
3212 PRINT_ER("Error in initializing monitor interface\n ");
3213 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003214 return priv->wdev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003215}
3216
3217/**
Chaehyun Limb4a73352015-09-14 12:24:10 +09003218 * @brief del_virtual_intf
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003219 * @details
3220 * @param[in]
3221 * @return int : Return 0 on Success.
3222 * @author mdaftedar
3223 * @date 01 JUL 2012
3224 * @version 1.0
3225 */
Chaehyun Lim956d7212015-09-22 18:34:49 +09003226static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003227{
3228 PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
Leo Kime6e12662015-09-16 18:36:03 +09003229 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003230}
3231
Chaehyun Lim08241922015-09-15 14:06:12 +09003232static struct cfg80211_ops wilc_cfg80211_ops = {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003233
Chaehyun Lim80785a92015-09-14 12:24:01 +09003234 .set_monitor_channel = set_channel,
Chaehyun Lim0e30d062015-09-14 12:24:02 +09003235 .scan = scan,
Chaehyun Lim4ffbcdb2015-09-14 12:24:03 +09003236 .connect = connect,
Chaehyun Limb027cde2015-09-14 12:24:04 +09003237 .disconnect = disconnect,
Chaehyun Lim953d4172015-09-14 12:24:05 +09003238 .add_key = add_key,
Chaehyun Lim3044ba72015-09-14 12:24:06 +09003239 .del_key = del_key,
Chaehyun Limf4893df2015-09-14 12:24:07 +09003240 .get_key = get_key,
Chaehyun Lim0f5b8ca2015-09-14 12:24:08 +09003241 .set_default_key = set_default_key,
Chaehyun Lim69deb4c2015-09-14 12:24:09 +09003242 .add_virtual_intf = add_virtual_intf,
Chaehyun Limb4a73352015-09-14 12:24:10 +09003243 .del_virtual_intf = del_virtual_intf,
Chaehyun Lim3615e9a2015-09-14 12:24:11 +09003244 .change_virtual_intf = change_virtual_intf,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003245
Chaehyun Lima13168d2015-09-14 12:24:12 +09003246 .start_ap = start_ap,
Chaehyun Lim2a4c84d2015-09-14 12:24:13 +09003247 .change_beacon = change_beacon,
Chaehyun Limc8cddd72015-09-14 12:24:14 +09003248 .stop_ap = stop_ap,
Chaehyun Limed269552015-09-14 12:24:15 +09003249 .add_station = add_station,
Chaehyun Lima0a8be92015-09-14 12:24:16 +09003250 .del_station = del_station,
Chaehyun Lim14b42082015-09-14 12:24:17 +09003251 .change_station = change_station,
Chaehyun Limf06f5622015-09-14 12:24:18 +09003252 .get_station = get_station,
Chaehyun Limbdb63382015-09-14 12:24:19 +09003253 .dump_station = dump_station,
Chaehyun Lima5f7db62015-09-14 12:24:20 +09003254 .change_bss = change_bss,
Chaehyun Lima76b63e2015-09-14 12:24:21 +09003255 .set_wiphy_params = set_wiphy_params,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003256
Chaehyun Lim4d466572015-09-14 12:24:22 +09003257 .set_pmksa = set_pmksa,
Chaehyun Lim1ff86d92015-09-14 12:24:23 +09003258 .del_pmksa = del_pmksa,
Chaehyun Limb33c39b2015-09-14 12:24:24 +09003259 .flush_pmksa = flush_pmksa,
Chaehyun Lim6d19d692015-09-14 12:24:25 +09003260 .remain_on_channel = remain_on_channel,
Chaehyun Lim1dd54402015-09-14 12:24:26 +09003261 .cancel_remain_on_channel = cancel_remain_on_channel,
Chaehyun Lim4a2f9b32015-09-14 12:24:27 +09003262 .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
Chaehyun Lim12a26a32015-09-14 12:24:28 +09003263 .mgmt_tx = mgmt_tx,
Chaehyun Lim8e0735c2015-09-20 15:51:16 +09003264 .mgmt_frame_register = wilc_mgmt_frame_register,
Chaehyun Lim46530672015-09-22 18:34:46 +09003265 .set_power_mgmt = set_power_mgmt,
Chaehyun Lima8047e22015-09-22 18:34:48 +09003266 .set_cqm_rssi_config = set_cqm_rssi_config,
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003267
3268};
3269
3270
3271
3272
3273
3274/**
3275 * @brief WILC_WFI_update_stats
3276 * @details Modify parameters for a given BSS.
3277 * @param[in]
3278 * @return int : Return 0 on Success.
3279 * @author mdaftedar
3280 * @date 01 MAR 2012
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003281 * @version 1.0
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003282 */
3283int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
3284{
3285
Chaehyun Lim27268872015-09-15 14:06:13 +09003286 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003287
3288 priv = wiphy_priv(wiphy);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003289 switch (changed) {
3290
3291 case WILC_WFI_RX_PKT:
3292 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003293 priv->netstats.rx_packets++;
3294 priv->netstats.rx_bytes += pktlen;
3295 priv->netstats.rx_time = get_jiffies_64();
3296 }
3297 break;
3298
3299 case WILC_WFI_TX_PKT:
3300 {
3301 priv->netstats.tx_packets++;
3302 priv->netstats.tx_bytes += pktlen;
3303 priv->netstats.tx_time = get_jiffies_64();
3304
3305 }
3306 break;
3307
3308 default:
3309 break;
3310 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003311 return 0;
3312}
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003313
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003314/**
3315 * @brief WILC_WFI_CfgAlloc
3316 * @details Allocation of the wireless device structure and assigning it
3317 * to the cfg80211 operations structure.
3318 * @param[in] NONE
3319 * @return wireless_dev : Returns pointer to wireless_dev structure.
3320 * @author mdaftedar
3321 * @date 01 MAR 2012
3322 * @version 1.0
3323 */
3324struct wireless_dev *WILC_WFI_CfgAlloc(void)
3325{
3326
3327 struct wireless_dev *wdev;
3328
3329
3330 PRINT_D(CFG80211_DBG, "Allocating wireless device\n");
3331 /*Allocating the wireless device structure*/
3332 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3333 if (!wdev) {
3334 PRINT_ER("Cannot allocate wireless device\n");
3335 goto _fail_;
3336 }
3337
3338 /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
Chaehyun Lim27268872015-09-15 14:06:13 +09003339 wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003340 if (!wdev->wiphy) {
3341 PRINT_ER("Cannot allocate wiphy\n");
3342 goto _fail_mem_;
3343
3344 }
3345
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003346 /* enable 802.11n HT */
3347 WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
3348 WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
3349 WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
3350 WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
3351 WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003352
3353 /*wiphy bands*/
3354 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
3355
3356 return wdev;
3357
3358_fail_mem_:
3359 kfree(wdev);
3360_fail_:
3361 return NULL;
3362
3363}
3364/**
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003365 * @brief wilc_create_wiphy
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003366 * @details Registering of the wiphy structure and interface modes
3367 * @param[in] NONE
3368 * @return NONE
3369 * @author mdaftedar
3370 * @date 01 MAR 2012
3371 * @version 1.0
3372 */
Chaehyun Lim8459fd52015-09-20 15:51:09 +09003373struct wireless_dev *wilc_create_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003374{
Chaehyun Lim27268872015-09-15 14:06:13 +09003375 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003376 struct wireless_dev *wdev;
Leo Kime6e12662015-09-16 18:36:03 +09003377 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003378
3379 PRINT_D(CFG80211_DBG, "Registering wifi device\n");
3380
3381 wdev = WILC_WFI_CfgAlloc();
3382 if (wdev == NULL) {
3383 PRINT_ER("CfgAlloc Failed\n");
3384 return NULL;
3385 }
3386
3387
3388 /*Return hardware description structure (wiphy)'s priv*/
3389 priv = wdev_priv(wdev);
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003390 sema_init(&(priv->SemHandleUpdateStats), 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003391
3392 /*Link the wiphy with wireless structure*/
3393 priv->wdev = wdev;
3394
3395 /*Maximum number of probed ssid to be added by user for the scan request*/
3396 wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003397 /*Maximum number of pmkids to be cashed*/
3398 wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
3399 PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003400
3401 wdev->wiphy->max_scan_ie_len = 1000;
3402
3403 /*signal strength in mBm (100*dBm) */
3404 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3405
3406 /*Set the availaible cipher suites*/
3407 wdev->wiphy->cipher_suites = cipher_suites;
3408 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003409 /*Setting default managment types: for register action frame: */
3410 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003411
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003412 wdev->wiphy->max_remain_on_channel_duration = 500;
3413 /*Setting the wiphy interfcae mode and type before registering the wiphy*/
3414 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
3415 BIT(NL80211_IFTYPE_P2P_CLIENT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003416 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003417 wdev->iftype = NL80211_IFTYPE_STATION;
3418
3419
3420
3421 PRINT_INFO(CFG80211_DBG, "Max scan ids = %d,Max scan IE len = %d,Signal Type = %d,Interface Modes = %d,Interface Type = %d\n",
3422 wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type,
3423 wdev->wiphy->interface_modes, wdev->iftype);
3424
3425 #ifdef WILC_SDIO
Chaehyun Limcdc9cba2015-09-22 18:34:47 +09003426 set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003427 #endif
3428
3429 /*Register wiphy structure*/
3430 s32Error = wiphy_register(wdev->wiphy);
3431 if (s32Error) {
3432 PRINT_ER("Cannot register wiphy device\n");
3433 /*should define what action to be taken in such failure*/
3434 } else {
3435 PRINT_D(CFG80211_DBG, "Successful Registering\n");
3436 }
3437
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003438 priv->dev = net;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003439 return wdev;
3440
3441
3442}
3443/**
3444 * @brief WILC_WFI_WiphyFree
3445 * @details Freeing allocation of the wireless device structure
3446 * @param[in] NONE
3447 * @return NONE
3448 * @author mdaftedar
3449 * @date 01 MAR 2012
3450 * @version 1.0
3451 */
Chaehyun Limdd4b6a82015-09-20 15:51:25 +09003452int wilc_init_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003453{
3454
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003455 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003456
Chaehyun Lim27268872015-09-15 14:06:13 +09003457 struct wilc_priv *priv;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003458
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003459 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3460 priv = wdev_priv(net->ieee80211_ptr);
3461 if (op_ifcs == 0) {
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003462 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
Greg Kroah-Hartman93dee8e2015-08-14 20:28:32 -07003463 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003464 }
3465 op_ifcs++;
3466 if (s32Error < 0) {
3467 PRINT_ER("Failed to creat refresh Timer\n");
3468 return s32Error;
3469 }
3470
Dean Lee72ed4dc2015-06-12 14:11:44 +09003471 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003472
Dean Lee72ed4dc2015-06-12 14:11:44 +09003473 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003474
Arnd Bergmann83383ea2015-06-01 21:06:43 +02003475 sema_init(&(priv->hSemScanReq), 1);
Glen Leed53822192015-10-27 18:27:49 +09003476 s32Error = host_int_init(net, &priv->hWILCWFIDrv);
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003477 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003478 PRINT_ER("Error while initializing hostinterface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003479
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003480 return s32Error;
3481}
3482
3483/**
3484 * @brief WILC_WFI_WiphyFree
3485 * @details Freeing allocation of the wireless device structure
3486 * @param[in] NONE
3487 * @return NONE
3488 * @author mdaftedar
3489 * @date 01 MAR 2012
3490 * @version 1.0
3491 */
Chaehyun Lima9a16822015-09-20 15:51:24 +09003492int wilc_deinit_host_int(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003493{
Chaehyun Lim1a8ccd82015-09-20 15:51:23 +09003494 int s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003495
Chaehyun Lim27268872015-09-15 14:06:13 +09003496 struct wilc_priv *priv;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09003497
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003498 priv = wdev_priv(net->ieee80211_ptr);
3499
Dean Lee72ed4dc2015-06-12 14:11:44 +09003500 priv->gbAutoRateAdjusted = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003501
Dean Lee72ed4dc2015-06-12 14:11:44 +09003502 priv->bInP2PlistenState = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003503
3504 op_ifcs--;
3505
3506 s32Error = host_int_deinit(priv->hWILCWFIDrv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003507
3508 /* Clear the Shadow scan */
3509 clear_shadow_scan(priv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003510 if (op_ifcs == 0) {
3511 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
Greg Kroah-Hartman4183e972015-08-14 20:11:16 -07003512 del_timer_sync(&hDuringIpTimer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003513 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003514
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003515 if (s32Error)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003516 PRINT_ER("Error while deintializing host interface\n");
Chaehyun Limf1fe9c42015-09-20 15:51:22 +09003517
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003518 return s32Error;
3519}
3520
3521
3522/**
3523 * @brief WILC_WFI_WiphyFree
3524 * @details Freeing allocation of the wireless device structure
3525 * @param[in] NONE
3526 * @return NONE
3527 * @author mdaftedar
3528 * @date 01 MAR 2012
3529 * @version 1.0
3530 */
Chaehyun Lim96da20a2015-09-20 15:51:08 +09003531void wilc_free_wiphy(struct net_device *net)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003532{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003533 PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
3534
Chaehyun Lim619837a2015-09-20 15:51:10 +09003535 if (!net) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003536 PRINT_D(INIT_DBG, "net_device is NULL\n");
3537 return;
3538 }
3539
Chaehyun Lim619837a2015-09-20 15:51:10 +09003540 if (!net->ieee80211_ptr) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003541 PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
3542 return;
3543 }
3544
Chaehyun Lim619837a2015-09-20 15:51:10 +09003545 if (!net->ieee80211_ptr->wiphy) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003546 PRINT_D(INIT_DBG, "wiphy is NULL\n");
3547 return;
3548 }
3549
3550 wiphy_unregister(net->ieee80211_ptr->wiphy);
3551
3552 PRINT_D(INIT_DBG, "Freeing wiphy\n");
3553 wiphy_free(net->ieee80211_ptr->wiphy);
3554 kfree(net->ieee80211_ptr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09003555}