blob: 7d865cf7f3415851713ebf15c70ee3043da5e60a [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam842dad02014-02-18 18:44:02 -08002 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
Kiet Lamaa8e15a2014-02-11 23:30:06 -080023 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
24 * All Rights Reserved.
25 * Qualcomm Atheros Confidential and Proprietary.
Kiet Lam842dad02014-02-18 18:44:02 -080026 *
Kiet Lamaa8e15a2014-02-11 23:30:06 -080027 */
Kiet Lam842dad02014-02-18 18:44:02 -080028
29
Jeff Johnson295189b2012-06-20 16:38:30 -070030/**========================================================================
31
32 \file wlan_hdd_cfg80211.c
33
34 \brief WLAN Host Device Driver implementation
35
Jeff Johnson295189b2012-06-20 16:38:30 -070036 ========================================================================*/
37
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070038/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070039
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070040 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 This section contains comments describing changes made to the module.
44 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070045
46
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070047 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070048
49
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070050 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070051 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070052 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070053
54 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070055 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070056 ==========================================================================*/
57
Jeff Johnson295189b2012-06-20 16:38:30 -070058
59#include <linux/version.h>
60#include <linux/module.h>
61#include <linux/kernel.h>
62#include <linux/init.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_includes.h>
65#include <net/arp.h>
66#include <net/cfg80211.h>
67#include <linux/wireless.h>
68#include <wlan_hdd_wowl.h>
69#include <aniGlobal.h>
70#include "ccmApi.h"
71#include "sirParams.h"
72#include "dot11f.h"
73#include "wlan_hdd_assoc.h"
74#include "wlan_hdd_wext.h"
75#include "sme_Api.h"
76#include "wlan_hdd_p2p.h"
77#include "wlan_hdd_cfg80211.h"
78#include "wlan_hdd_hostapd.h"
79#include "sapInternal.h"
80#include "wlan_hdd_softap_tx_rx.h"
81#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053082#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053083#include "wlan_hdd_power.h"
Sushant Kaushik4b7cb302014-01-06 17:45:01 +053084#include "wlan_hdd_trace.h"
85#include "vos_types.h"
86#include "vos_trace.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070087#ifdef WLAN_BTAMP_FEATURE
88#include "bap_hdd_misc.h"
89#endif
90#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080091#ifdef FEATURE_WLAN_TDLS
92#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053093#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053094#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080095#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053096#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070097#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070098
99#define g_mode_rates_size (12)
100#define a_mode_rates_size (8)
101#define FREQ_BASE_80211G (2407)
102#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700103#define MAX_SCAN_SSID 9
Kiet Lamac06e2c2013-10-23 16:25:07 +0530104#define MAX_PENDING_LOG 5
Jeff Johnson295189b2012-06-20 16:38:30 -0700105#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
krunal soni2a6a9062014-02-11 14:14:23 -0800106 ((uintptr_t)OFFSET_OF( tSirBssDescription, ieFields)))
Jeff Johnson295189b2012-06-20 16:38:30 -0700107
108#define HDD2GHZCHAN(freq, chan, flag) { \
109 .band = IEEE80211_BAND_2GHZ, \
110 .center_freq = (freq), \
111 .hw_value = (chan),\
112 .flags = (flag), \
113 .max_antenna_gain = 0 ,\
114 .max_power = 30, \
115}
116
117#define HDD5GHZCHAN(freq, chan, flag) { \
118 .band = IEEE80211_BAND_5GHZ, \
119 .center_freq = (freq), \
120 .hw_value = (chan),\
121 .flags = (flag), \
122 .max_antenna_gain = 0 ,\
123 .max_power = 30, \
124}
125
126#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
127{\
128 .bitrate = rate, \
129 .hw_value = rate_id, \
130 .flags = flag, \
131}
132
Lee Hoonkic1262f22013-01-24 21:59:00 -0800133#ifndef WLAN_FEATURE_TDLS_DEBUG
134#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
135#else
136#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
137#endif
138
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530139#ifdef WLAN_FEATURE_VOWIFI_11R
140#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
141#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
142#endif
143
Naresh Jayaram3180aa42014-02-12 21:47:26 +0530144#define HDD_CHANNEL_14 14
145
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530146static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700147{
148 WLAN_CIPHER_SUITE_WEP40,
149 WLAN_CIPHER_SUITE_WEP104,
150 WLAN_CIPHER_SUITE_TKIP,
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800151#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -0700152#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
153 WLAN_CIPHER_SUITE_KRK,
154 WLAN_CIPHER_SUITE_CCMP,
155#else
156 WLAN_CIPHER_SUITE_CCMP,
157#endif
158#ifdef FEATURE_WLAN_WAPI
159 WLAN_CIPHER_SUITE_SMS4,
160#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700161#ifdef WLAN_FEATURE_11W
162 WLAN_CIPHER_SUITE_AES_CMAC,
163#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700164};
165
166static inline int is_broadcast_ether_addr(const u8 *addr)
167{
168 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
169 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
170}
171
172static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530173{
Jeff Johnson295189b2012-06-20 16:38:30 -0700174 HDD2GHZCHAN(2412, 1, 0) ,
175 HDD2GHZCHAN(2417, 2, 0) ,
176 HDD2GHZCHAN(2422, 3, 0) ,
177 HDD2GHZCHAN(2427, 4, 0) ,
178 HDD2GHZCHAN(2432, 5, 0) ,
179 HDD2GHZCHAN(2437, 6, 0) ,
180 HDD2GHZCHAN(2442, 7, 0) ,
181 HDD2GHZCHAN(2447, 8, 0) ,
182 HDD2GHZCHAN(2452, 9, 0) ,
183 HDD2GHZCHAN(2457, 10, 0) ,
184 HDD2GHZCHAN(2462, 11, 0) ,
185 HDD2GHZCHAN(2467, 12, 0) ,
186 HDD2GHZCHAN(2472, 13, 0) ,
187 HDD2GHZCHAN(2484, 14, 0) ,
188};
189
Jeff Johnson295189b2012-06-20 16:38:30 -0700190static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
191{
192 HDD2GHZCHAN(2412, 1, 0) ,
193 HDD2GHZCHAN(2437, 6, 0) ,
194 HDD2GHZCHAN(2462, 11, 0) ,
195};
Jeff Johnson295189b2012-06-20 16:38:30 -0700196
197static struct ieee80211_channel hdd_channels_5_GHZ[] =
198{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700199 HDD5GHZCHAN(4920, 240, 0) ,
200 HDD5GHZCHAN(4940, 244, 0) ,
201 HDD5GHZCHAN(4960, 248, 0) ,
202 HDD5GHZCHAN(4980, 252, 0) ,
203 HDD5GHZCHAN(5040, 208, 0) ,
204 HDD5GHZCHAN(5060, 212, 0) ,
205 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700206 HDD5GHZCHAN(5180, 36, 0) ,
207 HDD5GHZCHAN(5200, 40, 0) ,
208 HDD5GHZCHAN(5220, 44, 0) ,
209 HDD5GHZCHAN(5240, 48, 0) ,
210 HDD5GHZCHAN(5260, 52, 0) ,
211 HDD5GHZCHAN(5280, 56, 0) ,
212 HDD5GHZCHAN(5300, 60, 0) ,
213 HDD5GHZCHAN(5320, 64, 0) ,
214 HDD5GHZCHAN(5500,100, 0) ,
215 HDD5GHZCHAN(5520,104, 0) ,
216 HDD5GHZCHAN(5540,108, 0) ,
217 HDD5GHZCHAN(5560,112, 0) ,
218 HDD5GHZCHAN(5580,116, 0) ,
219 HDD5GHZCHAN(5600,120, 0) ,
220 HDD5GHZCHAN(5620,124, 0) ,
221 HDD5GHZCHAN(5640,128, 0) ,
222 HDD5GHZCHAN(5660,132, 0) ,
223 HDD5GHZCHAN(5680,136, 0) ,
224 HDD5GHZCHAN(5700,140, 0) ,
Leo Chang80de3c22013-11-26 10:52:12 -0800225#ifdef FEATURE_WLAN_CH144
226 HDD5GHZCHAN(5720,144, 0) ,
227#endif /* FEATURE_WLAN_CH144 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700228 HDD5GHZCHAN(5745,149, 0) ,
229 HDD5GHZCHAN(5765,153, 0) ,
230 HDD5GHZCHAN(5785,157, 0) ,
231 HDD5GHZCHAN(5805,161, 0) ,
232 HDD5GHZCHAN(5825,165, 0) ,
233};
234
235static struct ieee80211_rate g_mode_rates[] =
236{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530237 HDD_G_MODE_RATETAB(10, 0x1, 0),
238 HDD_G_MODE_RATETAB(20, 0x2, 0),
239 HDD_G_MODE_RATETAB(55, 0x4, 0),
240 HDD_G_MODE_RATETAB(110, 0x8, 0),
241 HDD_G_MODE_RATETAB(60, 0x10, 0),
242 HDD_G_MODE_RATETAB(90, 0x20, 0),
243 HDD_G_MODE_RATETAB(120, 0x40, 0),
244 HDD_G_MODE_RATETAB(180, 0x80, 0),
245 HDD_G_MODE_RATETAB(240, 0x100, 0),
246 HDD_G_MODE_RATETAB(360, 0x200, 0),
247 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700248 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530249};
Jeff Johnson295189b2012-06-20 16:38:30 -0700250
251static struct ieee80211_rate a_mode_rates[] =
252{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530253 HDD_G_MODE_RATETAB(60, 0x10, 0),
254 HDD_G_MODE_RATETAB(90, 0x20, 0),
255 HDD_G_MODE_RATETAB(120, 0x40, 0),
256 HDD_G_MODE_RATETAB(180, 0x80, 0),
257 HDD_G_MODE_RATETAB(240, 0x100, 0),
258 HDD_G_MODE_RATETAB(360, 0x200, 0),
259 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700260 HDD_G_MODE_RATETAB(540, 0x800, 0),
261};
262
263static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
264{
265 .channels = hdd_channels_2_4_GHZ,
266 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
267 .band = IEEE80211_BAND_2GHZ,
268 .bitrates = g_mode_rates,
269 .n_bitrates = g_mode_rates_size,
270 .ht_cap.ht_supported = 1,
271 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
272 | IEEE80211_HT_CAP_GRN_FLD
273 | IEEE80211_HT_CAP_DSSSCCK40
274 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
275 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
276 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
277 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
278 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
279 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
280};
281
Jeff Johnson295189b2012-06-20 16:38:30 -0700282static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
283{
284 .channels = hdd_social_channels_2_4_GHZ,
285 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
286 .band = IEEE80211_BAND_2GHZ,
287 .bitrates = g_mode_rates,
288 .n_bitrates = g_mode_rates_size,
289 .ht_cap.ht_supported = 1,
290 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
291 | IEEE80211_HT_CAP_GRN_FLD
292 | IEEE80211_HT_CAP_DSSSCCK40
293 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
294 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
295 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
296 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
297 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
298 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
299};
Jeff Johnson295189b2012-06-20 16:38:30 -0700300
301static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
302{
303 .channels = hdd_channels_5_GHZ,
304 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
305 .band = IEEE80211_BAND_5GHZ,
306 .bitrates = a_mode_rates,
307 .n_bitrates = a_mode_rates_size,
308 .ht_cap.ht_supported = 1,
309 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
310 | IEEE80211_HT_CAP_GRN_FLD
311 | IEEE80211_HT_CAP_DSSSCCK40
312 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
313 | IEEE80211_HT_CAP_SGI_40
314 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
315 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
316 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
317 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
318 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
319 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
320};
321
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530322/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700323 TX/RX direction for each kind of interface */
324static const struct ieee80211_txrx_stypes
325wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
326 [NL80211_IFTYPE_STATION] = {
327 .tx = 0xffff,
328 .rx = BIT(SIR_MAC_MGMT_ACTION) |
329 BIT(SIR_MAC_MGMT_PROBE_REQ),
330 },
331 [NL80211_IFTYPE_AP] = {
332 .tx = 0xffff,
333 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
334 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
335 BIT(SIR_MAC_MGMT_PROBE_REQ) |
336 BIT(SIR_MAC_MGMT_DISASSOC) |
337 BIT(SIR_MAC_MGMT_AUTH) |
338 BIT(SIR_MAC_MGMT_DEAUTH) |
339 BIT(SIR_MAC_MGMT_ACTION),
340 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700341 [NL80211_IFTYPE_ADHOC] = {
342 .tx = 0xffff,
343 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
344 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
345 BIT(SIR_MAC_MGMT_PROBE_REQ) |
346 BIT(SIR_MAC_MGMT_DISASSOC) |
347 BIT(SIR_MAC_MGMT_AUTH) |
348 BIT(SIR_MAC_MGMT_DEAUTH) |
349 BIT(SIR_MAC_MGMT_ACTION),
350 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700351 [NL80211_IFTYPE_P2P_CLIENT] = {
352 .tx = 0xffff,
353 .rx = BIT(SIR_MAC_MGMT_ACTION) |
354 BIT(SIR_MAC_MGMT_PROBE_REQ),
355 },
356 [NL80211_IFTYPE_P2P_GO] = {
357 /* This is also same as for SoftAP */
358 .tx = 0xffff,
359 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
360 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
361 BIT(SIR_MAC_MGMT_PROBE_REQ) |
362 BIT(SIR_MAC_MGMT_DISASSOC) |
363 BIT(SIR_MAC_MGMT_AUTH) |
364 BIT(SIR_MAC_MGMT_DEAUTH) |
365 BIT(SIR_MAC_MGMT_ACTION),
366 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700367};
368
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800369#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800370static const struct ieee80211_iface_limit
371wlan_hdd_iface_limit[] = {
372 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800373 /* max = 3 ; Our driver create two interfaces during driver init
374 * wlan0 and p2p0 interfaces. p2p0 is considered as station
375 * interface until a group is formed. In JB architecture, once the
376 * group is formed, interface type of p2p0 is changed to P2P GO or
377 * Client.
378 * When supplicant remove the group, it first issue a set interface
379 * cmd to change the mode back to Station. In JB this works fine as
380 * we advertize two station type interface during driver init.
381 * Some vendors create separate interface for P2P GO/Client,
382 * after group formation(Third one). But while group remove
383 * supplicant first tries to change the mode(3rd interface) to STATION
384 * But as we advertized only two sta type interfaces nl80211 was
385 * returning error for the third one which was leading to failure in
386 * delete interface. Ideally while removing the group, supplicant
387 * should not try to change the 3rd interface mode to Station type.
388 * Till we get a fix in wpa_supplicant, we advertize max STA
389 * interface type to 3
390 */
391 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800392 .types = BIT(NL80211_IFTYPE_STATION),
393 },
394 {
395 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700396 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800397 },
398 {
399 .max = 1,
400 .types = BIT(NL80211_IFTYPE_P2P_GO) |
401 BIT(NL80211_IFTYPE_P2P_CLIENT),
402 },
403};
404
405/* By default, only single channel concurrency is allowed */
406static struct ieee80211_iface_combination
407wlan_hdd_iface_combination = {
408 .limits = wlan_hdd_iface_limit,
409 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800410 /*
411 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
412 * and p2p0 interfaces during driver init
413 * Some vendors create separate interface for P2P operations.
414 * wlan0: STA interface
415 * p2p0: P2P Device interface, action frames goes
416 * through this interface.
417 * p2p-xx: P2P interface, After GO negotiation this interface is
418 * created for p2p operations(GO/CLIENT interface).
419 */
420 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800421 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
422 .beacon_int_infra_match = false,
423};
424#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800425
Jeff Johnson295189b2012-06-20 16:38:30 -0700426static struct cfg80211_ops wlan_hdd_cfg80211_ops;
427
428/* Data rate 100KBPS based on IE Index */
429struct index_data_rate_type
430{
431 v_U8_t beacon_rate_index;
432 v_U16_t supported_rate[4];
433};
434
435/* 11B, 11G Rate table include Basic rate and Extended rate
436 The IDX field is the rate index
437 The HI field is the rate when RSSI is strong or being ignored
438 (in this case we report actual rate)
439 The MID field is the rate when RSSI is moderate
440 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
441 The LO field is the rate when RSSI is low
442 (in this case we don't report rates, actual current rate used)
443 */
444static const struct
445{
446 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700447 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700448} supported_data_rate[] =
449{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700450/* IDX HI HM LM LO (RSSI-based index */
451 {2, { 10, 10, 10, 0}},
452 {4, { 20, 20, 10, 0}},
453 {11, { 55, 20, 10, 0}},
454 {12, { 60, 55, 20, 0}},
455 {18, { 90, 55, 20, 0}},
456 {22, {110, 55, 20, 0}},
457 {24, {120, 90, 60, 0}},
458 {36, {180, 120, 60, 0}},
459 {44, {220, 180, 60, 0}},
460 {48, {240, 180, 90, 0}},
461 {66, {330, 180, 90, 0}},
462 {72, {360, 240, 90, 0}},
463 {96, {480, 240, 120, 0}},
464 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700465};
466
467/* MCS Based rate table */
468static struct index_data_rate_type supported_mcs_rate[] =
469{
470/* MCS L20 L40 S20 S40 */
471 {0, {65, 135, 72, 150}},
472 {1, {130, 270, 144, 300}},
473 {2, {195, 405, 217, 450}},
474 {3, {260, 540, 289, 600}},
475 {4, {390, 810, 433, 900}},
476 {5, {520, 1080, 578, 1200}},
477 {6, {585, 1215, 650, 1350}},
478 {7, {650, 1350, 722, 1500}}
479};
480
Leo Chang6f8870f2013-03-26 18:11:36 -0700481#ifdef WLAN_FEATURE_11AC
482
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530483#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700484
485struct index_vht_data_rate_type
486{
487 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530488 v_U16_t supported_VHT80_rate[2];
489 v_U16_t supported_VHT40_rate[2];
490 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700491};
492
493typedef enum
494{
495 DATA_RATE_11AC_MAX_MCS_7,
496 DATA_RATE_11AC_MAX_MCS_8,
497 DATA_RATE_11AC_MAX_MCS_9,
498 DATA_RATE_11AC_MAX_MCS_NA
499} eDataRate11ACMaxMcs;
500
501/* MCS Based VHT rate table */
502static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
503{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530504/* MCS L80 S80 L40 S40 L20 S40*/
505 {0, {293, 325}, {135, 150}, {65, 72}},
506 {1, {585, 650}, {270, 300}, {130, 144}},
507 {2, {878, 975}, {405, 450}, {195, 217}},
508 {3, {1170, 1300}, {540, 600}, {260, 289}},
509 {4, {1755, 1950}, {810, 900}, {390, 433}},
510 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
511 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
512 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
513 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
514 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700515};
516#endif /* WLAN_FEATURE_11AC */
517
Jeff Johnson295189b2012-06-20 16:38:30 -0700518extern struct net_device_ops net_ops_struct;
519
Leo Chang9056f462013-08-01 19:21:11 -0700520#ifdef WLAN_NL80211_TESTMODE
521enum wlan_hdd_tm_attr
522{
523 WLAN_HDD_TM_ATTR_INVALID = 0,
524 WLAN_HDD_TM_ATTR_CMD = 1,
525 WLAN_HDD_TM_ATTR_DATA = 2,
526 WLAN_HDD_TM_ATTR_TYPE = 3,
527 /* keep last */
528 WLAN_HDD_TM_ATTR_AFTER_LAST,
529 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
530};
531
532enum wlan_hdd_tm_cmd
533{
534 WLAN_HDD_TM_CMD_WLAN_HB = 1,
535};
536
537#define WLAN_HDD_TM_DATA_MAX_LEN 5000
538
539static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
540{
541 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
542 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
543 .len = WLAN_HDD_TM_DATA_MAX_LEN },
544};
545#endif /* WLAN_NL80211_TESTMODE */
546
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800547#ifdef FEATURE_WLAN_CH_AVOID
548/*
549 * FUNCTION: wlan_hdd_send_avoid_freq_event
550 * This is called when wlan driver needs to send vendor specific
551 * avoid frequency range event to userspace
552 */
553int wlan_hdd_send_avoid_freq_event(hdd_context_t *pHddCtx,
554 tHddAvoidFreqList *pAvoidFreqList)
555{
556 struct sk_buff *vendor_event;
557
558 ENTER();
559
560 if (!pHddCtx)
561 {
562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
563 "%s: HDD context is null", __func__);
564 return -1;
565 }
566
567 if (!pAvoidFreqList)
568 {
569 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
570 "%s: pAvoidFreqList is null", __func__);
571 return -1;
572 }
573
574 vendor_event = cfg80211_vendor_event_alloc(pHddCtx->wiphy,
575 sizeof(tHddAvoidFreqList),
576 QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX,
577 GFP_KERNEL);
578 if (!vendor_event)
579 {
580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
581 "%s: cfg80211_vendor_event_alloc failed", __func__);
582 return -1;
583 }
584
585 memcpy(skb_put(vendor_event, sizeof(tHddAvoidFreqList)),
586 (void *)pAvoidFreqList, sizeof(tHddAvoidFreqList));
587
588 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
589
590 EXIT();
591 return 0;
592}
593#endif /* FEATURE_WLAN_CH_AVOID */
594
595/* vendor specific events */
596static const struct nl80211_vendor_cmd_info wlan_hdd_cfg80211_vendor_events[] =
597{
598#ifdef FEATURE_WLAN_CH_AVOID
599 {
600 .vendor_id = QCOM_NL80211_VENDOR_ID,
601 .subcmd = QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY
602 },
603#endif /* FEATURE_WLAN_CH_AVOID */
604};
605
Jeff Johnson295189b2012-06-20 16:38:30 -0700606/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530607 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530608 * This function is called by hdd_wlan_startup()
609 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530610 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700611 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530612struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700613{
614 struct wiphy *wiphy;
615 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530616 /*
617 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700618 */
619 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
620
621 if (!wiphy)
622 {
623 /* Print error and jump into err label and free the memory */
624 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
625 return NULL;
626 }
627
628 return wiphy;
629}
630
631/*
632 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530633 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700634 * private ioctl to change the band value
635 */
636int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
637{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530638 int i, j;
639 eNVChannelEnabledType channelEnabledState;
640
Jeff Johnsone7245742012-09-05 17:12:55 -0700641 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +0530642
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530643 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700644 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530645
646 if (NULL == wiphy->bands[i])
647 {
648 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
649 __func__, i);
650 continue;
651 }
652
653 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
654 {
655 struct ieee80211_supported_band *band = wiphy->bands[i];
656
657 channelEnabledState = vos_nv_getChannelEnabledState(
658 band->channels[j].hw_value);
659
660 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
661 {
662 // Enable Social channels for P2P
663 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
664 NV_CHANNEL_ENABLE == channelEnabledState)
665 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
666 else
667 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
668 continue;
669 }
670 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
671 {
672 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
673 continue;
674 }
675
676 if (NV_CHANNEL_DISABLE == channelEnabledState ||
677 NV_CHANNEL_INVALID == channelEnabledState)
678 {
679 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
680 }
681 else if (NV_CHANNEL_DFS == channelEnabledState)
682 {
683 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
684 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
685 }
686 else
687 {
688 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
689 |IEEE80211_CHAN_RADAR);
690 }
691 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700692 }
693 return 0;
694}
695/*
696 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530697 * This function is called by hdd_wlan_startup()
698 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700699 * This function is used to initialize and register wiphy structure.
700 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530701int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 struct wiphy *wiphy,
703 hdd_config_t *pCfg
704 )
705{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530706 int i, j;
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +0530707 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
708
Jeff Johnsone7245742012-09-05 17:12:55 -0700709 ENTER();
710
Jeff Johnson295189b2012-06-20 16:38:30 -0700711 /* Now bind the underlying wlan device with wiphy */
712 set_wiphy_dev(wiphy, dev);
713
714 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700715
Kiet Lam6c583332013-10-14 05:37:09 +0530716#ifndef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -0700717 /* the flag for the other case would be initialzed in
718 vos_init_wiphy_from_nv_bin */
Amar Singhal0a402232013-10-11 20:57:16 -0700719 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
Kiet Lam6c583332013-10-14 05:37:09 +0530720#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700721
Amar Singhalfddc28c2013-09-05 13:03:40 -0700722 /* This will disable updating of NL channels from passive to
723 * active if a beacon is received on passive channel. */
724 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700725
Amar Singhalfddc28c2013-09-05 13:03:40 -0700726
Amar Singhala49cbc52013-10-08 18:37:44 -0700727
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700728#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700729 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
730 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
731 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700732 | WIPHY_FLAG_OFFCHAN_TX;
Kiet Lam6c583332013-10-14 05:37:09 +0530733 wiphy->country_ie_pref = NL80211_COUNTRY_IE_IGNORE_CORE;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700734#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700735
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800736#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700737 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800738#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700739 || pCfg->isFastRoamIniFeatureEnabled
740#endif
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -0800741#ifdef FEATURE_WLAN_ESE
742 || pCfg->isEseIniFeatureEnabled
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700743#endif
744 )
745 {
746 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
747 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800748#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800749#ifdef FEATURE_WLAN_TDLS
750 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
751 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
752#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530753#ifdef FEATURE_WLAN_SCAN_PNO
Hardik Kantilal Patel3dfd8792013-11-13 20:34:57 +0530754 if (pCfg->configPNOScanSupport)
755 {
756 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
757 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
758 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
759 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
760 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530761#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800762
Amar Singhalfddc28c2013-09-05 13:03:40 -0700763#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700764 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
765 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700766 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700767 driver need to determine what to do with both
768 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700769
770 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700771#else
772 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700773#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700774
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530775 wiphy->max_scan_ssids = MAX_SCAN_SSID;
776
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530777 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700778
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530779 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
780
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530782 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700783 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700784 | BIT(NL80211_IFTYPE_P2P_CLIENT)
785 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700786 | BIT(NL80211_IFTYPE_AP);
787
Rashmi Ramannabd3feb72014-02-25 16:14:48 +0530788 if( pCfg->advertiseConcurrentOperation )
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800789 {
Rashmi Ramannabd3feb72014-02-25 16:14:48 +0530790#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
791 if( pCfg->enableMCC )
792 {
793 /* Currently, supports up to two channels */
794 wlan_hdd_iface_combination.num_different_channels = 2;
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800795
Rashmi Ramannabd3feb72014-02-25 16:14:48 +0530796 if( !pCfg->allowMCCGODiffBI )
797 wlan_hdd_iface_combination.beacon_int_infra_match = true;
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800798
Rashmi Ramannabd3feb72014-02-25 16:14:48 +0530799 }
800 wiphy->iface_combinations = &wlan_hdd_iface_combination;
801 wiphy->n_iface_combinations = 1;
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800802#endif
Rashmi Ramannabd3feb72014-02-25 16:14:48 +0530803 }
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800804
Jeff Johnson295189b2012-06-20 16:38:30 -0700805 /* Before registering we need to update the ht capabilitied based
806 * on ini values*/
807 if( !pCfg->ShortGI20MhzEnable )
808 {
809 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
810 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
811 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
812 }
813
814 if( !pCfg->ShortGI40MhzEnable )
815 {
816 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
817 }
818
819 if( !pCfg->nChannelBondingMode5GHz )
820 {
821 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
822 }
823
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530824 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
Vinay Krishna Erannafacf5e22014-02-24 13:16:25 +0530825 if (true == hdd_is_5g_supported(pHddCtx))
826 {
827 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
828 }
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530829
830 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
831 {
832
833 if (NULL == wiphy->bands[i])
834 {
835 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
836 __func__, i);
837 continue;
838 }
839
840 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
841 {
842 struct ieee80211_supported_band *band = wiphy->bands[i];
843
844 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
845 {
846 // Enable social channels for P2P
847 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
848 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
849 else
850 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
851 continue;
852 }
853 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
854 {
855 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
856 continue;
857 }
858 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700859 }
860 /*Initialise the supported cipher suite details*/
861 wiphy->cipher_suites = hdd_cipher_suites;
862 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
863
864 /*signal strength in mBm (100*dBm) */
865 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
866
867#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700868 wiphy->max_remain_on_channel_duration = 1000;
869#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700870
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800871 wiphy->n_vendor_commands = 0;
872 wiphy->vendor_events = wlan_hdd_cfg80211_vendor_events;
873 wiphy->n_vendor_events = ARRAY_SIZE(wlan_hdd_cfg80211_vendor_events);
874
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530875 EXIT();
876 return 0;
877}
878
879/* In this function we are registering wiphy. */
880int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
881{
882 ENTER();
883 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700884 if (0 > wiphy_register(wiphy))
885 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530886 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700887 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
888 return -EIO;
889 }
890
891 EXIT();
892 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530893}
Jeff Johnson295189b2012-06-20 16:38:30 -0700894
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530895/* In this function we are updating channel list when,
896 regulatory domain is FCC and country code is US.
897 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
898 As per FCC smart phone is not a indoor device.
899 GO should not opeate on indoor channels */
900void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
901{
902 int j;
903 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
904 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
905 //Default counrtycode from NV at the time of wiphy initialization.
906 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
907 &defaultCountryCode[0]))
908 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -0700909 hddLog(LOGE, FL("Failed to get default country code from NV"));
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530910 }
911 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
912 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530913 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
914 {
915 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
916 return;
917 }
918 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
919 {
920 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
921 // Mark UNII -1 band channel as passive
922 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
923 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
924 }
925 }
926}
927
Jeff Johnson295189b2012-06-20 16:38:30 -0700928/* In this function we will do all post VOS start initialization.
929 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530930 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700931*/
932void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
933{
Jeff Johnson295189b2012-06-20 16:38:30 -0700934 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
935 /* Register for all P2P action, public action etc frames */
936 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
937
Jeff Johnsone7245742012-09-05 17:12:55 -0700938 ENTER();
939
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 /* Right now we are registering these frame when driver is getting
941 initialized. Once we will move to 2.6.37 kernel, in which we have
942 frame register ops, we will move this code as a part of that */
943 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530944 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
946
947 /* GAS Initial Response */
948 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
949 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530950
Jeff Johnson295189b2012-06-20 16:38:30 -0700951 /* GAS Comeback Request */
952 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
953 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
954
955 /* GAS Comeback Response */
956 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
957 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
958
959 /* P2P Public Action */
960 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530961 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700962 P2P_PUBLIC_ACTION_FRAME_SIZE );
963
964 /* P2P Action */
965 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
966 (v_U8_t*)P2P_ACTION_FRAME,
967 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700968
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530969 /* WNM BSS Transition Request frame */
970 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
971 (v_U8_t*)WNM_BSS_ACTION_FRAME,
972 WNM_BSS_ACTION_FRAME_SIZE );
Jeff Johnson295189b2012-06-20 16:38:30 -0700973}
974
975void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
976{
Jeff Johnson295189b2012-06-20 16:38:30 -0700977 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
978 /* Register for all P2P action, public action etc frames */
979 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
980
Jeff Johnsone7245742012-09-05 17:12:55 -0700981 ENTER();
982
Jeff Johnson295189b2012-06-20 16:38:30 -0700983 /* Right now we are registering these frame when driver is getting
984 initialized. Once we will move to 2.6.37 kernel, in which we have
985 frame register ops, we will move this code as a part of that */
986 /* GAS Initial Request */
987
988 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
989 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
990
991 /* GAS Initial Response */
992 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
993 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530994
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 /* GAS Comeback Request */
996 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
997 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
998
999 /* GAS Comeback Response */
1000 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1001 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
1002
1003 /* P2P Public Action */
1004 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301005 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 P2P_PUBLIC_ACTION_FRAME_SIZE );
1007
1008 /* P2P Action */
1009 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1010 (v_U8_t*)P2P_ACTION_FRAME,
1011 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -07001012
1013#ifdef WLAN_FEATURE_11W
1014 /* SA Query Response Action Frame */
1015 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1016 (v_U8_t*)SA_QUERY_FRAME_RSP,
1017 SA_QUERY_FRAME_RSP_SIZE );
1018#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -07001019}
1020
1021#ifdef FEATURE_WLAN_WAPI
1022void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
1023 const u8 *mac_addr, u8 *key , int key_Len)
1024{
1025 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1026 tCsrRoamSetKey setKey;
1027 v_BOOL_t isConnected = TRUE;
1028 int status = 0;
1029 v_U32_t roamId= 0xFF;
1030 tANI_U8 *pKeyPtr = NULL;
1031 int n = 0;
1032
Arif Hussain6d2a3322013-11-17 19:50:10 -08001033 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07001034 __func__,pAdapter->device_mode);
1035
Gopichand Nakkalae7480202013-02-11 15:24:22 +05301036 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07001037 setKey.keyId = key_index; // Store Key ID
1038 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
1039 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
1040 setKey.paeRole = 0 ; // the PAE role
1041 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
1042 {
1043 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
1044 }
1045 else
1046 {
1047 isConnected = hdd_connIsConnected(pHddStaCtx);
1048 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
1049 }
1050 setKey.keyLength = key_Len;
1051 pKeyPtr = setKey.Key;
1052 memcpy( pKeyPtr, key, key_Len);
1053
Arif Hussain6d2a3322013-11-17 19:50:10 -08001054 hddLog(VOS_TRACE_LEVEL_INFO,"%s: WAPI KEY LENGTH:0x%04x",
Jeff Johnson295189b2012-06-20 16:38:30 -07001055 __func__, key_Len);
1056 for (n = 0 ; n < key_Len; n++)
1057 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
1058 __func__,n,setKey.Key[n]);
1059
1060 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
1061 if ( isConnected )
1062 {
1063 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
1064 pAdapter->sessionId, &setKey, &roamId );
1065 }
1066 if ( status != 0 )
1067 {
1068 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1069 "[%4d] sme_RoamSetKey returned ERROR status= %d",
1070 __LINE__, status );
1071 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
1072 }
1073}
1074#endif /* FEATURE_WLAN_WAPI*/
1075
1076#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301077int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07001078 beacon_data_t **ppBeacon,
1079 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001080#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301081int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001082 beacon_data_t **ppBeacon,
1083 struct cfg80211_beacon_data *params,
1084 int dtim_period)
1085#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301086{
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 int size;
1088 beacon_data_t *beacon = NULL;
1089 beacon_data_t *old = NULL;
1090 int head_len,tail_len;
1091
Jeff Johnsone7245742012-09-05 17:12:55 -07001092 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001093 if (params->head && !params->head_len)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301094 {
1095 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1096 FL("head_len is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001097 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301098 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001099
1100 old = pAdapter->sessionCtx.ap.beacon;
1101
1102 if (!params->head && !old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301103 {
1104 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1105 FL("session(%d) old and new heads points to NULL"),
1106 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301108 }
1109
1110 if (params->tail && !params->tail_len)
1111 {
1112 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1113 FL("tail_len is zero but tail is not NULL"));
1114 return -EINVAL;
1115 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001116
Jeff Johnson295189b2012-06-20 16:38:30 -07001117#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1118 /* Kernel 3.0 is not updating dtim_period for set beacon */
1119 if (!params->dtim_period)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301120 {
1121 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1122 FL("dtim period is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001123 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301124 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001125#endif
1126
1127 if(params->head)
1128 head_len = params->head_len;
1129 else
1130 head_len = old->head_len;
1131
1132 if(params->tail || !old)
1133 tail_len = params->tail_len;
1134 else
1135 tail_len = old->tail_len;
1136
1137 size = sizeof(beacon_data_t) + head_len + tail_len;
1138
1139 beacon = kzalloc(size, GFP_KERNEL);
1140
1141 if( beacon == NULL )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301142 {
1143 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1144 FL("Mem allocation for beacon failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001145 return -ENOMEM;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301146 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001147
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001148#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001149 if(params->dtim_period || !old )
1150 beacon->dtim_period = params->dtim_period;
1151 else
1152 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001153#else
1154 if(dtim_period || !old )
1155 beacon->dtim_period = dtim_period;
1156 else
1157 beacon->dtim_period = old->dtim_period;
1158#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301159
Jeff Johnson295189b2012-06-20 16:38:30 -07001160 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1161 beacon->tail = beacon->head + head_len;
1162 beacon->head_len = head_len;
1163 beacon->tail_len = tail_len;
1164
1165 if(params->head) {
1166 memcpy (beacon->head,params->head,beacon->head_len);
1167 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301168 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001169 if(old)
1170 memcpy (beacon->head,old->head,beacon->head_len);
1171 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301172
Jeff Johnson295189b2012-06-20 16:38:30 -07001173 if(params->tail) {
1174 memcpy (beacon->tail,params->tail,beacon->tail_len);
1175 }
1176 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301177 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 memcpy (beacon->tail,old->tail,beacon->tail_len);
1179 }
1180
1181 *ppBeacon = beacon;
1182
1183 kfree(old);
1184
1185 return 0;
1186
1187}
Jeff Johnson295189b2012-06-20 16:38:30 -07001188
1189v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1190{
1191 int left = length;
1192 v_U8_t *ptr = pIes;
1193 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301194
Jeff Johnson295189b2012-06-20 16:38:30 -07001195 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301196 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001197 elem_id = ptr[0];
1198 elem_len = ptr[1];
1199 left -= 2;
1200 if(elem_len > left)
1201 {
1202 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001203 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001204 eid,elem_len,left);
1205 return NULL;
1206 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301207 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001208 {
1209 return ptr;
1210 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301211
Jeff Johnson295189b2012-06-20 16:38:30 -07001212 left -= elem_len;
1213 ptr += (elem_len + 2);
1214 }
1215 return NULL;
1216}
1217
Jeff Johnson295189b2012-06-20 16:38:30 -07001218/* Check if rate is 11g rate or not */
1219static int wlan_hdd_rate_is_11g(u8 rate)
1220{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001221 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001222 u8 i;
1223 for (i = 0; i < 8; i++)
1224 {
1225 if(rate == gRateArray[i])
1226 return TRUE;
1227 }
1228 return FALSE;
1229}
1230
1231/* Check for 11g rate and set proper 11g only mode */
1232static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1233 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1234{
1235 u8 i, num_rates = pIe[0];
1236
1237 pIe += 1;
1238 for ( i = 0; i < num_rates; i++)
1239 {
1240 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1241 {
1242 /* If rate set have 11g rate than change the mode to 11G */
1243 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1244 if (pIe[i] & BASIC_RATE_MASK)
1245 {
1246 /* If we have 11g rate as basic rate, it means mode
1247 is 11g only mode.
1248 */
1249 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1250 *pCheckRatesfor11g = FALSE;
1251 }
1252 }
1253 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1254 {
1255 *require_ht = TRUE;
1256 }
1257 }
1258 return;
1259}
1260
1261static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1262{
1263 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1264 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1265 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1266 u8 checkRatesfor11g = TRUE;
1267 u8 require_ht = FALSE;
1268 u8 *pIe=NULL;
1269
1270 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1271
1272 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1273 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1274 if (pIe != NULL)
1275 {
1276 pIe += 1;
1277 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1278 &pConfig->SapHw_mode);
1279 }
1280
1281 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1282 WLAN_EID_EXT_SUPP_RATES);
1283 if (pIe != NULL)
1284 {
1285
1286 pIe += 1;
1287 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1288 &pConfig->SapHw_mode);
1289 }
1290
1291 if( pConfig->channel > 14 )
1292 {
1293 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1294 }
1295
1296 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1297 WLAN_EID_HT_CAPABILITY);
1298
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301299 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 {
1301 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1302 if(require_ht)
1303 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1304 }
1305}
1306
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301307static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1308 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1309{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001310 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301311 v_U8_t *pIe = NULL;
1312 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1313
1314 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1315 pBeacon->tail, pBeacon->tail_len);
1316
1317 if (pIe)
1318 {
1319 ielen = pIe[1] + 2;
1320 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1321 {
1322 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1323 }
1324 else
1325 {
1326 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1327 return -EINVAL;
1328 }
1329 *total_ielen += ielen;
1330 }
1331 return 0;
1332}
1333
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001334static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1335 v_U8_t *genie, v_U8_t *total_ielen)
1336{
1337 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1338 int left = pBeacon->tail_len;
1339 v_U8_t *ptr = pBeacon->tail;
1340 v_U8_t elem_id, elem_len;
1341 v_U16_t ielen = 0;
1342
1343 if ( NULL == ptr || 0 == left )
1344 return;
1345
1346 while (left >= 2)
1347 {
1348 elem_id = ptr[0];
1349 elem_len = ptr[1];
1350 left -= 2;
1351 if (elem_len > left)
1352 {
1353 hddLog( VOS_TRACE_LEVEL_ERROR,
1354 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1355 elem_id, elem_len, left);
1356 return;
1357 }
1358 if (IE_EID_VENDOR == elem_id)
1359 {
1360 /* skipping the VSIE's which we don't want to include or
1361 * it will be included by existing code
1362 */
1363 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1364#ifdef WLAN_FEATURE_WFD
1365 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1366#endif
1367 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1368 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1369 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1370 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1371 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1372 {
1373 ielen = ptr[1] + 2;
1374 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1375 {
1376 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1377 *total_ielen += ielen;
1378 }
1379 else
1380 {
1381 hddLog( VOS_TRACE_LEVEL_ERROR,
1382 "IE Length is too big "
1383 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1384 elem_id, elem_len, *total_ielen);
1385 }
1386 }
1387 }
1388
1389 left -= elem_len;
1390 ptr += (elem_len + 2);
1391 }
1392 return;
1393}
1394
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001395#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001396static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1397 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001398#else
1399static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1400 struct cfg80211_beacon_data *params)
1401#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001402{
1403 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301404 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001405 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001406 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001407
1408 genie = vos_mem_malloc(MAX_GENIE_LEN);
1409
1410 if(genie == NULL) {
1411
1412 return -ENOMEM;
1413 }
1414
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301415 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1416 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001417 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301418 hddLog(LOGE,
1419 FL("Adding WPS IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301420 ret = -EINVAL;
1421 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001422 }
1423
1424#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301425 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1426 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1427 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301428 hddLog(LOGE,
1429 FL("Adding WFD IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301430 ret = -EINVAL;
1431 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001432 }
1433#endif
1434
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301435 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1436 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301438 hddLog(LOGE,
1439 FL("Adding P2P IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301440 ret = -EINVAL;
1441 goto done;
1442 }
1443
1444 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1445 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001446 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001447 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001448
1449 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1450 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1451 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1452 {
1453 hddLog(LOGE,
1454 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001455 ret = -EINVAL;
1456 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001457 }
1458
1459 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1460 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1461 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1462 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1463 ==eHAL_STATUS_FAILURE)
1464 {
1465 hddLog(LOGE,
1466 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001467 ret = -EINVAL;
1468 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001469 }
1470
1471 // Added for ProResp IE
1472 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1473 {
1474 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1475 u8 probe_rsp_ie_len[3] = {0};
1476 u8 counter = 0;
1477 /* Check Probe Resp Length if it is greater then 255 then Store
1478 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1479 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1480 Store More then 255 bytes into One Variable.
1481 */
1482 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1483 {
1484 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1485 {
1486 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1487 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1488 }
1489 else
1490 {
1491 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1492 rem_probe_resp_ie_len = 0;
1493 }
1494 }
1495
1496 rem_probe_resp_ie_len = 0;
1497
1498 if (probe_rsp_ie_len[0] > 0)
1499 {
1500 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1501 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1502 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1503 probe_rsp_ie_len[0], NULL,
1504 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1505 {
1506 hddLog(LOGE,
1507 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001508 ret = -EINVAL;
1509 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001510 }
1511 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1512 }
1513
1514 if (probe_rsp_ie_len[1] > 0)
1515 {
1516 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1517 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1518 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1519 probe_rsp_ie_len[1], NULL,
1520 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1521 {
1522 hddLog(LOGE,
1523 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001524 ret = -EINVAL;
1525 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001526 }
1527 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1528 }
1529
1530 if (probe_rsp_ie_len[2] > 0)
1531 {
1532 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1533 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1534 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1535 probe_rsp_ie_len[2], NULL,
1536 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1537 {
1538 hddLog(LOGE,
1539 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001540 ret = -EINVAL;
1541 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001542 }
1543 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1544 }
1545
1546 if (probe_rsp_ie_len[1] == 0 )
1547 {
1548 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1549 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1550 eANI_BOOLEAN_FALSE) )
1551 {
1552 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001553 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001554 }
1555 }
1556
1557 if (probe_rsp_ie_len[2] == 0 )
1558 {
1559 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1560 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1561 eANI_BOOLEAN_FALSE) )
1562 {
1563 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001564 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001565 }
1566 }
1567
1568 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1569 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1570 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1571 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1572 == eHAL_STATUS_FAILURE)
1573 {
1574 hddLog(LOGE,
1575 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001576 ret = -EINVAL;
1577 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001578 }
1579 }
1580 else
1581 {
1582 // Reset WNI_CFG_PROBE_RSP Flags
1583 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1584
1585 hddLog(VOS_TRACE_LEVEL_INFO,
1586 "%s: No Probe Response IE received in set beacon",
1587 __func__);
1588 }
1589
1590 // Added for AssocResp IE
1591 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1592 {
1593 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1594 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1595 params->assocresp_ies_len, NULL,
1596 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1597 {
1598 hddLog(LOGE,
1599 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001600 ret = -EINVAL;
1601 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001602 }
1603
1604 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1605 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1606 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1607 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1608 == eHAL_STATUS_FAILURE)
1609 {
1610 hddLog(LOGE,
1611 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001612 ret = -EINVAL;
1613 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001614 }
1615 }
1616 else
1617 {
1618 hddLog(VOS_TRACE_LEVEL_INFO,
1619 "%s: No Assoc Response IE received in set beacon",
1620 __func__);
1621
1622 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1623 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1624 eANI_BOOLEAN_FALSE) )
1625 {
1626 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001627 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001628 }
1629 }
1630
Jeff Johnsone7245742012-09-05 17:12:55 -07001631done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001632 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301633 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001634}
Jeff Johnson295189b2012-06-20 16:38:30 -07001635
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301636/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001637 * FUNCTION: wlan_hdd_validate_operation_channel
1638 * called by wlan_hdd_cfg80211_start_bss() and
1639 * wlan_hdd_cfg80211_set_channel()
1640 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301641 * channel list.
1642 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001643VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001644{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301645
Jeff Johnson295189b2012-06-20 16:38:30 -07001646 v_U32_t num_ch = 0;
1647 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1648 u32 indx = 0;
1649 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301650 v_U8_t fValidChannel = FALSE, count = 0;
1651 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301652
Jeff Johnson295189b2012-06-20 16:38:30 -07001653 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1654
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301655 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001656 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301657 /* Validate the channel */
1658 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001659 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301660 if ( channel == rfChannels[count].channelNum )
1661 {
1662 fValidChannel = TRUE;
1663 break;
1664 }
1665 }
1666 if (fValidChannel != TRUE)
1667 {
1668 hddLog(VOS_TRACE_LEVEL_ERROR,
1669 "%s: Invalid Channel [%d]", __func__, channel);
1670 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001671 }
1672 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301673 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001674 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301675 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1676 valid_ch, &num_ch))
1677 {
1678 hddLog(VOS_TRACE_LEVEL_ERROR,
1679 "%s: failed to get valid channel list", __func__);
1680 return VOS_STATUS_E_FAILURE;
1681 }
1682 for (indx = 0; indx < num_ch; indx++)
1683 {
1684 if (channel == valid_ch[indx])
1685 {
1686 break;
1687 }
1688 }
1689
1690 if (indx >= num_ch)
1691 {
1692 hddLog(VOS_TRACE_LEVEL_ERROR,
1693 "%s: Invalid Channel [%d]", __func__, channel);
1694 return VOS_STATUS_E_FAILURE;
1695 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001696 }
1697 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301698
Jeff Johnson295189b2012-06-20 16:38:30 -07001699}
1700
Viral Modi3a32cc52013-02-08 11:14:52 -08001701/**
1702 * FUNCTION: wlan_hdd_cfg80211_set_channel
1703 * This function is used to set the channel number
1704 */
1705static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1706 struct ieee80211_channel *chan,
1707 enum nl80211_channel_type channel_type
1708 )
1709{
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301710 hdd_adapter_t *pAdapter = NULL;
Viral Modi3a32cc52013-02-08 11:14:52 -08001711 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001712 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001713 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301714 hdd_context_t *pHddCtx;
1715 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001716
1717 ENTER();
1718
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301719
Viral Modi3a32cc52013-02-08 11:14:52 -08001720 if( NULL == dev )
1721 {
1722 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001723 "%s: Called with dev = NULL.", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001724 return -ENODEV;
1725 }
1726 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1727
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301728 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
1729 TRACE_CODE_HDD_CFG80211_SET_CHANNEL, pAdapter->sessionId,
1730 channel_type ));
Viral Modi3a32cc52013-02-08 11:14:52 -08001731 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001732 "%s: device_mode = %d freq = %d", __func__,
Viral Modi3a32cc52013-02-08 11:14:52 -08001733 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301734
1735 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1736 status = wlan_hdd_validate_context(pHddCtx);
1737
1738 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001739 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301740 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1741 "%s: HDD context is not valid", __func__);
1742 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001743 }
1744
1745 /*
1746 * Do freq to chan conversion
1747 * TODO: for 11a
1748 */
1749
1750 channel = ieee80211_frequency_to_channel(freq);
1751
1752 /* Check freq range */
1753 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1754 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1755 {
1756 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001757 "%s: Channel [%d] is outside valid range from %d to %d",
Viral Modi3a32cc52013-02-08 11:14:52 -08001758 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1759 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1760 return -EINVAL;
1761 }
1762
1763 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1764
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301765 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1766 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001767 {
1768 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1769 {
1770 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001771 "%s: Invalid Channel [%d]", __func__, channel);
Viral Modi3a32cc52013-02-08 11:14:52 -08001772 return -EINVAL;
1773 }
1774 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1775 "%s: set channel to [%d] for device mode =%d",
1776 __func__, channel,pAdapter->device_mode);
1777 }
1778 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001779 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001780 )
1781 {
1782 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1783 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1784 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1785
1786 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1787 {
1788 /* Link is up then return cant set channel*/
1789 hddLog( VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001790 "%s: IBSS Associated, can't set the channel", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001791 return -EINVAL;
1792 }
1793
1794 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1795 pHddStaCtx->conn_info.operationChannel = channel;
1796 pRoamProfile->ChannelInfo.ChannelList =
1797 &pHddStaCtx->conn_info.operationChannel;
1798 }
1799 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001800 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001801 )
1802 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301803 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1804 {
1805 if(VOS_STATUS_SUCCESS !=
1806 wlan_hdd_validate_operation_channel(pAdapter,channel))
1807 {
1808 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001809 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301810 return -EINVAL;
1811 }
1812 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1813 }
1814 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001815 {
1816 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1817
1818 /* If auto channel selection is configured as enable/ 1 then ignore
1819 channel set by supplicant
1820 */
1821 if ( cfg_param->apAutoChannelSelection )
1822 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301823 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1824 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001825 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1826 "%s: set channel to auto channel (0) for device mode =%d",
1827 __func__, pAdapter->device_mode);
1828 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301829 else
1830 {
1831 if(VOS_STATUS_SUCCESS !=
1832 wlan_hdd_validate_operation_channel(pAdapter,channel))
1833 {
1834 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001835 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301836 return -EINVAL;
1837 }
1838 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1839 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001840 }
1841 }
1842 else
1843 {
1844 hddLog(VOS_TRACE_LEVEL_FATAL,
1845 "%s: Invalid device mode failed to set valid channel", __func__);
1846 return -EINVAL;
1847 }
1848 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301849 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001850}
1851
Jeff Johnson295189b2012-06-20 16:38:30 -07001852#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1853static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1854 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001855#else
1856static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1857 struct cfg80211_beacon_data *params,
1858 const u8 *ssid, size_t ssid_len,
1859 enum nl80211_hidden_ssid hidden_ssid)
1860#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001861{
1862 tsap_Config_t *pConfig;
1863 beacon_data_t *pBeacon = NULL;
1864 struct ieee80211_mgmt *pMgmt_frame;
1865 v_U8_t *pIe=NULL;
1866 v_U16_t capab_info;
1867 eCsrAuthType RSNAuthType;
1868 eCsrEncryptionType RSNEncryptType;
1869 eCsrEncryptionType mcRSNEncryptType;
1870 int status = VOS_STATUS_SUCCESS;
1871 tpWLAN_SAPEventCB pSapEventCallback;
1872 hdd_hostapd_state_t *pHostapdState;
1873 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1874 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301875 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001876 struct qc_mac_acl_entry *acl_entry = NULL;
1877 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001878 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Chet Lanctot8cecea22014-02-11 19:09:36 -08001879 v_BOOL_t MFPCapable;
1880 v_BOOL_t MFPRequired;
Abhishek Singhf0ac1752014-03-05 17:47:09 +05301881 eHddDot11Mode sapDot11Mode =
1882 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->sapDot11Mode;
Jeff Johnson295189b2012-06-20 16:38:30 -07001883
1884 ENTER();
1885
1886 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1887
1888 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1889
1890 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1891
1892 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1893
1894 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1895
1896 //channel is already set in the set_channel Call back
1897 //pConfig->channel = pCommitConfig->channel;
1898
1899 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301900 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001901 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1902
1903 pConfig->dtim_period = pBeacon->dtim_period;
1904
Arif Hussain6d2a3322013-11-17 19:50:10 -08001905 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***",
Jeff Johnson295189b2012-06-20 16:38:30 -07001906 pConfig->dtim_period);
1907
1908
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001909 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001910 {
1911 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001912 WLAN_EID_COUNTRY);
Kiet Lam083504c2013-11-25 14:17:45 +05301913 if(memcmp(pHddCtx->cfg_ini->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0)
1914 {
1915 tANI_BOOLEAN restartNeeded;
1916 pConfig->ieee80211d = 1;
1917 vos_mem_copy(pConfig->countryCode, pHddCtx->cfg_ini->apCntryCode, 3);
1918 sme_setRegInfo(hHal, pConfig->countryCode);
1919 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
1920 }
1921 else if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001922 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001923 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001924 pConfig->ieee80211d = 1;
1925 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1926 sme_setRegInfo(hHal, pConfig->countryCode);
1927 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001928 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001929 else
1930 {
1931 pConfig->ieee80211d = 0;
1932 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301933 /*
1934 * If auto channel is configured i.e. channel is 0,
1935 * so skip channel validation.
1936 */
1937 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1938 {
1939 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1940 {
1941 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001942 "%s: Invalid Channel [%d]", __func__, pConfig->channel);
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301943 return -EINVAL;
1944 }
1945 }
1946 else
1947 {
1948 if(1 != pHddCtx->is_dynamic_channel_range_set)
1949 {
1950 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1951 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1952 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1953 }
1954 pHddCtx->is_dynamic_channel_range_set = 0;
1955 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001956 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001957 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 {
1959 pConfig->ieee80211d = 0;
1960 }
1961 pConfig->authType = eSAP_AUTO_SWITCH;
1962
1963 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301964
1965 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001966 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1967
1968 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1969
1970 /*Set wps station to configured*/
1971 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1972
1973 if(pIe)
1974 {
1975 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1976 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08001977 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***");
Jeff Johnson295189b2012-06-20 16:38:30 -07001978 return -EINVAL;
1979 }
1980 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1981 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001982 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001983 /* Check 15 bit of WPS IE as it contain information for wps state
1984 * WPS state
1985 */
1986 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1987 {
1988 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1989 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1990 {
1991 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1992 }
1993 }
1994 }
1995 else
1996 {
1997 pConfig->wps_state = SAP_WPS_DISABLED;
1998 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301999 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07002000
2001 pConfig->RSNWPAReqIELength = 0;
2002 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302003 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07002004 WLAN_EID_RSN);
2005 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302006 {
Jeff Johnson295189b2012-06-20 16:38:30 -07002007 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2008 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2009 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302010 /* The actual processing may eventually be more extensive than
2011 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07002012 * by the app.
2013 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302014 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002015 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2016 &RSNEncryptType,
2017 &mcRSNEncryptType,
2018 &RSNAuthType,
Chet Lanctot8cecea22014-02-11 19:09:36 -08002019 &MFPCapable,
2020 &MFPRequired,
Jeff Johnson295189b2012-06-20 16:38:30 -07002021 pConfig->pRSNWPAReqIE[1]+2,
2022 pConfig->pRSNWPAReqIE );
2023
2024 if( VOS_STATUS_SUCCESS == status )
2025 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302026 /* Now copy over all the security attributes you have
2027 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 * */
2029 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2030 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2031 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2032 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302033 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002034 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002035 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2036 }
2037 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302038
Jeff Johnson295189b2012-06-20 16:38:30 -07002039 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2040 pBeacon->tail, pBeacon->tail_len);
2041
2042 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
2043 {
2044 if (pConfig->pRSNWPAReqIE)
2045 {
2046 /*Mixed mode WPA/WPA2*/
2047 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
2048 pConfig->RSNWPAReqIELength += pIe[1] + 2;
2049 }
2050 else
2051 {
2052 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2053 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2054 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302055 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002056 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2057 &RSNEncryptType,
2058 &mcRSNEncryptType,
2059 &RSNAuthType,
Chet Lanctot8cecea22014-02-11 19:09:36 -08002060 &MFPCapable,
2061 &MFPRequired,
Jeff Johnson295189b2012-06-20 16:38:30 -07002062 pConfig->pRSNWPAReqIE[1]+2,
2063 pConfig->pRSNWPAReqIE );
2064
2065 if( VOS_STATUS_SUCCESS == status )
2066 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302067 /* Now copy over all the security attributes you have
2068 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 * */
2070 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2071 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2072 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2073 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302074 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002075 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002076 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2077 }
2078 }
2079 }
2080
Jeff Johnson4416a782013-03-25 14:17:50 -07002081 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
2082 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
2083 return -EINVAL;
2084 }
2085
Jeff Johnson295189b2012-06-20 16:38:30 -07002086 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
2087
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002088#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002089 if (params->ssid != NULL)
2090 {
2091 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
2092 pConfig->SSIDinfo.ssid.length = params->ssid_len;
2093 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2094 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2095 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002096#else
2097 if (ssid != NULL)
2098 {
2099 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
2100 pConfig->SSIDinfo.ssid.length = ssid_len;
2101 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2102 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2103 }
2104#endif
2105
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302106 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07002107 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302108
Jeff Johnson295189b2012-06-20 16:38:30 -07002109 /* default value */
2110 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
2111 pConfig->num_accept_mac = 0;
2112 pConfig->num_deny_mac = 0;
2113
2114 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2115 pBeacon->tail, pBeacon->tail_len);
2116
2117 /* pIe for black list is following form:
2118 type : 1 byte
2119 length : 1 byte
2120 OUI : 4 bytes
2121 acl type : 1 byte
2122 no of mac addr in black list: 1 byte
2123 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302124 */
2125 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002126 {
2127 pConfig->SapMacaddr_acl = pIe[6];
2128 pConfig->num_deny_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002129 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002130 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302131 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2132 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002133 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2134 for (i = 0; i < pConfig->num_deny_mac; i++)
2135 {
2136 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2137 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302138 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002139 }
2140 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2141 pBeacon->tail, pBeacon->tail_len);
2142
2143 /* pIe for white list is following form:
2144 type : 1 byte
2145 length : 1 byte
2146 OUI : 4 bytes
2147 acl type : 1 byte
2148 no of mac addr in white list: 1 byte
2149 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302150 */
2151 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002152 {
2153 pConfig->SapMacaddr_acl = pIe[6];
2154 pConfig->num_accept_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002155 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002156 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302157 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2158 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002159 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2160 for (i = 0; i < pConfig->num_accept_mac; i++)
2161 {
2162 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2163 acl_entry++;
2164 }
2165 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302166
Jeff Johnson295189b2012-06-20 16:38:30 -07002167 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2168
Jeff Johnsone7245742012-09-05 17:12:55 -07002169#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002170 /* Overwrite the hostapd setting for HW mode only for 11ac.
Kiet Lam0f320422013-11-21 19:29:17 +05302171 * This is valid only if mode is set to 11n in hostapd, either AUTO or
2172 * 11ac in .ini and 11ac is supported by both host and firmware.
2173 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode)
2174 */
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002175 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2176 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Abhishek Singhf0ac1752014-03-05 17:47:09 +05302177 (( sapDot11Mode == eHDD_DOT11_MODE_AUTO ) ||
2178 ( sapDot11Mode == eHDD_DOT11_MODE_11ac ) ||
2179 ( sapDot11Mode == eHDD_DOT11_MODE_11ac_ONLY ) ) &&
2180 (sme_IsFeatureSupportedByDriver(DOT11AC)) &&
2181 (sme_IsFeatureSupportedByFW(DOT11AC)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002182 {
2183 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002184
2185 /* Disable VHT support in 2.4 GHz band */
2186 if (pConfig->channel <= 14 &&
2187 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2188 {
2189 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2190 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002191 }
2192#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302193
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002194 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2195 {
2196 sme_SelectCBMode(hHal,
2197 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2198 pConfig->channel);
2199 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002200 // ht_capab is not what the name conveys,this is used for protection bitmap
2201 pConfig->ht_capab =
2202 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2203
2204 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2205 {
2206 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2207 return -EINVAL;
2208 }
2209
2210 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302211 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002212 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2213 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302214 pConfig->obssProtEnabled =
2215 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002216
Chet Lanctot8cecea22014-02-11 19:09:36 -08002217#ifdef WLAN_FEATURE_11W
2218 pConfig->mfpCapable = MFPCapable;
2219 pConfig->mfpRequired = MFPRequired;
2220 hddLog(LOGW, FL("Soft AP MFP capable %d, MFP required %d\n"),
2221 pConfig->mfpCapable, pConfig->mfpRequired);
2222#endif
2223
Arif Hussain6d2a3322013-11-17 19:50:10 -08002224 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR),
Jeff Johnson295189b2012-06-20 16:38:30 -07002225 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002226 hddLog(LOGW,FL("ssid =%s, beaconint=%d, channel=%d"),
2227 pConfig->SSIDinfo.ssid.ssId, (int)pConfig->beacon_int,
2228 (int)pConfig->channel);
2229 hddLog(LOGW,FL("hw_mode=%x, privacy=%d, authType=%d"),
2230 pConfig->SapHw_mode, pConfig->privacy,
2231 pConfig->authType);
2232 hddLog(LOGW,FL("RSN/WPALen=%d, Uapsd = %d"),
2233 (int)pConfig->RSNWPAReqIELength, pConfig->UapsdEnable);
2234 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d"),
2235 pConfig->protEnabled, pConfig->obssProtEnabled);
Jeff Johnson295189b2012-06-20 16:38:30 -07002236
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302237 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002238 {
2239 //Bss already started. just return.
2240 //TODO Probably it should update some beacon params.
2241 hddLog( LOGE, "Bss Already started...Ignore the request");
2242 EXIT();
2243 return 0;
2244 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302245
Jeff Johnson295189b2012-06-20 16:38:30 -07002246 pConfig->persona = pHostapdAdapter->device_mode;
2247
2248 pSapEventCallback = hdd_hostapd_SAPEventCB;
2249 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2250 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2251 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002252 hddLog(LOGE,FL("SAP Start Bss fail"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002253 return -EINVAL;
2254 }
2255
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302256 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002257 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2258
2259 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302260
Jeff Johnson295189b2012-06-20 16:38:30 -07002261 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302262 {
2263 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002264 ("ERROR: HDD vos wait for single_event failed!!"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002265 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002266 VOS_ASSERT(0);
2267 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302268
Jeff Johnson295189b2012-06-20 16:38:30 -07002269 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2270
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002271#ifdef WLAN_FEATURE_P2P_DEBUG
2272 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2273 {
2274 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2275 {
2276 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2277 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002278 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002279 }
2280 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2281 {
2282 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2283 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002284 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002285 }
2286 }
2287#endif
2288
Jeff Johnson295189b2012-06-20 16:38:30 -07002289 pHostapdState->bCommit = TRUE;
2290 EXIT();
2291
2292 return 0;
2293}
2294
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002295#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302296static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2297 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002298 struct beacon_parameters *params)
2299{
2300 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302301 hdd_context_t *pHddCtx;
2302 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002303
2304 ENTER();
2305
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302306 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2307 TRACE_CODE_HDD_CFG80211_ADD_BEACON,
2308 pAdapter->sessionId, params->interval));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002309 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d",pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002310
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302311 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2312 status = wlan_hdd_validate_context(pHddCtx);
2313
2314 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002315 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302316 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2317 "%s: HDD context is not valid", __func__);
2318 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002319 }
2320
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302321 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002322 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002323 )
2324 {
2325 beacon_data_t *old,*new;
2326
2327 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302328
Jeff Johnson295189b2012-06-20 16:38:30 -07002329 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302330 {
2331 hddLog(VOS_TRACE_LEVEL_WARN,
2332 FL("already beacon info added to session(%d)"),
2333 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002334 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302335 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002336
2337 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2338
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302339 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002340 {
2341 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002342 "%s:Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002343 return -EINVAL;
2344 }
2345
2346 pAdapter->sessionCtx.ap.beacon = new;
2347
2348 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2349 }
2350
2351 EXIT();
2352 return status;
2353}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302354
2355static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002356 struct net_device *dev,
2357 struct beacon_parameters *params)
2358{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302359 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302360 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302361 hdd_context_t *pHddCtx;
2362 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002363
2364 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302365 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2366 TRACE_CODE_HDD_CFG80211_SET_BEACON,
2367 pAdapter->sessionId, pHddStaCtx->conn_info.authType));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002368 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002369 __func__,pAdapter->device_mode);
2370
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302371 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2372 status = wlan_hdd_validate_context(pHddCtx);
2373
2374 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002375 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302376 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2377 "%s: HDD context is not valid", __func__);
2378 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002379 }
2380
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302381 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002382 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302383 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002384 {
2385 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302386
Jeff Johnson295189b2012-06-20 16:38:30 -07002387 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302388
Jeff Johnson295189b2012-06-20 16:38:30 -07002389 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302390 {
2391 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2392 FL("session(%d) old and new heads points to NULL"),
2393 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002394 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302395 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002396
2397 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2398
2399 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302400 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002401 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002402 return -EINVAL;
2403 }
2404
2405 pAdapter->sessionCtx.ap.beacon = new;
2406
2407 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2408 }
2409
2410 EXIT();
2411 return status;
2412}
2413
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002414#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2415
2416#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002417static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2418 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002419#else
2420static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2421 struct net_device *dev)
2422#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002423{
2424 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002425 hdd_context_t *pHddCtx = NULL;
2426 hdd_scaninfo_t *pScanInfo = NULL;
2427 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302428 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002429
2430 ENTER();
2431
2432 if (NULL == pAdapter)
2433 {
2434 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002435 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002436 return -ENODEV;
2437 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002438
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302439 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2440 TRACE_CODE_HDD_CFG80211_STOP_AP,
2441 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302442 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2443 status = wlan_hdd_validate_context(pHddCtx);
2444
2445 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002446 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302447 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2448 "%s: HDD context is not valid", __func__);
2449 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002450 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002451
2452 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2453 if (NULL == staAdapter)
2454 {
2455 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2456 if (NULL == staAdapter)
2457 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002458 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2459 "%s: HDD adapter context for STA/P2P-CLI is Null",
2460 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002461 }
2462 }
2463
2464 pScanInfo = &pHddCtx->scan_info;
2465
Arif Hussain6d2a3322013-11-17 19:50:10 -08002466 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002467 __func__,pAdapter->device_mode);
2468
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002469 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002470 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302471 long ret;
2472
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002473 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05302474 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId,
2475 eCSR_SCAN_ABORT_DEFAULT);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302476 ret = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002477 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002478 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302479 if (ret <= 0)
Jeff Johnsone7245742012-09-05 17:12:55 -07002480 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002481 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302482 FL("Timeout occurred while waiting for abortscan %ld"),
2483 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002484
2485 if (pHddCtx->isLogpInProgress)
2486 {
2487 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2488 "%s: LOGP in Progress. Ignore!!!", __func__);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302489
2490 VOS_ASSERT(pScanInfo->mScanPending);
Yue Ma4f55ef32014-01-23 16:45:33 -08002491 return -EAGAIN;
2492 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002493 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002494 }
2495 }
2496
Arun Kumar Khandavallia3bd8002014-01-17 16:21:19 +05302497 hdd_hostapd_stop(dev);
2498
Jeff Johnson295189b2012-06-20 16:38:30 -07002499 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002500 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002501 )
2502 {
2503 beacon_data_t *old;
2504
2505 old = pAdapter->sessionCtx.ap.beacon;
2506
2507 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302508 {
2509 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2510 FL("session(%d) beacon data points to NULL"),
2511 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002512 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302513 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002514
Jeff Johnson295189b2012-06-20 16:38:30 -07002515 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002516
2517 mutex_lock(&pHddCtx->sap_lock);
2518 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2519 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002520 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002521 {
2522 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2523
2524 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2525
2526 if (!VOS_IS_STATUS_SUCCESS(status))
2527 {
2528 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002529 ("ERROR: HDD vos wait for single_event failed!!"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002530 VOS_ASSERT(0);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302531 }
2532 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002533 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2534 }
2535 mutex_unlock(&pHddCtx->sap_lock);
2536
2537 if(status != VOS_STATUS_SUCCESS)
2538 {
2539 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002540 "%s:Error!!! Stopping the BSS",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002541 return -EINVAL;
2542 }
2543
Jeff Johnson4416a782013-03-25 14:17:50 -07002544 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002545 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2546 ==eHAL_STATUS_FAILURE)
2547 {
2548 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002549 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002550 }
2551
Jeff Johnson4416a782013-03-25 14:17:50 -07002552 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002553 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2554 eANI_BOOLEAN_FALSE) )
2555 {
2556 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002557 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002558 }
2559
2560 // Reset WNI_CFG_PROBE_RSP Flags
2561 wlan_hdd_reset_prob_rspies(pAdapter);
2562
2563 pAdapter->sessionCtx.ap.beacon = NULL;
2564 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002565#ifdef WLAN_FEATURE_P2P_DEBUG
2566 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2567 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2568 {
2569 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2570 "GO got removed");
2571 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2572 }
2573#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002574 }
2575 EXIT();
2576 return status;
2577}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002578
2579#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2580
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302581static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2582 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002583 struct cfg80211_ap_settings *params)
2584{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302585 hdd_adapter_t *pAdapter;
2586 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302587 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002588
2589 ENTER();
2590
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302591 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002592 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302594 "%s: Device is Null", __func__);
2595 return -ENODEV;
2596 }
2597
2598 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2599 if (NULL == pAdapter)
2600 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302601 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302602 "%s: HDD adapter is Null", __func__);
2603 return -ENODEV;
2604 }
2605
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302606 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2607 TRACE_CODE_HDD_CFG80211_START_AP, pAdapter->sessionId,
2608 params-> beacon_interval));
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302609 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2610 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302611 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302612 "%s: HDD adapter magic is invalid", __func__);
2613 return -ENODEV;
2614 }
2615
2616 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302617 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302618
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302619 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302620 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302621 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2622 "%s: HDD context is not valid", __func__);
2623 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302624 }
2625
2626 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2627 __func__, pAdapter->device_mode);
2628
2629 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002630 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002631 )
2632 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302633 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002634
2635 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302636
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002637 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302638 {
2639 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2640 FL("already beacon info added to session(%d)"),
2641 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002642 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302643 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002644
2645 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2646
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302647 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002648 {
2649 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302650 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002651 return -EINVAL;
2652 }
2653 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002654#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002655 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2656#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2657 params->channel, params->channel_type);
2658#else
2659 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2660#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002661#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002662 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2663 params->ssid_len, params->hidden_ssid);
2664 }
2665
2666 EXIT();
2667 return status;
2668}
2669
2670
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302671static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002672 struct net_device *dev,
2673 struct cfg80211_beacon_data *params)
2674{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302675 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302676 hdd_context_t *pHddCtx;
2677 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002678
2679 ENTER();
2680
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302681 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2682 TRACE_CODE_HDD_CFG80211_CHANGE_BEACON,
2683 pAdapter->sessionId, pAdapter->device_mode));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002684 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002685 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302686
2687 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2688 status = wlan_hdd_validate_context(pHddCtx);
2689
2690 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002691 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302692 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2693 "%s: HDD context is not valid", __func__);
2694 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002695 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002696
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302697 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002698 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302699 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002700 {
2701 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302702
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002703 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302704
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002705 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302706 {
2707 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2708 FL("session(%d) beacon data points to NULL"),
2709 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002710 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302711 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002712
2713 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2714
2715 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302716 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002717 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002718 return -EINVAL;
2719 }
2720
2721 pAdapter->sessionCtx.ap.beacon = new;
2722
2723 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2724 }
2725
2726 EXIT();
2727 return status;
2728}
2729
2730#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2731
Jeff Johnson295189b2012-06-20 16:38:30 -07002732
2733static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2734 struct net_device *dev,
2735 struct bss_parameters *params)
2736{
2737 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2738
2739 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302740
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302741 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2742 TRACE_CODE_HDD_CFG80211_CHANGE_BSS,
2743 pAdapter->sessionId, params->ap_isolate));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002744 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002745 __func__,pAdapter->device_mode);
2746
2747 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002748 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302749 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002750 {
2751 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2752 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302753 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002754 {
2755 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302756 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002757 }
2758
2759 EXIT();
2760 return 0;
2761}
2762
Kiet Lam10841362013-11-01 11:36:50 +05302763/* FUNCTION: wlan_hdd_change_country_code_cd
2764* to wait for contry code completion
2765*/
2766void* wlan_hdd_change_country_code_cb(void *pAdapter)
2767{
2768 hdd_adapter_t *call_back_pAdapter = pAdapter;
2769 complete(&call_back_pAdapter->change_country_code);
2770 return NULL;
2771}
2772
Jeff Johnson295189b2012-06-20 16:38:30 -07002773/*
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05302774 * FUNCTION: __wlan_hdd_cfg80211_change_iface
Jeff Johnson295189b2012-06-20 16:38:30 -07002775 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2776 */
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05302777int __wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002778 struct net_device *ndev,
2779 enum nl80211_iftype type,
2780 u32 *flags,
2781 struct vif_params *params
2782 )
2783{
2784 struct wireless_dev *wdev;
2785 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002786 hdd_context_t *pHddCtx;
Mohit Khanna0f232092012-09-11 14:46:08 -07002787 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002788 tCsrRoamProfile *pRoamProfile = NULL;
2789 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302790 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002791 eMib_dot11DesiredBssType connectedBssType;
2792 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302793 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07002794
2795 ENTER();
2796
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302797 if (!pAdapter)
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002798 {
2799 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2800 "%s: Adapter context is null", __func__);
2801 return VOS_STATUS_E_FAILURE;
2802 }
2803
2804 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2805 if (!pHddCtx)
2806 {
2807 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2808 "%s: HDD context is null", __func__);
2809 return VOS_STATUS_E_FAILURE;
2810 }
2811
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302812 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2813 TRACE_CODE_HDD_CFG80211_CHANGE_IFACE,
2814 pAdapter->sessionId, type));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302815 status = wlan_hdd_validate_context(pHddCtx);
2816
2817 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002818 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302819 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2820 "%s: HDD context is not valid", __func__);
2821 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002822 }
2823
2824 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2825 __func__, pAdapter->device_mode);
2826
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302827 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002828 wdev = ndev->ieee80211_ptr;
2829
2830#ifdef WLAN_BTAMP_FEATURE
2831 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2832 (NL80211_IFTYPE_ADHOC == type)||
2833 (NL80211_IFTYPE_AP == type)||
2834 (NL80211_IFTYPE_P2P_GO == type))
2835 {
2836 pHddCtx->isAmpAllowed = VOS_FALSE;
2837 // stop AMP traffic
2838 status = WLANBAP_StopAmp();
2839 if(VOS_STATUS_SUCCESS != status )
2840 {
2841 pHddCtx->isAmpAllowed = VOS_TRUE;
2842 hddLog(VOS_TRACE_LEVEL_FATAL,
2843 "%s: Failed to stop AMP", __func__);
2844 return -EINVAL;
2845 }
2846 }
2847#endif //WLAN_BTAMP_FEATURE
2848 /* Reset the current device mode bit mask*/
2849 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2850
2851 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002852 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002853 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002854 )
2855 {
2856 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002857 if (!pWextState)
2858 {
2859 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2860 "%s: pWextState is null", __func__);
2861 return VOS_STATUS_E_FAILURE;
2862 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 pRoamProfile = &pWextState->roamProfile;
2864 LastBSSType = pRoamProfile->BSSType;
2865
2866 switch (type)
2867 {
2868 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002869 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002870 hddLog(VOS_TRACE_LEVEL_INFO,
2871 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2872 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002873#ifdef WLAN_FEATURE_11AC
2874 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2875 {
2876 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2877 }
2878#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302879 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002880 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002881 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002882 //Check for sub-string p2p to confirm its a p2p interface
2883 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302884 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002885 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2886 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2887 }
2888 else
2889 {
2890 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002891 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002892 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302893#ifdef FEATURE_WLAN_TDLS
2894 /* The open adapter for the p2p shall skip initializations in
2895 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2896 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2897 * tdls_init when the change_iface sets the device mode to
2898 * WLAN_HDD_P2P_CLIENT.
2899 */
2900
2901 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2902 {
2903 if (0 != wlan_hdd_tdls_init (pAdapter))
2904 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302905 hddLog(VOS_TRACE_LEVEL_ERROR,
2906 "%s: tdls initialization failed", __func__);
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302907 return -EINVAL;
2908 }
2909 }
2910#endif
2911
Jeff Johnson295189b2012-06-20 16:38:30 -07002912 break;
2913 case NL80211_IFTYPE_ADHOC:
2914 hddLog(VOS_TRACE_LEVEL_INFO,
2915 "%s: setting interface Type to ADHOC", __func__);
2916 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2917 pRoamProfile->phyMode =
2918 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002919 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002920 wdev->iftype = type;
2921 break;
2922
2923 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002924 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002925 {
2926 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2927 "%s: setting interface Type to %s", __func__,
2928 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2929
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002930 //Cancel any remain on channel for GO mode
2931 if (NL80211_IFTYPE_P2P_GO == type)
2932 {
2933 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2934 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002935 if (NL80211_IFTYPE_AP == type)
2936 {
2937 /* As Loading WLAN Driver one interface being created for p2p device
2938 * address. This will take one HW STA and the max number of clients
2939 * that can connect to softAP will be reduced by one. so while changing
2940 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2941 * interface as it is not required in SoftAP mode.
2942 */
2943
2944 // Get P2P Adapter
2945 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2946
2947 if (pP2pAdapter)
2948 {
2949 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2950 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2951 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2952 }
2953 }
Swaroop Goltia2e32212014-04-09 23:37:33 +05302954 //Disable IMPS & BMPS for SAP/GO
2955 if(VOS_STATUS_E_FAILURE ==
2956 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2957 {
2958 //Fail to Exit BMPS
2959 VOS_ASSERT(0);
2960 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302961#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002962
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302963 /* A Mutex Lock is introduced while changing the mode to
2964 * protect the concurrent access for the Adapters by TDLS
2965 * module.
2966 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302967 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302968#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002969 //De-init the adapter.
2970 hdd_stop_adapter( pHddCtx, pAdapter );
2971 hdd_deinit_adapter( pHddCtx, pAdapter );
2972 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002973 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2974 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302975#ifdef FEATURE_WLAN_TDLS
2976 mutex_unlock(&pHddCtx->tdls_lock);
2977#endif
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002978 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2979 (pConfig->apRandomBssidEnabled))
2980 {
2981 /* To meet Android requirements create a randomized
2982 MAC address of the form 02:1A:11:Fx:xx:xx */
2983 get_random_bytes(&ndev->dev_addr[3], 3);
2984 ndev->dev_addr[0] = 0x02;
2985 ndev->dev_addr[1] = 0x1A;
2986 ndev->dev_addr[2] = 0x11;
2987 ndev->dev_addr[3] |= 0xF0;
2988 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2989 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08002990 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
2991 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002992 }
2993
Jeff Johnson295189b2012-06-20 16:38:30 -07002994 hdd_set_ap_ops( pAdapter->dev );
2995
Kiet Lam10841362013-11-01 11:36:50 +05302996 /* This is for only SAP mode where users can
2997 * control country through ini.
2998 * P2P GO follows station country code
2999 * acquired during the STA scanning. */
3000 if((NL80211_IFTYPE_AP == type) &&
3001 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
3002 {
3003 int status = 0;
3004 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
3005 "%s: setting country code from INI ", __func__);
3006 init_completion(&pAdapter->change_country_code);
3007 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
3008 (void *)(tSmeChangeCountryCallback)
3009 wlan_hdd_change_country_code_cb,
3010 pConfig->apCntryCode, pAdapter,
3011 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05303012 eSIR_FALSE,
3013 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05303014 if (eHAL_STATUS_SUCCESS == status)
3015 {
3016 /* Wait for completion */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303017 ret = wait_for_completion_interruptible_timeout(
Kiet Lam10841362013-11-01 11:36:50 +05303018 &pAdapter->change_country_code,
3019 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303020 if (ret <= 0)
Kiet Lam10841362013-11-01 11:36:50 +05303021 {
3022 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303023 FL("SME Timed out while setting country code %ld"),
3024 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08003025
3026 if (pHddCtx->isLogpInProgress)
3027 {
3028 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3029 "%s: LOGP in Progress. Ignore!!!", __func__);
3030 return -EAGAIN;
3031 }
Kiet Lam10841362013-11-01 11:36:50 +05303032 }
3033 }
3034 else
3035 {
3036 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003037 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05303038 return -EINVAL;
3039 }
3040 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003041 status = hdd_init_ap_mode(pAdapter);
3042 if(status != VOS_STATUS_SUCCESS)
3043 {
3044 hddLog(VOS_TRACE_LEVEL_FATAL,
3045 "%s: Error initializing the ap mode", __func__);
3046 return -EINVAL;
3047 }
3048 hdd_set_conparam(1);
3049
Jeff Johnson295189b2012-06-20 16:38:30 -07003050 /*interface type changed update in wiphy structure*/
3051 if(wdev)
3052 {
3053 wdev->iftype = type;
3054 pHddCtx->change_iface = type;
3055 }
3056 else
3057 {
3058 hddLog(VOS_TRACE_LEVEL_ERROR,
3059 "%s: ERROR !!!! Wireless dev is NULL", __func__);
3060 return -EINVAL;
3061 }
3062 goto done;
3063 }
3064
3065 default:
3066 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3067 __func__);
3068 return -EOPNOTSUPP;
3069 }
3070 }
3071 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003072 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003073 )
3074 {
3075 switch(type)
3076 {
3077 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07003078 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07003079 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303080#ifdef FEATURE_WLAN_TDLS
3081
3082 /* A Mutex Lock is introduced while changing the mode to
3083 * protect the concurrent access for the Adapters by TDLS
3084 * module.
3085 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303086 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303087#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07003088 hdd_stop_adapter( pHddCtx, pAdapter );
3089 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003090 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08003091 //Check for sub-string p2p to confirm its a p2p interface
3092 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003093 {
3094 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
3095 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
3096 }
3097 else
3098 {
3099 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07003100 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003101 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003102 hdd_set_conparam(0);
3103 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
3105 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303106#ifdef FEATURE_WLAN_TDLS
3107 mutex_unlock(&pHddCtx->tdls_lock);
3108#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05303109 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003110 if( VOS_STATUS_SUCCESS != status )
3111 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07003112 /* In case of JB, for P2P-GO, only change interface will be called,
3113 * This is the right place to enable back bmps_imps()
3114 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05303115 if (pHddCtx->hdd_wlan_suspended)
3116 {
3117 hdd_set_pwrparams(pHddCtx);
3118 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003119 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003120 goto done;
3121 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07003122 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07003123 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003124 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3125 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003126 goto done;
3127 default:
3128 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3129 __func__);
3130 return -EOPNOTSUPP;
3131
3132 }
3133
3134 }
3135 else
3136 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303137 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: unsupported device mode(%d)",
3138 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003139 return -EOPNOTSUPP;
3140 }
3141
3142
3143 if(pRoamProfile)
3144 {
3145 if ( LastBSSType != pRoamProfile->BSSType )
3146 {
3147 /*interface type changed update in wiphy structure*/
3148 wdev->iftype = type;
3149
3150 /*the BSS mode changed, We need to issue disconnect
3151 if connected or in IBSS disconnect state*/
3152 if ( hdd_connGetConnectedBssType(
3153 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
3154 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
3155 {
3156 /*need to issue a disconnect to CSR.*/
3157 INIT_COMPLETION(pAdapter->disconnect_comp_var);
3158 if( eHAL_STATUS_SUCCESS ==
3159 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
3160 pAdapter->sessionId,
3161 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
3162 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303163 ret = wait_for_completion_interruptible_timeout(
3164 &pAdapter->disconnect_comp_var,
3165 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
3166 if (ret <= 0)
3167 {
3168 hddLog(VOS_TRACE_LEVEL_ERROR,
3169 FL("wait on disconnect_comp_var failed %ld"), ret);
3170 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003171 }
3172 }
3173 }
3174 }
3175
3176done:
3177 /*set bitmask based on updated value*/
3178 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07003179
3180 /* Only STA mode support TM now
3181 * all other mode, TM feature should be disabled */
3182 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
3183 (~VOS_STA & pHddCtx->concurrency_mode) )
3184 {
3185 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
3186 }
3187
Jeff Johnson295189b2012-06-20 16:38:30 -07003188#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303189 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003190 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
3191 {
3192 //we are ok to do AMP
3193 pHddCtx->isAmpAllowed = VOS_TRUE;
3194 }
3195#endif //WLAN_BTAMP_FEATURE
3196 EXIT();
3197 return 0;
3198}
3199
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05303200/*
3201 * FUNCTION: wlan_hdd_cfg80211_change_iface
3202 * wrapper function to protect the actual implementation from SSR.
3203 */
3204int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
3205 struct net_device *ndev,
3206 enum nl80211_iftype type,
3207 u32 *flags,
3208 struct vif_params *params
3209 )
3210{
3211 int ret;
3212
3213 vos_ssr_protect(__func__);
3214 ret = __wlan_hdd_cfg80211_change_iface(wiphy, ndev, type, flags, params);
3215 vos_ssr_unprotect(__func__);
3216
3217 return ret;
3218}
3219
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003220#ifdef FEATURE_WLAN_TDLS
3221static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
3222 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
3223{
3224 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3225 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3226 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003227 hddTdlsPeer_t *pTdlsPeer;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303228 long ret;
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303229 tANI_U16 numCurrTdlsPeers;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003230
3231 ENTER();
3232
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303233 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003234 {
3235 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3236 "Invalid arguments");
3237 return -EINVAL;
3238 }
Hoonki Lee27511902013-03-14 18:19:06 -07003239
3240 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3241 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3242 {
3243 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3244 "%s: TDLS mode is disabled OR not enabled in FW."
3245 MAC_ADDRESS_STR " Request declined.",
3246 __func__, MAC_ADDR_ARRAY(mac));
3247 return -ENOTSUPP;
3248 }
3249
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003250 if (pHddCtx->isLogpInProgress)
3251 {
3252 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3253 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003254 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003255 return -EBUSY;
3256 }
3257
Naresh Jayaram9c6f4462014-02-13 12:20:31 +05303258 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003259
3260 if ( NULL == pTdlsPeer ) {
3261 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3262 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3263 __func__, MAC_ADDR_ARRAY(mac), update);
3264 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003265 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003266
3267 /* in add station, we accept existing valid staId if there is */
3268 if ((0 == update) &&
3269 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3270 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003271 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003272 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003273 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003274 " link_status %d. staId %d. add station ignored.",
3275 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3276 return 0;
3277 }
3278 /* in change station, we accept only when staId is valid */
3279 if ((1 == update) &&
3280 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3281 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3282 {
3283 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3284 "%s: " MAC_ADDRESS_STR
3285 " link status %d. staId %d. change station %s.",
3286 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3287 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3288 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003289 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003290
3291 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303292 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003293 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003294 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3295 "%s: " MAC_ADDRESS_STR
3296 " TDLS setup is ongoing. Request declined.",
3297 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003298 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003299 }
3300
3301 /* first to check if we reached to maximum supported TDLS peer.
3302 TODO: for now, return -EPERM looks working fine,
3303 but need to check if any other errno fit into this category.*/
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303304 numCurrTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
3305 if (HDD_MAX_NUM_TDLS_STA <= numCurrTdlsPeers)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003306 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003307 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3308 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303309 " TDLS Max peer already connected. Request declined."
3310 " Num of peers (%d), Max allowed (%d).",
3311 __func__, MAC_ADDR_ARRAY(mac), numCurrTdlsPeers,
3312 HDD_MAX_NUM_TDLS_STA);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003313 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003314 }
3315 else
3316 {
3317 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303318 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003319 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003320 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003321 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3322 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3323 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003324 return -EPERM;
3325 }
3326 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003327 if (0 == update)
3328 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003329
Jeff Johnsond75fe012013-04-06 10:53:06 -07003330 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303331 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003332 {
3333 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3334 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003335 if(StaParams->htcap_present)
3336 {
3337 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3338 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3339 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3340 "ht_capa->extended_capabilities: %0x",
3341 StaParams->HTCap.extendedHtCapInfo);
3342 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003343 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3344 "params->capability: %0x",StaParams->capability);
3345 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003346 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003347 if(StaParams->vhtcap_present)
3348 {
3349 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3350 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3351 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3352 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3353 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003354 {
3355 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003356 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003357 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3358 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3359 "[%d]: %x ", i, StaParams->supported_rates[i]);
3360 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003361 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303362 else if ((1 == update) && (NULL == StaParams))
3363 {
3364 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3365 "%s : update is true, but staParams is NULL. Error!", __func__);
3366 return -EPERM;
3367 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003368
3369 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3370
3371 if (!update)
3372 {
3373 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3374 pAdapter->sessionId, mac);
3375 }
3376 else
3377 {
3378 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3379 pAdapter->sessionId, mac, StaParams);
3380 }
3381
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303382 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003383 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3384
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303385 if (ret <= 0)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003386 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003387 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303388 "%s: timeout waiting for tdls add station indication %ld",
3389 __func__, ret);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003390 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003391 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303392
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003393 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3394 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003395 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003396 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003397 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003398 }
3399
3400 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003401
3402error:
3403 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3404 return -EPERM;
3405
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003406}
3407#endif
3408
Jeff Johnson295189b2012-06-20 16:38:30 -07003409static int wlan_hdd_change_station(struct wiphy *wiphy,
3410 struct net_device *dev,
3411 u8 *mac,
3412 struct station_parameters *params)
3413{
3414 VOS_STATUS status = VOS_STATUS_SUCCESS;
3415 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303416 hdd_context_t *pHddCtx;
3417 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003418 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003419#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003420 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003421 tANI_U8 isBufSta = 0;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303422 tANI_U8 isOffChannelSupported = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003423#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003424 ENTER();
3425
Gopichand Nakkala29149562013-05-10 21:43:41 +05303426 if ((NULL == pAdapter))
3427 {
3428 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3429 "invalid adapter ");
3430 return -EINVAL;
3431 }
3432
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303433 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3434 TRACE_CODE_HDD_CHANGE_STATION,
3435 pAdapter->sessionId, params->listen_interval));
Gopichand Nakkala29149562013-05-10 21:43:41 +05303436 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3437 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3438
3439 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3440 {
3441 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3442 "invalid HDD state or HDD station context");
3443 return -EINVAL;
3444 }
3445
3446 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003447 {
3448 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3449 "%s:LOGP in Progress. Ignore!!!", __func__);
3450 return -EAGAIN;
3451 }
3452
Jeff Johnson295189b2012-06-20 16:38:30 -07003453 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3454
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003455 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3456 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003457 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003458 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303460 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003461 WLANTL_STA_AUTHENTICATED);
3462
Gopichand Nakkala29149562013-05-10 21:43:41 +05303463 if (status != VOS_STATUS_SUCCESS)
3464 {
3465 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3466 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3467 return -EINVAL;
3468 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003469 }
3470 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003471 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3472 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303473#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003474 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3475 StaParams.capability = params->capability;
3476 StaParams.uapsd_queues = params->uapsd_queues;
3477 StaParams.max_sp = params->max_sp;
3478
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303479 /* Convert (first channel , number of channels) tuple to
3480 * the total list of channels. This goes with the assumption
3481 * that if the first channel is < 14, then the next channels
3482 * are an incremental of 1 else an incremental of 4 till the number
3483 * of channels.
3484 */
3485 if (0 != params->supported_channels_len) {
3486 int i = 0,j = 0,k = 0, no_of_channels = 0 ;
3487 for ( i = 0 ; i < params->supported_channels_len ; i+=2)
3488 {
3489 int wifi_chan_index;
3490 StaParams.supported_channels[j] = params->supported_channels[i];
3491 wifi_chan_index =
3492 ((StaParams.supported_channels[j] <= HDD_CHANNEL_14 ) ? 1 : 4 );
3493 no_of_channels = params->supported_channels[i+1];
3494 for(k=1; k <= no_of_channels; k++)
3495 {
3496 StaParams.supported_channels[j+1] =
3497 StaParams.supported_channels[j] + wifi_chan_index;
3498 j+=1;
3499 }
3500 }
3501 StaParams.supported_channels_len = j;
3502 }
3503 vos_mem_copy(StaParams.supported_oper_classes,
3504 params->supported_oper_classes,
3505 params->supported_oper_classes_len);
3506 StaParams.supported_oper_classes_len =
3507 params->supported_oper_classes_len;
3508
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003509 if (0 != params->ext_capab_len)
3510 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3511 sizeof(StaParams.extn_capability));
3512
3513 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003514 {
3515 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003516 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003517 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003518
3519 StaParams.supported_rates_len = params->supported_rates_len;
3520
3521 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3522 * The supported_rates array , for all the structures propogating till Add Sta
3523 * to the firmware has to be modified , if the supplicant (ieee80211) is
3524 * modified to send more rates.
3525 */
3526
3527 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3528 */
3529 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3530 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3531
3532 if (0 != StaParams.supported_rates_len) {
3533 int i = 0;
3534 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3535 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003536 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003537 "Supported Rates with Length %d", StaParams.supported_rates_len);
3538 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003539 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003540 "[%d]: %0x", i, StaParams.supported_rates[i]);
3541 }
3542
3543 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003544 {
3545 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003546 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003547 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003548
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003549 if (0 != params->ext_capab_len ) {
3550 /*Define A Macro : TODO Sunil*/
3551 if ((1<<4) & StaParams.extn_capability[3]) {
3552 isBufSta = 1;
3553 }
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303554 /* TDLS Channel Switching Support */
3555 if ((1<<6) & StaParams.extn_capability[3]) {
3556 isOffChannelSupported = 1;
3557 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003558 }
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303559 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac,
3560 &StaParams, isBufSta,
3561 isOffChannelSupported);
3562
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303563 if (VOS_STATUS_SUCCESS != status) {
3564 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3565 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3566 return -EINVAL;
3567 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003568 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3569
3570 if (VOS_STATUS_SUCCESS != status) {
3571 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3572 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3573 return -EINVAL;
3574 }
3575 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003576#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303577 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003578 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 return status;
3580}
3581
3582/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003583 * FUNCTION: wlan_hdd_cfg80211_add_key
3584 * This function is used to initialize the key information
3585 */
3586#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003587static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003588 struct net_device *ndev,
3589 u8 key_index, bool pairwise,
3590 const u8 *mac_addr,
3591 struct key_params *params
3592 )
3593#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003594static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003595 struct net_device *ndev,
3596 u8 key_index, const u8 *mac_addr,
3597 struct key_params *params
3598 )
3599#endif
3600{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003601 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003602 tCsrRoamSetKey setKey;
3603 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303604 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003605 v_U32_t roamId= 0xFF;
3606 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003607 hdd_hostapd_state_t *pHostapdState;
3608 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003609 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303610 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003611
3612 ENTER();
3613
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303614 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3615 TRACE_CODE_HDD_CFG80211_ADD_KEY,
3616 pAdapter->sessionId, params->key_len));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303617 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3618 status = wlan_hdd_validate_context(pHddCtx);
3619
3620 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003621 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3623 "%s: HDD context is not valid", __func__);
3624 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003625 }
3626
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003627 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3628 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003629
3630 if (CSR_MAX_NUM_KEY <= key_index)
3631 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003632 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003633 key_index);
3634
3635 return -EINVAL;
3636 }
3637
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003638 if (CSR_MAX_KEY_LEN < params->key_len)
3639 {
3640 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3641 params->key_len);
3642
3643 return -EINVAL;
3644 }
3645
3646 hddLog(VOS_TRACE_LEVEL_INFO,
3647 "%s: called with key index = %d & key length %d",
3648 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003649
3650 /*extract key idx, key len and key*/
3651 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3652 setKey.keyId = key_index;
3653 setKey.keyLength = params->key_len;
3654 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3655
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003656 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 {
3658 case WLAN_CIPHER_SUITE_WEP40:
3659 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3660 break;
3661
3662 case WLAN_CIPHER_SUITE_WEP104:
3663 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3664 break;
3665
3666 case WLAN_CIPHER_SUITE_TKIP:
3667 {
3668 u8 *pKey = &setKey.Key[0];
3669 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3670
3671 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3672
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003673 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003674
3675 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003676 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003677 |--------------|----------|----------|
3678 <---16bytes---><--8bytes--><--8bytes-->
3679
3680 */
3681 /*Sme expects the 32 bytes key to be in the below order
3682
3683 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003684 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003685 |--------------|----------|----------|
3686 <---16bytes---><--8bytes--><--8bytes-->
3687 */
3688 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003689 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003690
3691 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003692 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003693
3694 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003695 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003696
3697
3698 break;
3699 }
3700
3701 case WLAN_CIPHER_SUITE_CCMP:
3702 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3703 break;
3704
3705#ifdef FEATURE_WLAN_WAPI
3706 case WLAN_CIPHER_SUITE_SMS4:
3707 {
3708 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3709 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3710 params->key, params->key_len);
3711 return 0;
3712 }
3713#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003714
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003715#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07003716 case WLAN_CIPHER_SUITE_KRK:
3717 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3718 break;
3719#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003720
3721#ifdef WLAN_FEATURE_11W
3722 case WLAN_CIPHER_SUITE_AES_CMAC:
3723 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003724 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003725#endif
3726
Jeff Johnson295189b2012-06-20 16:38:30 -07003727 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003728 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003729 __func__, params->cipher);
3730 return -EOPNOTSUPP;
3731 }
3732
3733 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3734 __func__, setKey.encType);
3735
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003736 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003737#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3738 (!pairwise)
3739#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003740 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003741#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003742 )
3743 {
3744 /* set group key*/
3745 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3746 "%s- %d: setting Broadcast key",
3747 __func__, __LINE__);
3748 setKey.keyDirection = eSIR_RX_ONLY;
3749 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3750 }
3751 else
3752 {
3753 /* set pairwise key*/
3754 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3755 "%s- %d: setting pairwise key",
3756 __func__, __LINE__);
3757 setKey.keyDirection = eSIR_TX_RX;
3758 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3759 }
3760 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3761 {
3762 setKey.keyDirection = eSIR_TX_RX;
3763 /*Set the group key*/
3764 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3765 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003766
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003767 if ( 0 != status )
3768 {
3769 hddLog(VOS_TRACE_LEVEL_ERROR,
3770 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3771 return -EINVAL;
3772 }
3773 /*Save the keys here and call sme_RoamSetKey for setting
3774 the PTK after peer joins the IBSS network*/
3775 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3776 &setKey, sizeof(tCsrRoamSetKey));
3777 return status;
3778 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303779 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3780 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3781 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003782 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003783 if( pHostapdState->bssState == BSS_START )
3784 {
c_hpothu7c55da62014-01-23 18:34:02 +05303785 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3786 vos_status = wlan_hdd_check_ula_done(pAdapter);
3787
3788 if ( vos_status != VOS_STATUS_SUCCESS )
3789 {
3790 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3791 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3792 __LINE__, vos_status );
3793
3794 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3795
3796 return -EINVAL;
3797 }
3798
Jeff Johnson295189b2012-06-20 16:38:30 -07003799 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3800
3801 if ( status != eHAL_STATUS_SUCCESS )
3802 {
3803 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3804 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3805 __LINE__, status );
3806 }
3807 }
3808
3809 /* Saving WEP keys */
3810 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3811 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3812 {
3813 //Save the wep key in ap context. Issue setkey after the BSS is started.
3814 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3815 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3816 }
3817 else
3818 {
3819 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003820 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003821 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3822 }
3823 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003824 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3825 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003826 {
3827 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3828 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3829
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303830#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3831 if (!pairwise)
3832#else
3833 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3834#endif
3835 {
3836 /* set group key*/
3837 if (pHddStaCtx->roam_info.deferKeyComplete)
3838 {
3839 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3840 "%s- %d: Perform Set key Complete",
3841 __func__, __LINE__);
3842 hdd_PerformRoamSetKeyComplete(pAdapter);
3843 }
3844 }
3845
Jeff Johnson295189b2012-06-20 16:38:30 -07003846 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3847
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003848 pWextState->roamProfile.Keys.defaultIndex = key_index;
3849
3850
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003851 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003852 params->key, params->key_len);
3853
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303854
Jeff Johnson295189b2012-06-20 16:38:30 -07003855 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3856
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303857 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003858 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303859 __func__, setKey.peerMac[0], setKey.peerMac[1],
3860 setKey.peerMac[2], setKey.peerMac[3],
3861 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003862 setKey.keyDirection);
3863
3864 vos_status = wlan_hdd_check_ula_done(pAdapter);
3865
3866 if ( vos_status != VOS_STATUS_SUCCESS )
3867 {
3868 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3869 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3870 __LINE__, vos_status );
3871
3872 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3873
3874 return -EINVAL;
3875
3876 }
3877
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003878#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303879 /* The supplicant may attempt to set the PTK once pre-authentication
3880 is done. Save the key in the UMAC and include it in the ADD BSS
3881 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003882 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303883 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003884 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303885 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3886 "%s: Update PreAuth Key success", __func__);
3887 return 0;
3888 }
3889 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3890 {
3891 hddLog(VOS_TRACE_LEVEL_ERROR,
3892 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303893 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003894 }
3895#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003896
3897 /* issue set key request to SME*/
3898 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3899 pAdapter->sessionId, &setKey, &roamId );
3900
3901 if ( 0 != status )
3902 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303903 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003904 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3905 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3906 return -EINVAL;
3907 }
3908
3909
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303910 /* in case of IBSS as there was no information available about WEP keys during
3911 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003912 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303913 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3914 !( ( IW_AUTH_KEY_MGMT_802_1X
3915 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003916 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3917 )
3918 &&
3919 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3920 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3921 )
3922 )
3923 {
3924 setKey.keyDirection = eSIR_RX_ONLY;
3925 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3926
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303927 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003928 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303929 __func__, setKey.peerMac[0], setKey.peerMac[1],
3930 setKey.peerMac[2], setKey.peerMac[3],
3931 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003932 setKey.keyDirection);
3933
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303934 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003935 pAdapter->sessionId, &setKey, &roamId );
3936
3937 if ( 0 != status )
3938 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303939 hddLog(VOS_TRACE_LEVEL_ERROR,
3940 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003941 __func__, status);
3942 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3943 return -EINVAL;
3944 }
3945 }
3946 }
3947
3948 return 0;
3949}
3950
3951/*
3952 * FUNCTION: wlan_hdd_cfg80211_get_key
3953 * This function is used to get the key information
3954 */
3955#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303956static int wlan_hdd_cfg80211_get_key(
3957 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003958 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303959 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003960 const u8 *mac_addr, void *cookie,
3961 void (*callback)(void *cookie, struct key_params*)
3962 )
3963#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303964static int wlan_hdd_cfg80211_get_key(
3965 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003966 struct net_device *ndev,
3967 u8 key_index, const u8 *mac_addr, void *cookie,
3968 void (*callback)(void *cookie, struct key_params*)
3969 )
3970#endif
3971{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303972 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003973 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3974 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3975 struct key_params params;
3976
3977 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303978
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303979 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3980 TRACE_CODE_HDD_CFG80211_GET_KEY,
3981 pAdapter->sessionId, params.cipher));
Arif Hussain6d2a3322013-11-17 19:50:10 -08003982 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003983 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303984
Jeff Johnson295189b2012-06-20 16:38:30 -07003985 memset(&params, 0, sizeof(params));
3986
3987 if (CSR_MAX_NUM_KEY <= key_index)
3988 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303989 hddLog(VOS_TRACE_LEVEL_ERROR, FL("invalid key index %d"), key_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07003990 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303991 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003992
3993 switch(pRoamProfile->EncryptionType.encryptionType[0])
3994 {
3995 case eCSR_ENCRYPT_TYPE_NONE:
3996 params.cipher = IW_AUTH_CIPHER_NONE;
3997 break;
3998
3999 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
4000 case eCSR_ENCRYPT_TYPE_WEP40:
4001 params.cipher = WLAN_CIPHER_SUITE_WEP40;
4002 break;
4003
4004 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
4005 case eCSR_ENCRYPT_TYPE_WEP104:
4006 params.cipher = WLAN_CIPHER_SUITE_WEP104;
4007 break;
4008
4009 case eCSR_ENCRYPT_TYPE_TKIP:
4010 params.cipher = WLAN_CIPHER_SUITE_TKIP;
4011 break;
4012
4013 case eCSR_ENCRYPT_TYPE_AES:
4014 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
4015 break;
4016
4017 default:
4018 params.cipher = IW_AUTH_CIPHER_NONE;
4019 break;
4020 }
4021
4022 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
4023 params.seq_len = 0;
4024 params.seq = NULL;
4025 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
4026 callback(cookie, &params);
4027 return 0;
4028}
4029
4030/*
4031 * FUNCTION: wlan_hdd_cfg80211_del_key
4032 * This function is used to delete the key information
4033 */
4034#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304035static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004036 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304037 u8 key_index,
4038 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07004039 const u8 *mac_addr
4040 )
4041#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304042static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004043 struct net_device *ndev,
4044 u8 key_index,
4045 const u8 *mac_addr
4046 )
4047#endif
4048{
4049 int status = 0;
4050
4051 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304052 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07004053 //it is observed that this is invalidating peer
4054 //key index whenever re-key is done. This is affecting data link.
4055 //It should be ok to ignore del_key.
4056#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304057 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
4058 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07004059 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
4060 tCsrRoamSetKey setKey;
4061 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304062
Jeff Johnson295189b2012-06-20 16:38:30 -07004063 ENTER();
4064
4065 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
4066 __func__,pAdapter->device_mode);
4067
4068 if (CSR_MAX_NUM_KEY <= key_index)
4069 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304070 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004071 key_index);
4072
4073 return -EINVAL;
4074 }
4075
4076 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4077 setKey.keyId = key_index;
4078
4079 if (mac_addr)
4080 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
4081 else
4082 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
4083
4084 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
4085
4086 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004087 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304088 )
4089 {
4090
4091 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07004092 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
4093 if( pHostapdState->bssState == BSS_START)
4094 {
4095 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304096
Jeff Johnson295189b2012-06-20 16:38:30 -07004097 if ( status != eHAL_STATUS_SUCCESS )
4098 {
4099 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4100 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
4101 __LINE__, status );
4102 }
4103 }
4104 }
4105 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304106 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 )
4108 {
4109 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4110
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304111 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
4112
4113 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07004114 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304115 __func__, setKey.peerMac[0], setKey.peerMac[1],
4116 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07004117 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304118 if(pAdapter->sessionCtx.station.conn_info.connState ==
4119 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07004120 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304121 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004122 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304123
Jeff Johnson295189b2012-06-20 16:38:30 -07004124 if ( 0 != status )
4125 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304126 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004127 "%s: sme_RoamSetKey failure, returned %d",
4128 __func__, status);
4129 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
4130 return -EINVAL;
4131 }
4132 }
4133 }
4134#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07004135 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004136 return status;
4137}
4138
4139/*
4140 * FUNCTION: wlan_hdd_cfg80211_set_default_key
4141 * This function is used to set the default tx key index
4142 */
4143#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
4144static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4145 struct net_device *ndev,
4146 u8 key_index,
4147 bool unicast, bool multicast)
4148#else
4149static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4150 struct net_device *ndev,
4151 u8 key_index)
4152#endif
4153{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304154 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304155 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05304156 hdd_wext_state_t *pWextState;
4157 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304158 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004159
4160 ENTER();
4161
Gopichand Nakkala29149562013-05-10 21:43:41 +05304162 if ((NULL == pAdapter))
4163 {
4164 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4165 "invalid adapter");
4166 return -EINVAL;
4167 }
4168
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304169 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4170 TRACE_CODE_HDD_CFG80211_SET_DEFAULT_KEY,
4171 pAdapter->sessionId, key_index));
4172
Gopichand Nakkala29149562013-05-10 21:43:41 +05304173 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4174 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4175
4176 if ((NULL == pWextState) || (NULL == pHddStaCtx))
4177 {
4178 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4179 "invalid Wext state or HDD context");
4180 return -EINVAL;
4181 }
4182
Arif Hussain6d2a3322013-11-17 19:50:10 -08004183 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004184 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304185
Jeff Johnson295189b2012-06-20 16:38:30 -07004186 if (CSR_MAX_NUM_KEY <= key_index)
4187 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304188 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004189 key_index);
4190
4191 return -EINVAL;
4192 }
4193
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304194 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4195 status = wlan_hdd_validate_context(pHddCtx);
4196
4197 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004198 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304199 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4200 "%s: HDD context is not valid", __func__);
4201 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004202 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304203
Jeff Johnson295189b2012-06-20 16:38:30 -07004204 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07004205 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304206 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004207 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05304208 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08004209 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304210 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08004211 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07004212 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304213 {
4214 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07004215 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304216
Jeff Johnson295189b2012-06-20 16:38:30 -07004217 tCsrRoamSetKey setKey;
4218 v_U32_t roamId= 0xFF;
4219 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304220
4221 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004222 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304223
Jeff Johnson295189b2012-06-20 16:38:30 -07004224 Keys->defaultIndex = (u8)key_index;
4225 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4226 setKey.keyId = key_index;
4227 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304228
4229 vos_mem_copy(&setKey.Key[0],
4230 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07004231 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304232
Gopichand Nakkala29149562013-05-10 21:43:41 +05304233 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304234
4235 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07004236 &pHddStaCtx->conn_info.bssId[0],
4237 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304238
Gopichand Nakkala29149562013-05-10 21:43:41 +05304239 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
4240 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4241 eCSR_ENCRYPT_TYPE_WEP104)
4242 {
4243 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
4244 even though ap is configured for WEP-40 encryption. In this canse the key length
4245 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
4246 type(104) and switching encryption type to 40*/
4247 pWextState->roamProfile.EncryptionType.encryptionType[0] =
4248 eCSR_ENCRYPT_TYPE_WEP40;
4249 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
4250 eCSR_ENCRYPT_TYPE_WEP40;
4251 }
4252
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304253 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07004254 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304255
Jeff Johnson295189b2012-06-20 16:38:30 -07004256 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304257 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004258 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304259
Jeff Johnson295189b2012-06-20 16:38:30 -07004260 if ( 0 != status )
4261 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304262 hddLog(VOS_TRACE_LEVEL_ERROR,
4263 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004264 status);
4265 return -EINVAL;
4266 }
4267 }
4268 }
4269
4270 /* In SoftAp mode setting key direction for default mode */
4271 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
4272 {
4273 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
4274 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
4275 (eCSR_ENCRYPT_TYPE_AES !=
4276 pWextState->roamProfile.EncryptionType.encryptionType[0])
4277 )
4278 {
4279 /* Saving key direction for default key index to TX default */
4280 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
4281 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
4282 }
4283 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304284
Jeff Johnson295189b2012-06-20 16:38:30 -07004285 return status;
4286}
4287
Jeff Johnson295189b2012-06-20 16:38:30 -07004288/*
4289 * FUNCTION: wlan_hdd_cfg80211_inform_bss
4290 * This function is used to inform the BSS details to nl80211 interface.
4291 */
4292static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
4293 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
4294{
4295 struct net_device *dev = pAdapter->dev;
4296 struct wireless_dev *wdev = dev->ieee80211_ptr;
4297 struct wiphy *wiphy = wdev->wiphy;
4298 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4299 int chan_no;
4300 int ie_length;
4301 const char *ie;
4302 unsigned int freq;
4303 struct ieee80211_channel *chan;
4304 int rssi = 0;
4305 struct cfg80211_bss *bss = NULL;
4306
4307 ENTER();
4308
4309 if( NULL == pBssDesc )
4310 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004311 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 return bss;
4313 }
4314
4315 chan_no = pBssDesc->channelId;
4316 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4317 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4318
4319 if( NULL == ie )
4320 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004321 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004322 return bss;
4323 }
4324
4325#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4326 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4327 {
4328 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4329 }
4330 else
4331 {
4332 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4333 }
4334#else
4335 freq = ieee80211_channel_to_frequency(chan_no);
4336#endif
4337
4338 chan = __ieee80211_get_channel(wiphy, freq);
4339
4340 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4341 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4342 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4343 if (bss == NULL)
4344 {
4345 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4346
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304347 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4348 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004349 pBssDesc->capabilityInfo,
4350 pBssDesc->beaconInterval, ie, ie_length,
4351 rssi, GFP_KERNEL ));
4352}
4353 else
4354 {
4355 return bss;
4356 }
4357}
4358
4359
4360
4361/*
4362 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4363 * This function is used to inform the BSS details to nl80211 interface.
4364 */
4365struct cfg80211_bss*
4366wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4367 tSirBssDescription *bss_desc
4368 )
4369{
4370 /*
4371 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4372 already exists in bss data base of cfg80211 for that particular BSS ID.
4373 Using cfg80211_inform_bss_frame to update the bss entry instead of
4374 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4375 now there is no possibility to get the mgmt(probe response) frame from PE,
4376 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4377 cfg80211_inform_bss_frame.
4378 */
4379 struct net_device *dev = pAdapter->dev;
4380 struct wireless_dev *wdev = dev->ieee80211_ptr;
4381 struct wiphy *wiphy = wdev->wiphy;
4382 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004383#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4384 qcom_ie_age *qie_age = NULL;
4385 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4386#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004387 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004388#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004389 const char *ie =
4390 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4391 unsigned int freq;
4392 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304393 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004394 struct cfg80211_bss *bss_status = NULL;
4395 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4396 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004397 hdd_context_t *pHddCtx;
4398 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004399#ifdef WLAN_OPEN_SOURCE
4400 struct timespec ts;
4401#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004402
Wilson Yangf80a0542013-10-07 13:02:37 -07004403 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4404 status = wlan_hdd_validate_context(pHddCtx);
4405
4406 /*bss_update is not allowed during wlan driver loading or unloading*/
Mihir Shete18156292014-03-11 15:38:30 +05304407 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Wilson Yangf80a0542013-10-07 13:02:37 -07004408 {
4409 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4410 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4411 return NULL;
4412 }
4413
4414
4415 if (0 != status)
4416 {
4417 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4418 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004419 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004420 }
4421
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304422 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004423 if (!mgmt)
4424 {
4425 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4426 "%s: memory allocation failed ", __func__);
4427 return NULL;
4428 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004429
Jeff Johnson295189b2012-06-20 16:38:30 -07004430 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004431
4432#ifdef WLAN_OPEN_SOURCE
4433 /* Android does not want the timestamp from the frame.
4434 Instead it wants a monotonic increasing value */
4435 get_monotonic_boottime(&ts);
4436 mgmt->u.probe_resp.timestamp =
4437 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4438#else
4439 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004440 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4441 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004442
4443#endif
4444
Jeff Johnson295189b2012-06-20 16:38:30 -07004445 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4446 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004447
4448#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4449 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4450 /* Assuming this is the last IE, copy at the end */
4451 ie_length -=sizeof(qcom_ie_age);
4452 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4453 qie_age->element_id = QCOM_VENDOR_IE_ID;
4454 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4455 qie_age->oui_1 = QCOM_OUI1;
4456 qie_age->oui_2 = QCOM_OUI2;
4457 qie_age->oui_3 = QCOM_OUI3;
4458 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4459 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4460#endif
4461
Jeff Johnson295189b2012-06-20 16:38:30 -07004462 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304463 if (bss_desc->fProbeRsp)
4464 {
4465 mgmt->frame_control |=
4466 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4467 }
4468 else
4469 {
4470 mgmt->frame_control |=
4471 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4472 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004473
4474#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304475 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004476 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4477 {
4478 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4479 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304480 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004481 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4482
4483 {
4484 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4485 }
4486 else
4487 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304488 hddLog(VOS_TRACE_LEVEL_ERROR, "%s Invalid chan_no:%d",
4489 __func__, chan_no);
Jeff Johnson295189b2012-06-20 16:38:30 -07004490 kfree(mgmt);
4491 return NULL;
4492 }
4493#else
4494 freq = ieee80211_channel_to_frequency(chan_no);
4495#endif
4496 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004497 /*when the band is changed on the fly using the GUI, three things are done
4498 * 1. scan abort 2.flush scan results from cache 3.update the band with the new band user specified(refer to the hdd_setBand_helper function)
4499 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4500 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4501 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4502 * and discards the channels correponding to previous band and calls back with zero bss results.
4503 * but if the time between band update and scan done callback is very small then band change will not reflect in SME and SME reports to HDD
4504 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4505 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4506 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4507 * So drop the bss and continue to next bss.
4508 */
4509 if(chan == NULL)
4510 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304511 hddLog(VOS_TRACE_LEVEL_ERROR, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004512 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004513 return NULL;
4514 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004515 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304516 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 * */
4518 if (( eConnectionState_Associated ==
4519 pAdapter->sessionCtx.station.conn_info.connState ) &&
4520 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4521 pAdapter->sessionCtx.station.conn_info.bssId,
4522 WNI_CFG_BSSID_LEN)))
4523 {
4524 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4525 rssi = (pAdapter->rssi * 100);
4526 }
4527 else
4528 {
4529 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4530 }
4531
Nirav Shah20ac06f2013-12-12 18:14:06 +05304532 hddLog(VOS_TRACE_LEVEL_INFO, "%s: BSSID:" MAC_ADDRESS_STR " Channel:%d"
4533 "RSSI:%d", __func__, MAC_ADDR_ARRAY(mgmt->bssid),
4534 chan->center_freq, (int)(rssi/100));
4535
Jeff Johnson295189b2012-06-20 16:38:30 -07004536 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4537 frame_len, rssi, GFP_KERNEL);
4538 kfree(mgmt);
4539 return bss_status;
4540}
4541
4542/*
4543 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4544 * This function is used to update the BSS data base of CFG8011
4545 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304546struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004547 tCsrRoamInfo *pRoamInfo
4548 )
4549{
4550 tCsrRoamConnectedProfile roamProfile;
4551 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4552 struct cfg80211_bss *bss = NULL;
4553
4554 ENTER();
4555
4556 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4557 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4558
4559 if (NULL != roamProfile.pBssDesc)
4560 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304561 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 &roamProfile);
4563
4564 if (NULL == bss)
4565 {
4566 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4567 __func__);
4568 }
4569
4570 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4571 }
4572 else
4573 {
4574 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4575 __func__);
4576 }
4577 return bss;
4578}
4579
4580/*
4581 * FUNCTION: wlan_hdd_cfg80211_update_bss
4582 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304583static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4584 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004585 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304586{
Jeff Johnson295189b2012-06-20 16:38:30 -07004587 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4588 tCsrScanResultInfo *pScanResult;
4589 eHalStatus status = 0;
4590 tScanResultHandle pResult;
4591 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004592 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004593
4594 ENTER();
4595
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304596 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4597 TRACE_CODE_HDD_CFG80211_UPDATE_BSS,
4598 NO_SESSION, pAdapter->sessionId));
4599
Wilson Yangf80a0542013-10-07 13:02:37 -07004600 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4601
4602 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004603 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004604 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4605 "%s:LOGP in Progress. Ignore!!!",__func__);
4606 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004607 }
4608
Wilson Yangf80a0542013-10-07 13:02:37 -07004609
4610 /*bss_update is not allowed during wlan driver loading or unloading*/
Mihir Shete18156292014-03-11 15:38:30 +05304611 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Wilson Yangf80a0542013-10-07 13:02:37 -07004612 {
4613 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4614 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4615 return VOS_STATUS_E_PERM;
4616 }
4617
4618
Jeff Johnson295189b2012-06-20 16:38:30 -07004619 /*
4620 * start getting scan results and populate cgf80211 BSS database
4621 */
4622 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4623
4624 /* no scan results */
4625 if (NULL == pResult)
4626 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304627 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result Status %d",
4628 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004629 return status;
4630 }
4631
4632 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4633
4634 while (pScanResult)
4635 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304636 /*
4637 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4638 * entry already exists in bss data base of cfg80211 for that
4639 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4640 * bss entry instead of cfg80211_inform_bss, But this call expects
4641 * mgmt packet as input. As of now there is no possibility to get
4642 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004643 * ieee80211_mgmt(probe response) and passing to c
4644 * fg80211_inform_bss_frame.
4645 * */
4646
4647 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4648 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304649
Jeff Johnson295189b2012-06-20 16:38:30 -07004650
4651 if (NULL == bss_status)
4652 {
4653 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004654 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004655 }
4656 else
4657 {
Yue Maf49ba872013-08-19 12:04:25 -07004658 cfg80211_put_bss(
4659#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4660 wiphy,
4661#endif
4662 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004663 }
4664
4665 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4666 }
4667
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304668 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004669
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304670 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004671}
4672
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004673void
4674hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4675{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304676 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004677 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004678} /****** end hddPrintMacAddr() ******/
4679
4680void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004681hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004682{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304683 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004684 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004685 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4686 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4687 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004688} /****** end hddPrintPmkId() ******/
4689
4690//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4691//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4692
4693//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4694//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4695
4696#define dump_bssid(bssid) \
4697 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004698 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4699 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004700 }
4701
4702#define dump_pmkid(pMac, pmkid) \
4703 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004704 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4705 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004706 }
4707
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004708#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004709/*
4710 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4711 * This function is used to notify the supplicant of a new PMKSA candidate.
4712 */
4713int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304714 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004715 int index, bool preauth )
4716{
Jeff Johnsone7245742012-09-05 17:12:55 -07004717#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004718 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004719 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004720
4721 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004722 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004723
4724 if( NULL == pRoamInfo )
4725 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004726 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004727 return -EINVAL;
4728 }
4729
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004730 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4731 {
4732 dump_bssid(pRoamInfo->bssid);
4733 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004734 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004735 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004736#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304737 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004738}
4739#endif //FEATURE_WLAN_LFR
4740
Yue Maef608272013-04-08 23:09:17 -07004741#ifdef FEATURE_WLAN_LFR_METRICS
4742/*
4743 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4744 * 802.11r/LFR metrics reporting function to report preauth initiation
4745 *
4746 */
4747#define MAX_LFR_METRICS_EVENT_LENGTH 100
4748VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4749 tCsrRoamInfo *pRoamInfo)
4750{
4751 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4752 union iwreq_data wrqu;
4753
4754 ENTER();
4755
4756 if (NULL == pAdapter)
4757 {
4758 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4759 return VOS_STATUS_E_FAILURE;
4760 }
4761
4762 /* create the event */
4763 memset(&wrqu, 0, sizeof(wrqu));
4764 memset(metrics_notification, 0, sizeof(metrics_notification));
4765
4766 wrqu.data.pointer = metrics_notification;
4767 wrqu.data.length = scnprintf(metrics_notification,
4768 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4769 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4770
4771 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4772
4773 EXIT();
4774
4775 return VOS_STATUS_SUCCESS;
4776}
4777
4778/*
4779 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4780 * 802.11r/LFR metrics reporting function to report preauth completion
4781 * or failure
4782 */
4783VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4784 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4785{
4786 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4787 union iwreq_data wrqu;
4788
4789 ENTER();
4790
4791 if (NULL == pAdapter)
4792 {
4793 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4794 return VOS_STATUS_E_FAILURE;
4795 }
4796
4797 /* create the event */
4798 memset(&wrqu, 0, sizeof(wrqu));
4799 memset(metrics_notification, 0, sizeof(metrics_notification));
4800
4801 scnprintf(metrics_notification, sizeof(metrics_notification),
4802 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4803 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4804
4805 if (1 == preauth_status)
4806 strncat(metrics_notification, " TRUE", 5);
4807 else
4808 strncat(metrics_notification, " FALSE", 6);
4809
4810 wrqu.data.pointer = metrics_notification;
4811 wrqu.data.length = strlen(metrics_notification);
4812
4813 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4814
4815 EXIT();
4816
4817 return VOS_STATUS_SUCCESS;
4818}
4819
4820/*
4821 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4822 * 802.11r/LFR metrics reporting function to report handover initiation
4823 *
4824 */
4825VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4826 tCsrRoamInfo *pRoamInfo)
4827{
4828 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4829 union iwreq_data wrqu;
4830
4831 ENTER();
4832
4833 if (NULL == pAdapter)
4834 {
4835 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4836 return VOS_STATUS_E_FAILURE;
4837 }
4838
4839 /* create the event */
4840 memset(&wrqu, 0, sizeof(wrqu));
4841 memset(metrics_notification, 0, sizeof(metrics_notification));
4842
4843 wrqu.data.pointer = metrics_notification;
4844 wrqu.data.length = scnprintf(metrics_notification,
4845 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4846 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4847
4848 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4849
4850 EXIT();
4851
4852 return VOS_STATUS_SUCCESS;
4853}
4854#endif
4855
Jeff Johnson295189b2012-06-20 16:38:30 -07004856/*
4857 * FUNCTION: hdd_cfg80211_scan_done_callback
4858 * scanning callback function, called after finishing scan
4859 *
4860 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304861static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004862 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4863{
4864 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304865 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004866 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004867 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4868 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004869 struct cfg80211_scan_request *req = NULL;
4870 int ret = 0;
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05304871 bool aborted = false;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304872 long waitRet = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004873
4874 ENTER();
4875
4876 hddLog(VOS_TRACE_LEVEL_INFO,
4877 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004878 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004879 __func__, halHandle, pContext, (int) scanId, (int) status);
4880
Kiet Lamac06e2c2013-10-23 16:25:07 +05304881 pScanInfo->mScanPendingCounter = 0;
4882
Jeff Johnson295189b2012-06-20 16:38:30 -07004883 //Block on scan req completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304884 waitRet = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07004885 &pScanInfo->scan_req_completion_event,
4886 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304887 if (waitRet <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07004888 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304889 hddLog(VOS_TRACE_LEVEL_ERROR,
4890 "%s wait on scan_req_completion_event failed %ld",__func__, waitRet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004891 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004892 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004893 }
4894
Yue Maef608272013-04-08 23:09:17 -07004895 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004896 {
4897 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004898 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004899 }
4900
4901 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304902 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004903 {
4904 hddLog(VOS_TRACE_LEVEL_INFO,
4905 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004906 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004907 (int) scanId);
4908 }
4909
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304910 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004911 pAdapter);
4912
4913 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304914 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004915
4916
4917 /* If any client wait scan result through WEXT
4918 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004919 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004920 {
4921 /* The other scan request waiting for current scan finish
4922 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004923 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004924 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004925 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004926 }
4927 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004928 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004929 {
4930 struct net_device *dev = pAdapter->dev;
4931 union iwreq_data wrqu;
4932 int we_event;
4933 char *msg;
4934
4935 memset(&wrqu, '\0', sizeof(wrqu));
4936 we_event = SIOCGIWSCAN;
4937 msg = NULL;
4938 wireless_send_event(dev, we_event, &wrqu, msg);
4939 }
4940 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004941 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004942
4943 /* Get the Scan Req */
4944 req = pAdapter->request;
4945
4946 if (!req)
4947 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004948 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004949 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004950 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004951 }
4952
4953 /*
4954 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304955 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004956 req->n_ssids = 0;
4957 req->n_channels = 0;
4958 req->ie = 0;
4959
Jeff Johnson295189b2012-06-20 16:38:30 -07004960 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004961 /* Scan is no longer pending */
4962 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004963
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004964 /*
4965 * cfg80211_scan_done informing NL80211 about completion
4966 * of scanning
4967 */
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05304968 if (status == eCSR_SCAN_ABORT || status == eCSR_SCAN_FAILURE)
4969 {
4970 aborted = true;
4971 }
4972 cfg80211_scan_done(req, aborted);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004973 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004974
Jeff Johnsone7245742012-09-05 17:12:55 -07004975allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004976 /* release the wake lock at the end of the scan*/
4977 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004978
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004979 /* Acquire wakelock to handle the case where APP's tries to suspend
4980 * immediatly after the driver gets connect request(i.e after scan)
4981 * from supplicant, this result in app's is suspending and not able
4982 * to process the connect request to AP */
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05304983 hdd_prevent_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004984
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004985#ifdef FEATURE_WLAN_TDLS
4986 wlan_hdd_tdls_scan_done_callback(pAdapter);
4987#endif
4988
Jeff Johnson295189b2012-06-20 16:38:30 -07004989 EXIT();
4990 return 0;
4991}
4992
4993/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004994 * FUNCTION: hdd_isScanAllowed
4995 * Go through each adapter and check if scan allowed
4996 *
4997 */
4998v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4999{
5000 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
5001 hdd_station_ctx_t *pHddStaCtx = NULL;
5002 hdd_adapter_t *pAdapter = NULL;
5003 VOS_STATUS status = 0;
5004 v_U8_t staId = 0;
5005 v_U8_t *staMac = NULL;
5006
c_hpothu9b781ba2013-12-30 20:57:45 +05305007 if (TRUE == pHddCtx->btCoexModeSet)
5008 {
5009 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
5010 FL("BTCoex Mode operation in progress, Do not allow scan"));
5011 return VOS_FALSE;
5012 }
5013
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005014 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
5015
5016 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
5017 {
5018 pAdapter = pAdapterNode->pAdapter;
5019
5020 if( pAdapter )
5021 {
5022 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305023 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005024 __func__, pAdapter->device_mode);
5025 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5026 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
5027 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
5028 {
5029 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5030 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
5031 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
5032 {
5033 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
5034 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08005035 "%s: client " MAC_ADDRESS_STR
5036 " is in the middle of WPS/EAPOL exchange.", __func__,
5037 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005038 return VOS_FALSE;
5039 }
5040 }
5041 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
5042 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
5043 {
5044 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
5045 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305046 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005047 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
5048 {
5049 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
5050
5051 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08005052 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
5053 "middle of WPS/EAPOL exchange.", __func__,
5054 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005055 return VOS_FALSE;
5056 }
5057 }
5058 }
5059 }
5060 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
5061 pAdapterNode = pNext;
5062 }
5063 hddLog(VOS_TRACE_LEVEL_INFO,
5064 "%s: Scan allowed", __func__);
5065 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305066}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005067
5068/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005069 * FUNCTION: wlan_hdd_cfg80211_scan
5070 * this scan respond to scan trigger and update cfg80211 scan database
5071 * later, scan dump command can be used to recieve scan results
5072 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08005073int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
5074#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5075 struct net_device *dev,
5076#endif
5077 struct cfg80211_scan_request *request)
5078{
5079#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
5080 struct net_device *dev = request->wdev->netdev;
5081#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305082 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005083 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
5084 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305085 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005086 tCsrScanRequest scanRequest;
5087 tANI_U8 *channelList = NULL, i;
5088 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305089 int status;
5090 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005091 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005092
5093 ENTER();
5094
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05305095 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
5096 TRACE_CODE_HDD_CFG80211_SCAN,
5097 pAdapter->sessionId, request->n_channels));
5098
Arif Hussain6d2a3322013-11-17 19:50:10 -08005099 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005100 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005101
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305102 status = wlan_hdd_validate_context(pHddCtx);
5103
5104 if (0 != status)
5105 {
5106 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5107 "%s: HDD context is not valid", __func__);
5108 return status;
5109 }
5110
5111 cfg_param = pHddCtx->cfg_ini;
5112 pScanInfo = &pHddCtx->scan_info;
5113
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005114 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005115 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005116 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005117 {
5118 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005119 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
5120 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005121 return -EBUSY;
5122 }
5123
Jeff Johnson295189b2012-06-20 16:38:30 -07005124#ifdef WLAN_BTAMP_FEATURE
5125 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005126 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07005127 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005128 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005129 "%s: No scanning when AMP is on", __func__);
5130 return -EOPNOTSUPP;
5131 }
5132#endif
5133 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005134 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005136 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005137 "%s: Not scanning on device_mode = %d",
5138 __func__, pAdapter->device_mode);
5139 return -EOPNOTSUPP;
5140 }
5141
5142 if (TRUE == pScanInfo->mScanPending)
5143 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305144 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
5145 {
5146 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
5147 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005148 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005149 }
5150
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305151 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07005152 //Channel and action frame is pending
5153 //Otherwise Cancel Remain On Channel and allow Scan
5154 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005155 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07005156 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305157 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005158 return -EBUSY;
5159 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005160#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005161 /* if tdls disagree scan right now, return immediately.
5162 tdls will schedule the scan when scan is allowed. (return SUCCESS)
5163 or will reject the scan if any TDLS is in progress. (return -EBUSY)
5164 */
5165 status = wlan_hdd_tdls_scan_callback (pAdapter,
5166 wiphy,
5167#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5168 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07005169#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005170 request);
5171 if(status <= 0)
5172 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305173 if(!status)
5174 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS in progress."
5175 "scan rejected %d", __func__, status);
5176 else
5177 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS teardown is ongoing %d",
5178 __func__, status);
5179
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005180 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005181 }
5182#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07005183
Jeff Johnson295189b2012-06-20 16:38:30 -07005184 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
5185 {
5186 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08005187 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005188 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305189 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005190 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
5191 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305192 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005193 "%s: MAX TM Level Scan not allowed", __func__);
5194 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305195 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005196 }
5197 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
5198
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005199 /* Check if scan is allowed at this point of time.
5200 */
5201 if (!hdd_isScanAllowed(pHddCtx))
5202 {
5203 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
5204 return -EBUSY;
5205 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305206
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 vos_mem_zero( &scanRequest, sizeof(scanRequest));
5208
5209 if (NULL != request)
5210 {
5211 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305212 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07005213
5214 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
5215 * Becasue of this, driver is assuming that this is not wildcard scan and so
5216 * is not aging out the scan results.
5217 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07005218 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07005219 {
5220 request->n_ssids = 0;
5221 }
5222
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07005223 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07005224 {
5225 tCsrSSIDInfo *SsidInfo;
5226 int j;
5227 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
5228 /* Allocate num_ssid tCsrSSIDInfo structure */
5229 SsidInfo = scanRequest.SSIDs.SSIDList =
5230 ( tCsrSSIDInfo *)vos_mem_malloc(
5231 request->n_ssids*sizeof(tCsrSSIDInfo));
5232
5233 if(NULL == scanRequest.SSIDs.SSIDList)
5234 {
5235 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305236 "%s: memory alloc failed SSIDInfo buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005237 return -ENOMEM;
5238 }
5239
5240 /* copy all the ssid's and their length */
5241 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
5242 {
5243 /* get the ssid length */
5244 SsidInfo->SSID.length = request->ssids[j].ssid_len;
5245 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
5246 SsidInfo->SSID.length);
5247 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
Nirav Shah20ac06f2013-12-12 18:14:06 +05305248 hddLog(VOS_TRACE_LEVEL_INFO, "SSID number %d: %s",
Jeff Johnson295189b2012-06-20 16:38:30 -07005249 j, SsidInfo->SSID.ssId);
5250 }
5251 /* set the scan type to active */
5252 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5253 }
5254 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
5255 {
5256 /* set the scan type to active */
5257 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5258 }
5259 else
5260 {
5261 /*Set the scan type to default type, in this case it is ACTIVE*/
5262 scanRequest.scanType = pScanInfo->scan_mode;
5263 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305264 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07005265 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
5266 }
5267 else
5268 {
5269 /* set the scan type to active */
5270 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5271 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
5272
5273 /* set min and max channel time to zero */
5274 scanRequest.minChnTime = 0;
5275 scanRequest.maxChnTime = 0;
5276 }
5277
5278 /* set BSSType to default type */
5279 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
5280
5281 /*TODO: scan the requested channels only*/
5282
5283 /*Right now scanning all the channels */
5284 if( request )
5285 {
c_hpothu53512302014-04-15 18:49:53 +05305286 if (MAX_CHANNEL < request->n_channels)
5287 {
5288 hddLog(VOS_TRACE_LEVEL_WARN,
5289 "No of Scan Channels exceeded limit: %d", request->n_channels);
5290 request->n_channels = MAX_CHANNEL;
5291 }
Nirav Shah20ac06f2013-12-12 18:14:06 +05305292 hddLog(VOS_TRACE_LEVEL_INFO,
5293 "No of Scan Channels: %d", request->n_channels);
c_hpothu53512302014-04-15 18:49:53 +05305294
Jeff Johnson295189b2012-06-20 16:38:30 -07005295 if( request->n_channels )
5296 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305297 char chList [(request->n_channels*5)+1];
5298 int len;
Jeff Johnson295189b2012-06-20 16:38:30 -07005299 channelList = vos_mem_malloc( request->n_channels );
5300 if( NULL == channelList )
5301 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305302 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305303 "%s: memory alloc failed channelList", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005304 status = -ENOMEM;
5305 goto free_mem;
5306 }
5307
Nirav Shah20ac06f2013-12-12 18:14:06 +05305308 for( i = 0, len = 0; i < request->n_channels ; i++ )
5309 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005310 channelList[i] = request->channels[i]->hw_value;
Nirav Shah20ac06f2013-12-12 18:14:06 +05305311 len += snprintf(chList+len, 5, "%d ", channelList[i]);
5312 }
5313
5314 hddLog(VOS_TRACE_LEVEL_INFO,
5315 "Channel-List: %s ", chList);
Jeff Johnson295189b2012-06-20 16:38:30 -07005316 }
5317
5318 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
5319 scanRequest.ChannelInfo.ChannelList = channelList;
5320
5321 /* set requestType to full scan */
5322 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305323
5324 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005325 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305326 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005327 */
5328
5329 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305330 * and in that case driver shoudnt flush scan results. If
5331 * driver flushes the scan results here and unfortunately if
5332 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005333 * fails which is not desired
5334 */
5335
5336 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
5337 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305338 hddLog(VOS_TRACE_LEVEL_DEBUG, "Flushing P2P Results");
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005339 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
5340 pAdapter->sessionId );
5341 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005342
5343 if( request->ie_len )
5344 {
5345 /* save this for future association (join requires this) */
Agarwal Ashish4f616132013-12-30 23:32:50 +05305346 /*TODO: Array needs to be converted to dynamic allocation,
5347 * as multiple ie.s can be sent in cfg80211_scan_request structure
5348 * CR 597966
5349 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005350 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5351 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5352 pScanInfo->scanAddIE.length = request->ie_len;
5353
Agarwal Ashish4f616132013-12-30 23:32:50 +05305354 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07005355 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
Agarwal Ashish4f616132013-12-30 23:32:50 +05305356 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 {
Agarwal Ashish4f616132013-12-30 23:32:50 +05305358 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
5359 {
5360 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5361 memcpy( pwextBuf->roamProfile.addIEScan,
5362 request->ie, request->ie_len);
5363 }
5364 else
5365 {
5366 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
Arun Kumar Khandavalli75eeb122014-03-27 21:43:12 +05305367 "%zu", request->ie_len);
Agarwal Ashish4f616132013-12-30 23:32:50 +05305368 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005369
Agarwal Ashish4f616132013-12-30 23:32:50 +05305370 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5372 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5373
Jeff Johnson295189b2012-06-20 16:38:30 -07005374 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5375 request->ie_len);
5376 if (pP2pIe != NULL)
5377 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005378#ifdef WLAN_FEATURE_P2P_DEBUG
5379 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5380 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5381 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5382 {
5383 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5384 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5385 "Go nego completed to Connection is started");
5386 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5387 "for 8way Handshake");
5388 }
5389 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5390 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5391 {
5392 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5393 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5394 "Disconnected state to Connection is started");
5395 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5396 "for 4way Handshake");
5397 }
5398#endif
5399
Jeff Johnsone7245742012-09-05 17:12:55 -07005400 /* no_cck will be set during p2p find to disable 11b rates */
5401 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005402 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005403 hddLog(VOS_TRACE_LEVEL_INFO,
5404 "%s: This is a P2P Search", __func__);
5405 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005406
Jeff Johnsone7245742012-09-05 17:12:55 -07005407 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5408 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005409 /* set requestType to P2P Discovery */
5410 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005411 }
5412
5413 /*
5414 Skip Dfs Channel in case of P2P Search
5415 if it is set in ini file
5416 */
5417 if(cfg_param->skipDfsChnlInP2pSearch)
5418 {
5419 scanRequest.skipDfsChnlInP2pSearch = 1;
5420 }
5421 else
5422 {
5423 scanRequest.skipDfsChnlInP2pSearch = 0;
5424 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005425
Jeff Johnson295189b2012-06-20 16:38:30 -07005426 }
5427 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005428 }
5429 }
5430
5431 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5432
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005433 /* acquire the wakelock to avoid the apps suspend during the scan. To
5434 * address the following issues.
5435 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5436 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5437 * for long time, this result in apps running at full power for long time.
5438 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5439 * be stuck in full power because of resume BMPS
5440 */
5441 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005442
Nirav Shah20ac06f2013-12-12 18:14:06 +05305443 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
5444 "requestType %d, scanType %d, minChnTime %d, maxChnTime %d,"
5445 "p2pSearch %d, skipDfsChnlInP2pSearch %d", scanRequest.requestType,
5446 scanRequest.scanType, scanRequest.minChnTime, scanRequest.maxChnTime,
5447 scanRequest.p2pSearch, scanRequest.skipDfsChnlInP2pSearch);
5448
Jeff Johnsone7245742012-09-05 17:12:55 -07005449 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 pAdapter->sessionId, &scanRequest, &scanId,
5451 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005452
Jeff Johnson295189b2012-06-20 16:38:30 -07005453 if (eHAL_STATUS_SUCCESS != status)
5454 {
5455 hddLog(VOS_TRACE_LEVEL_ERROR,
5456 "%s: sme_ScanRequest returned error %d", __func__, status);
5457 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005458 if(eHAL_STATUS_RESOURCES == status)
5459 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305460 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: HO is in progress."
5461 "So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005462 status = -EBUSY;
5463 } else {
5464 status = -EIO;
5465 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005466 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005467 goto free_mem;
5468 }
5469
5470 pScanInfo->mScanPending = TRUE;
5471 pAdapter->request = request;
5472 pScanInfo->scanId = scanId;
5473
5474 complete(&pScanInfo->scan_req_completion_event);
5475
5476free_mem:
5477 if( scanRequest.SSIDs.SSIDList )
5478 {
5479 vos_mem_free(scanRequest.SSIDs.SSIDList);
5480 }
5481
5482 if( channelList )
5483 vos_mem_free( channelList );
5484
5485 EXIT();
5486
5487 return status;
5488}
5489
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005490
5491void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5492{
5493 v_U8_t iniDot11Mode =
5494 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5495 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5496
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305497 hddLog(LOG1, FL("Channel Bonding Mode Selected is %u"),
5498 iniDot11Mode);
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005499 switch ( iniDot11Mode )
5500 {
5501 case eHDD_DOT11_MODE_AUTO:
5502 case eHDD_DOT11_MODE_11ac:
5503 case eHDD_DOT11_MODE_11ac_ONLY:
5504#ifdef WLAN_FEATURE_11AC
5505 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5506#else
5507 hddDot11Mode = eHDD_DOT11_MODE_11n;
5508#endif
5509 break;
5510 case eHDD_DOT11_MODE_11n:
5511 case eHDD_DOT11_MODE_11n_ONLY:
5512 hddDot11Mode = eHDD_DOT11_MODE_11n;
5513 break;
5514 default:
5515 hddDot11Mode = iniDot11Mode;
5516 break;
5517 }
5518 /* This call decides required channel bonding mode */
5519 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5520 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5521 operationChannel);
5522}
5523
Jeff Johnson295189b2012-06-20 16:38:30 -07005524/*
5525 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305526 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005527 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305528int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005529 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005530{
5531 int status = 0;
5532 hdd_wext_state_t *pWextState;
Yue Mae36e3552014-03-05 17:06:20 -08005533 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07005534 v_U32_t roamId;
5535 tCsrRoamProfile *pRoamProfile;
Jeff Johnson295189b2012-06-20 16:38:30 -07005536 eCsrAuthType RSNAuthType;
5537
5538 ENTER();
5539
5540 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Yue Mae36e3552014-03-05 17:06:20 -08005541 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5542
5543 status = wlan_hdd_validate_context(pHddCtx);
5544 if (status)
5545 {
5546 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5547 "%s: HDD context is not valid!", __func__);
5548 return status;
5549 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305550
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5552 {
5553 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5554 return -EINVAL;
5555 }
5556
5557 pRoamProfile = &pWextState->roamProfile;
5558
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305559 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005561 hdd_station_ctx_t *pHddStaCtx;
5562 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005563
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305564 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005565 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5566 {
5567 /*QoS not enabled in cfg file*/
5568 pRoamProfile->uapsd_mask = 0;
5569 }
5570 else
5571 {
5572 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305573 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005574 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5575 }
5576
5577 pRoamProfile->SSIDs.numOfSSIDs = 1;
5578 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5579 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305580 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005581 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5582 ssid, ssid_len);
5583
5584 if (bssid)
5585 {
5586 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5587 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5588 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305589 /* Save BSSID in seperate variable as well, as RoamProfile
5590 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005591 case of join failure we should send valid BSSID to supplicant
5592 */
5593 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5594 WNI_CFG_BSSID_LEN);
5595 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005596 else
5597 {
5598 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5599 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005600
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305601 hddLog(LOG1, FL("Connect to SSID: %s opertating Channel: %u"),
5602 pRoamProfile->SSIDs.SSIDList->SSID.ssId, operatingChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5604 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305605 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005606 /*set gen ie*/
5607 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5608 /*set auth*/
5609 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5610 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005611#ifdef FEATURE_WLAN_WAPI
5612 if (pAdapter->wapi_info.nWapiMode)
5613 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005614 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005615 switch (pAdapter->wapi_info.wapiAuthMode)
5616 {
5617 case WAPI_AUTH_MODE_PSK:
5618 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005619 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005620 pAdapter->wapi_info.wapiAuthMode);
5621 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5622 break;
5623 }
5624 case WAPI_AUTH_MODE_CERT:
5625 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005626 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005627 pAdapter->wapi_info.wapiAuthMode);
5628 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5629 break;
5630 }
5631 } // End of switch
5632 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5633 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5634 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005635 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005636 pRoamProfile->AuthType.numEntries = 1;
5637 pRoamProfile->EncryptionType.numEntries = 1;
5638 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5639 pRoamProfile->mcEncryptionType.numEntries = 1;
5640 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5641 }
5642 }
5643#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305644#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305645 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305646 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5647 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5648 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305649 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5650 sizeof (tSirGtkOffloadParams));
5651 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305652 }
5653#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 pRoamProfile->csrPersona = pAdapter->device_mode;
5655
Jeff Johnson32d95a32012-09-10 13:15:23 -07005656 if( operatingChannel )
5657 {
5658 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5659 pRoamProfile->ChannelInfo.numOfChannels = 1;
5660 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005661 else
5662 {
5663 pRoamProfile->ChannelInfo.ChannelList = NULL;
5664 pRoamProfile->ChannelInfo.numOfChannels = 0;
5665 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005666 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5667 {
5668 hdd_select_cbmode(pAdapter,operatingChannel);
5669 }
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305670
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005671 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5672 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305673 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005674 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005675 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5676 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305677 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5678 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005679 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5680 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305681
5682 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 pAdapter->sessionId, pRoamProfile, &roamId);
5684
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305685 if ((eHAL_STATUS_SUCCESS != status) &&
5686 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5687 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305688
5689 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005690 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5691 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5692 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305693 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005694 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305695 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005696
5697 pRoamProfile->ChannelInfo.ChannelList = NULL;
5698 pRoamProfile->ChannelInfo.numOfChannels = 0;
5699
Jeff Johnson295189b2012-06-20 16:38:30 -07005700 }
5701 else
5702 {
5703 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5704 return -EINVAL;
5705 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005706 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005707 return status;
5708}
5709
5710/*
5711 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5712 * This function is used to set the authentication type (OPEN/SHARED).
5713 *
5714 */
5715static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5716 enum nl80211_auth_type auth_type)
5717{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305718 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005719 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5720
5721 ENTER();
5722
5723 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305724 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005725 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005726 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305727 hddLog(VOS_TRACE_LEVEL_INFO,
5728 "%s: set authentication type to AUTOSWITCH", __func__);
5729 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5730 break;
5731
5732 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005733#ifdef WLAN_FEATURE_VOWIFI_11R
5734 case NL80211_AUTHTYPE_FT:
5735#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305736 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005737 "%s: set authentication type to OPEN", __func__);
5738 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5739 break;
5740
5741 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305742 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005743 "%s: set authentication type to SHARED", __func__);
5744 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5745 break;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005746#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005747 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305748 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005749 "%s: set authentication type to CCKM WPA", __func__);
5750 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5751 break;
5752#endif
5753
5754
5755 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305756 hddLog(VOS_TRACE_LEVEL_ERROR,
5757 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 auth_type);
5759 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5760 return -EINVAL;
5761 }
5762
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305763 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 pHddStaCtx->conn_info.authType;
5765 return 0;
5766}
5767
5768/*
5769 * FUNCTION: wlan_hdd_set_akm_suite
5770 * This function is used to set the key mgmt type(PSK/8021x).
5771 *
5772 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305773static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005774 u32 key_mgmt
5775 )
5776{
5777 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5778 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305779
Jeff Johnson295189b2012-06-20 16:38:30 -07005780 /*set key mgmt type*/
5781 switch(key_mgmt)
5782 {
5783 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305784#ifdef WLAN_FEATURE_VOWIFI_11R
5785 case WLAN_AKM_SUITE_FT_PSK:
5786#endif
5787 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005788 __func__);
5789 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5790 break;
5791
5792 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305793#ifdef WLAN_FEATURE_VOWIFI_11R
5794 case WLAN_AKM_SUITE_FT_8021X:
5795#endif
5796 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005797 __func__);
5798 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5799 break;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005800#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005801#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5802#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5803 case WLAN_AKM_SUITE_CCKM:
5804 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5805 __func__);
5806 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5807 break;
5808#endif
5809
5810 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305811 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 __func__, key_mgmt);
5813 return -EINVAL;
5814
5815 }
5816 return 0;
5817}
5818
5819/*
5820 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305821 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005822 * (NONE/WEP40/WEP104/TKIP/CCMP).
5823 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305824static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5825 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005826 bool ucast
5827 )
5828{
5829 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305830 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005831 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5832
5833 ENTER();
5834
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305835 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005836 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305837 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005838 __func__, cipher);
5839 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5840 }
5841 else
5842 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305843
Jeff Johnson295189b2012-06-20 16:38:30 -07005844 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305845 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005846 {
5847 case IW_AUTH_CIPHER_NONE:
5848 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5849 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305850
Jeff Johnson295189b2012-06-20 16:38:30 -07005851 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305852 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005853 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305854
Jeff Johnson295189b2012-06-20 16:38:30 -07005855 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305856 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005857 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305858
Jeff Johnson295189b2012-06-20 16:38:30 -07005859 case WLAN_CIPHER_SUITE_TKIP:
5860 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5861 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305862
Jeff Johnson295189b2012-06-20 16:38:30 -07005863 case WLAN_CIPHER_SUITE_CCMP:
5864 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5865 break;
5866#ifdef FEATURE_WLAN_WAPI
5867 case WLAN_CIPHER_SUITE_SMS4:
5868 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5869 break;
5870#endif
5871
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005872#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005873 case WLAN_CIPHER_SUITE_KRK:
5874 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5875 break;
5876#endif
5877 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305878 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 __func__, cipher);
5880 return -EOPNOTSUPP;
5881 }
5882 }
5883
5884 if (ucast)
5885 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305886 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005887 __func__, encryptionType);
5888 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5889 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305890 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005891 encryptionType;
5892 }
5893 else
5894 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305895 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005896 __func__, encryptionType);
5897 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5898 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5899 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5900 }
5901
5902 return 0;
5903}
5904
5905
5906/*
5907 * FUNCTION: wlan_hdd_cfg80211_set_ie
5908 * This function is used to parse WPA/RSN IE's.
5909 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305910int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5911 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005912 size_t ie_len
5913 )
5914{
5915 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5916 u8 *genie = ie;
5917 v_U16_t remLen = ie_len;
5918#ifdef FEATURE_WLAN_WAPI
5919 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5920 u16 *tmp;
5921 v_U16_t akmsuiteCount;
5922 int *akmlist;
5923#endif
5924 ENTER();
5925
5926 /* clear previous assocAddIE */
5927 pWextState->assocAddIE.length = 0;
5928 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07005929 pWextState->roamProfile.bOSENAssociation = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005930
5931 while (remLen >= 2)
5932 {
5933 v_U16_t eLen = 0;
5934 v_U8_t elementId;
5935 elementId = *genie++;
5936 eLen = *genie++;
5937 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305938
Arif Hussain6d2a3322013-11-17 19:50:10 -08005939 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305941
5942 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005943 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305944 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005945 if (4 > eLen) /* should have at least OUI which is 4 bytes so extra 2 bytes not needed */
Jeff Johnson295189b2012-06-20 16:38:30 -07005946 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305947 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005948 "%s: Invalid WPA IE", __func__);
5949 return -EINVAL;
5950 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305951 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005952 {
5953 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305954 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005955 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305956
Jeff Johnson295189b2012-06-20 16:38:30 -07005957 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5958 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005959 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5960 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005961 VOS_ASSERT(0);
5962 return -ENOMEM;
5963 }
5964 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5965 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5966 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305967
Jeff Johnson295189b2012-06-20 16:38:30 -07005968 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5969 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5970 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5971 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305972 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5973 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005974 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5975 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5976 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5977 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5978 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5979 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305980 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05305981 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005982 {
5983 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305984 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005985 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305986
Jeff Johnson295189b2012-06-20 16:38:30 -07005987 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5988 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005989 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5990 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005991 VOS_ASSERT(0);
5992 return -ENOMEM;
5993 }
5994 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5995 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5996 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305997
Jeff Johnson295189b2012-06-20 16:38:30 -07005998 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5999 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6000 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006001#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306002 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
6003 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006004 /*Consider WFD IE, only for P2P Client */
6005 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
6006 {
6007 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306008 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07006009 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306010
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6012 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006013 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6014 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07006015 VOS_ASSERT(0);
6016 return -ENOMEM;
6017 }
6018 // WFD IE is saved to Additional IE ; it should be accumulated to handle
6019 // WPS IE + P2P IE + WFD IE
6020 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6021 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306022
Jeff Johnson295189b2012-06-20 16:38:30 -07006023 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6024 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6025 }
6026#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006027 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306028 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006029 HS20_OUI_TYPE_SIZE)) )
6030 {
6031 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306032 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006033 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006034
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006035 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6036 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006037 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6038 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006039 VOS_ASSERT(0);
6040 return -ENOMEM;
6041 }
6042 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6043 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006044
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006045 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6046 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6047 }
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07006048 /* Appending OSEN Information Element in Assiciation Request */
6049 else if ( (0 == memcmp(&genie[0], OSEN_OUI_TYPE,
6050 OSEN_OUI_TYPE_SIZE)) )
6051 {
6052 v_U16_t curAddIELen = pWextState->assocAddIE.length;
6053 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set OSEN IE(len %d)",
6054 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006055
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07006056 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6057 {
6058 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6059 "Need bigger buffer space");
6060 VOS_ASSERT(0);
6061 return -ENOMEM;
6062 }
6063 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6064 pWextState->assocAddIE.length += eLen + 2;
6065
6066 pWextState->roamProfile.bOSENAssociation = VOS_TRUE;
6067 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6068 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6069 }
6070
6071 break;
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07006072 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
6073
6074 /* populating as ADDIE in beacon frames */
6075 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6076 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
6077 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
6078 {
6079 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6080 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
6081 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6082 {
6083 hddLog(LOGE,
6084 "Coldn't pass "
6085 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
6086 }
6087 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
6088 else
6089 hddLog(LOGE,
6090 "Could not pass on "
6091 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
6092
6093 /* IBSS mode doesn't contain params->proberesp_ies still
6094 beaconIE's need to be populated in probe response frames */
6095 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
6096 {
6097 u16 rem_probe_resp_ie_len = eLen + 2;
6098 u8 probe_rsp_ie_len[3] = {0};
6099 u8 counter = 0;
6100
6101 /* Check Probe Resp Length if it is greater then 255 then
6102 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
6103 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
6104 not able Store More then 255 bytes into One Variable */
6105
6106 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
6107 {
6108 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
6109 {
6110 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
6111 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
6112 }
6113 else
6114 {
6115 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
6116 rem_probe_resp_ie_len = 0;
6117 }
6118 }
6119
6120 rem_probe_resp_ie_len = 0;
6121
6122 if (probe_rsp_ie_len[0] > 0)
6123 {
6124 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6125 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
6126 (tANI_U8*)(genie - 2),
6127 probe_rsp_ie_len[0], NULL,
6128 eANI_BOOLEAN_FALSE)
6129 == eHAL_STATUS_FAILURE)
6130 {
6131 hddLog(LOGE,
6132 "Could not pass"
6133 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
6134 }
6135 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
6136 }
6137
6138 if (probe_rsp_ie_len[1] > 0)
6139 {
6140 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6141 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
6142 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
6143 probe_rsp_ie_len[1], NULL,
6144 eANI_BOOLEAN_FALSE)
6145 == eHAL_STATUS_FAILURE)
6146 {
6147 hddLog(LOGE,
6148 "Could not pass"
6149 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
6150 }
6151 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
6152 }
6153
6154 if (probe_rsp_ie_len[2] > 0)
6155 {
6156 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6157 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
6158 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
6159 probe_rsp_ie_len[2], NULL,
6160 eANI_BOOLEAN_FALSE)
6161 == eHAL_STATUS_FAILURE)
6162 {
6163 hddLog(LOGE,
6164 "Could not pass"
6165 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
6166 }
6167 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
6168 }
6169
6170 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6171 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6172 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6173 {
6174 hddLog(LOGE,
6175 "Could not pass"
6176 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
6177 }
6178 }
6179 else
6180 {
6181 // Reset WNI_CFG_PROBE_RSP Flags
6182 wlan_hdd_reset_prob_rspies(pAdapter);
6183
6184 hddLog(VOS_TRACE_LEVEL_INFO,
6185 "%s: No Probe Response IE received in set beacon",
6186 __func__);
6187 }
6188 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07006189 break;
6190 case DOT11F_EID_RSN:
6191 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
6192 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
6193 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
6194 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
6195 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
6196 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006197 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
6198 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306199 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006200 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306201 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006202 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306203
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006204 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6205 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006206 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6207 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006208 VOS_ASSERT(0);
6209 return -ENOMEM;
6210 }
6211 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6212 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306213
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006214 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6215 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6216 break;
6217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006218#ifdef FEATURE_WLAN_WAPI
6219 case WLAN_EID_WAPI:
6220 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006221 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07006222 pAdapter->wapi_info.nWapiMode);
6223 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306224 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07006225 akmsuiteCount = WPA_GET_LE16(tmp);
6226 tmp = tmp + 1;
6227 akmlist = (int *)(tmp);
6228 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
6229 {
6230 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
6231 }
6232 else
6233 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006234 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 VOS_ASSERT(0);
6236 return -EINVAL;
6237 }
6238
6239 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
6240 {
6241 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006242 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306244 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306246 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006247 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006248 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
6250 }
6251 break;
6252#endif
6253 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306254 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006255 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006256 /* when Unknown IE is received we should break and continue
6257 * to the next IE in the buffer instead we were returning
6258 * so changing this to break */
6259 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006260 }
6261 genie += eLen;
6262 remLen -= eLen;
6263 }
6264 EXIT();
6265 return 0;
6266}
6267
6268/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05306269 * FUNCTION: hdd_isWPAIEPresent
6270 * Parse the received IE to find the WPA IE
6271 *
6272 */
6273static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
6274{
6275 v_U8_t eLen = 0;
6276 v_U16_t remLen = ie_len;
6277 v_U8_t elementId = 0;
6278
6279 while (remLen >= 2)
6280 {
6281 elementId = *ie++;
6282 eLen = *ie++;
6283 remLen -= 2;
6284 if (eLen > remLen)
6285 {
6286 hddLog(VOS_TRACE_LEVEL_ERROR,
6287 "%s: IE length is wrong %d", __func__, eLen);
6288 return FALSE;
6289 }
6290 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
6291 {
6292 /* OUI - 0x00 0X50 0XF2
6293 WPA Information Element - 0x01
6294 WPA version - 0x01*/
6295 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
6296 return TRUE;
6297 }
6298 ie += eLen;
6299 remLen -= eLen;
6300 }
6301 return FALSE;
6302}
6303
6304/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006305 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306306 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 * parameters during connect operation.
6308 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306309int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006310 struct cfg80211_connect_params *req
6311 )
6312{
6313 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306314 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006315 ENTER();
6316
6317 /*set wpa version*/
6318 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6319
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306320 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05306322 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006323 {
6324 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6325 }
6326 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
6327 {
6328 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6329 }
6330 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306331
6332 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006333 pWextState->wpaVersion);
6334
6335 /*set authentication type*/
6336 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
6337
6338 if (0 > status)
6339 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306340 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006341 "%s: failed to set authentication type ", __func__);
6342 return status;
6343 }
6344
6345 /*set key mgmt type*/
6346 if (req->crypto.n_akm_suites)
6347 {
6348 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
6349 if (0 > status)
6350 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306351 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07006352 __func__);
6353 return status;
6354 }
6355 }
6356
6357 /*set pairwise cipher type*/
6358 if (req->crypto.n_ciphers_pairwise)
6359 {
6360 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6361 req->crypto.ciphers_pairwise[0], true);
6362 if (0 > status)
6363 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306364 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006365 "%s: failed to set unicast cipher type", __func__);
6366 return status;
6367 }
6368 }
6369 else
6370 {
6371 /*Reset previous cipher suite to none*/
6372 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6373 if (0 > status)
6374 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306375 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006376 "%s: failed to set unicast cipher type", __func__);
6377 return status;
6378 }
6379 }
6380
6381 /*set group cipher type*/
6382 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6383 false);
6384
6385 if (0 > status)
6386 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306387 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006388 __func__);
6389 return status;
6390 }
6391
Chet Lanctot186b5732013-03-18 10:26:30 -07006392#ifdef WLAN_FEATURE_11W
6393 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6394#endif
6395
Jeff Johnson295189b2012-06-20 16:38:30 -07006396 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6397 if (req->ie_len)
6398 {
6399 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6400 if ( 0 > status)
6401 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306402 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 __func__);
6404 return status;
6405 }
6406 }
6407
6408 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306409 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006410 {
6411 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6412 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6413 )
6414 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306415 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006416 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6417 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306418 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006419 __func__);
6420 return -EOPNOTSUPP;
6421 }
6422 else
6423 {
6424 u8 key_len = req->key_len;
6425 u8 key_idx = req->key_idx;
6426
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306427 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006428 && (CSR_MAX_NUM_KEY > key_idx)
6429 )
6430 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306431 hddLog(VOS_TRACE_LEVEL_INFO,
6432 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006433 __func__, key_idx, key_len);
6434 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306435 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306437 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006438 (u8)key_len;
6439 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6440 }
6441 }
6442 }
6443 }
6444
6445 return status;
6446}
6447
6448/*
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306449 * FUNCTION: wlan_hdd_try_disconnect
6450 * This function is used to disconnect from previous
6451 * connection
6452 */
6453static int wlan_hdd_try_disconnect( hdd_adapter_t *pAdapter )
6454{
6455 long ret = 0;
6456 hdd_station_ctx_t *pHddStaCtx;
6457 eMib_dot11DesiredBssType connectedBssType;
6458
6459 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6460
6461 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
6462
6463 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
6464 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
6465 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
6466 {
6467 /* Issue disconnect to CSR */
6468 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6469 if( eHAL_STATUS_SUCCESS ==
6470 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6471 pAdapter->sessionId,
6472 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
6473 {
6474 ret = wait_for_completion_interruptible_timeout(
6475 &pAdapter->disconnect_comp_var,
6476 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6477 if (0 >= ret)
6478 {
6479 hddLog(LOGE, FL("Failed to receive disconnect event"));
6480 return -EALREADY;
6481 }
6482 }
6483 }
6484 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
6485 {
6486 ret = wait_for_completion_interruptible_timeout(
6487 &pAdapter->disconnect_comp_var,
6488 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6489 if (0 >= ret)
6490 {
6491 hddLog(LOGE, FL("Failed to receive disconnect event"));
6492 return -EALREADY;
6493 }
6494 }
6495
6496 return 0;
6497}
6498
6499/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006500 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306501 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006502 * parameters during connect operation.
6503 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306504static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006505 struct net_device *ndev,
6506 struct cfg80211_connect_params *req
6507 )
6508{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306509 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306510 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006511 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006512 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006513
6514 ENTER();
6515
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306516 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6517 TRACE_CODE_HDD_CFG80211_CONNECT,
6518 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306519 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006520 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006521
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306522 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006523 if (!pHddCtx)
6524 {
6525 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6526 "%s: HDD context is null", __func__);
6527 return VOS_STATUS_E_FAILURE;
6528 }
6529
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306530 status = wlan_hdd_validate_context(pHddCtx);
6531
6532 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006533 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306534 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6535 "%s: HDD context is not valid", __func__);
6536 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006537 }
6538
6539#ifdef WLAN_BTAMP_FEATURE
6540 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306541 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006542 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306543 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006544 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006545 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006546 }
6547#endif
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306548
6549 //If Device Mode is Station Concurrent Sessions Exit BMps
6550 //P2P Mode will be taken care in Open/close adapter
6551 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6552 (vos_concurrent_sessions_running()))
6553 {
6554 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
6555 }
6556
6557 /*Try disconnecting if already in connected state*/
6558 status = wlan_hdd_try_disconnect(pAdapter);
6559 if ( 0 > status)
6560 {
6561 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6562 " connection"));
6563 return -EALREADY;
6564 }
6565
Jeff Johnson295189b2012-06-20 16:38:30 -07006566 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306567 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006568
6569 if ( 0 > status)
6570 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306571 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006572 __func__);
6573 return status;
6574 }
6575
Mohit Khanna765234a2012-09-11 15:08:35 -07006576 if ( req->channel )
6577 {
6578 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6579 req->ssid_len, req->bssid,
6580 req->channel->hw_value);
6581 }
6582 else
6583 {
6584 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306585 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006586 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006587
6588 if (0 > status)
6589 {
6590 //ReEnable BMPS if disabled
6591 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6592 (NULL != pHddCtx))
6593 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306594 if (pHddCtx->hdd_wlan_suspended)
6595 {
6596 hdd_set_pwrparams(pHddCtx);
6597 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006598 //ReEnable Bmps and Imps back
6599 hdd_enable_bmps_imps(pHddCtx);
6600 }
6601
6602 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6603 return status;
6604 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306605 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006606 EXIT();
6607 return status;
6608}
6609
6610
6611/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306612 * FUNCTION: wlan_hdd_disconnect
6613 * This function is used to issue a disconnect request to SME
6614 */
6615int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6616{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306617 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306618 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306619 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6620
6621 status = wlan_hdd_validate_context(pHddCtx);
6622
6623 if (0 != status)
6624 {
6625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6626 "%s: HDD context is not valid", __func__);
6627 return status;
6628 }
6629
6630 pHddCtx->isAmpAllowed = VOS_TRUE;
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05306631 pHddStaCtx->conn_info.connState = eConnectionState_Disconnecting;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306632 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306633
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306634 /*issue disconnect*/
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05306635
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306636 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6637 pAdapter->sessionId, reason);
6638
6639 if ( 0 != status )
6640 {
6641 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006642 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306643 __func__, (int)status );
6644 return -EINVAL;
6645 }
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306646 status = wait_for_completion_interruptible_timeout(
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306647 &pAdapter->disconnect_comp_var,
6648 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306649 if (!status)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306650 {
6651 hddLog(VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306652 "%s: Failed to disconnect, timed out", __func__);
6653 return -ETIMEDOUT;
6654 }
6655 else if (status == -ERESTARTSYS)
6656 {
6657 hddLog(VOS_TRACE_LEVEL_ERROR,
6658 "%s: Failed to disconnect, wait interrupted", __func__);
6659 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306660 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306661 /*stop tx queues*/
6662 netif_tx_disable(pAdapter->dev);
6663 netif_carrier_off(pAdapter->dev);
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306664 return 0;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306665}
6666
6667
6668/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006669 * FUNCTION: wlan_hdd_cfg80211_disconnect
6670 * This function is used to issue a disconnect request to SME
6671 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306672static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006673 struct net_device *dev,
6674 u16 reason
6675 )
6676{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306677 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6678 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006679 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306680 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006682 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306683#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006684 tANI_U8 staIdx;
6685#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306686
Jeff Johnson295189b2012-06-20 16:38:30 -07006687 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306688
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306689 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6690 TRACE_CODE_HDD_CFG80211_DISCONNECT,
6691 pAdapter->sessionId, reason));
6692 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006693 __func__,pAdapter->device_mode);
6694
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306695 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6696 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006697
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306698 status = wlan_hdd_validate_context(pHddCtx);
6699
6700 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006701 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306702 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6703 "%s: HDD context is not valid", __func__);
6704 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006705 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306706
Jeff Johnson295189b2012-06-20 16:38:30 -07006707 if (NULL != pRoamProfile)
6708 {
6709 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306710 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6711 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006712 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306713 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006714 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306715 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006716 switch(reason)
6717 {
6718 case WLAN_REASON_MIC_FAILURE:
6719 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6720 break;
6721
6722 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6723 case WLAN_REASON_DISASSOC_AP_BUSY:
6724 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6725 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6726 break;
6727
6728 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6729 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6730 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6731 break;
6732
6733 case WLAN_REASON_DEAUTH_LEAVING:
6734 default:
6735 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6736 break;
6737 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306738 pScanInfo = &pHddCtx->scan_info;
6739 if (pScanInfo->mScanPending)
6740 {
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306741 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306742 "Aborting Scan");
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306743 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId,
6744 eCSR_SCAN_ABORT_DEFAULT);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306745 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006746
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006747#ifdef FEATURE_WLAN_TDLS
6748 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006749 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006750 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006751 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6752 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006753 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006754 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006755 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006756 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006757 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006758 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006759 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006760 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006761 pAdapter->sessionId,
6762 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006763 }
6764 }
6765#endif
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05306766 hddLog(LOG1, FL("Disconnecting with reasoncode:%u"), reasonCode);
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306767 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6768 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006769 {
6770 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006771 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006772 __func__, (int)status );
6773 return -EINVAL;
6774 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006775 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306776 else
6777 {
6778 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6779 "called while in %d state", __func__,
6780 pHddStaCtx->conn_info.connState);
6781 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006782 }
6783 else
6784 {
6785 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6786 }
6787
6788 return status;
6789}
6790
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306791
Jeff Johnson295189b2012-06-20 16:38:30 -07006792/*
6793 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306794 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006795 * settings in IBSS mode.
6796 */
6797static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306798 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006799 struct cfg80211_ibss_params *params
6800 )
6801{
6802 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306803 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006804 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6805 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306806
Jeff Johnson295189b2012-06-20 16:38:30 -07006807 ENTER();
6808
6809 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006810 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006811
6812 if (params->ie_len && ( NULL != params->ie) )
6813 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006814 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6815 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 {
6817 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6818 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6819 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006820 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006821 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006822 tDot11fIEWPA dot11WPAIE;
6823 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006824 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006825
Wilson Yang00256342013-10-10 23:13:38 -07006826 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006827 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6828 params->ie_len, DOT11F_EID_WPA);
6829 if ( NULL != ie )
6830 {
6831 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6832 // Unpack the WPA IE
6833 //Skip past the EID byte and length byte - and four byte WiFi OUI
6834 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6835 &ie[2+4],
6836 ie[1] - 4,
6837 &dot11WPAIE);
6838 /*Extract the multicast cipher, the encType for unicast
6839 cipher for wpa-none is none*/
6840 encryptionType =
6841 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6842 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006843 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006844
Jeff Johnson295189b2012-06-20 16:38:30 -07006845 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6846
6847 if (0 > status)
6848 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306849 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006850 __func__);
6851 return status;
6852 }
6853 }
6854
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306855 pWextState->roamProfile.AuthType.authType[0] =
6856 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6858
6859 if (params->privacy)
6860 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306861 /* Security enabled IBSS, At this time there is no information available
6862 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006863 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306864 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006865 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306866 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006867 *enable privacy bit in beacons */
6868
6869 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6870 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006871 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6872 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006873 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6874 pWextState->roamProfile.EncryptionType.numEntries = 1;
6875 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 return status;
6877}
6878
6879/*
6880 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306881 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006882 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306883static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 struct net_device *dev,
6885 struct cfg80211_ibss_params *params
6886 )
6887{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306888 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006889 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6890 tCsrRoamProfile *pRoamProfile;
6891 int status;
krunal sonie9002db2013-11-25 14:24:17 -08006892 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006893 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306894 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006895
6896 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306897
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306898 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6899 TRACE_CODE_HDD_CFG80211_JOIN_IBSS,
6900 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306901 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006902 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006903
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306904 status = wlan_hdd_validate_context(pHddCtx);
6905
6906 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006907 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306908 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6909 "%s: HDD context is not valid", __func__);
6910 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006911 }
6912
6913 if (NULL == pWextState)
6914 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006915 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006916 __func__);
6917 return -EIO;
6918 }
6919
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306920 /*Try disconnecting if already in connected state*/
6921 status = wlan_hdd_try_disconnect(pAdapter);
6922 if ( 0 > status)
6923 {
6924 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6925 " IBSS connection"));
6926 return -EALREADY;
6927 }
6928
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 pRoamProfile = &pWextState->roamProfile;
6930
6931 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6932 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306933 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006934 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006935 return -EINVAL;
6936 }
6937
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006938 /* BSSID is provided by upper layers hence no need to AUTO generate */
6939 if (NULL != params->bssid) {
6940 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6941 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
6942 hddLog (VOS_TRACE_LEVEL_ERROR,
6943 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6944 return -EIO;
6945 }
6946 }
krunal sonie9002db2013-11-25 14:24:17 -08006947 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
6948 {
6949 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6950 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
6951 {
6952 hddLog (VOS_TRACE_LEVEL_ERROR,
6953 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6954 return -EIO;
6955 }
6956 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
6957 if (!params->bssid)
6958 {
6959 hddLog (VOS_TRACE_LEVEL_ERROR,
6960 "%s:Failed memory allocation", __func__);
6961 return -EIO;
6962 }
6963 vos_mem_copy((v_U8_t *)params->bssid,
6964 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
6965 VOS_MAC_ADDR_SIZE);
6966 alloc_bssid = VOS_TRUE;
6967 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006968
Jeff Johnson295189b2012-06-20 16:38:30 -07006969 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006970 if (NULL !=
6971#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6972 params->chandef.chan)
6973#else
6974 params->channel)
6975#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006976 {
6977 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006978 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6979 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6980 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6981 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006982
6983 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306984 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006985 ieee80211_frequency_to_channel(
6986#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6987 params->chandef.chan->center_freq);
6988#else
6989 params->channel->center_freq);
6990#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006991
6992 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6993 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006994 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006995 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6996 __func__);
6997 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006998 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006999
7000 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007002 if (channelNum == validChan[indx])
7003 {
7004 break;
7005 }
7006 }
7007 if (indx >= numChans)
7008 {
7009 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07007010 __func__, channelNum);
7011 return -EINVAL;
7012 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007013 /* Set the Operational Channel */
7014 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
7015 channelNum);
7016 pRoamProfile->ChannelInfo.numOfChannels = 1;
7017 pHddStaCtx->conn_info.operationChannel = channelNum;
7018 pRoamProfile->ChannelInfo.ChannelList =
7019 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07007020 }
7021
7022 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307023 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07007024 if (status < 0)
7025 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307026 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 __func__);
7028 return status;
7029 }
7030
7031 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307032 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007033 params->ssid_len, params->bssid,
7034 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007035
7036 if (0 > status)
7037 {
7038 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
7039 return status;
7040 }
7041
krunal sonie9002db2013-11-25 14:24:17 -08007042 if (NULL != params->bssid &&
7043 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
7044 alloc_bssid == VOS_TRUE)
7045 {
7046 vos_mem_free(params->bssid);
7047 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007048 return 0;
7049}
7050
7051/*
7052 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307053 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07007054 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307055static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07007056 struct net_device *dev
7057 )
7058{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307059 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07007060 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
7061 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307062 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7063 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007064
7065 ENTER();
7066
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307067 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7068 TRACE_CODE_HDD_CFG80211_LEAVE_IBSS,
7069 pAdapter->sessionId, eCSR_DISCONNECT_REASON_IBSS_LEAVE));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307070 status = wlan_hdd_validate_context(pHddCtx);
7071
7072 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007073 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307074 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7075 "%s: HDD context is not valid", __func__);
7076 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007077 }
7078
Arif Hussain6d2a3322013-11-17 19:50:10 -08007079 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07007080 if (NULL == pWextState)
7081 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007082 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07007083 __func__);
7084 return -EIO;
7085 }
7086
7087 pRoamProfile = &pWextState->roamProfile;
7088
7089 /* Issue disconnect only if interface type is set to IBSS */
7090 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
7091 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307092 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07007093 __func__);
7094 return -EINVAL;
7095 }
7096
7097 /* Issue Disconnect request */
7098 INIT_COMPLETION(pAdapter->disconnect_comp_var);
7099 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7100 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
7101
7102 return 0;
7103}
7104
7105/*
7106 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
7107 * This function is used to set the phy parameters
7108 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
7109 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307110static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07007111 u32 changed)
7112{
7113 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
7114 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307115 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007116
7117 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307118 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7119 TRACE_CODE_HDD_CFG80211_SET_WIPHY_PARAMS,
7120 NO_SESSION, wiphy->rts_threshold));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307121 status = wlan_hdd_validate_context(pHddCtx);
7122
7123 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007124 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307125 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7126 "%s: HDD context is not valid", __func__);
7127 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007128 }
7129
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
7131 {
7132 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
7133 WNI_CFG_RTS_THRESHOLD_STAMAX :
7134 wiphy->rts_threshold;
7135
7136 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307137 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07007138 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307139 hddLog(VOS_TRACE_LEVEL_ERROR,
7140 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007141 __func__, rts_threshold);
7142 return -EINVAL;
7143 }
7144
7145 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
7146 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307147 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007148 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307149 hddLog(VOS_TRACE_LEVEL_ERROR,
7150 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007151 __func__, rts_threshold);
7152 return -EIO;
7153 }
7154
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307155 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007156 rts_threshold);
7157 }
7158
7159 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
7160 {
7161 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
7162 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
7163 wiphy->frag_threshold;
7164
7165 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307166 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007167 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307168 hddLog(VOS_TRACE_LEVEL_ERROR,
7169 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007170 frag_threshold);
7171 return -EINVAL;
7172 }
7173
7174 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
7175 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307176 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007177 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307178 hddLog(VOS_TRACE_LEVEL_ERROR,
7179 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007180 __func__, frag_threshold);
7181 return -EIO;
7182 }
7183
7184 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
7185 frag_threshold);
7186 }
7187
7188 if ((changed & WIPHY_PARAM_RETRY_SHORT)
7189 || (changed & WIPHY_PARAM_RETRY_LONG))
7190 {
7191 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
7192 wiphy->retry_short :
7193 wiphy->retry_long;
7194
7195 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
7196 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
7197 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307198 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007199 __func__, retry_value);
7200 return -EINVAL;
7201 }
7202
7203 if (changed & WIPHY_PARAM_RETRY_SHORT)
7204 {
7205 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
7206 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307207 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007208 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307209 hddLog(VOS_TRACE_LEVEL_ERROR,
7210 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007211 __func__, retry_value);
7212 return -EIO;
7213 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307214 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007215 __func__, retry_value);
7216 }
7217 else if (changed & WIPHY_PARAM_RETRY_SHORT)
7218 {
7219 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
7220 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307221 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007222 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307223 hddLog(VOS_TRACE_LEVEL_ERROR,
7224 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007225 __func__, retry_value);
7226 return -EIO;
7227 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307228 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 __func__, retry_value);
7230 }
7231 }
7232
7233 return 0;
7234}
7235
7236/*
7237 * FUNCTION: wlan_hdd_cfg80211_set_txpower
7238 * This function is used to set the txpower
7239 */
7240static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07007241#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7242 struct wireless_dev *wdev,
7243#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007244#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307245 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007246#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307247 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007248#endif
7249 int dbm)
7250{
7251 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307252 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007253 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
7254 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307255 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007256
7257 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307258 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7259 TRACE_CODE_HDD_CFG80211_SET_TXPOWER,
7260 NO_SESSION, type ));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307261 status = wlan_hdd_validate_context(pHddCtx);
7262
7263 if (0 != status)
7264 {
7265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7266 "%s: HDD context is not valid", __func__);
7267 return status;
7268 }
7269
7270 hHal = pHddCtx->hHal;
7271
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307272 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
7273 dbm, ccmCfgSetCallback,
7274 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007275 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307276 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007277 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
7278 return -EIO;
7279 }
7280
7281 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
7282 dbm);
7283
7284 switch(type)
7285 {
7286 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
7287 /* Fall through */
7288 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
7289 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
7290 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307291 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
7292 __func__);
7293 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07007294 }
7295 break;
7296 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307297 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07007298 __func__);
7299 return -EOPNOTSUPP;
7300 break;
7301 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307302 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
7303 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07007304 return -EIO;
7305 }
7306
7307 return 0;
7308}
7309
7310/*
7311 * FUNCTION: wlan_hdd_cfg80211_get_txpower
7312 * This function is used to read the txpower
7313 */
Yue Maf49ba872013-08-19 12:04:25 -07007314static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
7315#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7316 struct wireless_dev *wdev,
7317#endif
7318 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07007319{
7320
7321 hdd_adapter_t *pAdapter;
7322 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307323 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007324
Jeff Johnsone7245742012-09-05 17:12:55 -07007325 ENTER();
7326
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307327 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007328
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307329 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007330 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307331 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7332 "%s: HDD context is not valid", __func__);
7333 *dbm = 0;
7334 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007335 }
7336
Jeff Johnson295189b2012-06-20 16:38:30 -07007337 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
7338 if (NULL == pAdapter)
7339 {
7340 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
7341 return -ENOENT;
7342 }
7343
7344 wlan_hdd_get_classAstats(pAdapter);
7345 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
7346
Jeff Johnsone7245742012-09-05 17:12:55 -07007347 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007348 return 0;
7349}
7350
7351static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
7352 u8* mac, struct station_info *sinfo)
7353{
7354 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
7355 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7356 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
7357 tANI_U8 rate_flags;
7358
7359 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
7360 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07007361
7362 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
7363 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
7364 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
7365 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
7366 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
7367 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
7368 tANI_U16 maxRate = 0;
7369 tANI_U16 myRate;
7370 tANI_U16 currentRate = 0;
7371 tANI_U8 maxSpeedMCS = 0;
7372 tANI_U8 maxMCSIdx = 0;
7373 tANI_U8 rateFlag = 1;
7374 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07007375 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307376 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007377
Leo Chang6f8870f2013-03-26 18:11:36 -07007378#ifdef WLAN_FEATURE_11AC
7379 tANI_U32 vht_mcs_map;
7380 eDataRate11ACMaxMcs vhtMaxMcs;
7381#endif /* WLAN_FEATURE_11AC */
7382
Jeff Johnsone7245742012-09-05 17:12:55 -07007383 ENTER();
7384
Jeff Johnson295189b2012-06-20 16:38:30 -07007385 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
7386 (0 == ssidlen))
7387 {
7388 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
7389 " Invalid ssidlen, %d", __func__, ssidlen);
7390 /*To keep GUI happy*/
7391 return 0;
7392 }
7393
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307394 status = wlan_hdd_validate_context(pHddCtx);
7395
7396 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007397 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307398 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7399 "%s: HDD context is not valid", __func__);
7400 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007401 }
7402
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007403 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007404 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
7405
Kiet Lam3b17fc82013-09-27 05:24:08 +05307406 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
7407 sinfo->filled |= STATION_INFO_SIGNAL;
7408
Jeff Johnson295189b2012-06-20 16:38:30 -07007409 //convert to the UI units of 100kbps
7410 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
7411
7412#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07007413 pr_info("RSSI %d, RLMS %u, rate %d, rssi high %d, rssi mid %d, rssi low %d, rate_flags 0x%x, MCS %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07007414 sinfo->signal,
7415 pCfg->reportMaxLinkSpeed,
7416 myRate,
7417 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007418 (int) pCfg->linkSpeedRssiMid,
7419 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07007420 (int) rate_flags,
7421 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07007422#endif //LINKSPEED_DEBUG_ENABLED
7423
7424 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
7425 {
7426 // we do not want to necessarily report the current speed
7427 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
7428 {
7429 // report the max possible speed
7430 rssidx = 0;
7431 }
7432 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
7433 {
7434 // report the max possible speed with RSSI scaling
7435 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
7436 {
7437 // report the max possible speed
7438 rssidx = 0;
7439 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007440 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07007441 {
7442 // report middle speed
7443 rssidx = 1;
7444 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007445 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
7446 {
7447 // report middle speed
7448 rssidx = 2;
7449 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007450 else
7451 {
7452 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007453 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07007454 }
7455 }
7456 else
7457 {
7458 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
7459 hddLog(VOS_TRACE_LEVEL_ERROR,
7460 "%s: Invalid value for reportMaxLinkSpeed: %u",
7461 __func__, pCfg->reportMaxLinkSpeed);
7462 rssidx = 0;
7463 }
7464
7465 maxRate = 0;
7466
7467 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307468 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7469 OperationalRates, &ORLeng))
7470 {
7471 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7472 /*To keep GUI happy*/
7473 return 0;
7474 }
7475
Jeff Johnson295189b2012-06-20 16:38:30 -07007476 for (i = 0; i < ORLeng; i++)
7477 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007478 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007479 {
7480 /* Validate Rate Set */
7481 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7482 {
7483 currentRate = supported_data_rate[j].supported_rate[rssidx];
7484 break;
7485 }
7486 }
7487 /* Update MAX rate */
7488 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7489 }
7490
7491 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307492 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7493 ExtendedRates, &ERLeng))
7494 {
7495 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7496 /*To keep GUI happy*/
7497 return 0;
7498 }
7499
Jeff Johnson295189b2012-06-20 16:38:30 -07007500 for (i = 0; i < ERLeng; i++)
7501 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007502 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007503 {
7504 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7505 {
7506 currentRate = supported_data_rate[j].supported_rate[rssidx];
7507 break;
7508 }
7509 }
7510 /* Update MAX rate */
7511 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7512 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307513 /* Get MCS Rate Set --
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307514 Only if we are always reporting max speed (or)
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307515 if we have good rssi */
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307516 if ((0 == rssidx) ||
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307517 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007518 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307519 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7520 MCSRates, &MCSLeng))
7521 {
7522 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7523 /*To keep GUI happy*/
7524 return 0;
7525 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007526 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007527#ifdef WLAN_FEATURE_11AC
7528 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307529 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007530 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007531 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307532 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007533 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007534 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007535 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007536 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007537 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007538 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007539 maxMCSIdx = 7;
7540 }
7541 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7542 {
7543 maxMCSIdx = 8;
7544 }
7545 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7546 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307547 //VHT20 is supporting 0~8
7548 if (rate_flags & eHAL_TX_RATE_VHT20)
7549 maxMCSIdx = 8;
7550 else
7551 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007552 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307553
7554 if (rate_flags & eHAL_TX_RATE_VHT80)
7555 {
7556 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7557 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7558 }
7559 else if (rate_flags & eHAL_TX_RATE_VHT40)
7560 {
7561 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7562 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7563 }
7564 else if (rate_flags & eHAL_TX_RATE_VHT20)
7565 {
7566 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7567 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7568 }
7569
Leo Chang6f8870f2013-03-26 18:11:36 -07007570 maxSpeedMCS = 1;
7571 if (currentRate > maxRate)
7572 {
7573 maxRate = currentRate;
7574 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307575
Leo Chang6f8870f2013-03-26 18:11:36 -07007576 }
7577 else
7578#endif /* WLAN_FEATURE_11AC */
7579 {
7580 if (rate_flags & eHAL_TX_RATE_HT40)
7581 {
7582 rateFlag |= 1;
7583 }
7584 if (rate_flags & eHAL_TX_RATE_SGI)
7585 {
7586 rateFlag |= 2;
7587 }
7588
7589 for (i = 0; i < MCSLeng; i++)
7590 {
7591 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7592 for (j = 0; j < temp; j++)
7593 {
7594 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7595 {
7596 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7597 break;
7598 }
7599 }
7600 if ((j < temp) && (currentRate > maxRate))
7601 {
7602 maxRate = currentRate;
7603 maxSpeedMCS = 1;
7604 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7605 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007606 }
7607 }
7608 }
7609
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307610 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7611 {
7612 maxRate = myRate;
7613 maxSpeedMCS = 1;
7614 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7615 }
7616
Jeff Johnson295189b2012-06-20 16:38:30 -07007617 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007618 if (((maxRate < myRate) && (0 == rssidx)) ||
7619 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007620 {
7621 maxRate = myRate;
7622 if (rate_flags & eHAL_TX_RATE_LEGACY)
7623 {
7624 maxSpeedMCS = 0;
7625 }
7626 else
7627 {
7628 maxSpeedMCS = 1;
7629 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7630 }
7631 }
7632
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307633 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007634 {
7635 sinfo->txrate.legacy = maxRate;
7636#ifdef LINKSPEED_DEBUG_ENABLED
7637 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7638#endif //LINKSPEED_DEBUG_ENABLED
7639 }
7640 else
7641 {
7642 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007643#ifdef WLAN_FEATURE_11AC
7644 sinfo->txrate.nss = 1;
7645 if (rate_flags & eHAL_TX_RATE_VHT80)
7646 {
7647 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307648 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007649 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307650 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007651 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307652 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7653 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7654 }
7655 else if (rate_flags & eHAL_TX_RATE_VHT20)
7656 {
7657 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7658 }
7659#endif /* WLAN_FEATURE_11AC */
7660 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7661 {
7662 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7663 if (rate_flags & eHAL_TX_RATE_HT40)
7664 {
7665 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7666 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007667 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007668 if (rate_flags & eHAL_TX_RATE_SGI)
7669 {
7670 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7671 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307672
Jeff Johnson295189b2012-06-20 16:38:30 -07007673#ifdef LINKSPEED_DEBUG_ENABLED
7674 pr_info("Reporting MCS rate %d flags %x\n",
7675 sinfo->txrate.mcs,
7676 sinfo->txrate.flags );
7677#endif //LINKSPEED_DEBUG_ENABLED
7678 }
7679 }
7680 else
7681 {
7682 // report current rate instead of max rate
7683
7684 if (rate_flags & eHAL_TX_RATE_LEGACY)
7685 {
7686 //provide to the UI in units of 100kbps
7687 sinfo->txrate.legacy = myRate;
7688#ifdef LINKSPEED_DEBUG_ENABLED
7689 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7690#endif //LINKSPEED_DEBUG_ENABLED
7691 }
7692 else
7693 {
7694 //must be MCS
7695 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007696#ifdef WLAN_FEATURE_11AC
7697 sinfo->txrate.nss = 1;
7698 if (rate_flags & eHAL_TX_RATE_VHT80)
7699 {
7700 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7701 }
7702 else
7703#endif /* WLAN_FEATURE_11AC */
7704 {
7705 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7706 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007707 if (rate_flags & eHAL_TX_RATE_SGI)
7708 {
7709 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7710 }
7711 if (rate_flags & eHAL_TX_RATE_HT40)
7712 {
7713 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7714 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007715#ifdef WLAN_FEATURE_11AC
7716 else if (rate_flags & eHAL_TX_RATE_VHT80)
7717 {
7718 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7719 }
7720#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007721#ifdef LINKSPEED_DEBUG_ENABLED
7722 pr_info("Reporting actual MCS rate %d flags %x\n",
7723 sinfo->txrate.mcs,
7724 sinfo->txrate.flags );
7725#endif //LINKSPEED_DEBUG_ENABLED
7726 }
7727 }
7728 sinfo->filled |= STATION_INFO_TX_BITRATE;
7729
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007730 sinfo->tx_packets =
7731 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7732 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7733 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7734 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7735
7736 sinfo->tx_retries =
7737 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7738 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7739 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7740 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7741
7742 sinfo->tx_failed =
7743 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7744 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7745 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7746 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7747
7748 sinfo->filled |=
7749 STATION_INFO_TX_PACKETS |
7750 STATION_INFO_TX_RETRIES |
7751 STATION_INFO_TX_FAILED;
7752
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307753 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7754 TRACE_CODE_HDD_CFG80211_GET_STA,
7755 pAdapter->sessionId, maxRate));
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007756 EXIT();
7757 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007758}
7759
7760static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007761 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007762{
7763 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307764 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007765 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307766 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007767
Jeff Johnsone7245742012-09-05 17:12:55 -07007768 ENTER();
7769
Jeff Johnson295189b2012-06-20 16:38:30 -07007770 if (NULL == pAdapter)
7771 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007772 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007773 return -ENODEV;
7774 }
7775
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307776 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7777 TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT,
7778 pAdapter->sessionId, timeout));
7779
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307780 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307781 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307782
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307783 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307784 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307785 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7786 "%s: HDD context is not valid", __func__);
7787 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307788 }
7789
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307790 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7791 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7792 (pHddCtx->cfg_ini->fhostArpOffload) &&
7793 (eConnectionState_Associated ==
7794 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7795 {
Amar Singhald53568e2013-09-26 11:03:45 -07007796
7797 hddLog(VOS_TRACE_LEVEL_INFO,
7798 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307799 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307800 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7801 {
7802 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007803 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307804 __func__, vos_status);
7805 }
7806 }
7807
Jeff Johnson295189b2012-06-20 16:38:30 -07007808 /**The get power cmd from the supplicant gets updated by the nl only
7809 *on successful execution of the function call
7810 *we are oppositely mapped w.r.t mode in the driver
7811 **/
7812 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7813
Jeff Johnsone7245742012-09-05 17:12:55 -07007814 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007815 if (VOS_STATUS_E_FAILURE == vos_status)
7816 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307817 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7818 "%s: failed to enter bmps mode", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007819 return -EINVAL;
7820 }
7821 return 0;
7822}
7823
7824
7825#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7826static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7827 struct net_device *netdev,
7828 u8 key_index)
7829{
Jeff Johnsone7245742012-09-05 17:12:55 -07007830 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007831 return 0;
7832}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307833#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007834
7835#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7836static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7837 struct net_device *dev,
7838 struct ieee80211_txq_params *params)
7839{
Jeff Johnsone7245742012-09-05 17:12:55 -07007840 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007841 return 0;
7842}
7843#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7844static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7845 struct ieee80211_txq_params *params)
7846{
Jeff Johnsone7245742012-09-05 17:12:55 -07007847 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007848 return 0;
7849}
7850#endif //LINUX_VERSION_CODE
7851
7852static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7853 struct net_device *dev, u8 *mac)
7854{
7855 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307856 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007857 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307858 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007859 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007860
Jeff Johnsone7245742012-09-05 17:12:55 -07007861 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307862
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307863 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007864 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307865 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007866 return -EINVAL;
7867 }
7868
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307869 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7870 TRACE_CODE_HDD_CFG80211_DEL_STA,
7871 pAdapter->sessionId, pAdapter->device_mode));
7872
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307873 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7874 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007875
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307876 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007877 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307878 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7879 "%s: HDD context is not valid", __func__);
7880 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007881 }
7882
Jeff Johnson295189b2012-06-20 16:38:30 -07007883 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007884 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007885 )
7886 {
7887 if( NULL == mac )
7888 {
7889 v_U16_t i;
7890 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7891 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007892 if ((pAdapter->aStaInfo[i].isUsed) &&
7893 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 {
7895 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7896 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007897 "%s: Delete STA with MAC::"
7898 MAC_ADDRESS_STR,
7899 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007900 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7901 if (VOS_IS_STATUS_SUCCESS(vos_status))
7902 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007903 }
7904 }
7905 }
7906 else
7907 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007908
7909 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7910 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7911 {
7912 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007913 "%s: Skip this DEL STA as this is not used::"
7914 MAC_ADDRESS_STR,
7915 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007916 return -ENOENT;
7917 }
7918
7919 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7920 {
7921 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007922 "%s: Skip this DEL STA as deauth is in progress::"
7923 MAC_ADDRESS_STR,
7924 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007925 return -ENOENT;
7926 }
7927
7928 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7929
Jeff Johnson295189b2012-06-20 16:38:30 -07007930 hddLog(VOS_TRACE_LEVEL_INFO,
7931 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007932 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007933 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007934 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007935
7936 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7937 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7938 {
7939 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7940 hddLog(VOS_TRACE_LEVEL_INFO,
7941 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007942 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007943 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007944 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007945 return -ENOENT;
7946 }
7947
Jeff Johnson295189b2012-06-20 16:38:30 -07007948 }
7949 }
7950
7951 EXIT();
7952
7953 return 0;
7954}
7955
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007956static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7957 struct net_device *dev, u8 *mac, struct station_parameters *params)
7958{
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307959 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007960 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007961#ifdef FEATURE_WLAN_TDLS
7962 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007963 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307964
7965 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7966 TRACE_CODE_HDD_CFG80211_ADD_STA,
7967 pAdapter->sessionId, params->listen_interval));
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007968 mask = params->sta_flags_mask;
7969
7970 set = params->sta_flags_set;
7971
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007972#ifdef WLAN_FEATURE_TDLS_DEBUG
7973 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7974 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7975 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7976#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007977
7978 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7979 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007980 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007981 }
7982 }
7983#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007984 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007985}
7986
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007987
7988#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007989#define MAX_PMKSAIDS_IN_CACHE 8
7990
7991static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7992static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7993
7994
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007995static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007996 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007997{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307998 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007999 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8000 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308001 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308002 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008003 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308004 hdd_context_t *pHddCtx;
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008005 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
8006 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07008007
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308008 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308009 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008010 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308011 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008012 return -EINVAL;
8013 }
8014
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308015 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8016 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008017
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308018 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008019 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308020 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8021 "%s: HDD context is not valid", __func__);
8022 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008023 }
8024
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308025 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008026 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8027
Wilson Yang6507c4e2013-10-01 20:11:19 -07008028 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008029 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308030 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008031 pmksa->bssid, WNI_CFG_BSSID_LEN))
8032 {
8033 /* BSSID matched previous entry. Overwrite it. */
8034 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308035 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008036 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308037 vos_mem_copy(PMKIDCache[j].PMKID,
8038 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008039 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308040 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008041 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008042 dump_bssid(pmksa->bssid);
8043 dump_pmkid(halHandle, pmksa->pmkid);
8044 break;
8045 }
8046 }
8047
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07008048 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07008049 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07008050
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008051 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308052 {
8053 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07008054 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308055 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008056 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308057 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008058 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308059 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07008060 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008061 dump_bssid(pmksa->bssid);
8062 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308063 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008064 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07008065 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008066 }
8067
8068
8069 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308070 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008071 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308072 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07008073 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008074 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308075 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
8076 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07008077 PMKIDCacheIndex);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308078 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8079 TRACE_CODE_HDD_CFG80211_SET_PMKSA,
8080 pAdapter->sessionId, result));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008081 return 0;
8082}
8083
8084
Wilson Yang6507c4e2013-10-01 20:11:19 -07008085
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008086static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07008087 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008088{
Wilson Yang6507c4e2013-10-01 20:11:19 -07008089 tANI_U32 j=0;
8090 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8091 tHalHandle halHandle;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008092 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008093 hdd_context_t *pHddCtx;
Wilson Yangef657d32014-01-15 19:19:23 -08008094 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008095
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008096 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
8097 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07008098
8099 /* Validate pAdapter */
8100 if (NULL == pAdapter)
8101 {
8102 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
8103 return -EINVAL;
8104 }
8105
8106 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8107 status = wlan_hdd_validate_context(pHddCtx);
8108
8109 if (0 != status)
8110 {
8111 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8112 "%s: HDD context is not valid", __func__);
8113 return status;
8114 }
8115
8116 /*Retrieve halHandle*/
8117 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8118
8119 /*in case index is 0,no entry to delete*/
8120 if (0 == PMKIDCacheIndex)
8121 {
8122 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
8123 __func__);
8124 return -EINVAL;
8125 }
8126
8127 /*find the matching PMKSA entry from j=0 to (index-1),
8128 * and delete the matched one
8129 */
8130 for (j = 0; j<PMKIDCacheIndex; j++)
8131 {
8132 if (vos_mem_compare(PMKIDCache[j].BSSID,
8133 pmksa->bssid,
8134 WNI_CFG_BSSID_LEN))
8135 {
8136 /* BSSID matched entry */
8137 BSSIDMatched = 1;
8138
8139 if (j<PMKIDCacheIndex-1)
8140 {
8141 /*replace the matching entry with the last entry in HDD local cache*/
8142 vos_mem_copy(PMKIDCache[j].BSSID,
8143 PMKIDCache[PMKIDCacheIndex-1].BSSID,
8144 WNI_CFG_BSSID_LEN);
8145 vos_mem_copy(PMKIDCache[j].PMKID,
8146 PMKIDCache[PMKIDCacheIndex-1].PMKID,
8147 CSR_RSN_PMKID_SIZE);
8148 }
8149
8150 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07008151 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
8152 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
8153
8154 /*reduce the PMKID array index*/
8155 PMKIDCacheIndex--;
8156
8157 /*delete the last PMKID cache in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008158 if (eHAL_STATUS_SUCCESS !=
8159 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008160 {
8161 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
8162 __func__,PMKIDCacheIndex);
Wilson Yangef657d32014-01-15 19:19:23 -08008163 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008164 }
8165
8166 dump_bssid(pmksa->bssid);
8167 dump_pmkid(halHandle,pmksa->pmkid);
8168
8169 break;
8170 }
8171 }
8172
8173 /* we compare all entries,but cannot find matching entry */
8174 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
8175 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008176 hddLog(VOS_TRACE_LEVEL_FATAL,
8177 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
8178 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07008179 dump_bssid(pmksa->bssid);
8180 dump_pmkid(halHandle, pmksa->pmkid);
8181 return -EINVAL;
8182 }
Wilson Yangef657d32014-01-15 19:19:23 -08008183 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008184}
8185
Wilson Yang6507c4e2013-10-01 20:11:19 -07008186
8187
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008188static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
8189{
Wilson Yang6507c4e2013-10-01 20:11:19 -07008190 tANI_U32 j=0;
8191 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8192 tHalHandle halHandle;
8193 hdd_context_t *pHddCtx;
8194 tANI_U8 *pBSSId;
Wilson Yangef657d32014-01-15 19:19:23 -08008195 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008196
8197 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
8198
8199 /* Validate pAdapter */
8200 if (NULL == pAdapter)
8201 {
8202 hddLog(VOS_TRACE_LEVEL_ERROR,
8203 "%s: Invalid Adapter" ,__func__);
8204 return -EINVAL;
8205 }
8206
8207 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8208 status = wlan_hdd_validate_context(pHddCtx);
8209
8210 if (0 != status)
8211 {
8212 hddLog(VOS_TRACE_LEVEL_ERROR,
8213 "%s: HDD context is not valid", __func__);
8214 return status;
8215 }
8216
8217 /*Retrieve halHandle*/
8218 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8219
8220 /*in case index is 0,no entry to delete*/
8221 if (0 == PMKIDCacheIndex)
8222 {
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308223 hddLog(VOS_TRACE_LEVEL_ERROR, FL("No entries to flush"));
Wilson Yang6507c4e2013-10-01 20:11:19 -07008224 return -EINVAL;
8225 }
8226
8227 /*delete all the PMKSA one by one */
8228 for (j = 0; j<PMKIDCacheIndex; j++)
8229 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07008230 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008231
8232 /*delete the PMKID in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008233 if (eHAL_STATUS_SUCCESS !=
8234 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008235 {
8236 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
8237 __func__,j);
Wilson Yangef657d32014-01-15 19:19:23 -08008238 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008239 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05308240 /*clear the entry in HDD cache 0--index-1 */
8241 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
8242 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008243 }
8244
8245 PMKIDCacheIndex = 0;
Wilson Yangef657d32014-01-15 19:19:23 -08008246 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008247}
8248#endif
8249
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008250#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308251static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008252 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
8253{
8254 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8255 hdd_station_ctx_t *pHddStaCtx;
8256
8257 if (NULL == pAdapter)
8258 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008259 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008260 return -ENODEV;
8261 }
8262
8263 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8264
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308265 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8266 TRACE_CODE_HDD_CFG80211_UPDATE_FT_IES,
8267 pAdapter->sessionId, pHddStaCtx->conn_info.connState));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008268 // Added for debug on reception of Re-assoc Req.
8269 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
8270 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008271 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008272 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08008273 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008274 }
8275
8276#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08008277 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008278 ftie->ie_len);
8279#endif
8280
8281 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05308282 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
8283 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008284 ftie->ie_len);
8285 return 0;
8286}
8287#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008288
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308289#ifdef FEATURE_WLAN_SCAN_PNO
8290
8291void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
8292 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8293{
8294 int ret;
8295 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
8296 hdd_context_t *pHddCtx;
8297
Nirav Shah80830bf2013-12-31 16:35:12 +05308298 ENTER();
8299
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308300 if (NULL == pAdapter)
8301 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308302 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308303 "%s: HDD adapter is Null", __func__);
8304 return ;
8305 }
8306
8307 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8308 if (NULL == pHddCtx)
8309 {
8310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8311 "%s: HDD context is Null!!!", __func__);
8312 return ;
8313 }
8314
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308315 spin_lock(&pHddCtx->schedScan_lock);
8316 if (TRUE == pHddCtx->isWiphySuspended)
8317 {
8318 pHddCtx->isSchedScanUpdatePending = TRUE;
8319 spin_unlock(&pHddCtx->schedScan_lock);
8320 hddLog(VOS_TRACE_LEVEL_INFO,
8321 "%s: Update cfg80211 scan database after it resume", __func__);
8322 return ;
8323 }
8324 spin_unlock(&pHddCtx->schedScan_lock);
8325
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308326 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
8327
8328 if (0 > ret)
8329 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
8330
8331 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308332 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8333 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308334}
8335
8336/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308337 * FUNCTION: wlan_hdd_is_pno_allowed
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308338 * Disallow pno if any session is active
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308339 */
8340static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
8341{
8342 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8343 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308344 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308345 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8346 int status = 0;
8347 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
8348
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308349 /* The current firmware design does not allow PNO during any
8350 * active sessions. Hence, determine the active sessions
8351 * and return a failure.
8352 */
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308353 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
8354 {
8355 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308356 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308357
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308358 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
8359 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
8360 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
8361 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
8362 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
8363 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308364 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308365 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308366 }
8367 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8368 pAdapterNode = pNext;
8369 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308370 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308371}
8372
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308373void hdd_cfg80211_sched_scan_start_status_cb(void *callbackContext, VOS_STATUS status)
8374{
8375 hdd_adapter_t *pAdapter = callbackContext;
8376 hdd_context_t *pHddCtx;
8377
8378 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
8379 {
8380 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8381 FL("Invalid adapter or adapter has invalid magic"));
8382 return;
8383 }
8384
8385 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8386 if (0 != wlan_hdd_validate_context(pHddCtx))
8387 {
8388 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8389 FL("HDD context is not valid"));
8390 return;
8391 }
8392
8393 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8394 FL("PNO enable response status = %d"), status);
8395
8396 pAdapter->pno_req_status = (status == VOS_STATUS_SUCCESS) ? 0 : -EBUSY;
8397 complete(&pAdapter->pno_comp_var);
8398}
8399
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308400/*
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308401 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
8402 * NL interface to enable PNO
8403 */
8404static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
8405 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8406{
8407 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8408 tpSirPNOScanReq pPnoRequest = NULL;
8409 hdd_context_t *pHddCtx;
8410 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308411 v_U32_t i, indx, num_ch, tempInterval;
Sushant Kaushikd62d9782014-02-19 15:39:40 +05308412 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
8413 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308414 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8415 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308416 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308417
8418 if (NULL == pAdapter)
8419 {
8420 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8421 "%s: HDD adapter is Null", __func__);
8422 return -ENODEV;
8423 }
8424
8425 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308426 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308427
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308428 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308429 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308430 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8431 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308432 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308433 }
8434
8435 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8436 if (NULL == hHal)
8437 {
8438 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8439 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308440 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308441 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308442
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308443 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308444 {
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308445 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308446 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308447 return -EBUSY;
8448 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308449
c_hpothu37f21312014-04-09 21:49:54 +05308450 if (TRUE == pHddCtx->isPnoEnable)
8451 {
8452 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8453 FL("already PNO is enabled"));
8454 return -EBUSY;
8455 }
8456 pHddCtx->isPnoEnable = TRUE;
8457
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308458 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8459 if (NULL == pPnoRequest)
8460 {
8461 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8462 "%s: vos_mem_malloc failed", __func__);
c_hpothu37f21312014-04-09 21:49:54 +05308463 pHddCtx->isPnoEnable = FALSE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308464 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308465 }
8466
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05308467 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308468 pPnoRequest->enable = 1; /*Enable PNO */
8469 pPnoRequest->ucNetworksCount = request->n_match_sets;
8470
8471 if (( !pPnoRequest->ucNetworksCount ) ||
8472 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
8473 {
8474 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308475 "%s: Network input is not correct %d",
8476 __func__, pPnoRequest->ucNetworksCount);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308477 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308478 goto error;
8479 }
8480
8481 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
8482 {
8483 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308484 "%s: Incorrect number of channels %d",
8485 __func__, request->n_channels);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308486 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308487 goto error;
8488 }
8489
8490 /* Framework provides one set of channels(all)
8491 * common for all saved profile */
8492 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
8493 channels_allowed, &num_channels_allowed))
8494 {
8495 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8496 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308497 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308498 goto error;
8499 }
8500 /* Checking each channel against allowed channel list */
8501 num_ch = 0;
Nirav Shah80830bf2013-12-31 16:35:12 +05308502 if (request->n_channels)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308503 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308504 char chList [(request->n_channels*5)+1];
8505 int len;
8506 for (i = 0, len = 0; i < request->n_channels; i++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308507 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308508 for (indx = 0; indx < num_channels_allowed; indx++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308509 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308510 if (request->channels[i]->hw_value == channels_allowed[indx])
8511 {
8512 valid_ch[num_ch++] = request->channels[i]->hw_value;
8513 len += snprintf(chList+len, 5, "%d ",
8514 request->channels[i]->hw_value);
8515 break ;
8516 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308517 }
8518 }
Nirav Shah80830bf2013-12-31 16:35:12 +05308519 hddLog(VOS_TRACE_LEVEL_INFO,"Channel-List: %s ", chList);
8520 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308521
8522 /* Filling per profile params */
8523 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
8524 {
8525 pPnoRequest->aNetworks[i].ssId.length =
8526 request->match_sets[i].ssid.ssid_len;
8527
8528 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8529 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8530 {
8531 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308532 "%s: SSID Len %d is not correct for network %d",
8533 __func__, pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308534 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308535 goto error;
8536 }
8537
8538 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8539 request->match_sets[i].ssid.ssid,
8540 request->match_sets[i].ssid.ssid_len);
8541 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8542 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8543 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8544
8545 /*Copying list of valid channel into request */
8546 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8547 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8548
8549 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8550 }
8551
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308552 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008553 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308554 if ((0 < request->ie_len) && (NULL != request->ie))
8555 {
8556 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8557 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8558 pPnoRequest->us24GProbeTemplateLen);
8559
8560 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8561 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8562 pPnoRequest->us5GProbeTemplateLen);
8563 }
8564
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308565 /* Driver gets only one time interval which is hardcoded in
8566 * supplicant for 10000ms. Taking power consumption into account 6 timers
8567 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8568 * 80,160,320 secs. And number of scan cycle for each timer
8569 * is configurable through INI param gPNOScanTimerRepeatValue.
8570 * If it is set to 0 only one timer will be used and PNO scan cycle
8571 * will be repeated after each interval specified by supplicant
8572 * till PNO is disabled.
8573 */
8574 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8575 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8576 else
8577 pPnoRequest->scanTimers.ucScanTimersCount =
8578 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8579
8580 tempInterval = (request->interval)/1000;
8581 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8582 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8583 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8584 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8585 {
8586 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8587 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8588 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8589 tempInterval *= 2;
8590 }
8591 //Repeat last timer until pno disabled.
8592 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8593
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308594 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308595
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308596 INIT_COMPLETION(pAdapter->pno_comp_var);
8597 pPnoRequest->statusCallback = hdd_cfg80211_sched_scan_start_status_cb;
8598 pPnoRequest->callbackContext = pAdapter;
8599 pAdapter->pno_req_status = 0;
8600
Nirav Shah80830bf2013-12-31 16:35:12 +05308601 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8602 "SessionId %d, enable %d, modePNO %d, ucScanTimersCount %d",
8603 pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO,
8604 pPnoRequest->scanTimers.ucScanTimersCount);
8605
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308606 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8607 pPnoRequest, pAdapter->sessionId,
8608 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8609 if (eHAL_STATUS_SUCCESS != status)
8610 {
8611 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308612 "%s: Failed to enable PNO", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308613 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308614 goto error;
8615 }
8616
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308617 ret = wait_for_completion_timeout(
8618 &pAdapter->pno_comp_var,
8619 msecs_to_jiffies(WLAN_WAIT_TIME_PNO));
8620 if (0 >= ret)
8621 {
8622 // Did not receive the response for PNO enable in time.
8623 // Assuming the PNO enable was success.
8624 // Returning error from here, because we timeout, results
8625 // in side effect of Wifi (Wifi Setting) not to work.
8626 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8627 FL("Timed out waiting for PNO to be Enabled"));
8628 ret = 0;
8629 goto error;
8630 }
8631
8632 ret = pAdapter->pno_req_status;
c_hpothu37f21312014-04-09 21:49:54 +05308633 return ret;
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308634
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308635error:
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308636 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8637 FL("PNO scanRequest offloaded ret = %d"), ret);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308638 vos_mem_free(pPnoRequest);
c_hpothu37f21312014-04-09 21:49:54 +05308639 pHddCtx->isPnoEnable = FALSE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308640 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308641}
8642
8643/*
8644 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8645 * NL interface to disable PNO
8646 */
8647static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8648 struct net_device *dev)
8649{
8650 eHalStatus status = eHAL_STATUS_FAILURE;
8651 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8652 hdd_context_t *pHddCtx;
8653 tHalHandle hHal;
8654 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308655 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308656
8657 ENTER();
8658
8659 if (NULL == pAdapter)
8660 {
8661 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8662 "%s: HDD adapter is Null", __func__);
8663 return -ENODEV;
8664 }
8665
8666 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308667
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308668 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308669 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308670 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308671 "%s: HDD context is Null", __func__);
8672 return -ENODEV;
8673 }
8674
8675 /* The return 0 is intentional when isLogpInProgress and
8676 * isLoadUnloadInProgress. We did observe a crash due to a return of
8677 * failure in sched_scan_stop , especially for a case where the unload
8678 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8679 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8680 * success. If it returns a failure , then its next invocation due to the
8681 * clean up of the second interface will have the dev pointer corresponding
8682 * to the first one leading to a crash.
8683 */
8684 if (pHddCtx->isLogpInProgress)
8685 {
8686 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8687 "%s: LOGP in Progress. Ignore!!!", __func__);
8688 return ret;
8689 }
8690
Mihir Shete18156292014-03-11 15:38:30 +05308691 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308692 {
8693 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8694 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8695 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308696 }
8697
8698 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8699 if (NULL == hHal)
8700 {
8701 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8702 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308703 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308704 }
8705
8706 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8707 if (NULL == pPnoRequest)
8708 {
8709 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8710 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308711 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308712 }
8713
8714 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8715 pPnoRequest->enable = 0; /* Disable PNO */
8716 pPnoRequest->ucNetworksCount = 0;
8717
8718 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8719 pAdapter->sessionId,
8720 NULL, pAdapter);
8721 if (eHAL_STATUS_SUCCESS != status)
8722 {
8723 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8724 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308725 ret = -EINVAL;
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308726 goto error;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308727 }
c_hpothu37f21312014-04-09 21:49:54 +05308728 pHddCtx->isPnoEnable = FALSE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308729
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308730error:
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308731 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308732 FL("PNO scan disabled ret = %d"), ret);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308733 vos_mem_free(pPnoRequest);
8734
8735 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308736 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308737}
8738
8739#endif /*FEATURE_WLAN_SCAN_PNO*/
8740
8741
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008742#ifdef FEATURE_WLAN_TDLS
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308743#if TDLS_MGMT_VERSION2
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008744static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8745 u8 *peer, u8 action_code, u8 dialog_token,
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308746 u16 status_code, u32 peer_capability, const u8 *buf, size_t len)
8747#else
8748static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8749 u8 *peer, u8 action_code, u8 dialog_token,
8750 u16 status_code, const u8 *buf, size_t len)
8751#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008752{
8753
8754 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8755 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008756 u8 peerMac[6];
8757 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008758 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008759 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008760 long rc;
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308761#if !(TDLS_MGMT_VERSION2)
8762 u32 peer_capability = 0;
8763#endif
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308764 tANI_U16 numCurrTdlsPeers;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008765
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308766 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8767 TRACE_CODE_HDD_CFG80211_TDLS_MGMT,
8768 pAdapter->sessionId, action_code));
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008769 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008770 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308771 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008772 "Invalid arguments");
8773 return -EINVAL;
8774 }
8775
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008776 if (pHddCtx->isLogpInProgress)
8777 {
8778 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8779 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008780 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008781 return -EBUSY;
8782 }
8783
Hoonki Lee27511902013-03-14 18:19:06 -07008784 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008785 {
Hoonki Lee27511902013-03-14 18:19:06 -07008786 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8787 "%s: TDLS mode is disabled OR not enabled in FW."
8788 MAC_ADDRESS_STR " action %d declined.",
8789 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008790 return -ENOTSUPP;
8791 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008792
Hoonki Lee27511902013-03-14 18:19:06 -07008793 /* other than teardown frame, other mgmt frames are not sent if disabled */
8794 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8795 {
8796 /* if tdls_mode is disabled to respond to peer's request */
8797 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8798 {
8799 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8800 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008801 " TDLS mode is disabled. action %d declined.",
8802 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008803
8804 return -ENOTSUPP;
8805 }
8806 }
8807
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008808 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8809 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308810 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008811 {
8812 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008813 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008814 " TDLS setup is ongoing. action %d declined.",
8815 __func__, MAC_ADDR_ARRAY(peer), action_code);
8816 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008817 }
8818 }
8819
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008820 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8821 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008822 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308823 numCurrTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
8824 if (HDD_MAX_NUM_TDLS_STA <= numCurrTdlsPeers)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008825 {
8826 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8827 we return error code at 'add_station()'. Hence we have this
8828 check again in addtion to add_station().
8829 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008830 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008831 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008832 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8833 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308834 " TDLS Max peer already connected. action (%d) declined. Num of peers (%d), Max allowed (%d).",
8835 __func__, MAC_ADDR_ARRAY(peer), action_code,
8836 numCurrTdlsPeers, HDD_MAX_NUM_TDLS_STA);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308837 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008838 }
8839 else
8840 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008841 /* maximum reached. tweak to send error code to peer and return
8842 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008843 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008844 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8845 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308846 " TDLS Max peer already connected, send response status (%d). Num of peers (%d), Max allowed (%d).",
8847 __func__, MAC_ADDR_ARRAY(peer), status_code,
8848 numCurrTdlsPeers, HDD_MAX_NUM_TDLS_STA);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008849 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008850 /* fall through to send setup resp with failure status
8851 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008852 }
8853 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008854 else
8855 {
8856 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308857 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008858 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008859 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008860 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008861 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8862 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008863 return -EPERM;
8864 }
8865 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008866 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008867 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008868
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008869#ifdef WLAN_FEATURE_TDLS_DEBUG
8870 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Kumar Khandavalli9fb625e2014-03-17 16:07:40 +05308871 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %zu",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008872 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8873 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008874#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008875
Hoonki Leea34dd892013-02-05 22:56:02 -08008876 /*Except teardown responder will not be used so just make 0*/
8877 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008878 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008879 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008880
8881 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308882 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008883
8884 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8885 responder = pTdlsPeer->is_responder;
8886 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008887 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Kumar Khandavalli9fb625e2014-03-17 16:07:40 +05308889 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %zu",
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008890 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8891 dialog_token, status_code, len);
8892 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008893 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008894 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008895
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308896 /* For explicit trigger of DIS_REQ come out of BMPS for
8897 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008898 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308899 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8900 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008901 {
8902 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8903 {
8904 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308905 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008906 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8907 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308908 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8909 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008910 }
8911
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008912 /* make sure doesn't call send_mgmt() while it is pending */
8913 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8914 {
8915 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008916 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008917 __func__, MAC_ADDR_ARRAY(peer), action_code);
8918 return -EBUSY;
8919 }
8920
8921 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008922 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8923
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008924 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Pradeep Reddy POTTETIca171f82014-03-21 14:17:35 +05308925 peerMac, action_code, dialog_token, status_code, peer_capability, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008926
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008927 if (VOS_STATUS_SUCCESS != status)
8928 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008929 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8930 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008931 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008932 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308933 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008934 }
8935
Hoonki Leed37cbb32013-04-20 00:31:14 -07008936 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8937 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8938
8939 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008940 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008941 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008942 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008943 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008944 pAdapter->mgmtTxCompletionStatus = FALSE;
Yue Ma4f55ef32014-01-23 16:45:33 -08008945
8946 if (pHddCtx->isLogpInProgress)
8947 {
8948 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8949 "%s: LOGP in Progress. Ignore!!!", __func__);
8950 return -EAGAIN;
8951 }
8952
Hoonki Leed37cbb32013-04-20 00:31:14 -07008953 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308954 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008955 }
8956
Gopichand Nakkala05922802013-03-14 12:23:19 -07008957 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008958 {
8959 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008960 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008961 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008962
Hoonki Leea34dd892013-02-05 22:56:02 -08008963 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8964 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008965 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008966 }
8967 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8968 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008969 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008970 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008971
8972 return 0;
8973}
8974
8975static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8976 u8 *peer, enum nl80211_tdls_operation oper)
8977{
8978 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8979 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308980 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008981 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008982
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308983 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8984 TRACE_CODE_HDD_CFG80211_TDLS_OPER,
8985 pAdapter->sessionId, oper));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308986 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008987 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008988 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008989 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008990 return -EINVAL;
8991 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008992
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308993 status = wlan_hdd_validate_context(pHddCtx);
8994
8995 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008996 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308997 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8998 "%s: HDD context is not valid", __func__);
8999 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08009000 }
9001
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009002
9003 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009004 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009005 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009006 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07009007 "TDLS Disabled in INI OR not enabled in FW. "
9008 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009009 return -ENOTSUPP;
9010 }
9011
9012 switch (oper) {
9013 case NL80211_TDLS_ENABLE_LINK:
9014 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009015 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309016 long ret;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309017 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009018
Sunil Dutt41de4e22013-11-14 18:09:02 +05309019 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9020
9021 if ( NULL == pTdlsPeer ) {
9022 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
9023 " (oper %d) not exsting. ignored",
9024 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
9025 return -EINVAL;
9026 }
9027
9028 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9029 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
9030 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
9031 "NL80211_TDLS_ENABLE_LINK");
9032
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07009033 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
9034 {
9035 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
9036 MAC_ADDRESS_STR " failed",
9037 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
9038 return -EINVAL;
9039 }
9040
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009041 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009042 {
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309043 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05309044
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309045 if (0 != wlan_hdd_tdls_get_link_establish_params(
9046 pAdapter, peer,&tdlsLinkEstablishParams)) {
9047 return -EINVAL;
9048 }
9049 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309050
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309051 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
9052 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
9053 /* Send TDLS peer UAPSD capabilities to the firmware and
9054 * register with the TL on after the response for this operation
9055 * is received .
9056 */
9057 ret = wait_for_completion_interruptible_timeout(
9058 &pAdapter->tdls_link_establish_req_comp,
9059 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
9060 if (ret <= 0)
9061 {
9062 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9063 "%s: Link Establish Request Faled Status %ld",
9064 __func__, ret);
9065 return -EINVAL;
9066 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309067 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009068 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05309069 /* Mark TDLS client Authenticated .*/
9070 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
9071 pTdlsPeer->staId,
9072 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009073 if (VOS_STATUS_SUCCESS == status)
9074 {
Hoonki Lee14621352013-04-16 17:51:19 -07009075 if (pTdlsPeer->is_responder == 0)
9076 {
9077 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
9078
9079 wlan_hdd_tdls_timer_restart(pAdapter,
9080 &pTdlsPeer->initiatorWaitTimeoutTimer,
9081 WAIT_TIME_TDLS_INITIATOR);
9082 /* suspend initiator TX until it receives direct packet from the
9083 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
9084 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
9085 &staId, NULL);
9086 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009087 wlan_hdd_tdls_increment_peer_count(pAdapter);
9088 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009089 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309090
9091 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05309092 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
9093 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309094 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05309095 int ac;
9096 uint8 ucAc[4] = { WLANTL_AC_VO,
9097 WLANTL_AC_VI,
9098 WLANTL_AC_BK,
9099 WLANTL_AC_BE };
9100 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
9101 for(ac=0; ac < 4; ac++)
9102 {
9103 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
9104 pTdlsPeer->staId, ucAc[ac],
9105 tlTid[ac], tlTid[ac], 0, 0,
9106 WLANTL_BI_DIR );
9107 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309108 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009109 }
9110
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009111 }
9112 break;
9113 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08009114 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05309115 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9116
9117 if ( NULL == pTdlsPeer ) {
9118 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
9119 " (oper %d) not exsting. ignored",
9120 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
9121 return -EINVAL;
9122 }
9123
9124 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9125 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
9126 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
9127 "NL80211_TDLS_DISABLE_LINK");
9128
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009129 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08009130 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009131 long status;
9132
9133 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
9134
Lee Hoonkic1262f22013-01-24 21:59:00 -08009135 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
9136 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009137
9138 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
9139 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
9140 if (status <= 0)
9141 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009142 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009143 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9144 "%s: Del station failed status %ld",
9145 __func__, status);
9146 return -EPERM;
9147 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009148 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08009149 }
9150 else
9151 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009152 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9153 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08009154 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08009155 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009156 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009157 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05309158 {
9159 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9160 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
9161 __func__, MAC_ADDR_ARRAY(peer));
9162
9163 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
9164 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
9165
9166 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9167 " %s TDLS External control and Implicit Trigger not enabled ",
9168 __func__);
9169 return -ENOTSUPP;
9170 }
9171
Sunil Dutt41de4e22013-11-14 18:09:02 +05309172
9173 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9174
9175 if ( NULL == pTdlsPeer ) {
9176 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
9177 " peer not exsting",
9178 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309179 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309180 }
9181 else {
9182 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
9183 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
9184 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309185
9186 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
9187 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309188 break;
9189 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009190 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05309191 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309192 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309193 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9194 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
9195 __func__, MAC_ADDR_ARRAY(peer));
9196
9197 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
9198 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
9199
9200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9201 " %s TDLS External control and Implicit Trigger not enabled ",
9202 __func__);
9203 return -ENOTSUPP;
9204 }
9205
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309206 /* To cater the requirement of establishing the TDLS link
9207 * irrespective of the data traffic , get an entry of TDLS peer.
9208 */
9209 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
9210 if (pTdlsPeer == NULL) {
9211 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9212 "%s: peer " MAC_ADDRESS_STR " not existing",
9213 __func__, MAC_ADDR_ARRAY(peer));
9214 return -EINVAL;
9215 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309216
9217 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
9218
9219 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9220 " %s TDLS Add Force Peer Failed",
9221 __func__);
9222 return -EINVAL;
9223 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309224 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309225 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009226 case NL80211_TDLS_DISCOVERY_REQ:
9227 /* We don't support in-driver setup/teardown/discovery */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309228 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9229 "%s: We don't support in-driver setup/teardown/discovery "
9230 ,__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009231 return -ENOTSUPP;
9232 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9234 "%s: unsupported event",__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009235 return -ENOTSUPP;
9236 }
9237 return 0;
9238}
Chilam NG571c65a2013-01-19 12:27:36 +05309239
9240int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
9241 struct net_device *dev, u8 *peer)
9242{
Arif Hussaina7c8e412013-11-20 11:06:42 -08009243 hddLog(VOS_TRACE_LEVEL_INFO,
9244 "tdls send discover req: "MAC_ADDRESS_STR,
9245 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05309246
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05309247#if TDLS_MGMT_VERSION2
9248 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
9249 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, 0, NULL, 0);
9250#else
Chilam NG571c65a2013-01-19 12:27:36 +05309251 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
9252 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05309253#endif
Chilam NG571c65a2013-01-19 12:27:36 +05309254}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009255#endif
9256
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309257#ifdef WLAN_FEATURE_GTK_OFFLOAD
9258/*
9259 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
9260 * Callback rountine called upon receiving response for
9261 * get offload info
9262 */
9263void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
9264 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
9265{
9266
9267 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309268 tANI_U8 tempReplayCounter[8];
9269 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309270
9271 ENTER();
9272
9273 if (NULL == pAdapter)
9274 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05309275 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309276 "%s: HDD adapter is Null", __func__);
9277 return ;
9278 }
9279
9280 if (NULL == pGtkOffloadGetInfoRsp)
9281 {
9282 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9283 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
9284 return ;
9285 }
9286
9287 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
9288 {
9289 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9290 "%s: wlan Failed to get replay counter value",
9291 __func__);
9292 return ;
9293 }
9294
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309295 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9296 /* Update replay counter */
9297 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
9298 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9299
9300 {
9301 /* changing from little to big endian since supplicant
9302 * works on big endian format
9303 */
9304 int i;
9305 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9306
9307 for (i = 0; i < 8; i++)
9308 {
9309 tempReplayCounter[7-i] = (tANI_U8)p[i];
9310 }
9311 }
9312
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309313 /* Update replay counter to NL */
9314 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309315 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309316}
9317
9318/*
9319 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
9320 * This function is used to offload GTK rekeying job to the firmware.
9321 */
9322int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
9323 struct cfg80211_gtk_rekey_data *data)
9324{
9325 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9326 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9327 hdd_station_ctx_t *pHddStaCtx;
9328 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309329 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309330 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309331 eHalStatus status = eHAL_STATUS_FAILURE;
9332
9333 ENTER();
9334
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309335
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309336 if (NULL == pAdapter)
9337 {
9338 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9339 "%s: HDD adapter is Null", __func__);
9340 return -ENODEV;
9341 }
9342
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309343 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
9344 TRACE_CODE_HDD_CFG80211_SET_REKEY_DATA,
9345 pAdapter->sessionId, pAdapter->device_mode));
9346
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309347 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309348
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309349 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309350 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309351 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9352 "%s: HDD context is not valid", __func__);
9353 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309354 }
9355
9356 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9357 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9358 if (NULL == hHal)
9359 {
9360 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9361 "%s: HAL context is Null!!!", __func__);
9362 return -EAGAIN;
9363 }
9364
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309365 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
9366 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
9367 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
9368 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309369 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309370 {
9371 /* changing from big to little endian since driver
9372 * works on little endian format
9373 */
9374 tANI_U8 *p =
9375 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
9376 int i;
9377
9378 for (i = 0; i < 8; i++)
9379 {
9380 p[7-i] = data->replay_ctr[i];
9381 }
9382 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309383
9384 if (TRUE == pHddCtx->hdd_wlan_suspended)
9385 {
9386 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309387 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
9388 sizeof (tSirGtkOffloadParams));
9389 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309390 pAdapter->sessionId);
9391
9392 if (eHAL_STATUS_SUCCESS != status)
9393 {
9394 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9395 "%s: sme_SetGTKOffload failed, returned %d",
9396 __func__, status);
9397 return status;
9398 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309399 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9400 "%s: sme_SetGTKOffload successfull", __func__);
9401 }
9402 else
9403 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309404 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9405 "%s: wlan not suspended GTKOffload request is stored",
9406 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309407 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309408
9409 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309410}
9411#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
9412
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309413/*
9414 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
9415 * This function is used to set access control policy
9416 */
9417static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
9418 struct net_device *dev, const struct cfg80211_acl_data *params)
9419{
9420 int i;
9421 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9422 hdd_hostapd_state_t *pHostapdState;
9423 tsap_Config_t *pConfig;
9424 v_CONTEXT_t pVosContext = NULL;
9425 hdd_context_t *pHddCtx;
9426 int status;
9427
9428 ENTER();
9429
9430 if (NULL == pAdapter)
9431 {
9432 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9433 "%s: HDD adapter is Null", __func__);
9434 return -ENODEV;
9435 }
9436
9437 if (NULL == params)
9438 {
9439 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9440 "%s: params is Null", __func__);
9441 return -EINVAL;
9442 }
9443
9444 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9445 status = wlan_hdd_validate_context(pHddCtx);
9446
9447 if (0 != status)
9448 {
9449 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9450 "%s: HDD context is not valid", __func__);
9451 return status;
9452 }
9453
9454 pVosContext = pHddCtx->pvosContext;
9455 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9456
9457 if (NULL == pHostapdState)
9458 {
9459 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9460 "%s: pHostapdState is Null", __func__);
9461 return -EINVAL;
9462 }
9463
9464 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
9465 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
9466
9467 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
9468 {
9469 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
9470
9471 /* default value */
9472 pConfig->num_accept_mac = 0;
9473 pConfig->num_deny_mac = 0;
9474
9475 /**
9476 * access control policy
9477 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
9478 * listed in hostapd.deny file.
9479 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
9480 * listed in hostapd.accept file.
9481 */
9482 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
9483 {
9484 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
9485 }
9486 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
9487 {
9488 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
9489 }
9490 else
9491 {
9492 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9493 "%s:Acl Policy : %d is not supported",
9494 __func__, params->acl_policy);
9495 return -ENOTSUPP;
9496 }
9497
9498 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
9499 {
9500 pConfig->num_accept_mac = params->n_acl_entries;
9501 for (i = 0; i < params->n_acl_entries; i++)
9502 {
9503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9504 "** Add ACL MAC entry %i in WhiletList :"
9505 MAC_ADDRESS_STR, i,
9506 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9507
9508 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
9509 sizeof(qcmacaddr));
9510 }
9511 }
9512 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
9513 {
9514 pConfig->num_deny_mac = params->n_acl_entries;
9515 for (i = 0; i < params->n_acl_entries; i++)
9516 {
9517 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9518 "** Add ACL MAC entry %i in BlackList :"
9519 MAC_ADDRESS_STR, i,
9520 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9521
9522 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
9523 sizeof(qcmacaddr));
9524 }
9525 }
9526
9527 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
9528 {
9529 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9530 "%s: SAP Set Mac Acl fail", __func__);
9531 return -EINVAL;
9532 }
9533 }
9534 else
9535 {
9536 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9537 "%s: Invalid device_mode = %d",
9538 __func__, pAdapter->device_mode);
9539 return -EINVAL;
9540 }
9541
9542 return 0;
9543}
9544
Leo Chang9056f462013-08-01 19:21:11 -07009545#ifdef WLAN_NL80211_TESTMODE
9546#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07009547void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07009548(
9549 void *pAdapter,
9550 void *indCont
9551)
9552{
Leo Changd9df8aa2013-09-26 13:32:26 -07009553 tSirLPHBInd *lphbInd;
9554 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07009555
9556 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009557 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07009558
9559 if (NULL == indCont)
9560 {
9561 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009562 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07009563 return;
9564 }
9565
Leo Changd9df8aa2013-09-26 13:32:26 -07009566 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07009567 skb = cfg80211_testmode_alloc_event_skb(
9568 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07009569 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07009570 GFP_ATOMIC);
9571 if (!skb)
9572 {
9573 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9574 "LPHB timeout, NL buffer alloc fail");
9575 return;
9576 }
9577
Leo Changac3ba772013-10-07 09:47:04 -07009578 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07009579 {
9580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9581 "WLAN_HDD_TM_ATTR_CMD put fail");
9582 goto nla_put_failure;
9583 }
Leo Changac3ba772013-10-07 09:47:04 -07009584 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07009585 {
9586 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9587 "WLAN_HDD_TM_ATTR_TYPE put fail");
9588 goto nla_put_failure;
9589 }
Leo Changac3ba772013-10-07 09:47:04 -07009590 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07009591 sizeof(tSirLPHBInd), lphbInd))
9592 {
9593 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9594 "WLAN_HDD_TM_ATTR_DATA put fail");
9595 goto nla_put_failure;
9596 }
Leo Chang9056f462013-08-01 19:21:11 -07009597 cfg80211_testmode_event(skb, GFP_ATOMIC);
9598 return;
9599
9600nla_put_failure:
9601 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9602 "NLA Put fail");
9603 kfree_skb(skb);
9604
9605 return;
9606}
9607#endif /* FEATURE_WLAN_LPHB */
9608
9609static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9610{
9611 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9612 int err = 0;
9613#ifdef FEATURE_WLAN_LPHB
9614 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009615 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009616#endif /* FEATURE_WLAN_LPHB */
9617
9618 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9619 if (err)
9620 {
9621 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9622 "%s Testmode INV ATTR", __func__);
9623 return err;
9624 }
9625
9626 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9627 {
9628 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9629 "%s Testmode INV CMD", __func__);
9630 return -EINVAL;
9631 }
9632
9633 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9634 {
9635#ifdef FEATURE_WLAN_LPHB
9636 /* Low Power Heartbeat configuration request */
9637 case WLAN_HDD_TM_CMD_WLAN_HB:
9638 {
9639 int buf_len;
9640 void *buf;
9641 tSirLPHBReq *hb_params = NULL;
Amar Singhal05852702014-02-04 14:40:00 -08009642 tSirLPHBReq *hb_params_temp = NULL;
Leo Chang9056f462013-08-01 19:21:11 -07009643
9644 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9645 {
9646 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9647 "%s Testmode INV DATA", __func__);
9648 return -EINVAL;
9649 }
9650
9651 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9652 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
Amar Singhal05852702014-02-04 14:40:00 -08009653
9654 hb_params_temp =(tSirLPHBReq *)buf;
9655 if ((hb_params_temp->cmd == LPHB_SET_TCP_PARAMS_INDID) &&
9656 (hb_params_temp->params.lphbTcpParamReq.timePeriodSec == 0))
9657 return -EINVAL;
9658
Leo Chang9056f462013-08-01 19:21:11 -07009659 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9660 if (NULL == hb_params)
9661 {
9662 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9663 "%s Request Buffer Alloc Fail", __func__);
9664 return -EINVAL;
9665 }
9666
9667 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009668 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9669 hb_params,
9670 wlan_hdd_cfg80211_lphb_ind_handler);
9671 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009672 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009673 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9674 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009675 vos_mem_free(hb_params);
9676 }
Leo Chang9056f462013-08-01 19:21:11 -07009677 return 0;
9678 }
9679#endif /* FEATURE_WLAN_LPHB */
9680 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309681 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9682 "%s: unsupported event",__func__);
Leo Chang9056f462013-08-01 19:21:11 -07009683 return -EOPNOTSUPP;
9684 }
9685
9686 return err;
9687}
9688#endif /* CONFIG_NL80211_TESTMODE */
9689
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309690static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9691 struct net_device *dev,
9692 int idx, struct survey_info *survey)
9693{
9694 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9695 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309696 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309697 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309698 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309699 v_S7_t snr,rssi;
9700 int status, i, j, filled = 0;
9701
9702 ENTER();
9703
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309704 if (NULL == pAdapter)
9705 {
9706 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9707 "%s: HDD adapter is Null", __func__);
9708 return -ENODEV;
9709 }
9710
9711 if (NULL == wiphy)
9712 {
9713 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9714 "%s: wiphy is Null", __func__);
9715 return -ENODEV;
9716 }
9717
9718 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9719 status = wlan_hdd_validate_context(pHddCtx);
9720
9721 if (0 != status)
9722 {
9723 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9724 "%s: HDD context is not valid", __func__);
9725 return status;
9726 }
9727
Mihir Sheted9072e02013-08-21 17:02:29 +05309728 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9729
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309730 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309731 0 != pAdapter->survey_idx ||
9732 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309733 {
9734 /* The survey dump ops when implemented completely is expected to
9735 * return a survey of all channels and the ops is called by the
9736 * kernel with incremental values of the argument 'idx' till it
9737 * returns -ENONET. But we can only support the survey for the
9738 * operating channel for now. survey_idx is used to track
9739 * that the ops is called only once and then return -ENONET for
9740 * the next iteration
9741 */
9742 pAdapter->survey_idx = 0;
9743 return -ENONET;
9744 }
9745
9746 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9747
9748 wlan_hdd_get_snr(pAdapter, &snr);
9749 wlan_hdd_get_rssi(pAdapter, &rssi);
9750
9751 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9752 hdd_wlan_get_freq(channel, &freq);
9753
9754
9755 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9756 {
9757 if (NULL == wiphy->bands[i])
9758 {
9759 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9760 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9761 continue;
9762 }
9763
9764 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9765 {
9766 struct ieee80211_supported_band *band = wiphy->bands[i];
9767
9768 if (band->channels[j].center_freq == (v_U16_t)freq)
9769 {
9770 survey->channel = &band->channels[j];
9771 /* The Rx BDs contain SNR values in dB for the received frames
9772 * while the supplicant expects noise. So we calculate and
9773 * return the value of noise (dBm)
9774 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9775 */
9776 survey->noise = rssi - snr;
9777 survey->filled = SURVEY_INFO_NOISE_DBM;
9778 filled = 1;
9779 }
9780 }
9781 }
9782
9783 if (filled)
9784 pAdapter->survey_idx = 1;
9785 else
9786 {
9787 pAdapter->survey_idx = 0;
9788 return -ENONET;
9789 }
9790
9791 return 0;
9792}
9793
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309794/*
9795 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9796 * this is called when cfg80211 driver resume
9797 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9798 */
9799int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9800{
9801 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9802 hdd_adapter_t *pAdapter;
9803 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9804 VOS_STATUS status = VOS_STATUS_SUCCESS;
9805
9806 ENTER();
9807
9808 if ( NULL == pHddCtx )
9809 {
9810 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9811 "%s: HddCtx validation failed", __func__);
9812 return 0;
9813 }
9814
9815 if (pHddCtx->isLogpInProgress)
9816 {
9817 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9818 "%s: LOGP in Progress. Ignore!!!", __func__);
9819 return 0;
9820 }
9821
Mihir Shete18156292014-03-11 15:38:30 +05309822 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309823 {
9824 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9825 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9826 return 0;
9827 }
9828
9829 spin_lock(&pHddCtx->schedScan_lock);
9830 pHddCtx->isWiphySuspended = FALSE;
9831 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9832 {
9833 spin_unlock(&pHddCtx->schedScan_lock);
9834 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9835 "%s: Return resume is not due to PNO indication", __func__);
9836 return 0;
9837 }
9838 // Reset flag to avoid updatating cfg80211 data old results again
9839 pHddCtx->isSchedScanUpdatePending = FALSE;
9840 spin_unlock(&pHddCtx->schedScan_lock);
9841
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309842
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309843 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9844
9845 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9846 {
9847 pAdapter = pAdapterNode->pAdapter;
9848 if ( (NULL != pAdapter) &&
9849 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9850 {
9851 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309852 {
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9854 "%s: NO SCAN result", __func__);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309855 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309856 else
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309857 {
9858 /* Acquire wakelock to handle the case where APP's tries to
9859 * suspend immediately after updating the scan results. Whis
9860 * results in app's is in suspended state and not able to
9861 * process the connect request to AP
9862 */
9863 hdd_prevent_suspend_timeout(2000);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309864 cfg80211_sched_scan_results(pHddCtx->wiphy);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309865 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309866
9867 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9868 "%s : cfg80211 scan result database updated", __func__);
9869
9870 return 0;
9871
9872 }
9873 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9874 pAdapterNode = pNext;
9875 }
9876
9877 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9878 "%s: Failed to find Adapter", __func__);
9879 return 0;
9880}
9881
9882/*
9883 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9884 * this is called when cfg80211 driver suspends
9885 */
9886int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9887 struct cfg80211_wowlan *wow)
9888{
9889 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9890
9891 ENTER();
9892 if (NULL == pHddCtx)
9893 {
9894 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9895 "%s: HddCtx validation failed", __func__);
9896 return 0;
9897 }
9898
9899 pHddCtx->isWiphySuspended = TRUE;
9900
9901 EXIT();
9902
9903 return 0;
9904}
9905
Jeff Johnson295189b2012-06-20 16:38:30 -07009906/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309907static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009908{
9909 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9910 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9911 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9912 .change_station = wlan_hdd_change_station,
9913#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9914 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9915 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9916 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009917#else
9918 .start_ap = wlan_hdd_cfg80211_start_ap,
9919 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9920 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009921#endif
9922 .change_bss = wlan_hdd_cfg80211_change_bss,
9923 .add_key = wlan_hdd_cfg80211_add_key,
9924 .get_key = wlan_hdd_cfg80211_get_key,
9925 .del_key = wlan_hdd_cfg80211_del_key,
9926 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009927#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009928 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009929#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009930 .scan = wlan_hdd_cfg80211_scan,
9931 .connect = wlan_hdd_cfg80211_connect,
9932 .disconnect = wlan_hdd_cfg80211_disconnect,
9933 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9934 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9935 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9936 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9937 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009938 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9939 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
DARAM SUDHA39eede62014-02-12 11:16:40 +05309940 .mgmt_tx = wlan_hdd_mgmt_tx,
Jeff Johnson295189b2012-06-20 16:38:30 -07009941#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9942 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9943 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9944 .set_txq_params = wlan_hdd_set_txq_params,
9945#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009946 .get_station = wlan_hdd_cfg80211_get_station,
9947 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9948 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009949 .add_station = wlan_hdd_cfg80211_add_station,
9950#ifdef FEATURE_WLAN_LFR
9951 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9952 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9953 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9954#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009955#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9956 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9957#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009958#ifdef FEATURE_WLAN_TDLS
9959 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9960 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9961#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309962#ifdef WLAN_FEATURE_GTK_OFFLOAD
9963 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9964#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309965#ifdef FEATURE_WLAN_SCAN_PNO
9966 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9967 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9968#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309969 .resume = wlan_hdd_cfg80211_resume_wlan,
9970 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309971 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009972#ifdef WLAN_NL80211_TESTMODE
9973 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9974#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309975 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009976};
9977