blob: 07d0d3a2e726a9e6dfa9b1aad84b0038237a3c23 [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
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +0530928/* This function registers for all frame which supplicant is interested in */
929void wlan_hdd_cfg80211_register_frames(hdd_adapter_t* pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700930{
Jeff Johnson295189b2012-06-20 16:38:30 -0700931 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
932 /* Register for all P2P action, public action etc frames */
933 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
934
Jeff Johnsone7245742012-09-05 17:12:55 -0700935 ENTER();
936
Jeff Johnson295189b2012-06-20 16:38:30 -0700937 /* Right now we are registering these frame when driver is getting
938 initialized. Once we will move to 2.6.37 kernel, in which we have
939 frame register ops, we will move this code as a part of that */
940 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530941 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700942 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
943
944 /* GAS Initial Response */
945 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
946 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530947
Jeff Johnson295189b2012-06-20 16:38:30 -0700948 /* GAS Comeback Request */
949 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
950 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
951
952 /* GAS Comeback Response */
953 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
954 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
955
956 /* P2P Public Action */
957 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530958 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700959 P2P_PUBLIC_ACTION_FRAME_SIZE );
960
961 /* P2P Action */
962 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
963 (v_U8_t*)P2P_ACTION_FRAME,
964 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700965
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530966 /* WNM BSS Transition Request frame */
967 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
968 (v_U8_t*)WNM_BSS_ACTION_FRAME,
969 WNM_BSS_ACTION_FRAME_SIZE );
Leela Venkata Kiran Kumar Reddy Chiralae8e62c82013-10-29 18:23:26 -0700970
971 /* WNM-Notification */
972 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
973 (v_U8_t*)WNM_NOTIFICATION_FRAME,
974 WNM_NOTIFICATION_FRAME_SIZE );
Jeff Johnson295189b2012-06-20 16:38:30 -0700975}
976
Agarwal Ashish8fa0e9a2014-05-23 00:40:12 +0530977void wlan_hdd_cfg80211_deregister_frames(hdd_adapter_t* pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700978{
Jeff Johnson295189b2012-06-20 16:38:30 -0700979 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
980 /* Register for all P2P action, public action etc frames */
981 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
982
Jeff Johnsone7245742012-09-05 17:12:55 -0700983 ENTER();
984
Jeff Johnson295189b2012-06-20 16:38:30 -0700985 /* Right now we are registering these frame when driver is getting
986 initialized. Once we will move to 2.6.37 kernel, in which we have
987 frame register ops, we will move this code as a part of that */
988 /* GAS Initial Request */
989
990 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
991 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
992
993 /* GAS Initial Response */
994 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
995 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530996
Jeff Johnson295189b2012-06-20 16:38:30 -0700997 /* GAS Comeback Request */
998 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
999 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
1000
1001 /* GAS Comeback Response */
1002 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1003 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
1004
1005 /* P2P Public Action */
1006 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301007 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -07001008 P2P_PUBLIC_ACTION_FRAME_SIZE );
1009
1010 /* P2P Action */
1011 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1012 (v_U8_t*)P2P_ACTION_FRAME,
1013 P2P_ACTION_FRAME_SIZE );
Leela Venkata Kiran Kumar Reddy Chiralae8e62c82013-10-29 18:23:26 -07001014 /* WNM-Notification */
1015 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1016 (v_U8_t*)WNM_NOTIFICATION_FRAME,
1017 WNM_NOTIFICATION_FRAME_SIZE );
Jeff Johnson295189b2012-06-20 16:38:30 -07001018}
1019
1020#ifdef FEATURE_WLAN_WAPI
1021void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
1022 const u8 *mac_addr, u8 *key , int key_Len)
1023{
1024 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1025 tCsrRoamSetKey setKey;
1026 v_BOOL_t isConnected = TRUE;
1027 int status = 0;
1028 v_U32_t roamId= 0xFF;
1029 tANI_U8 *pKeyPtr = NULL;
1030 int n = 0;
1031
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05301032 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s(%d)",
1033 __func__, hdd_device_modetoString(pAdapter->device_mode),
1034 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07001035
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
Rashmi Ramanna3b59e122014-04-10 14:45:13 +05301690 if (indx >= num_ch)
1691 {
1692 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1693 {
1694 eCsrBand band;
1695 unsigned int freq;
1696
1697 sme_GetFreqBand(hHal, &band);
1698
1699 if (eCSR_BAND_5G == band)
1700 {
1701#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
1702 if (channel <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
1703 {
1704 freq = ieee80211_channel_to_frequency(channel,
1705 IEEE80211_BAND_2GHZ);
1706 }
1707 else
1708 {
1709 freq = ieee80211_channel_to_frequency(channel,
1710 IEEE80211_BAND_5GHZ);
1711 }
1712#else
1713 freq = ieee80211_channel_to_frequency(channel);
1714#endif
1715 if(WLAN_HDD_IS_SOCIAL_CHANNEL(freq))
1716 return VOS_STATUS_SUCCESS;
1717 }
1718 }
1719
1720 hddLog(VOS_TRACE_LEVEL_ERROR,
1721 "%s: Invalid Channel [%d]", __func__, channel);
1722 return VOS_STATUS_E_FAILURE;
1723 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001724 }
Rashmi Ramanna3b59e122014-04-10 14:45:13 +05301725
Jeff Johnson295189b2012-06-20 16:38:30 -07001726 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301727
Jeff Johnson295189b2012-06-20 16:38:30 -07001728}
1729
Viral Modi3a32cc52013-02-08 11:14:52 -08001730/**
1731 * FUNCTION: wlan_hdd_cfg80211_set_channel
1732 * This function is used to set the channel number
1733 */
1734static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1735 struct ieee80211_channel *chan,
1736 enum nl80211_channel_type channel_type
1737 )
1738{
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301739 hdd_adapter_t *pAdapter = NULL;
Viral Modi3a32cc52013-02-08 11:14:52 -08001740 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001741 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001742 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301743 hdd_context_t *pHddCtx;
1744 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001745
1746 ENTER();
1747
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301748
Viral Modi3a32cc52013-02-08 11:14:52 -08001749 if( NULL == dev )
1750 {
1751 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001752 "%s: Called with dev = NULL.", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001753 return -ENODEV;
1754 }
1755 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1756
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05301757 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
1758 TRACE_CODE_HDD_CFG80211_SET_CHANNEL, pAdapter->sessionId,
1759 channel_type ));
Viral Modi3a32cc52013-02-08 11:14:52 -08001760 hddLog(VOS_TRACE_LEVEL_INFO,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05301761 "%s: device_mode = %s (%d) freq = %d", __func__,
1762 hdd_device_modetoString(pAdapter->device_mode),
1763 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301764
1765 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1766 status = wlan_hdd_validate_context(pHddCtx);
1767
1768 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001769 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301770 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1771 "%s: HDD context is not valid", __func__);
1772 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001773 }
1774
1775 /*
1776 * Do freq to chan conversion
1777 * TODO: for 11a
1778 */
1779
1780 channel = ieee80211_frequency_to_channel(freq);
1781
1782 /* Check freq range */
1783 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1784 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1785 {
1786 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001787 "%s: Channel [%d] is outside valid range from %d to %d",
Viral Modi3a32cc52013-02-08 11:14:52 -08001788 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1789 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1790 return -EINVAL;
1791 }
1792
1793 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1794
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301795 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1796 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001797 {
1798 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1799 {
1800 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001801 "%s: Invalid Channel [%d]", __func__, channel);
Viral Modi3a32cc52013-02-08 11:14:52 -08001802 return -EINVAL;
1803 }
1804 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1805 "%s: set channel to [%d] for device mode =%d",
1806 __func__, channel,pAdapter->device_mode);
1807 }
1808 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001809 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001810 )
1811 {
1812 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1813 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1814 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1815
1816 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1817 {
1818 /* Link is up then return cant set channel*/
1819 hddLog( VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001820 "%s: IBSS Associated, can't set the channel", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001821 return -EINVAL;
1822 }
1823
1824 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1825 pHddStaCtx->conn_info.operationChannel = channel;
1826 pRoamProfile->ChannelInfo.ChannelList =
1827 &pHddStaCtx->conn_info.operationChannel;
1828 }
1829 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001830 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001831 )
1832 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301833 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1834 {
1835 if(VOS_STATUS_SUCCESS !=
1836 wlan_hdd_validate_operation_channel(pAdapter,channel))
1837 {
1838 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001839 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301840 return -EINVAL;
1841 }
1842 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1843 }
1844 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001845 {
1846 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1847
1848 /* If auto channel selection is configured as enable/ 1 then ignore
1849 channel set by supplicant
1850 */
1851 if ( cfg_param->apAutoChannelSelection )
1852 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301853 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1854 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001855 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05301856 "%s: set channel to auto channel (0) for device mode =%s (%d)",
1857 __func__, hdd_device_modetoString(pAdapter->device_mode),
1858 pAdapter->device_mode);
Viral Modi3a32cc52013-02-08 11:14:52 -08001859 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301860 else
1861 {
1862 if(VOS_STATUS_SUCCESS !=
1863 wlan_hdd_validate_operation_channel(pAdapter,channel))
1864 {
1865 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001866 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301867 return -EINVAL;
1868 }
1869 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1870 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001871 }
1872 }
1873 else
1874 {
1875 hddLog(VOS_TRACE_LEVEL_FATAL,
1876 "%s: Invalid device mode failed to set valid channel", __func__);
1877 return -EINVAL;
1878 }
1879 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301880 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001881}
1882
Jeff Johnson295189b2012-06-20 16:38:30 -07001883#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1884static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1885 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001886#else
1887static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1888 struct cfg80211_beacon_data *params,
1889 const u8 *ssid, size_t ssid_len,
1890 enum nl80211_hidden_ssid hidden_ssid)
1891#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001892{
1893 tsap_Config_t *pConfig;
1894 beacon_data_t *pBeacon = NULL;
1895 struct ieee80211_mgmt *pMgmt_frame;
1896 v_U8_t *pIe=NULL;
1897 v_U16_t capab_info;
1898 eCsrAuthType RSNAuthType;
1899 eCsrEncryptionType RSNEncryptType;
1900 eCsrEncryptionType mcRSNEncryptType;
1901 int status = VOS_STATUS_SUCCESS;
1902 tpWLAN_SAPEventCB pSapEventCallback;
1903 hdd_hostapd_state_t *pHostapdState;
1904 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1905 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301906 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001907 struct qc_mac_acl_entry *acl_entry = NULL;
Siddharth Bhal5cba24e2014-05-08 18:59:39 +05301908 hdd_config_t *iniConfig;
Jeff Johnson295189b2012-06-20 16:38:30 -07001909 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001910 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Chet Lanctot40142442014-05-20 13:39:25 -07001911 v_BOOL_t MFPCapable = VOS_FALSE;
1912 v_BOOL_t MFPRequired = VOS_FALSE;
Abhishek Singhf0ac1752014-03-05 17:47:09 +05301913 eHddDot11Mode sapDot11Mode =
1914 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->sapDot11Mode;
Jeff Johnson295189b2012-06-20 16:38:30 -07001915
1916 ENTER();
1917
Siddharth Bhal5cba24e2014-05-08 18:59:39 +05301918 iniConfig = pHddCtx->cfg_ini;
1919
Jeff Johnson295189b2012-06-20 16:38:30 -07001920 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1921
1922 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1923
1924 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1925
1926 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1927
1928 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1929
1930 //channel is already set in the set_channel Call back
1931 //pConfig->channel = pCommitConfig->channel;
1932
1933 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301934 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001935 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1936
1937 pConfig->dtim_period = pBeacon->dtim_period;
1938
Arif Hussain6d2a3322013-11-17 19:50:10 -08001939 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***",
Jeff Johnson295189b2012-06-20 16:38:30 -07001940 pConfig->dtim_period);
1941
1942
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001943 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001944 {
1945 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001946 WLAN_EID_COUNTRY);
Kiet Lam083504c2013-11-25 14:17:45 +05301947 if(memcmp(pHddCtx->cfg_ini->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0)
1948 {
1949 tANI_BOOLEAN restartNeeded;
1950 pConfig->ieee80211d = 1;
1951 vos_mem_copy(pConfig->countryCode, pHddCtx->cfg_ini->apCntryCode, 3);
1952 sme_setRegInfo(hHal, pConfig->countryCode);
1953 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
1954 }
1955 else if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001956 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001957 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001958 pConfig->ieee80211d = 1;
1959 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1960 sme_setRegInfo(hHal, pConfig->countryCode);
1961 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001962 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001963 else
1964 {
1965 pConfig->ieee80211d = 0;
1966 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301967 /*
1968 * If auto channel is configured i.e. channel is 0,
1969 * so skip channel validation.
1970 */
1971 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1972 {
1973 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1974 {
1975 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001976 "%s: Invalid Channel [%d]", __func__, pConfig->channel);
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301977 return -EINVAL;
1978 }
1979 }
1980 else
1981 {
1982 if(1 != pHddCtx->is_dynamic_channel_range_set)
1983 {
1984 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1985 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1986 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1987 }
1988 pHddCtx->is_dynamic_channel_range_set = 0;
1989 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001990 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001991 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001992 {
1993 pConfig->ieee80211d = 0;
1994 }
1995 pConfig->authType = eSAP_AUTO_SWITCH;
1996
1997 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301998
1999 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07002000 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
2001
2002 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
2003
2004 /*Set wps station to configured*/
2005 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
2006
2007 if(pIe)
2008 {
2009 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
2010 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002011 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***");
Jeff Johnson295189b2012-06-20 16:38:30 -07002012 return -EINVAL;
2013 }
2014 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
2015 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07002016 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07002017 /* Check 15 bit of WPS IE as it contain information for wps state
2018 * WPS state
2019 */
2020 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
2021 {
2022 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
2023 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
2024 {
2025 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
2026 }
2027 }
2028 }
2029 else
2030 {
2031 pConfig->wps_state = SAP_WPS_DISABLED;
2032 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302033 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07002034
2035 pConfig->RSNWPAReqIELength = 0;
2036 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302037 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07002038 WLAN_EID_RSN);
2039 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302040 {
Jeff Johnson295189b2012-06-20 16:38:30 -07002041 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2042 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2043 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302044 /* The actual processing may eventually be more extensive than
2045 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07002046 * by the app.
2047 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302048 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002049 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2050 &RSNEncryptType,
2051 &mcRSNEncryptType,
2052 &RSNAuthType,
Chet Lanctot8cecea22014-02-11 19:09:36 -08002053 &MFPCapable,
2054 &MFPRequired,
Jeff Johnson295189b2012-06-20 16:38:30 -07002055 pConfig->pRSNWPAReqIE[1]+2,
2056 pConfig->pRSNWPAReqIE );
2057
2058 if( VOS_STATUS_SUCCESS == status )
2059 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302060 /* Now copy over all the security attributes you have
2061 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002062 * */
2063 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2064 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2065 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2066 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302067 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002068 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2070 }
2071 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302072
Jeff Johnson295189b2012-06-20 16:38:30 -07002073 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2074 pBeacon->tail, pBeacon->tail_len);
2075
2076 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
2077 {
2078 if (pConfig->pRSNWPAReqIE)
2079 {
2080 /*Mixed mode WPA/WPA2*/
2081 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
2082 pConfig->RSNWPAReqIELength += pIe[1] + 2;
2083 }
2084 else
2085 {
2086 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2087 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2088 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302089 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002090 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2091 &RSNEncryptType,
2092 &mcRSNEncryptType,
2093 &RSNAuthType,
Chet Lanctot8cecea22014-02-11 19:09:36 -08002094 &MFPCapable,
2095 &MFPRequired,
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 pConfig->pRSNWPAReqIE[1]+2,
2097 pConfig->pRSNWPAReqIE );
2098
2099 if( VOS_STATUS_SUCCESS == status )
2100 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302101 /* Now copy over all the security attributes you have
2102 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002103 * */
2104 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2105 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2106 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2107 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302108 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002109 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002110 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2111 }
2112 }
2113 }
2114
Jeff Johnson4416a782013-03-25 14:17:50 -07002115 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
2116 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
2117 return -EINVAL;
2118 }
2119
Jeff Johnson295189b2012-06-20 16:38:30 -07002120 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
2121
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002122#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002123 if (params->ssid != NULL)
2124 {
2125 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
2126 pConfig->SSIDinfo.ssid.length = params->ssid_len;
2127 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2128 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2129 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002130#else
2131 if (ssid != NULL)
2132 {
2133 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
2134 pConfig->SSIDinfo.ssid.length = ssid_len;
2135 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2136 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2137 }
2138#endif
2139
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302140 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07002141 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302142
Jeff Johnson295189b2012-06-20 16:38:30 -07002143 /* default value */
2144 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
2145 pConfig->num_accept_mac = 0;
2146 pConfig->num_deny_mac = 0;
2147
2148 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2149 pBeacon->tail, pBeacon->tail_len);
2150
2151 /* pIe for black list is following form:
2152 type : 1 byte
2153 length : 1 byte
2154 OUI : 4 bytes
2155 acl type : 1 byte
2156 no of mac addr in black list: 1 byte
2157 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302158 */
2159 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002160 {
2161 pConfig->SapMacaddr_acl = pIe[6];
2162 pConfig->num_deny_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002163 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002164 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302165 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2166 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002167 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2168 for (i = 0; i < pConfig->num_deny_mac; i++)
2169 {
2170 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2171 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302172 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002173 }
2174 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2175 pBeacon->tail, pBeacon->tail_len);
2176
2177 /* pIe for white list is following form:
2178 type : 1 byte
2179 length : 1 byte
2180 OUI : 4 bytes
2181 acl type : 1 byte
2182 no of mac addr in white list: 1 byte
2183 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302184 */
2185 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002186 {
2187 pConfig->SapMacaddr_acl = pIe[6];
2188 pConfig->num_accept_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002189 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002190 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302191 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2192 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002193 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2194 for (i = 0; i < pConfig->num_accept_mac; i++)
2195 {
2196 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2197 acl_entry++;
2198 }
2199 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302200
Jeff Johnson295189b2012-06-20 16:38:30 -07002201 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2202
Jeff Johnsone7245742012-09-05 17:12:55 -07002203#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002204 /* Overwrite the hostapd setting for HW mode only for 11ac.
Kiet Lam0f320422013-11-21 19:29:17 +05302205 * This is valid only if mode is set to 11n in hostapd, either AUTO or
2206 * 11ac in .ini and 11ac is supported by both host and firmware.
2207 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode)
2208 */
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002209 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2210 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Abhishek Singhf0ac1752014-03-05 17:47:09 +05302211 (( sapDot11Mode == eHDD_DOT11_MODE_AUTO ) ||
2212 ( sapDot11Mode == eHDD_DOT11_MODE_11ac ) ||
2213 ( sapDot11Mode == eHDD_DOT11_MODE_11ac_ONLY ) ) &&
2214 (sme_IsFeatureSupportedByDriver(DOT11AC)) &&
2215 (sme_IsFeatureSupportedByFW(DOT11AC)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002216 {
Siddharth Bhalf42f8592014-05-15 13:39:07 +05302217 v_U32_t operatingBand = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07002218 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Siddharth Bhalf42f8592014-05-15 13:39:07 +05302219 ccmCfgGetInt(hHal, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002220
Siddharth Bhal5cba24e2014-05-08 18:59:39 +05302221 /* If ACS disable and selected channel <= 14
2222 * OR
2223 * ACS enabled and ACS operating band is choosen as 2.4
2224 * AND
2225 * VHT in 2.4G Disabled
2226 * THEN
2227 * Fallback to 11N mode
2228 */
2229 if (((AUTO_CHANNEL_SELECT != pConfig->channel && pConfig->channel <= SIR_11B_CHANNEL_END)
2230 || (AUTO_CHANNEL_SELECT == pConfig->channel &&
Siddharth Bhalf42f8592014-05-15 13:39:07 +05302231 operatingBand == RF_SUBBAND_2_4_GHZ)) &&
Siddharth Bhal5cba24e2014-05-08 18:59:39 +05302232 iniConfig->enableVhtFor24GHzBand == FALSE)
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002233 {
Siddharth Bhalf42f8592014-05-15 13:39:07 +05302234 hddLog(LOGW, FL("Setting hwmode to 11n, operatingBand = %d, Channel = %d"),
2235 operatingBand, pConfig->channel);
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002236 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2237 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002238 }
2239#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302240
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002241 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2242 {
2243 sme_SelectCBMode(hHal,
2244 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2245 pConfig->channel);
2246 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002247 // ht_capab is not what the name conveys,this is used for protection bitmap
2248 pConfig->ht_capab =
2249 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2250
2251 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2252 {
2253 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2254 return -EINVAL;
2255 }
2256
2257 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302258 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002259 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2260 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302261 pConfig->obssProtEnabled =
2262 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002263
Chet Lanctot8cecea22014-02-11 19:09:36 -08002264#ifdef WLAN_FEATURE_11W
2265 pConfig->mfpCapable = MFPCapable;
2266 pConfig->mfpRequired = MFPRequired;
2267 hddLog(LOGW, FL("Soft AP MFP capable %d, MFP required %d\n"),
2268 pConfig->mfpCapable, pConfig->mfpRequired);
2269#endif
2270
Arif Hussain6d2a3322013-11-17 19:50:10 -08002271 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR),
Jeff Johnson295189b2012-06-20 16:38:30 -07002272 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002273 hddLog(LOGW,FL("ssid =%s, beaconint=%d, channel=%d"),
2274 pConfig->SSIDinfo.ssid.ssId, (int)pConfig->beacon_int,
2275 (int)pConfig->channel);
2276 hddLog(LOGW,FL("hw_mode=%x, privacy=%d, authType=%d"),
2277 pConfig->SapHw_mode, pConfig->privacy,
2278 pConfig->authType);
2279 hddLog(LOGW,FL("RSN/WPALen=%d, Uapsd = %d"),
2280 (int)pConfig->RSNWPAReqIELength, pConfig->UapsdEnable);
2281 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d"),
2282 pConfig->protEnabled, pConfig->obssProtEnabled);
Jeff Johnson295189b2012-06-20 16:38:30 -07002283
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302284 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002285 {
2286 //Bss already started. just return.
2287 //TODO Probably it should update some beacon params.
2288 hddLog( LOGE, "Bss Already started...Ignore the request");
2289 EXIT();
2290 return 0;
2291 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302292
Jeff Johnson295189b2012-06-20 16:38:30 -07002293 pConfig->persona = pHostapdAdapter->device_mode;
2294
2295 pSapEventCallback = hdd_hostapd_SAPEventCB;
2296 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2297 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2298 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002299 hddLog(LOGE,FL("SAP Start Bss fail"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002300 return -EINVAL;
2301 }
2302
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302303 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002304 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2305
2306 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302307
Jeff Johnson295189b2012-06-20 16:38:30 -07002308 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302309 {
2310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002311 ("ERROR: HDD vos wait for single_event failed!!"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002312 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002313 VOS_ASSERT(0);
2314 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302315
Jeff Johnson295189b2012-06-20 16:38:30 -07002316 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2317
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002318#ifdef WLAN_FEATURE_P2P_DEBUG
2319 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2320 {
2321 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2322 {
2323 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2324 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002325 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002326 }
2327 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2328 {
2329 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2330 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002331 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002332 }
2333 }
2334#endif
2335
Jeff Johnson295189b2012-06-20 16:38:30 -07002336 pHostapdState->bCommit = TRUE;
2337 EXIT();
2338
2339 return 0;
2340}
2341
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002342#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302343static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2344 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002345 struct beacon_parameters *params)
2346{
2347 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302348 hdd_context_t *pHddCtx;
2349 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002350
2351 ENTER();
2352
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302353 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2354 TRACE_CODE_HDD_CFG80211_ADD_BEACON,
2355 pAdapter->sessionId, params->interval));
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302356 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%s (%d)",
2357 hdd_device_modetoString(pAdapter->device_mode),
2358 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002359
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302360 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2361 status = wlan_hdd_validate_context(pHddCtx);
2362
2363 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002364 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302365 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2366 "%s: HDD context is not valid", __func__);
2367 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002368 }
2369
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302370 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002371 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002372 )
2373 {
2374 beacon_data_t *old,*new;
2375
2376 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302377
Jeff Johnson295189b2012-06-20 16:38:30 -07002378 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302379 {
2380 hddLog(VOS_TRACE_LEVEL_WARN,
2381 FL("already beacon info added to session(%d)"),
2382 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002383 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302384 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002385
2386 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2387
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302388 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002389 {
2390 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002391 "%s:Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002392 return -EINVAL;
2393 }
2394
2395 pAdapter->sessionCtx.ap.beacon = new;
2396
2397 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2398 }
2399
2400 EXIT();
2401 return status;
2402}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302403
2404static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002405 struct net_device *dev,
2406 struct beacon_parameters *params)
2407{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302408 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302409 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302410 hdd_context_t *pHddCtx;
2411 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002412
2413 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302414 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2415 TRACE_CODE_HDD_CFG80211_SET_BEACON,
2416 pAdapter->sessionId, pHddStaCtx->conn_info.authType));
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302417 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
2418 __func__, hdd_device_modetoString(pAdapter->device_mode),
2419 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002420
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302421 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2422 status = wlan_hdd_validate_context(pHddCtx);
2423
2424 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002425 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2427 "%s: HDD context is not valid", __func__);
2428 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002429 }
2430
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302431 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002432 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302433 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002434 {
2435 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302436
Jeff Johnson295189b2012-06-20 16:38:30 -07002437 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302438
Jeff Johnson295189b2012-06-20 16:38:30 -07002439 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302440 {
2441 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2442 FL("session(%d) old and new heads points to NULL"),
2443 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002444 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302445 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002446
2447 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2448
2449 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302450 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002451 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002452 return -EINVAL;
2453 }
2454
2455 pAdapter->sessionCtx.ap.beacon = new;
2456
2457 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2458 }
2459
2460 EXIT();
2461 return status;
2462}
2463
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002464#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2465
2466#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002467static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2468 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002469#else
2470static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2471 struct net_device *dev)
2472#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002473{
2474 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002475 hdd_context_t *pHddCtx = NULL;
2476 hdd_scaninfo_t *pScanInfo = NULL;
2477 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302478 VOS_STATUS status;
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302479 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07002480
2481 ENTER();
2482
2483 if (NULL == pAdapter)
2484 {
2485 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002486 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002487 return -ENODEV;
2488 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002489
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302490 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2491 TRACE_CODE_HDD_CFG80211_STOP_AP,
2492 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302493 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2494 status = wlan_hdd_validate_context(pHddCtx);
2495
2496 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002497 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302498 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2499 "%s: HDD context is not valid", __func__);
2500 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002501 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002502
2503 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2504 if (NULL == staAdapter)
2505 {
2506 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2507 if (NULL == staAdapter)
2508 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002509 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2510 "%s: HDD adapter context for STA/P2P-CLI is Null",
2511 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002512 }
2513 }
2514
2515 pScanInfo = &pHddCtx->scan_info;
2516
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302517 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
2518 __func__, hdd_device_modetoString(pAdapter->device_mode),
2519 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002520
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302521 ret = wlan_hdd_scan_abort(pAdapter);
2522
2523 if (ret <= 0)
Jeff Johnsone7245742012-09-05 17:12:55 -07002524 {
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2526 FL("Timeout occurred while waiting for abortscan %ld"), ret);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302527
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302528 if (pHddCtx->isLogpInProgress)
Jeff Johnsone7245742012-09-05 17:12:55 -07002529 {
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302530 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2531 "%s: LOGP in Progress. Ignore!!!", __func__);
Yue Ma4f55ef32014-01-23 16:45:33 -08002532
Jeff Johnsone7245742012-09-05 17:12:55 -07002533 VOS_ASSERT(pScanInfo->mScanPending);
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302534 return -EAGAIN;
Jeff Johnsone7245742012-09-05 17:12:55 -07002535 }
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05302536 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002537 }
2538
Arun Kumar Khandavallia3bd8002014-01-17 16:21:19 +05302539 hdd_hostapd_stop(dev);
2540
Jeff Johnson295189b2012-06-20 16:38:30 -07002541 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002542 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002543 )
2544 {
2545 beacon_data_t *old;
2546
2547 old = pAdapter->sessionCtx.ap.beacon;
2548
2549 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302550 {
2551 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2552 FL("session(%d) beacon data points to NULL"),
2553 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002554 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302555 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002556
Jeff Johnson295189b2012-06-20 16:38:30 -07002557 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002558
2559 mutex_lock(&pHddCtx->sap_lock);
2560 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2561 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002562 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002563 {
2564 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2565
2566 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2567
2568 if (!VOS_IS_STATUS_SUCCESS(status))
2569 {
2570 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002571 ("ERROR: HDD vos wait for single_event failed!!"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002572 VOS_ASSERT(0);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302573 }
2574 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2576 }
2577 mutex_unlock(&pHddCtx->sap_lock);
2578
2579 if(status != VOS_STATUS_SUCCESS)
2580 {
2581 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002582 "%s:Error!!! Stopping the BSS",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002583 return -EINVAL;
2584 }
2585
Jeff Johnson4416a782013-03-25 14:17:50 -07002586 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002587 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2588 ==eHAL_STATUS_FAILURE)
2589 {
2590 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002591 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002592 }
2593
Jeff Johnson4416a782013-03-25 14:17:50 -07002594 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002595 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2596 eANI_BOOLEAN_FALSE) )
2597 {
2598 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002599 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 }
2601
2602 // Reset WNI_CFG_PROBE_RSP Flags
2603 wlan_hdd_reset_prob_rspies(pAdapter);
2604
2605 pAdapter->sessionCtx.ap.beacon = NULL;
2606 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002607#ifdef WLAN_FEATURE_P2P_DEBUG
2608 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2609 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2610 {
2611 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2612 "GO got removed");
2613 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2614 }
2615#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002616 }
2617 EXIT();
2618 return status;
2619}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002620
2621#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2622
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302623static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2624 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002625 struct cfg80211_ap_settings *params)
2626{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302627 hdd_adapter_t *pAdapter;
2628 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302629 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002630
2631 ENTER();
2632
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302633 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002634 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302635 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302636 "%s: Device is Null", __func__);
2637 return -ENODEV;
2638 }
2639
2640 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2641 if (NULL == pAdapter)
2642 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302643 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302644 "%s: HDD adapter is Null", __func__);
2645 return -ENODEV;
2646 }
2647
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302648 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2649 TRACE_CODE_HDD_CFG80211_START_AP, pAdapter->sessionId,
2650 params-> beacon_interval));
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302651 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2652 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302653 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302654 "%s: HDD adapter magic is invalid", __func__);
2655 return -ENODEV;
2656 }
2657
2658 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302659 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302660
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302661 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302662 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302663 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2664 "%s: HDD context is not valid", __func__);
2665 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302666 }
2667
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302668 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %s (%d)",
2669 __func__, hdd_device_modetoString(pAdapter->device_mode),
2670 pAdapter->device_mode);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302671
2672 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002673 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002674 )
2675 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302676 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002677
2678 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302679
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002680 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302681 {
2682 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2683 FL("already beacon info added to session(%d)"),
2684 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002685 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302686 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002687
2688 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2689
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302690 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002691 {
2692 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302693 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002694 return -EINVAL;
2695 }
2696 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002697#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002698 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2699#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2700 params->channel, params->channel_type);
2701#else
2702 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2703#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002704#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002705 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2706 params->ssid_len, params->hidden_ssid);
2707 }
2708
2709 EXIT();
2710 return status;
2711}
2712
2713
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302714static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002715 struct net_device *dev,
2716 struct cfg80211_beacon_data *params)
2717{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302718 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302719 hdd_context_t *pHddCtx;
2720 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002721
2722 ENTER();
2723
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302724 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2725 TRACE_CODE_HDD_CFG80211_CHANGE_BEACON,
2726 pAdapter->sessionId, pAdapter->device_mode));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002727 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002728 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302729
2730 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2731 status = wlan_hdd_validate_context(pHddCtx);
2732
2733 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002734 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302735 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2736 "%s: HDD context is not valid", __func__);
2737 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002738 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002739
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302740 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002741 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302742 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002743 {
2744 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302745
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002746 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302747
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002748 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302749 {
2750 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2751 FL("session(%d) beacon data points to NULL"),
2752 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002753 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302754 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002755
2756 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2757
2758 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302759 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002760 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002761 return -EINVAL;
2762 }
2763
2764 pAdapter->sessionCtx.ap.beacon = new;
2765
2766 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2767 }
2768
2769 EXIT();
2770 return status;
2771}
2772
2773#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2774
Jeff Johnson295189b2012-06-20 16:38:30 -07002775
2776static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2777 struct net_device *dev,
2778 struct bss_parameters *params)
2779{
2780 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2781
2782 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302783
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302784 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2785 TRACE_CODE_HDD_CFG80211_CHANGE_BSS,
2786 pAdapter->sessionId, params->ap_isolate));
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302787 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
2788 __func__, hdd_device_modetoString(pAdapter->device_mode),
2789 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002790
2791 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002792 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302793 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002794 {
2795 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2796 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302797 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002798 {
2799 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302800 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002801 }
2802
2803 EXIT();
2804 return 0;
2805}
2806
Kiet Lam10841362013-11-01 11:36:50 +05302807/* FUNCTION: wlan_hdd_change_country_code_cd
2808* to wait for contry code completion
2809*/
2810void* wlan_hdd_change_country_code_cb(void *pAdapter)
2811{
2812 hdd_adapter_t *call_back_pAdapter = pAdapter;
2813 complete(&call_back_pAdapter->change_country_code);
2814 return NULL;
2815}
2816
Jeff Johnson295189b2012-06-20 16:38:30 -07002817/*
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05302818 * FUNCTION: __wlan_hdd_cfg80211_change_iface
Jeff Johnson295189b2012-06-20 16:38:30 -07002819 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2820 */
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05302821int __wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002822 struct net_device *ndev,
2823 enum nl80211_iftype type,
2824 u32 *flags,
2825 struct vif_params *params
2826 )
2827{
2828 struct wireless_dev *wdev;
2829 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002830 hdd_context_t *pHddCtx;
Mohit Khanna0f232092012-09-11 14:46:08 -07002831 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002832 tCsrRoamProfile *pRoamProfile = NULL;
2833 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302834 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002835 eMib_dot11DesiredBssType connectedBssType;
2836 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302837 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07002838
2839 ENTER();
2840
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302841 if (!pAdapter)
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002842 {
2843 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2844 "%s: Adapter context is null", __func__);
2845 return VOS_STATUS_E_FAILURE;
2846 }
2847
2848 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2849 if (!pHddCtx)
2850 {
2851 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2852 "%s: HDD context is null", __func__);
2853 return VOS_STATUS_E_FAILURE;
2854 }
2855
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05302856 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
2857 TRACE_CODE_HDD_CFG80211_CHANGE_IFACE,
2858 pAdapter->sessionId, type));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302859 status = wlan_hdd_validate_context(pHddCtx);
2860
2861 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002862 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302863 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2864 "%s: HDD context is not valid", __func__);
2865 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002866 }
2867
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05302868 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
2869 __func__, hdd_device_modetoString(pAdapter->device_mode),
2870 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002871
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302872 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002873 wdev = ndev->ieee80211_ptr;
2874
2875#ifdef WLAN_BTAMP_FEATURE
2876 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2877 (NL80211_IFTYPE_ADHOC == type)||
2878 (NL80211_IFTYPE_AP == type)||
2879 (NL80211_IFTYPE_P2P_GO == type))
2880 {
2881 pHddCtx->isAmpAllowed = VOS_FALSE;
2882 // stop AMP traffic
2883 status = WLANBAP_StopAmp();
2884 if(VOS_STATUS_SUCCESS != status )
2885 {
2886 pHddCtx->isAmpAllowed = VOS_TRUE;
2887 hddLog(VOS_TRACE_LEVEL_FATAL,
2888 "%s: Failed to stop AMP", __func__);
2889 return -EINVAL;
2890 }
2891 }
2892#endif //WLAN_BTAMP_FEATURE
2893 /* Reset the current device mode bit mask*/
2894 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2895
2896 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002897 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002898 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002899 )
2900 {
2901 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002902 if (!pWextState)
2903 {
2904 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2905 "%s: pWextState is null", __func__);
2906 return VOS_STATUS_E_FAILURE;
2907 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002908 pRoamProfile = &pWextState->roamProfile;
2909 LastBSSType = pRoamProfile->BSSType;
2910
2911 switch (type)
2912 {
2913 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002914 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002915 hddLog(VOS_TRACE_LEVEL_INFO,
2916 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2917 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002918#ifdef WLAN_FEATURE_11AC
2919 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2920 {
2921 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2922 }
2923#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302924 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002925 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002926 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002927 //Check for sub-string p2p to confirm its a p2p interface
2928 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302929 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002930 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2931 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2932 }
2933 else
2934 {
2935 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002936 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002937 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302938#ifdef FEATURE_WLAN_TDLS
2939 /* The open adapter for the p2p shall skip initializations in
2940 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2941 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2942 * tdls_init when the change_iface sets the device mode to
2943 * WLAN_HDD_P2P_CLIENT.
2944 */
2945
2946 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2947 {
2948 if (0 != wlan_hdd_tdls_init (pAdapter))
2949 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302950 hddLog(VOS_TRACE_LEVEL_ERROR,
2951 "%s: tdls initialization failed", __func__);
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302952 return -EINVAL;
2953 }
2954 }
2955#endif
2956
Jeff Johnson295189b2012-06-20 16:38:30 -07002957 break;
2958 case NL80211_IFTYPE_ADHOC:
2959 hddLog(VOS_TRACE_LEVEL_INFO,
2960 "%s: setting interface Type to ADHOC", __func__);
2961 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2962 pRoamProfile->phyMode =
2963 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002964 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002965 wdev->iftype = type;
2966 break;
2967
2968 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002969 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002970 {
2971 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2972 "%s: setting interface Type to %s", __func__,
2973 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2974
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002975 //Cancel any remain on channel for GO mode
2976 if (NL80211_IFTYPE_P2P_GO == type)
2977 {
2978 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2979 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002980 if (NL80211_IFTYPE_AP == type)
2981 {
2982 /* As Loading WLAN Driver one interface being created for p2p device
2983 * address. This will take one HW STA and the max number of clients
2984 * that can connect to softAP will be reduced by one. so while changing
2985 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2986 * interface as it is not required in SoftAP mode.
2987 */
2988
2989 // Get P2P Adapter
2990 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2991
2992 if (pP2pAdapter)
2993 {
2994 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2995 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2996 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2997 }
2998 }
Swaroop Goltia2e32212014-04-09 23:37:33 +05302999 //Disable IMPS & BMPS for SAP/GO
3000 if(VOS_STATUS_E_FAILURE ==
3001 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
3002 {
3003 //Fail to Exit BMPS
3004 VOS_ASSERT(0);
3005 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303006#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07003007
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303008 /* A Mutex Lock is introduced while changing the mode to
3009 * protect the concurrent access for the Adapters by TDLS
3010 * module.
3011 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303012 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303013#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003014 //De-init the adapter.
3015 hdd_stop_adapter( pHddCtx, pAdapter );
3016 hdd_deinit_adapter( pHddCtx, pAdapter );
3017 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07003018 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3019 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303020#ifdef FEATURE_WLAN_TDLS
3021 mutex_unlock(&pHddCtx->tdls_lock);
3022#endif
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07003023 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
3024 (pConfig->apRandomBssidEnabled))
3025 {
3026 /* To meet Android requirements create a randomized
3027 MAC address of the form 02:1A:11:Fx:xx:xx */
3028 get_random_bytes(&ndev->dev_addr[3], 3);
3029 ndev->dev_addr[0] = 0x02;
3030 ndev->dev_addr[1] = 0x1A;
3031 ndev->dev_addr[2] = 0x11;
3032 ndev->dev_addr[3] |= 0xF0;
3033 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
3034 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08003035 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
3036 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07003037 }
3038
Jeff Johnson295189b2012-06-20 16:38:30 -07003039 hdd_set_ap_ops( pAdapter->dev );
3040
Kiet Lam10841362013-11-01 11:36:50 +05303041 /* This is for only SAP mode where users can
3042 * control country through ini.
3043 * P2P GO follows station country code
3044 * acquired during the STA scanning. */
3045 if((NL80211_IFTYPE_AP == type) &&
3046 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
3047 {
3048 int status = 0;
3049 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
3050 "%s: setting country code from INI ", __func__);
3051 init_completion(&pAdapter->change_country_code);
3052 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
3053 (void *)(tSmeChangeCountryCallback)
3054 wlan_hdd_change_country_code_cb,
3055 pConfig->apCntryCode, pAdapter,
3056 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05303057 eSIR_FALSE,
3058 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05303059 if (eHAL_STATUS_SUCCESS == status)
3060 {
3061 /* Wait for completion */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303062 ret = wait_for_completion_interruptible_timeout(
Kiet Lam10841362013-11-01 11:36:50 +05303063 &pAdapter->change_country_code,
3064 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303065 if (ret <= 0)
Kiet Lam10841362013-11-01 11:36:50 +05303066 {
3067 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303068 FL("SME Timed out while setting country code %ld"),
3069 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08003070
3071 if (pHddCtx->isLogpInProgress)
3072 {
3073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3074 "%s: LOGP in Progress. Ignore!!!", __func__);
3075 return -EAGAIN;
3076 }
Kiet Lam10841362013-11-01 11:36:50 +05303077 }
3078 }
3079 else
3080 {
3081 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08003082 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05303083 return -EINVAL;
3084 }
3085 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003086 status = hdd_init_ap_mode(pAdapter);
3087 if(status != VOS_STATUS_SUCCESS)
3088 {
3089 hddLog(VOS_TRACE_LEVEL_FATAL,
3090 "%s: Error initializing the ap mode", __func__);
3091 return -EINVAL;
3092 }
3093 hdd_set_conparam(1);
3094
Jeff Johnson295189b2012-06-20 16:38:30 -07003095 /*interface type changed update in wiphy structure*/
3096 if(wdev)
3097 {
3098 wdev->iftype = type;
3099 pHddCtx->change_iface = type;
3100 }
3101 else
3102 {
3103 hddLog(VOS_TRACE_LEVEL_ERROR,
3104 "%s: ERROR !!!! Wireless dev is NULL", __func__);
3105 return -EINVAL;
3106 }
3107 goto done;
3108 }
3109
3110 default:
3111 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3112 __func__);
3113 return -EOPNOTSUPP;
3114 }
3115 }
3116 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003117 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003118 )
3119 {
3120 switch(type)
3121 {
3122 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07003123 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07003124 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303125#ifdef FEATURE_WLAN_TDLS
3126
3127 /* A Mutex Lock is introduced while changing the mode to
3128 * protect the concurrent access for the Adapters by TDLS
3129 * module.
3130 */
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303131 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303132#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07003133 hdd_stop_adapter( pHddCtx, pAdapter );
3134 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003135 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08003136 //Check for sub-string p2p to confirm its a p2p interface
3137 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003138 {
3139 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
3140 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
3141 }
3142 else
3143 {
3144 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07003145 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003146 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003147 hdd_set_conparam(0);
3148 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003149 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
3150 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303151#ifdef FEATURE_WLAN_TDLS
3152 mutex_unlock(&pHddCtx->tdls_lock);
3153#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05303154 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003155 if( VOS_STATUS_SUCCESS != status )
3156 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07003157 /* In case of JB, for P2P-GO, only change interface will be called,
3158 * This is the right place to enable back bmps_imps()
3159 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05303160 if (pHddCtx->hdd_wlan_suspended)
3161 {
3162 hdd_set_pwrparams(pHddCtx);
3163 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003164 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003165 goto done;
3166 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07003167 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07003168 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003169 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3170 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003171 goto done;
3172 default:
3173 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3174 __func__);
3175 return -EOPNOTSUPP;
3176
3177 }
3178
3179 }
3180 else
3181 {
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05303182 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: unsupported device mode(%s (%d))",
3183 __func__, hdd_device_modetoString(pAdapter->device_mode),
3184 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003185 return -EOPNOTSUPP;
3186 }
3187
3188
3189 if(pRoamProfile)
3190 {
3191 if ( LastBSSType != pRoamProfile->BSSType )
3192 {
3193 /*interface type changed update in wiphy structure*/
3194 wdev->iftype = type;
3195
3196 /*the BSS mode changed, We need to issue disconnect
3197 if connected or in IBSS disconnect state*/
3198 if ( hdd_connGetConnectedBssType(
3199 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
3200 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
3201 {
3202 /*need to issue a disconnect to CSR.*/
3203 INIT_COMPLETION(pAdapter->disconnect_comp_var);
3204 if( eHAL_STATUS_SUCCESS ==
3205 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
3206 pAdapter->sessionId,
3207 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
3208 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303209 ret = wait_for_completion_interruptible_timeout(
3210 &pAdapter->disconnect_comp_var,
3211 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
3212 if (ret <= 0)
3213 {
3214 hddLog(VOS_TRACE_LEVEL_ERROR,
3215 FL("wait on disconnect_comp_var failed %ld"), ret);
3216 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003217 }
3218 }
3219 }
3220 }
3221
3222done:
3223 /*set bitmask based on updated value*/
3224 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07003225
3226 /* Only STA mode support TM now
3227 * all other mode, TM feature should be disabled */
3228 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
3229 (~VOS_STA & pHddCtx->concurrency_mode) )
3230 {
3231 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
3232 }
3233
Jeff Johnson295189b2012-06-20 16:38:30 -07003234#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303235 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003236 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
3237 {
3238 //we are ok to do AMP
3239 pHddCtx->isAmpAllowed = VOS_TRUE;
3240 }
3241#endif //WLAN_BTAMP_FEATURE
3242 EXIT();
3243 return 0;
3244}
3245
Mahesh A Saptasagar0e59c472014-04-14 19:17:41 +05303246/*
3247 * FUNCTION: wlan_hdd_cfg80211_change_iface
3248 * wrapper function to protect the actual implementation from SSR.
3249 */
3250int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
3251 struct net_device *ndev,
3252 enum nl80211_iftype type,
3253 u32 *flags,
3254 struct vif_params *params
3255 )
3256{
3257 int ret;
3258
3259 vos_ssr_protect(__func__);
3260 ret = __wlan_hdd_cfg80211_change_iface(wiphy, ndev, type, flags, params);
3261 vos_ssr_unprotect(__func__);
3262
3263 return ret;
3264}
3265
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003266#ifdef FEATURE_WLAN_TDLS
3267static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
3268 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
3269{
3270 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3271 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3272 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003273 hddTdlsPeer_t *pTdlsPeer;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303274 long ret;
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303275 tANI_U16 numCurrTdlsPeers;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003276
3277 ENTER();
3278
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303279 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003280 {
3281 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3282 "Invalid arguments");
3283 return -EINVAL;
3284 }
Hoonki Lee27511902013-03-14 18:19:06 -07003285
3286 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3287 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3288 {
3289 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3290 "%s: TDLS mode is disabled OR not enabled in FW."
3291 MAC_ADDRESS_STR " Request declined.",
3292 __func__, MAC_ADDR_ARRAY(mac));
3293 return -ENOTSUPP;
3294 }
3295
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003296 if (pHddCtx->isLogpInProgress)
3297 {
3298 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3299 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003300 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003301 return -EBUSY;
3302 }
3303
Naresh Jayaram9c6f4462014-02-13 12:20:31 +05303304 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003305
3306 if ( NULL == pTdlsPeer ) {
3307 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3308 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3309 __func__, MAC_ADDR_ARRAY(mac), update);
3310 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003311 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003312
3313 /* in add station, we accept existing valid staId if there is */
3314 if ((0 == update) &&
3315 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3316 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003317 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003318 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003319 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003320 " link_status %d. staId %d. add station ignored.",
3321 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3322 return 0;
3323 }
3324 /* in change station, we accept only when staId is valid */
3325 if ((1 == update) &&
3326 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3327 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3328 {
3329 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3330 "%s: " MAC_ADDRESS_STR
3331 " link status %d. staId %d. change station %s.",
3332 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3333 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3334 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003335 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003336
3337 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303338 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003339 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003340 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3341 "%s: " MAC_ADDRESS_STR
3342 " TDLS setup is ongoing. Request declined.",
3343 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003344 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003345 }
3346
3347 /* first to check if we reached to maximum supported TDLS peer.
3348 TODO: for now, return -EPERM looks working fine,
3349 but need to check if any other errno fit into this category.*/
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303350 numCurrTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
3351 if (HDD_MAX_NUM_TDLS_STA <= numCurrTdlsPeers)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003352 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003353 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3354 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05303355 " TDLS Max peer already connected. Request declined."
3356 " Num of peers (%d), Max allowed (%d).",
3357 __func__, MAC_ADDR_ARRAY(mac), numCurrTdlsPeers,
3358 HDD_MAX_NUM_TDLS_STA);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003359 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003360 }
3361 else
3362 {
3363 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303364 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003365 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003366 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003367 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3368 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3369 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003370 return -EPERM;
3371 }
3372 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003373 if (0 == update)
3374 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003375
Jeff Johnsond75fe012013-04-06 10:53:06 -07003376 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303377 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003378 {
3379 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3380 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003381 if(StaParams->htcap_present)
3382 {
3383 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3384 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3385 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3386 "ht_capa->extended_capabilities: %0x",
3387 StaParams->HTCap.extendedHtCapInfo);
3388 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003389 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3390 "params->capability: %0x",StaParams->capability);
3391 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003392 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003393 if(StaParams->vhtcap_present)
3394 {
3395 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3396 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3397 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3398 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3399 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003400 {
3401 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003403 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3404 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3405 "[%d]: %x ", i, StaParams->supported_rates[i]);
3406 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003407 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303408 else if ((1 == update) && (NULL == StaParams))
3409 {
3410 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3411 "%s : update is true, but staParams is NULL. Error!", __func__);
3412 return -EPERM;
3413 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003414
3415 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3416
3417 if (!update)
3418 {
3419 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3420 pAdapter->sessionId, mac);
3421 }
3422 else
3423 {
3424 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3425 pAdapter->sessionId, mac, StaParams);
3426 }
3427
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303428 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003429 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3430
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303431 if (ret <= 0)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003432 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003433 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303434 "%s: timeout waiting for tdls add station indication %ld",
3435 __func__, ret);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003436 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003437 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303438
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003439 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3440 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003441 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003442 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003443 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003444 }
3445
3446 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003447
3448error:
3449 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3450 return -EPERM;
3451
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003452}
3453#endif
3454
Jeff Johnson295189b2012-06-20 16:38:30 -07003455static int wlan_hdd_change_station(struct wiphy *wiphy,
3456 struct net_device *dev,
3457 u8 *mac,
3458 struct station_parameters *params)
3459{
3460 VOS_STATUS status = VOS_STATUS_SUCCESS;
3461 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303462 hdd_context_t *pHddCtx;
3463 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003464 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003465#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003466 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003467 tANI_U8 isBufSta = 0;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303468 tANI_U8 isOffChannelSupported = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003469#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003470 ENTER();
3471
Gopichand Nakkala29149562013-05-10 21:43:41 +05303472 if ((NULL == pAdapter))
3473 {
3474 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3475 "invalid adapter ");
3476 return -EINVAL;
3477 }
3478
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303479 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3480 TRACE_CODE_HDD_CHANGE_STATION,
3481 pAdapter->sessionId, params->listen_interval));
Gopichand Nakkala29149562013-05-10 21:43:41 +05303482 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3483 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3484
3485 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3486 {
3487 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3488 "invalid HDD state or HDD station context");
3489 return -EINVAL;
3490 }
3491
3492 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003493 {
3494 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3495 "%s:LOGP in Progress. Ignore!!!", __func__);
3496 return -EAGAIN;
3497 }
3498
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3500
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003501 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3502 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003503 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003504 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003505 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303506 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003507 WLANTL_STA_AUTHENTICATED);
3508
Gopichand Nakkala29149562013-05-10 21:43:41 +05303509 if (status != VOS_STATUS_SUCCESS)
3510 {
3511 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3512 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3513 return -EINVAL;
3514 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003515 }
3516 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003517 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3518 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303519#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003520 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3521 StaParams.capability = params->capability;
3522 StaParams.uapsd_queues = params->uapsd_queues;
3523 StaParams.max_sp = params->max_sp;
3524
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303525 /* Convert (first channel , number of channels) tuple to
3526 * the total list of channels. This goes with the assumption
3527 * that if the first channel is < 14, then the next channels
3528 * are an incremental of 1 else an incremental of 4 till the number
3529 * of channels.
3530 */
3531 if (0 != params->supported_channels_len) {
3532 int i = 0,j = 0,k = 0, no_of_channels = 0 ;
3533 for ( i = 0 ; i < params->supported_channels_len ; i+=2)
3534 {
3535 int wifi_chan_index;
3536 StaParams.supported_channels[j] = params->supported_channels[i];
3537 wifi_chan_index =
3538 ((StaParams.supported_channels[j] <= HDD_CHANNEL_14 ) ? 1 : 4 );
3539 no_of_channels = params->supported_channels[i+1];
3540 for(k=1; k <= no_of_channels; k++)
3541 {
3542 StaParams.supported_channels[j+1] =
3543 StaParams.supported_channels[j] + wifi_chan_index;
3544 j+=1;
3545 }
3546 }
3547 StaParams.supported_channels_len = j;
3548 }
3549 vos_mem_copy(StaParams.supported_oper_classes,
3550 params->supported_oper_classes,
3551 params->supported_oper_classes_len);
3552 StaParams.supported_oper_classes_len =
3553 params->supported_oper_classes_len;
3554
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003555 if (0 != params->ext_capab_len)
3556 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3557 sizeof(StaParams.extn_capability));
3558
3559 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003560 {
3561 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003562 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003563 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003564
3565 StaParams.supported_rates_len = params->supported_rates_len;
3566
3567 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3568 * The supported_rates array , for all the structures propogating till Add Sta
3569 * to the firmware has to be modified , if the supplicant (ieee80211) is
3570 * modified to send more rates.
3571 */
3572
3573 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3574 */
3575 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3576 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3577
3578 if (0 != StaParams.supported_rates_len) {
3579 int i = 0;
3580 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3581 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003582 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003583 "Supported Rates with Length %d", StaParams.supported_rates_len);
3584 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003585 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003586 "[%d]: %0x", i, StaParams.supported_rates[i]);
3587 }
3588
3589 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003590 {
3591 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003592 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003593 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003594
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003595 if (0 != params->ext_capab_len ) {
3596 /*Define A Macro : TODO Sunil*/
3597 if ((1<<4) & StaParams.extn_capability[3]) {
3598 isBufSta = 1;
3599 }
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303600 /* TDLS Channel Switching Support */
3601 if ((1<<6) & StaParams.extn_capability[3]) {
3602 isOffChannelSupported = 1;
3603 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003604 }
Naresh Jayaram3180aa42014-02-12 21:47:26 +05303605 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac,
3606 &StaParams, isBufSta,
3607 isOffChannelSupported);
3608
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303609 if (VOS_STATUS_SUCCESS != status) {
3610 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3611 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3612 return -EINVAL;
3613 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003614 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3615
3616 if (VOS_STATUS_SUCCESS != status) {
3617 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3618 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3619 return -EINVAL;
3620 }
3621 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003622#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303623 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003624 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003625 return status;
3626}
3627
3628/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003629 * FUNCTION: wlan_hdd_cfg80211_add_key
3630 * This function is used to initialize the key information
3631 */
3632#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003633static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003634 struct net_device *ndev,
3635 u8 key_index, bool pairwise,
3636 const u8 *mac_addr,
3637 struct key_params *params
3638 )
3639#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003640static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003641 struct net_device *ndev,
3642 u8 key_index, const u8 *mac_addr,
3643 struct key_params *params
3644 )
3645#endif
3646{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003647 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 tCsrRoamSetKey setKey;
3649 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303650 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003651 v_U32_t roamId= 0xFF;
3652 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003653 hdd_hostapd_state_t *pHostapdState;
3654 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003655 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303656 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003657
3658 ENTER();
3659
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05303660 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
3661 TRACE_CODE_HDD_CFG80211_ADD_KEY,
3662 pAdapter->sessionId, params->key_len));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303663 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3664 status = wlan_hdd_validate_context(pHddCtx);
3665
3666 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003667 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303668 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3669 "%s: HDD context is not valid", __func__);
3670 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003671 }
3672
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05303673 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
3674 __func__, hdd_device_modetoString(pAdapter->device_mode),
3675 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003676
3677 if (CSR_MAX_NUM_KEY <= key_index)
3678 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003679 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 key_index);
3681
3682 return -EINVAL;
3683 }
3684
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003685 if (CSR_MAX_KEY_LEN < params->key_len)
3686 {
3687 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3688 params->key_len);
3689
3690 return -EINVAL;
3691 }
3692
3693 hddLog(VOS_TRACE_LEVEL_INFO,
3694 "%s: called with key index = %d & key length %d",
3695 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003696
3697 /*extract key idx, key len and key*/
3698 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3699 setKey.keyId = key_index;
3700 setKey.keyLength = params->key_len;
3701 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3702
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003703 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003704 {
3705 case WLAN_CIPHER_SUITE_WEP40:
3706 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3707 break;
3708
3709 case WLAN_CIPHER_SUITE_WEP104:
3710 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3711 break;
3712
3713 case WLAN_CIPHER_SUITE_TKIP:
3714 {
3715 u8 *pKey = &setKey.Key[0];
3716 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3717
3718 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3719
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003720 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003721
3722 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003723 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003724 |--------------|----------|----------|
3725 <---16bytes---><--8bytes--><--8bytes-->
3726
3727 */
3728 /*Sme expects the 32 bytes key to be in the below order
3729
3730 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003731 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003732 |--------------|----------|----------|
3733 <---16bytes---><--8bytes--><--8bytes-->
3734 */
3735 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003736 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003737
3738 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003739 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003740
3741 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003742 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003743
3744
3745 break;
3746 }
3747
3748 case WLAN_CIPHER_SUITE_CCMP:
3749 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3750 break;
3751
3752#ifdef FEATURE_WLAN_WAPI
3753 case WLAN_CIPHER_SUITE_SMS4:
3754 {
3755 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3756 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3757 params->key, params->key_len);
3758 return 0;
3759 }
3760#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003761
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08003762#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07003763 case WLAN_CIPHER_SUITE_KRK:
3764 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3765 break;
3766#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003767
3768#ifdef WLAN_FEATURE_11W
3769 case WLAN_CIPHER_SUITE_AES_CMAC:
3770 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003771 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003772#endif
3773
Jeff Johnson295189b2012-06-20 16:38:30 -07003774 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003775 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003776 __func__, params->cipher);
3777 return -EOPNOTSUPP;
3778 }
3779
3780 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3781 __func__, setKey.encType);
3782
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003783 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003784#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3785 (!pairwise)
3786#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003787 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003788#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003789 )
3790 {
3791 /* set group key*/
3792 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3793 "%s- %d: setting Broadcast key",
3794 __func__, __LINE__);
3795 setKey.keyDirection = eSIR_RX_ONLY;
3796 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3797 }
3798 else
3799 {
3800 /* set pairwise key*/
3801 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3802 "%s- %d: setting pairwise key",
3803 __func__, __LINE__);
3804 setKey.keyDirection = eSIR_TX_RX;
3805 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3806 }
3807 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3808 {
3809 setKey.keyDirection = eSIR_TX_RX;
3810 /*Set the group key*/
3811 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3812 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003813
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003814 if ( 0 != status )
3815 {
3816 hddLog(VOS_TRACE_LEVEL_ERROR,
3817 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3818 return -EINVAL;
3819 }
3820 /*Save the keys here and call sme_RoamSetKey for setting
3821 the PTK after peer joins the IBSS network*/
3822 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3823 &setKey, sizeof(tCsrRoamSetKey));
3824 return status;
3825 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303826 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3827 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3828 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003830 if( pHostapdState->bssState == BSS_START )
3831 {
c_hpothu7c55da62014-01-23 18:34:02 +05303832 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3833 vos_status = wlan_hdd_check_ula_done(pAdapter);
3834
3835 if ( vos_status != VOS_STATUS_SUCCESS )
3836 {
3837 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3838 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3839 __LINE__, vos_status );
3840
3841 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3842
3843 return -EINVAL;
3844 }
3845
Jeff Johnson295189b2012-06-20 16:38:30 -07003846 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3847
3848 if ( status != eHAL_STATUS_SUCCESS )
3849 {
3850 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3851 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3852 __LINE__, status );
3853 }
3854 }
3855
3856 /* Saving WEP keys */
3857 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3858 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3859 {
3860 //Save the wep key in ap context. Issue setkey after the BSS is started.
3861 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3862 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3863 }
3864 else
3865 {
3866 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003867 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003868 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3869 }
3870 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003871 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3872 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003873 {
3874 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3875 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3876
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303877#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3878 if (!pairwise)
3879#else
3880 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3881#endif
3882 {
3883 /* set group key*/
3884 if (pHddStaCtx->roam_info.deferKeyComplete)
3885 {
3886 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3887 "%s- %d: Perform Set key Complete",
3888 __func__, __LINE__);
3889 hdd_PerformRoamSetKeyComplete(pAdapter);
3890 }
3891 }
3892
Jeff Johnson295189b2012-06-20 16:38:30 -07003893 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3894
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003895 pWextState->roamProfile.Keys.defaultIndex = key_index;
3896
3897
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003898 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003899 params->key, params->key_len);
3900
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303901
Jeff Johnson295189b2012-06-20 16:38:30 -07003902 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3903
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303904 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003905 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303906 __func__, setKey.peerMac[0], setKey.peerMac[1],
3907 setKey.peerMac[2], setKey.peerMac[3],
3908 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 setKey.keyDirection);
3910
3911 vos_status = wlan_hdd_check_ula_done(pAdapter);
3912
3913 if ( vos_status != VOS_STATUS_SUCCESS )
3914 {
3915 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3916 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3917 __LINE__, vos_status );
3918
3919 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3920
3921 return -EINVAL;
3922
3923 }
3924
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003925#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303926 /* The supplicant may attempt to set the PTK once pre-authentication
3927 is done. Save the key in the UMAC and include it in the ADD BSS
3928 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003929 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303930 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003931 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303932 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3933 "%s: Update PreAuth Key success", __func__);
3934 return 0;
3935 }
3936 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3937 {
3938 hddLog(VOS_TRACE_LEVEL_ERROR,
3939 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303940 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003941 }
3942#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003943
3944 /* issue set key request to SME*/
3945 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3946 pAdapter->sessionId, &setKey, &roamId );
3947
3948 if ( 0 != status )
3949 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303950 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003951 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3952 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3953 return -EINVAL;
3954 }
3955
3956
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303957 /* in case of IBSS as there was no information available about WEP keys during
3958 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003959 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303960 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3961 !( ( IW_AUTH_KEY_MGMT_802_1X
3962 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003963 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3964 )
3965 &&
3966 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3967 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3968 )
3969 )
3970 {
3971 setKey.keyDirection = eSIR_RX_ONLY;
3972 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3973
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303974 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003975 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303976 __func__, setKey.peerMac[0], setKey.peerMac[1],
3977 setKey.peerMac[2], setKey.peerMac[3],
3978 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 setKey.keyDirection);
3980
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303981 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 pAdapter->sessionId, &setKey, &roamId );
3983
3984 if ( 0 != status )
3985 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303986 hddLog(VOS_TRACE_LEVEL_ERROR,
3987 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003988 __func__, status);
3989 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3990 return -EINVAL;
3991 }
3992 }
3993 }
3994
3995 return 0;
3996}
3997
3998/*
3999 * FUNCTION: wlan_hdd_cfg80211_get_key
4000 * This function is used to get the key information
4001 */
4002#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304003static int wlan_hdd_cfg80211_get_key(
4004 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004005 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304006 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07004007 const u8 *mac_addr, void *cookie,
4008 void (*callback)(void *cookie, struct key_params*)
4009 )
4010#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304011static int wlan_hdd_cfg80211_get_key(
4012 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004013 struct net_device *ndev,
4014 u8 key_index, const u8 *mac_addr, void *cookie,
4015 void (*callback)(void *cookie, struct key_params*)
4016 )
4017#endif
4018{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304019 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004020 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4021 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
4022 struct key_params params;
4023
4024 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304025
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05304026 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
4027 __func__, hdd_device_modetoString(pAdapter->device_mode),
4028 pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304029
Jeff Johnson295189b2012-06-20 16:38:30 -07004030 memset(&params, 0, sizeof(params));
4031
4032 if (CSR_MAX_NUM_KEY <= key_index)
4033 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304034 hddLog(VOS_TRACE_LEVEL_ERROR, FL("invalid key index %d"), key_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07004035 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304036 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004037
4038 switch(pRoamProfile->EncryptionType.encryptionType[0])
4039 {
4040 case eCSR_ENCRYPT_TYPE_NONE:
4041 params.cipher = IW_AUTH_CIPHER_NONE;
4042 break;
4043
4044 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
4045 case eCSR_ENCRYPT_TYPE_WEP40:
4046 params.cipher = WLAN_CIPHER_SUITE_WEP40;
4047 break;
4048
4049 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
4050 case eCSR_ENCRYPT_TYPE_WEP104:
4051 params.cipher = WLAN_CIPHER_SUITE_WEP104;
4052 break;
4053
4054 case eCSR_ENCRYPT_TYPE_TKIP:
4055 params.cipher = WLAN_CIPHER_SUITE_TKIP;
4056 break;
4057
4058 case eCSR_ENCRYPT_TYPE_AES:
4059 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
4060 break;
4061
4062 default:
4063 params.cipher = IW_AUTH_CIPHER_NONE;
4064 break;
4065 }
4066
c_hpothuaaf19692014-05-17 17:01:48 +05304067 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4068 TRACE_CODE_HDD_CFG80211_GET_KEY,
4069 pAdapter->sessionId, params.cipher));
4070
Jeff Johnson295189b2012-06-20 16:38:30 -07004071 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
4072 params.seq_len = 0;
4073 params.seq = NULL;
4074 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
4075 callback(cookie, &params);
4076 return 0;
4077}
4078
4079/*
4080 * FUNCTION: wlan_hdd_cfg80211_del_key
4081 * This function is used to delete the key information
4082 */
4083#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304084static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004085 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304086 u8 key_index,
4087 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07004088 const u8 *mac_addr
4089 )
4090#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304091static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004092 struct net_device *ndev,
4093 u8 key_index,
4094 const u8 *mac_addr
4095 )
4096#endif
4097{
4098 int status = 0;
4099
4100 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304101 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07004102 //it is observed that this is invalidating peer
4103 //key index whenever re-key is done. This is affecting data link.
4104 //It should be ok to ignore del_key.
4105#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304106 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
4107 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07004108 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
4109 tCsrRoamSetKey setKey;
4110 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304111
Jeff Johnson295189b2012-06-20 16:38:30 -07004112 ENTER();
4113
4114 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
4115 __func__,pAdapter->device_mode);
4116
4117 if (CSR_MAX_NUM_KEY <= key_index)
4118 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304119 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004120 key_index);
4121
4122 return -EINVAL;
4123 }
4124
4125 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4126 setKey.keyId = key_index;
4127
4128 if (mac_addr)
4129 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
4130 else
4131 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
4132
4133 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
4134
4135 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004136 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304137 )
4138 {
4139
4140 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07004141 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
4142 if( pHostapdState->bssState == BSS_START)
4143 {
4144 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304145
Jeff Johnson295189b2012-06-20 16:38:30 -07004146 if ( status != eHAL_STATUS_SUCCESS )
4147 {
4148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4149 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
4150 __LINE__, status );
4151 }
4152 }
4153 }
4154 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304155 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07004156 )
4157 {
4158 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4159
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304160 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
4161
4162 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304164 __func__, setKey.peerMac[0], setKey.peerMac[1],
4165 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07004166 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304167 if(pAdapter->sessionCtx.station.conn_info.connState ==
4168 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07004169 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304170 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004171 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304172
Jeff Johnson295189b2012-06-20 16:38:30 -07004173 if ( 0 != status )
4174 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304175 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004176 "%s: sme_RoamSetKey failure, returned %d",
4177 __func__, status);
4178 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
4179 return -EINVAL;
4180 }
4181 }
4182 }
4183#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07004184 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004185 return status;
4186}
4187
4188/*
4189 * FUNCTION: wlan_hdd_cfg80211_set_default_key
4190 * This function is used to set the default tx key index
4191 */
4192#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
4193static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4194 struct net_device *ndev,
4195 u8 key_index,
4196 bool unicast, bool multicast)
4197#else
4198static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4199 struct net_device *ndev,
4200 u8 key_index)
4201#endif
4202{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304203 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304204 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05304205 hdd_wext_state_t *pWextState;
4206 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304207 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004208
4209 ENTER();
4210
Gopichand Nakkala29149562013-05-10 21:43:41 +05304211 if ((NULL == pAdapter))
4212 {
4213 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4214 "invalid adapter");
4215 return -EINVAL;
4216 }
4217
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304218 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4219 TRACE_CODE_HDD_CFG80211_SET_DEFAULT_KEY,
4220 pAdapter->sessionId, key_index));
4221
Gopichand Nakkala29149562013-05-10 21:43:41 +05304222 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4223 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4224
4225 if ((NULL == pWextState) || (NULL == pHddStaCtx))
4226 {
4227 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4228 "invalid Wext state or HDD context");
4229 return -EINVAL;
4230 }
4231
Arif Hussain6d2a3322013-11-17 19:50:10 -08004232 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004233 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304234
Jeff Johnson295189b2012-06-20 16:38:30 -07004235 if (CSR_MAX_NUM_KEY <= key_index)
4236 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304237 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004238 key_index);
4239
4240 return -EINVAL;
4241 }
4242
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304243 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4244 status = wlan_hdd_validate_context(pHddCtx);
4245
4246 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004247 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304248 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4249 "%s: HDD context is not valid", __func__);
4250 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004251 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304252
Jeff Johnson295189b2012-06-20 16:38:30 -07004253 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07004254 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304255 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004256 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05304257 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08004258 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304259 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08004260 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07004261 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304262 {
4263 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07004264 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304265
Jeff Johnson295189b2012-06-20 16:38:30 -07004266 tCsrRoamSetKey setKey;
4267 v_U32_t roamId= 0xFF;
4268 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304269
4270 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004271 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304272
Jeff Johnson295189b2012-06-20 16:38:30 -07004273 Keys->defaultIndex = (u8)key_index;
4274 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4275 setKey.keyId = key_index;
4276 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304277
4278 vos_mem_copy(&setKey.Key[0],
4279 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07004280 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304281
Gopichand Nakkala29149562013-05-10 21:43:41 +05304282 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304283
4284 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07004285 &pHddStaCtx->conn_info.bssId[0],
4286 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304287
Gopichand Nakkala29149562013-05-10 21:43:41 +05304288 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
4289 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4290 eCSR_ENCRYPT_TYPE_WEP104)
4291 {
4292 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
4293 even though ap is configured for WEP-40 encryption. In this canse the key length
4294 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
4295 type(104) and switching encryption type to 40*/
4296 pWextState->roamProfile.EncryptionType.encryptionType[0] =
4297 eCSR_ENCRYPT_TYPE_WEP40;
4298 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
4299 eCSR_ENCRYPT_TYPE_WEP40;
4300 }
4301
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304302 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07004303 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304304
Jeff Johnson295189b2012-06-20 16:38:30 -07004305 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304306 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304308
Jeff Johnson295189b2012-06-20 16:38:30 -07004309 if ( 0 != status )
4310 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304311 hddLog(VOS_TRACE_LEVEL_ERROR,
4312 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004313 status);
4314 return -EINVAL;
4315 }
4316 }
4317 }
4318
4319 /* In SoftAp mode setting key direction for default mode */
4320 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
4321 {
4322 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
4323 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
4324 (eCSR_ENCRYPT_TYPE_AES !=
4325 pWextState->roamProfile.EncryptionType.encryptionType[0])
4326 )
4327 {
4328 /* Saving key direction for default key index to TX default */
4329 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
4330 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
4331 }
4332 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304333
Jeff Johnson295189b2012-06-20 16:38:30 -07004334 return status;
4335}
4336
Jeff Johnson295189b2012-06-20 16:38:30 -07004337/*
4338 * FUNCTION: wlan_hdd_cfg80211_inform_bss
4339 * This function is used to inform the BSS details to nl80211 interface.
4340 */
4341static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
4342 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
4343{
4344 struct net_device *dev = pAdapter->dev;
4345 struct wireless_dev *wdev = dev->ieee80211_ptr;
4346 struct wiphy *wiphy = wdev->wiphy;
4347 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4348 int chan_no;
4349 int ie_length;
4350 const char *ie;
4351 unsigned int freq;
4352 struct ieee80211_channel *chan;
4353 int rssi = 0;
4354 struct cfg80211_bss *bss = NULL;
4355
4356 ENTER();
4357
4358 if( NULL == pBssDesc )
4359 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004360 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004361 return bss;
4362 }
4363
4364 chan_no = pBssDesc->channelId;
4365 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4366 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4367
4368 if( NULL == ie )
4369 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004370 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004371 return bss;
4372 }
4373
4374#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4375 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4376 {
4377 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4378 }
4379 else
4380 {
4381 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4382 }
4383#else
4384 freq = ieee80211_channel_to_frequency(chan_no);
4385#endif
4386
4387 chan = __ieee80211_get_channel(wiphy, freq);
4388
Santhosh Kumar Padmaa45fdb12014-04-15 15:54:38 +05304389 if (!chan) {
4390 hddLog(VOS_TRACE_LEVEL_ERROR, "%s chan pointer is NULL", __func__);
4391 return NULL;
4392 }
4393
Jeff Johnson295189b2012-06-20 16:38:30 -07004394 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4395 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4396 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4397 if (bss == NULL)
4398 {
4399 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4400
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304401 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4402 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004403 pBssDesc->capabilityInfo,
4404 pBssDesc->beaconInterval, ie, ie_length,
4405 rssi, GFP_KERNEL ));
4406}
4407 else
4408 {
4409 return bss;
4410 }
4411}
4412
4413
4414
4415/*
4416 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4417 * This function is used to inform the BSS details to nl80211 interface.
4418 */
4419struct cfg80211_bss*
4420wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4421 tSirBssDescription *bss_desc
4422 )
4423{
4424 /*
4425 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4426 already exists in bss data base of cfg80211 for that particular BSS ID.
4427 Using cfg80211_inform_bss_frame to update the bss entry instead of
4428 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4429 now there is no possibility to get the mgmt(probe response) frame from PE,
4430 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4431 cfg80211_inform_bss_frame.
4432 */
4433 struct net_device *dev = pAdapter->dev;
4434 struct wireless_dev *wdev = dev->ieee80211_ptr;
4435 struct wiphy *wiphy = wdev->wiphy;
4436 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004437#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4438 qcom_ie_age *qie_age = NULL;
4439 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4440#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004441 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004442#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004443 const char *ie =
4444 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4445 unsigned int freq;
4446 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304447 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004448 struct cfg80211_bss *bss_status = NULL;
4449 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4450 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004451 hdd_context_t *pHddCtx;
4452 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004453#ifdef WLAN_OPEN_SOURCE
4454 struct timespec ts;
4455#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004456
Wilson Yangf80a0542013-10-07 13:02:37 -07004457 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4458 status = wlan_hdd_validate_context(pHddCtx);
4459
4460 /*bss_update is not allowed during wlan driver loading or unloading*/
Mihir Shete18156292014-03-11 15:38:30 +05304461 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Wilson Yangf80a0542013-10-07 13:02:37 -07004462 {
4463 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4464 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4465 return NULL;
4466 }
4467
4468
4469 if (0 != status)
4470 {
4471 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4472 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004473 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004474 }
4475
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304476 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004477 if (!mgmt)
4478 {
4479 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4480 "%s: memory allocation failed ", __func__);
4481 return NULL;
4482 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004483
Jeff Johnson295189b2012-06-20 16:38:30 -07004484 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004485
4486#ifdef WLAN_OPEN_SOURCE
4487 /* Android does not want the timestamp from the frame.
4488 Instead it wants a monotonic increasing value */
4489 get_monotonic_boottime(&ts);
4490 mgmt->u.probe_resp.timestamp =
4491 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4492#else
4493 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004494 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4495 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004496
4497#endif
4498
Jeff Johnson295189b2012-06-20 16:38:30 -07004499 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4500 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004501
4502#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4503 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4504 /* Assuming this is the last IE, copy at the end */
4505 ie_length -=sizeof(qcom_ie_age);
4506 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4507 qie_age->element_id = QCOM_VENDOR_IE_ID;
4508 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4509 qie_age->oui_1 = QCOM_OUI1;
4510 qie_age->oui_2 = QCOM_OUI2;
4511 qie_age->oui_3 = QCOM_OUI3;
4512 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4513 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4514#endif
4515
Jeff Johnson295189b2012-06-20 16:38:30 -07004516 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304517 if (bss_desc->fProbeRsp)
4518 {
4519 mgmt->frame_control |=
4520 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4521 }
4522 else
4523 {
4524 mgmt->frame_control |=
4525 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4526 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004527
4528#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304529 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004530 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4531 {
4532 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4533 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304534 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004535 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4536
4537 {
4538 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4539 }
4540 else
4541 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304542 hddLog(VOS_TRACE_LEVEL_ERROR, "%s Invalid chan_no:%d",
4543 __func__, chan_no);
Jeff Johnson295189b2012-06-20 16:38:30 -07004544 kfree(mgmt);
4545 return NULL;
4546 }
4547#else
4548 freq = ieee80211_channel_to_frequency(chan_no);
4549#endif
4550 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004551 /*when the band is changed on the fly using the GUI, three things are done
4552 * 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)
4553 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4554 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4555 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4556 * and discards the channels correponding to previous band and calls back with zero bss results.
4557 * 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
4558 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4559 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4560 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4561 * So drop the bss and continue to next bss.
4562 */
4563 if(chan == NULL)
4564 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304565 hddLog(VOS_TRACE_LEVEL_ERROR, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004566 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004567 return NULL;
4568 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004569 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304570 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004571 * */
4572 if (( eConnectionState_Associated ==
4573 pAdapter->sessionCtx.station.conn_info.connState ) &&
4574 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4575 pAdapter->sessionCtx.station.conn_info.bssId,
4576 WNI_CFG_BSSID_LEN)))
4577 {
4578 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4579 rssi = (pAdapter->rssi * 100);
4580 }
4581 else
4582 {
4583 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4584 }
4585
Nirav Shah20ac06f2013-12-12 18:14:06 +05304586 hddLog(VOS_TRACE_LEVEL_INFO, "%s: BSSID:" MAC_ADDRESS_STR " Channel:%d"
4587 "RSSI:%d", __func__, MAC_ADDR_ARRAY(mgmt->bssid),
4588 chan->center_freq, (int)(rssi/100));
4589
Jeff Johnson295189b2012-06-20 16:38:30 -07004590 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4591 frame_len, rssi, GFP_KERNEL);
4592 kfree(mgmt);
4593 return bss_status;
4594}
4595
4596/*
4597 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4598 * This function is used to update the BSS data base of CFG8011
4599 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304600struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004601 tCsrRoamInfo *pRoamInfo
4602 )
4603{
4604 tCsrRoamConnectedProfile roamProfile;
4605 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4606 struct cfg80211_bss *bss = NULL;
4607
4608 ENTER();
4609
4610 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4611 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4612
4613 if (NULL != roamProfile.pBssDesc)
4614 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304615 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004616 &roamProfile);
4617
4618 if (NULL == bss)
4619 {
4620 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4621 __func__);
4622 }
4623
4624 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4625 }
4626 else
4627 {
4628 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4629 __func__);
4630 }
4631 return bss;
4632}
4633
4634/*
4635 * FUNCTION: wlan_hdd_cfg80211_update_bss
4636 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304637static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4638 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004639 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304640{
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4642 tCsrScanResultInfo *pScanResult;
4643 eHalStatus status = 0;
4644 tScanResultHandle pResult;
4645 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004646 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004647
4648 ENTER();
4649
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05304650 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
4651 TRACE_CODE_HDD_CFG80211_UPDATE_BSS,
4652 NO_SESSION, pAdapter->sessionId));
4653
Wilson Yangf80a0542013-10-07 13:02:37 -07004654 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4655
4656 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004657 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004658 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4659 "%s:LOGP in Progress. Ignore!!!",__func__);
4660 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004661 }
4662
Wilson Yangf80a0542013-10-07 13:02:37 -07004663
4664 /*bss_update is not allowed during wlan driver loading or unloading*/
Mihir Shete18156292014-03-11 15:38:30 +05304665 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Wilson Yangf80a0542013-10-07 13:02:37 -07004666 {
4667 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4668 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4669 return VOS_STATUS_E_PERM;
4670 }
4671
4672
Jeff Johnson295189b2012-06-20 16:38:30 -07004673 /*
4674 * start getting scan results and populate cgf80211 BSS database
4675 */
4676 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4677
4678 /* no scan results */
4679 if (NULL == pResult)
4680 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304681 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result Status %d",
4682 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004683 return status;
4684 }
4685
4686 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4687
4688 while (pScanResult)
4689 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304690 /*
4691 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4692 * entry already exists in bss data base of cfg80211 for that
4693 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4694 * bss entry instead of cfg80211_inform_bss, But this call expects
4695 * mgmt packet as input. As of now there is no possibility to get
4696 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004697 * ieee80211_mgmt(probe response) and passing to c
4698 * fg80211_inform_bss_frame.
4699 * */
4700
4701 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4702 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304703
Jeff Johnson295189b2012-06-20 16:38:30 -07004704
4705 if (NULL == bss_status)
4706 {
4707 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004708 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004709 }
4710 else
4711 {
Yue Maf49ba872013-08-19 12:04:25 -07004712 cfg80211_put_bss(
4713#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4714 wiphy,
4715#endif
4716 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004717 }
4718
4719 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4720 }
4721
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304722 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004723
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304724 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004725}
4726
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004727void
4728hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4729{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304730 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004731 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004732} /****** end hddPrintMacAddr() ******/
4733
4734void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004735hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004736{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304737 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004738 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004739 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4740 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4741 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004742} /****** end hddPrintPmkId() ******/
4743
4744//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4745//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4746
4747//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4748//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4749
4750#define dump_bssid(bssid) \
4751 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004752 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4753 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004754 }
4755
4756#define dump_pmkid(pMac, pmkid) \
4757 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004758 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4759 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004760 }
4761
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004762#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004763/*
4764 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4765 * This function is used to notify the supplicant of a new PMKSA candidate.
4766 */
4767int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304768 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004769 int index, bool preauth )
4770{
Jeff Johnsone7245742012-09-05 17:12:55 -07004771#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004772 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004773 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004774
4775 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004776 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004777
4778 if( NULL == pRoamInfo )
4779 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004780 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004781 return -EINVAL;
4782 }
4783
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004784 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4785 {
4786 dump_bssid(pRoamInfo->bssid);
4787 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004788 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004789 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004790#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304791 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004792}
4793#endif //FEATURE_WLAN_LFR
4794
Yue Maef608272013-04-08 23:09:17 -07004795#ifdef FEATURE_WLAN_LFR_METRICS
4796/*
4797 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4798 * 802.11r/LFR metrics reporting function to report preauth initiation
4799 *
4800 */
4801#define MAX_LFR_METRICS_EVENT_LENGTH 100
4802VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4803 tCsrRoamInfo *pRoamInfo)
4804{
4805 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4806 union iwreq_data wrqu;
4807
4808 ENTER();
4809
4810 if (NULL == pAdapter)
4811 {
4812 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4813 return VOS_STATUS_E_FAILURE;
4814 }
4815
4816 /* create the event */
4817 memset(&wrqu, 0, sizeof(wrqu));
4818 memset(metrics_notification, 0, sizeof(metrics_notification));
4819
4820 wrqu.data.pointer = metrics_notification;
4821 wrqu.data.length = scnprintf(metrics_notification,
4822 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4823 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4824
4825 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4826
4827 EXIT();
4828
4829 return VOS_STATUS_SUCCESS;
4830}
4831
4832/*
4833 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4834 * 802.11r/LFR metrics reporting function to report preauth completion
4835 * or failure
4836 */
4837VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4838 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4839{
4840 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4841 union iwreq_data wrqu;
4842
4843 ENTER();
4844
4845 if (NULL == pAdapter)
4846 {
4847 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4848 return VOS_STATUS_E_FAILURE;
4849 }
4850
4851 /* create the event */
4852 memset(&wrqu, 0, sizeof(wrqu));
4853 memset(metrics_notification, 0, sizeof(metrics_notification));
4854
4855 scnprintf(metrics_notification, sizeof(metrics_notification),
4856 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4857 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4858
4859 if (1 == preauth_status)
4860 strncat(metrics_notification, " TRUE", 5);
4861 else
4862 strncat(metrics_notification, " FALSE", 6);
4863
4864 wrqu.data.pointer = metrics_notification;
4865 wrqu.data.length = strlen(metrics_notification);
4866
4867 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4868
4869 EXIT();
4870
4871 return VOS_STATUS_SUCCESS;
4872}
4873
4874/*
4875 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4876 * 802.11r/LFR metrics reporting function to report handover initiation
4877 *
4878 */
4879VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4880 tCsrRoamInfo *pRoamInfo)
4881{
4882 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4883 union iwreq_data wrqu;
4884
4885 ENTER();
4886
4887 if (NULL == pAdapter)
4888 {
4889 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4890 return VOS_STATUS_E_FAILURE;
4891 }
4892
4893 /* create the event */
4894 memset(&wrqu, 0, sizeof(wrqu));
4895 memset(metrics_notification, 0, sizeof(metrics_notification));
4896
4897 wrqu.data.pointer = metrics_notification;
4898 wrqu.data.length = scnprintf(metrics_notification,
4899 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4900 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4901
4902 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4903
4904 EXIT();
4905
4906 return VOS_STATUS_SUCCESS;
4907}
4908#endif
4909
Jeff Johnson295189b2012-06-20 16:38:30 -07004910/*
4911 * FUNCTION: hdd_cfg80211_scan_done_callback
4912 * scanning callback function, called after finishing scan
4913 *
4914 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304915static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004916 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4917{
4918 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304919 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004920 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004921 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4922 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004923 struct cfg80211_scan_request *req = NULL;
4924 int ret = 0;
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05304925 bool aborted = false;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304926 long waitRet = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004927
4928 ENTER();
4929
4930 hddLog(VOS_TRACE_LEVEL_INFO,
4931 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004932 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004933 __func__, halHandle, pContext, (int) scanId, (int) status);
4934
Kiet Lamac06e2c2013-10-23 16:25:07 +05304935 pScanInfo->mScanPendingCounter = 0;
4936
Jeff Johnson295189b2012-06-20 16:38:30 -07004937 //Block on scan req completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304938 waitRet = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07004939 &pScanInfo->scan_req_completion_event,
4940 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304941 if (waitRet <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07004942 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304943 hddLog(VOS_TRACE_LEVEL_ERROR,
4944 "%s wait on scan_req_completion_event failed %ld",__func__, waitRet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004945 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004946 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004947 }
4948
Yue Maef608272013-04-08 23:09:17 -07004949 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004950 {
4951 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004952 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004953 }
4954
4955 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304956 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004957 {
4958 hddLog(VOS_TRACE_LEVEL_INFO,
4959 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004960 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004961 (int) scanId);
4962 }
4963
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304964 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004965 pAdapter);
4966
4967 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304968 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004969
4970
4971 /* If any client wait scan result through WEXT
4972 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004973 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004974 {
4975 /* The other scan request waiting for current scan finish
4976 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004977 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004979 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004980 }
4981 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004982 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004983 {
4984 struct net_device *dev = pAdapter->dev;
4985 union iwreq_data wrqu;
4986 int we_event;
4987 char *msg;
4988
4989 memset(&wrqu, '\0', sizeof(wrqu));
4990 we_event = SIOCGIWSCAN;
4991 msg = NULL;
4992 wireless_send_event(dev, we_event, &wrqu, msg);
4993 }
4994 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004995 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004996
4997 /* Get the Scan Req */
4998 req = pAdapter->request;
4999
5000 if (!req)
5001 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08005002 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005003 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005004 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 }
5006
5007 /*
5008 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305009 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005010 req->n_ssids = 0;
5011 req->n_channels = 0;
5012 req->ie = 0;
5013
Jeff Johnson295189b2012-06-20 16:38:30 -07005014 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005015 /* Scan is no longer pending */
5016 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005017
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07005018 /*
5019 * cfg80211_scan_done informing NL80211 about completion
5020 * of scanning
5021 */
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05305022 if (status == eCSR_SCAN_ABORT || status == eCSR_SCAN_FAILURE)
5023 {
5024 aborted = true;
5025 }
5026 cfg80211_scan_done(req, aborted);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08005027 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07005028
Jeff Johnsone7245742012-09-05 17:12:55 -07005029allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005030 /* release the wake lock at the end of the scan*/
5031 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005032
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07005033 /* Acquire wakelock to handle the case where APP's tries to suspend
5034 * immediatly after the driver gets connect request(i.e after scan)
5035 * from supplicant, this result in app's is suspending and not able
5036 * to process the connect request to AP */
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05305037 hdd_prevent_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07005038
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005039#ifdef FEATURE_WLAN_TDLS
5040 wlan_hdd_tdls_scan_done_callback(pAdapter);
5041#endif
5042
Jeff Johnson295189b2012-06-20 16:38:30 -07005043 EXIT();
5044 return 0;
5045}
5046
5047/*
Rashmi Ramannab1429032014-04-26 14:59:09 +05305048 * FUNCTION: hdd_isConnectionInProgress
5049 * Go through each adapter and check if Connection is in progress
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005050 *
5051 */
Rashmi Ramannab1429032014-04-26 14:59:09 +05305052v_BOOL_t hdd_isConnectionInProgress( hdd_context_t *pHddCtx )
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005053{
5054 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
5055 hdd_station_ctx_t *pHddStaCtx = NULL;
5056 hdd_adapter_t *pAdapter = NULL;
5057 VOS_STATUS status = 0;
5058 v_U8_t staId = 0;
5059 v_U8_t *staMac = NULL;
5060
c_hpothu9b781ba2013-12-30 20:57:45 +05305061 if (TRUE == pHddCtx->btCoexModeSet)
5062 {
5063 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rashmi Ramannab1429032014-04-26 14:59:09 +05305064 FL("BTCoex Mode operation in progress"));
5065 return VOS_TRUE;
c_hpothu9b781ba2013-12-30 20:57:45 +05305066 }
5067
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005068 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
5069
5070 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
5071 {
5072 pAdapter = pAdapterNode->pAdapter;
5073
5074 if( pAdapter )
5075 {
5076 hddLog(VOS_TRACE_LEVEL_INFO,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305077 "%s: Adapter with device mode %s (%d) exists",
5078 __func__, hdd_device_modetoString(pAdapter->device_mode),
5079 pAdapter->device_mode);
Rashmi Ramannab1429032014-04-26 14:59:09 +05305080 if (((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5081 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
5082 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)) &&
5083 (eConnectionState_Connecting ==
5084 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
5085 {
5086 hddLog(VOS_TRACE_LEVEL_ERROR,
5087 "%s: %p(%d) Connection is in progress", __func__,
5088 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
5089 return VOS_TRUE;
5090 }
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005091 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305092 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
5093 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005094 {
5095 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5096 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305097 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005098 {
5099 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
5100 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08005101 "%s: client " MAC_ADDRESS_STR
5102 " is in the middle of WPS/EAPOL exchange.", __func__,
5103 MAC_ADDR_ARRAY(staMac));
Rashmi Ramannab1429032014-04-26 14:59:09 +05305104 return VOS_TRUE;
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005105 }
5106 }
5107 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
5108 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
5109 {
5110 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
5111 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305112 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005113 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
5114 {
5115 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
5116
5117 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08005118 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
5119 "middle of WPS/EAPOL exchange.", __func__,
5120 MAC_ADDR_ARRAY(staMac));
Rashmi Ramannab1429032014-04-26 14:59:09 +05305121 return VOS_TRUE;
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005122 }
5123 }
5124 }
5125 }
5126 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
5127 pAdapterNode = pNext;
5128 }
Rashmi Ramannab1429032014-04-26 14:59:09 +05305129 return VOS_FALSE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305130}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005131
5132/*
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05305133 * FUNCTION: __wlan_hdd_cfg80211_scan
Jeff Johnson295189b2012-06-20 16:38:30 -07005134 * this scan respond to scan trigger and update cfg80211 scan database
5135 * later, scan dump command can be used to recieve scan results
5136 */
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05305137int __wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08005138#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5139 struct net_device *dev,
5140#endif
5141 struct cfg80211_scan_request *request)
5142{
Siddharth Bhal0c162d02014-05-06 19:50:42 +05305143 hdd_adapter_t *pAdapter = NULL;
5144 hdd_context_t *pHddCtx = NULL;
5145 hdd_wext_state_t *pwextBuf = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305146 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005147 tCsrScanRequest scanRequest;
5148 tANI_U8 *channelList = NULL, i;
5149 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305150 int status;
5151 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005152 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005153
Siddharth Bhal0c162d02014-05-06 19:50:42 +05305154#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
5155 struct net_device *dev = NULL;
5156 if (NULL == request)
5157 {
5158 hddLog(VOS_TRACE_LEVEL_ERROR,
5159 "%s: scan req param null", __func__);
5160 return -EINVAL;
5161 }
5162 dev = request->wdev->netdev;
5163#endif
5164
5165 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5166 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
5167 pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5168
Jeff Johnson295189b2012-06-20 16:38:30 -07005169 ENTER();
5170
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05305171
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305172 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)",
5173 __func__, hdd_device_modetoString(pAdapter->device_mode),
5174 pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005175
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305176 status = wlan_hdd_validate_context(pHddCtx);
5177
5178 if (0 != status)
5179 {
5180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5181 "%s: HDD context is not valid", __func__);
5182 return status;
5183 }
5184
Siddharth Bhal0c162d02014-05-06 19:50:42 +05305185 if (NULL == pwextBuf)
5186 {
5187 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: invalid WEXT state\n",
5188 __func__);
5189 return -EIO;
5190 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305191 cfg_param = pHddCtx->cfg_ini;
5192 pScanInfo = &pHddCtx->scan_info;
5193
Jeff Johnson295189b2012-06-20 16:38:30 -07005194#ifdef WLAN_BTAMP_FEATURE
5195 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005196 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07005197 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005198 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005199 "%s: No scanning when AMP is on", __func__);
5200 return -EOPNOTSUPP;
5201 }
5202#endif
5203 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005204 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07005205 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005206 hddLog(VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305207 "%s: Not scanning on device_mode = %s (%d)",
5208 __func__, hdd_device_modetoString(pAdapter->device_mode),
5209 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07005210 return -EOPNOTSUPP;
5211 }
5212
5213 if (TRUE == pScanInfo->mScanPending)
5214 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305215 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
5216 {
5217 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
5218 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005219 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 }
5221
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305222 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07005223 //Channel and action frame is pending
5224 //Otherwise Cancel Remain On Channel and allow Scan
5225 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005226 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07005227 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305228 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005229 return -EBUSY;
5230 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005231#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005232 /* if tdls disagree scan right now, return immediately.
5233 tdls will schedule the scan when scan is allowed. (return SUCCESS)
5234 or will reject the scan if any TDLS is in progress. (return -EBUSY)
5235 */
5236 status = wlan_hdd_tdls_scan_callback (pAdapter,
5237 wiphy,
5238#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5239 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07005240#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005241 request);
5242 if(status <= 0)
5243 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305244 if(!status)
5245 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS in progress."
5246 "scan rejected %d", __func__, status);
5247 else
5248 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS teardown is ongoing %d",
5249 __func__, status);
5250
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005251 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005252 }
5253#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07005254
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
5256 {
5257 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08005258 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005259 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305260 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
5262 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305263 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005264 "%s: MAX TM Level Scan not allowed", __func__);
5265 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305266 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005267 }
5268 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
5269
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005270 /* Check if scan is allowed at this point of time.
5271 */
Rashmi Ramannab1429032014-04-26 14:59:09 +05305272 if (hdd_isConnectionInProgress(pHddCtx))
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005273 {
5274 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
5275 return -EBUSY;
5276 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305277
Jeff Johnson295189b2012-06-20 16:38:30 -07005278 vos_mem_zero( &scanRequest, sizeof(scanRequest));
5279
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305280 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
5281 (int)request->n_ssids);
5282
5283 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
5284 * Becasue of this, driver is assuming that this is not wildcard scan and so
5285 * is not aging out the scan results.
5286 */
5287 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07005288 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305289 request->n_ssids = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005290 }
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305291
5292 if ((request->ssids) && (0 < request->n_ssids))
5293 {
5294 tCsrSSIDInfo *SsidInfo;
5295 int j;
5296 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
5297 /* Allocate num_ssid tCsrSSIDInfo structure */
5298 SsidInfo = scanRequest.SSIDs.SSIDList =
5299 ( tCsrSSIDInfo *)vos_mem_malloc(
5300 request->n_ssids*sizeof(tCsrSSIDInfo));
5301
5302 if(NULL == scanRequest.SSIDs.SSIDList)
5303 {
5304 hddLog(VOS_TRACE_LEVEL_ERROR,
5305 "%s: memory alloc failed SSIDInfo buffer", __func__);
5306 return -ENOMEM;
5307 }
5308
5309 /* copy all the ssid's and their length */
5310 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
5311 {
5312 /* get the ssid length */
5313 SsidInfo->SSID.length = request->ssids[j].ssid_len;
5314 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
5315 SsidInfo->SSID.length);
5316 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
5317 hddLog(VOS_TRACE_LEVEL_INFO, "SSID number %d: %s",
5318 j, SsidInfo->SSID.ssId);
5319 }
5320 /* set the scan type to active */
5321 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5322 }
5323 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07005324 {
Siddharth Bhal0c162d02014-05-06 19:50:42 +05305325 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
5326 TRACE_CODE_HDD_CFG80211_SCAN,
5327 pAdapter->sessionId, 0));
Jeff Johnson295189b2012-06-20 16:38:30 -07005328 /* set the scan type to active */
5329 scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07005330 }
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305331 else
5332 {
5333 /*Set the scan type to default type, in this case it is ACTIVE*/
5334 scanRequest.scanType = pScanInfo->scan_mode;
5335 }
5336 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
5337 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07005338
5339 /* set BSSType to default type */
5340 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
5341
5342 /*TODO: scan the requested channels only*/
5343
5344 /*Right now scanning all the channels */
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305345 if (MAX_CHANNEL < request->n_channels)
Jeff Johnson295189b2012-06-20 16:38:30 -07005346 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305347 hddLog(VOS_TRACE_LEVEL_WARN,
5348 "No of Scan Channels exceeded limit: %d", request->n_channels);
5349 request->n_channels = MAX_CHANNEL;
5350 }
5351
5352 hddLog(VOS_TRACE_LEVEL_INFO,
5353 "No of Scan Channels: %d", request->n_channels);
5354
5355
5356 if( request->n_channels )
5357 {
5358 char chList [(request->n_channels*5)+1];
5359 int len;
5360 channelList = vos_mem_malloc( request->n_channels );
5361 if( NULL == channelList )
c_hpothu53512302014-04-15 18:49:53 +05305362 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305363 hddLog(VOS_TRACE_LEVEL_ERROR,
5364 "%s: memory alloc failed channelList", __func__);
5365 status = -ENOMEM;
5366 goto free_mem;
c_hpothu53512302014-04-15 18:49:53 +05305367 }
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305368
5369 for( i = 0, len = 0; i < request->n_channels ; i++ )
5370 {
5371 channelList[i] = request->channels[i]->hw_value;
5372 len += snprintf(chList+len, 5, "%d ", channelList[i]);
5373 }
5374
Nirav Shah20ac06f2013-12-12 18:14:06 +05305375 hddLog(VOS_TRACE_LEVEL_INFO,
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305376 "Channel-List: %s ", chList);
5377 }
c_hpothu53512302014-04-15 18:49:53 +05305378
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305379 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
5380 scanRequest.ChannelInfo.ChannelList = channelList;
5381
5382 /* set requestType to full scan */
5383 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
5384
5385 /* Flush the scan results(only p2p beacons) for STA scan and P2P
5386 * search (Flush on both full scan and social scan but not on single
5387 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
5388 */
5389
5390 /* Supplicant does single channel scan after 8-way handshake
5391 * and in that case driver shoudnt flush scan results. If
5392 * driver flushes the scan results here and unfortunately if
5393 * the AP doesnt respond to our probe req then association
5394 * fails which is not desired
5395 */
5396
5397 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
5398 {
5399 hddLog(VOS_TRACE_LEVEL_DEBUG, "Flushing P2P Results");
5400 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
5401 pAdapter->sessionId );
5402 }
5403
5404 if( request->ie_len )
5405 {
5406 /* save this for future association (join requires this) */
5407 /*TODO: Array needs to be converted to dynamic allocation,
5408 * as multiple ie.s can be sent in cfg80211_scan_request structure
5409 * CR 597966
5410 */
5411 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5412 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5413 pScanInfo->scanAddIE.length = request->ie_len;
5414
5415 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5416 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
5417 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005418 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305419 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
Jeff Johnson295189b2012-06-20 16:38:30 -07005420 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305421 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5422 memcpy( pwextBuf->roamProfile.addIEScan,
5423 request->ie, request->ie_len);
5424 }
5425 else
5426 {
5427 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
5428 "%zu", request->ie_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005429 }
5430
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305431 }
5432 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5433 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5434
5435 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5436 request->ie_len);
5437 if (pP2pIe != NULL)
5438 {
5439#ifdef WLAN_FEATURE_P2P_DEBUG
5440 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5441 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5442 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Nirav Shah20ac06f2013-12-12 18:14:06 +05305443 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305444 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5445 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5446 "Go nego completed to Connection is started");
5447 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5448 "for 8way Handshake");
Nirav Shah20ac06f2013-12-12 18:14:06 +05305449 }
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305450 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5451 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005452 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305453 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5454 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5455 "Disconnected state to Connection is started");
5456 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5457 "for 4way Handshake");
5458 }
5459#endif
5460
5461 /* no_cck will be set during p2p find to disable 11b rates */
5462 if(TRUE == request->no_cck)
5463 {
5464 hddLog(VOS_TRACE_LEVEL_INFO,
5465 "%s: This is a P2P Search", __func__);
5466 scanRequest.p2pSearch = 1;
5467
5468 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
Agarwal Ashish4f616132013-12-30 23:32:50 +05305469 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305470 /* set requestType to P2P Discovery */
5471 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
5472 }
5473
5474 /*
5475 Skip Dfs Channel in case of P2P Search
5476 if it is set in ini file
5477 */
5478 if(cfg_param->skipDfsChnlInP2pSearch)
5479 {
5480 scanRequest.skipDfsChnlInP2pSearch = 1;
Agarwal Ashish4f616132013-12-30 23:32:50 +05305481 }
5482 else
5483 {
Padma, Santhosh Kumar787bd5c2014-05-15 20:09:31 +05305484 scanRequest.skipDfsChnlInP2pSearch = 0;
Agarwal Ashish4f616132013-12-30 23:32:50 +05305485 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005486
Agarwal Ashish4f616132013-12-30 23:32:50 +05305487 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005488 }
5489 }
5490
5491 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5492
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005493 /* acquire the wakelock to avoid the apps suspend during the scan. To
5494 * address the following issues.
5495 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5496 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5497 * for long time, this result in apps running at full power for long time.
5498 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5499 * be stuck in full power because of resume BMPS
5500 */
5501 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005502
Nirav Shah20ac06f2013-12-12 18:14:06 +05305503 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
5504 "requestType %d, scanType %d, minChnTime %d, maxChnTime %d,"
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05305505 "p2pSearch %d, skipDfsChnlInP2pSearch %d",
5506 scanRequest.requestType, scanRequest.scanType,
5507 scanRequest.minChnTime, scanRequest.maxChnTime,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305508 scanRequest.p2pSearch, scanRequest.skipDfsChnlInP2pSearch);
5509
Jeff Johnsone7245742012-09-05 17:12:55 -07005510 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005511 pAdapter->sessionId, &scanRequest, &scanId,
5512 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005513
Jeff Johnson295189b2012-06-20 16:38:30 -07005514 if (eHAL_STATUS_SUCCESS != status)
5515 {
5516 hddLog(VOS_TRACE_LEVEL_ERROR,
5517 "%s: sme_ScanRequest returned error %d", __func__, status);
5518 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005519 if(eHAL_STATUS_RESOURCES == status)
5520 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305521 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: HO is in progress."
5522 "So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005523 status = -EBUSY;
5524 } else {
5525 status = -EIO;
5526 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005527 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005528 goto free_mem;
5529 }
5530
5531 pScanInfo->mScanPending = TRUE;
5532 pAdapter->request = request;
5533 pScanInfo->scanId = scanId;
5534
5535 complete(&pScanInfo->scan_req_completion_event);
5536
5537free_mem:
5538 if( scanRequest.SSIDs.SSIDList )
5539 {
5540 vos_mem_free(scanRequest.SSIDs.SSIDList);
5541 }
5542
5543 if( channelList )
5544 vos_mem_free( channelList );
5545
5546 EXIT();
5547
5548 return status;
5549}
5550
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05305551int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
5552#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5553 struct net_device *dev,
5554#endif
5555 struct cfg80211_scan_request *request)
5556{
5557 int ret;
5558
5559 vos_ssr_protect(__func__);
5560 ret = __wlan_hdd_cfg80211_scan(wiphy,
5561#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5562 dev,
5563#endif
5564 request);
5565 vos_ssr_unprotect(__func__);
5566
5567 return ret;
5568}
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005569
5570void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5571{
5572 v_U8_t iniDot11Mode =
5573 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5574 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5575
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305576 hddLog(LOG1, FL("Channel Bonding Mode Selected is %u"),
5577 iniDot11Mode);
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005578 switch ( iniDot11Mode )
5579 {
5580 case eHDD_DOT11_MODE_AUTO:
5581 case eHDD_DOT11_MODE_11ac:
5582 case eHDD_DOT11_MODE_11ac_ONLY:
5583#ifdef WLAN_FEATURE_11AC
5584 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5585#else
5586 hddDot11Mode = eHDD_DOT11_MODE_11n;
5587#endif
5588 break;
5589 case eHDD_DOT11_MODE_11n:
5590 case eHDD_DOT11_MODE_11n_ONLY:
5591 hddDot11Mode = eHDD_DOT11_MODE_11n;
5592 break;
5593 default:
5594 hddDot11Mode = iniDot11Mode;
5595 break;
5596 }
5597 /* This call decides required channel bonding mode */
5598 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5599 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5600 operationChannel);
5601}
5602
Jeff Johnson295189b2012-06-20 16:38:30 -07005603/*
5604 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305605 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005606 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305607int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005608 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005609{
5610 int status = 0;
5611 hdd_wext_state_t *pWextState;
Yue Mae36e3552014-03-05 17:06:20 -08005612 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07005613 v_U32_t roamId;
5614 tCsrRoamProfile *pRoamProfile;
Jeff Johnson295189b2012-06-20 16:38:30 -07005615 eCsrAuthType RSNAuthType;
5616
5617 ENTER();
5618
5619 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Yue Mae36e3552014-03-05 17:06:20 -08005620 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5621
5622 status = wlan_hdd_validate_context(pHddCtx);
5623 if (status)
5624 {
5625 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5626 "%s: HDD context is not valid!", __func__);
5627 return status;
5628 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305629
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5631 {
5632 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5633 return -EINVAL;
5634 }
5635
5636 pRoamProfile = &pWextState->roamProfile;
5637
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305638 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005639 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005640 hdd_station_ctx_t *pHddStaCtx;
5641 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005642
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305643 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5645 {
5646 /*QoS not enabled in cfg file*/
5647 pRoamProfile->uapsd_mask = 0;
5648 }
5649 else
5650 {
5651 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305652 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5654 }
5655
5656 pRoamProfile->SSIDs.numOfSSIDs = 1;
5657 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5658 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305659 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005660 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5661 ssid, ssid_len);
5662
5663 if (bssid)
5664 {
5665 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5666 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5667 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305668 /* Save BSSID in seperate variable as well, as RoamProfile
5669 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005670 case of join failure we should send valid BSSID to supplicant
5671 */
5672 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5673 WNI_CFG_BSSID_LEN);
5674 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005675 else
5676 {
5677 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5678 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005679
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305680 hddLog(LOG1, FL("Connect to SSID: %s opertating Channel: %u"),
5681 pRoamProfile->SSIDs.SSIDList->SSID.ssId, operatingChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005682 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5683 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305684 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005685 /*set gen ie*/
5686 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5687 /*set auth*/
5688 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5689 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005690#ifdef FEATURE_WLAN_WAPI
5691 if (pAdapter->wapi_info.nWapiMode)
5692 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005693 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005694 switch (pAdapter->wapi_info.wapiAuthMode)
5695 {
5696 case WAPI_AUTH_MODE_PSK:
5697 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005698 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 pAdapter->wapi_info.wapiAuthMode);
5700 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5701 break;
5702 }
5703 case WAPI_AUTH_MODE_CERT:
5704 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005705 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005706 pAdapter->wapi_info.wapiAuthMode);
5707 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5708 break;
5709 }
5710 } // End of switch
5711 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5712 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5713 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005714 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005715 pRoamProfile->AuthType.numEntries = 1;
5716 pRoamProfile->EncryptionType.numEntries = 1;
5717 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5718 pRoamProfile->mcEncryptionType.numEntries = 1;
5719 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5720 }
5721 }
5722#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305723#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305724 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305725 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5726 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5727 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305728 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5729 sizeof (tSirGtkOffloadParams));
5730 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305731 }
5732#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005733 pRoamProfile->csrPersona = pAdapter->device_mode;
5734
Jeff Johnson32d95a32012-09-10 13:15:23 -07005735 if( operatingChannel )
5736 {
5737 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5738 pRoamProfile->ChannelInfo.numOfChannels = 1;
5739 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005740 else
5741 {
5742 pRoamProfile->ChannelInfo.ChannelList = NULL;
5743 pRoamProfile->ChannelInfo.numOfChannels = 0;
5744 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005745 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5746 {
5747 hdd_select_cbmode(pAdapter,operatingChannel);
5748 }
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05305749
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005750 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5751 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305752 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005753 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005754 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5755 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305756 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5757 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005758 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5759 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305760
5761 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005762 pAdapter->sessionId, pRoamProfile, &roamId);
5763
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305764 if ((eHAL_STATUS_SUCCESS != status) &&
5765 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5766 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305767
5768 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005769 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5770 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5771 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305772 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005773 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305774 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005775
5776 pRoamProfile->ChannelInfo.ChannelList = NULL;
5777 pRoamProfile->ChannelInfo.numOfChannels = 0;
5778
Jeff Johnson295189b2012-06-20 16:38:30 -07005779 }
5780 else
5781 {
5782 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5783 return -EINVAL;
5784 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005785 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 return status;
5787}
5788
5789/*
5790 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5791 * This function is used to set the authentication type (OPEN/SHARED).
5792 *
5793 */
5794static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5795 enum nl80211_auth_type auth_type)
5796{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305797 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005798 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5799
5800 ENTER();
5801
5802 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305803 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005804 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005805 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305806 hddLog(VOS_TRACE_LEVEL_INFO,
5807 "%s: set authentication type to AUTOSWITCH", __func__);
5808 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5809 break;
5810
5811 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005812#ifdef WLAN_FEATURE_VOWIFI_11R
5813 case NL80211_AUTHTYPE_FT:
5814#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305815 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005816 "%s: set authentication type to OPEN", __func__);
5817 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5818 break;
5819
5820 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305821 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005822 "%s: set authentication type to SHARED", __func__);
5823 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5824 break;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005825#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005826 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305827 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005828 "%s: set authentication type to CCKM WPA", __func__);
5829 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5830 break;
5831#endif
5832
5833
5834 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305835 hddLog(VOS_TRACE_LEVEL_ERROR,
5836 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005837 auth_type);
5838 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5839 return -EINVAL;
5840 }
5841
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305842 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 pHddStaCtx->conn_info.authType;
5844 return 0;
5845}
5846
5847/*
5848 * FUNCTION: wlan_hdd_set_akm_suite
5849 * This function is used to set the key mgmt type(PSK/8021x).
5850 *
5851 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305852static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005853 u32 key_mgmt
5854 )
5855{
5856 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5857 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305858
Jeff Johnson295189b2012-06-20 16:38:30 -07005859 /*set key mgmt type*/
5860 switch(key_mgmt)
5861 {
5862 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305863#ifdef WLAN_FEATURE_VOWIFI_11R
5864 case WLAN_AKM_SUITE_FT_PSK:
5865#endif
5866 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005867 __func__);
5868 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5869 break;
5870
5871 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305872#ifdef WLAN_FEATURE_VOWIFI_11R
5873 case WLAN_AKM_SUITE_FT_8021X:
5874#endif
5875 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005876 __func__);
5877 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5878 break;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005879#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005880#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5881#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5882 case WLAN_AKM_SUITE_CCKM:
5883 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5884 __func__);
5885 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5886 break;
5887#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07005888#ifndef WLAN_AKM_SUITE_OSEN
5889#define WLAN_AKM_SUITE_OSEN 0x506f9a01 /* Should be in ieee802_11_defs.h */
5890 case WLAN_AKM_SUITE_OSEN:
5891 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to OSEN",
5892 __func__);
5893 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5894 break;
5895#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005896
5897 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305898 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005899 __func__, key_mgmt);
5900 return -EINVAL;
5901
5902 }
5903 return 0;
5904}
5905
5906/*
5907 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305908 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005909 * (NONE/WEP40/WEP104/TKIP/CCMP).
5910 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305911static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5912 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005913 bool ucast
5914 )
5915{
5916 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305917 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005918 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5919
5920 ENTER();
5921
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305922 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005923 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305924 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005925 __func__, cipher);
5926 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5927 }
5928 else
5929 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305930
Jeff Johnson295189b2012-06-20 16:38:30 -07005931 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305932 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005933 {
5934 case IW_AUTH_CIPHER_NONE:
5935 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5936 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305937
Jeff Johnson295189b2012-06-20 16:38:30 -07005938 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305939 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305941
Jeff Johnson295189b2012-06-20 16:38:30 -07005942 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305943 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005944 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305945
Jeff Johnson295189b2012-06-20 16:38:30 -07005946 case WLAN_CIPHER_SUITE_TKIP:
5947 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5948 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305949
Jeff Johnson295189b2012-06-20 16:38:30 -07005950 case WLAN_CIPHER_SUITE_CCMP:
5951 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5952 break;
5953#ifdef FEATURE_WLAN_WAPI
5954 case WLAN_CIPHER_SUITE_SMS4:
5955 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5956 break;
5957#endif
5958
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08005959#ifdef FEATURE_WLAN_ESE
Jeff Johnson295189b2012-06-20 16:38:30 -07005960 case WLAN_CIPHER_SUITE_KRK:
5961 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5962 break;
5963#endif
5964 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305965 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 __func__, cipher);
5967 return -EOPNOTSUPP;
5968 }
5969 }
5970
5971 if (ucast)
5972 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305973 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005974 __func__, encryptionType);
5975 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5976 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305977 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005978 encryptionType;
5979 }
5980 else
5981 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305982 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005983 __func__, encryptionType);
5984 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5985 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5986 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5987 }
5988
5989 return 0;
5990}
5991
5992
5993/*
5994 * FUNCTION: wlan_hdd_cfg80211_set_ie
5995 * This function is used to parse WPA/RSN IE's.
5996 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305997int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5998 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 size_t ie_len
6000 )
6001{
6002 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6003 u8 *genie = ie;
6004 v_U16_t remLen = ie_len;
6005#ifdef FEATURE_WLAN_WAPI
6006 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
6007 u16 *tmp;
6008 v_U16_t akmsuiteCount;
6009 int *akmlist;
6010#endif
6011 ENTER();
6012
6013 /* clear previous assocAddIE */
6014 pWextState->assocAddIE.length = 0;
6015 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07006016 pWextState->roamProfile.bOSENAssociation = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006017
6018 while (remLen >= 2)
6019 {
6020 v_U16_t eLen = 0;
6021 v_U8_t elementId;
6022 elementId = *genie++;
6023 eLen = *genie++;
6024 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306025
Arif Hussain6d2a3322013-11-17 19:50:10 -08006026 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306028
6029 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306031 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006032 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 -07006033 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306034 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006035 "%s: Invalid WPA IE", __func__);
6036 return -EINVAL;
6037 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306038 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07006039 {
6040 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306041 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07006042 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306043
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6045 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006046 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
6047 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07006048 VOS_ASSERT(0);
6049 return -ENOMEM;
6050 }
6051 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
6052 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6053 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306054
Jeff Johnson295189b2012-06-20 16:38:30 -07006055 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
6056 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6057 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6058 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306059 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
6060 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006061 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
6062 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
6063 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
6064 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
6065 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
6066 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306067 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05306068 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006069 {
6070 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306071 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07006072 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306073
Jeff Johnson295189b2012-06-20 16:38:30 -07006074 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6075 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006076 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6077 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07006078 VOS_ASSERT(0);
6079 return -ENOMEM;
6080 }
6081 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
6082 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6083 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306084
Jeff Johnson295189b2012-06-20 16:38:30 -07006085 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6086 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6087 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006088#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306089 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
6090 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006091 /*Consider WFD IE, only for P2P Client */
6092 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
6093 {
6094 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306095 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07006096 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306097
Jeff Johnson295189b2012-06-20 16:38:30 -07006098 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6099 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006100 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6101 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07006102 VOS_ASSERT(0);
6103 return -ENOMEM;
6104 }
6105 // WFD IE is saved to Additional IE ; it should be accumulated to handle
6106 // WPS IE + P2P IE + WFD IE
6107 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6108 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306109
Jeff Johnson295189b2012-06-20 16:38:30 -07006110 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6111 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6112 }
6113#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006114 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306115 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006116 HS20_OUI_TYPE_SIZE)) )
6117 {
6118 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306119 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006120 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006121
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006122 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6123 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006124 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6125 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006126 VOS_ASSERT(0);
6127 return -ENOMEM;
6128 }
6129 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6130 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006131
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07006132 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6133 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6134 }
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07006135 /* Appending OSEN Information Element in Assiciation Request */
6136 else if ( (0 == memcmp(&genie[0], OSEN_OUI_TYPE,
6137 OSEN_OUI_TYPE_SIZE)) )
6138 {
6139 v_U16_t curAddIELen = pWextState->assocAddIE.length;
6140 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set OSEN IE(len %d)",
6141 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006142
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07006143 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6144 {
6145 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6146 "Need bigger buffer space");
6147 VOS_ASSERT(0);
6148 return -ENOMEM;
6149 }
6150 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6151 pWextState->assocAddIE.length += eLen + 2;
6152
6153 pWextState->roamProfile.bOSENAssociation = VOS_TRUE;
6154 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6155 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6156 }
6157
6158 break;
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07006159 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
6160
6161 /* populating as ADDIE in beacon frames */
6162 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6163 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
6164 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
6165 {
6166 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6167 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
6168 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6169 {
6170 hddLog(LOGE,
6171 "Coldn't pass "
6172 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
6173 }
6174 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
6175 else
6176 hddLog(LOGE,
6177 "Could not pass on "
6178 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
6179
6180 /* IBSS mode doesn't contain params->proberesp_ies still
6181 beaconIE's need to be populated in probe response frames */
6182 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
6183 {
6184 u16 rem_probe_resp_ie_len = eLen + 2;
6185 u8 probe_rsp_ie_len[3] = {0};
6186 u8 counter = 0;
6187
6188 /* Check Probe Resp Length if it is greater then 255 then
6189 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
6190 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
6191 not able Store More then 255 bytes into One Variable */
6192
6193 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
6194 {
6195 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
6196 {
6197 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
6198 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
6199 }
6200 else
6201 {
6202 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
6203 rem_probe_resp_ie_len = 0;
6204 }
6205 }
6206
6207 rem_probe_resp_ie_len = 0;
6208
6209 if (probe_rsp_ie_len[0] > 0)
6210 {
6211 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6212 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
6213 (tANI_U8*)(genie - 2),
6214 probe_rsp_ie_len[0], NULL,
6215 eANI_BOOLEAN_FALSE)
6216 == eHAL_STATUS_FAILURE)
6217 {
6218 hddLog(LOGE,
6219 "Could not pass"
6220 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
6221 }
6222 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
6223 }
6224
6225 if (probe_rsp_ie_len[1] > 0)
6226 {
6227 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6228 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
6229 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
6230 probe_rsp_ie_len[1], NULL,
6231 eANI_BOOLEAN_FALSE)
6232 == eHAL_STATUS_FAILURE)
6233 {
6234 hddLog(LOGE,
6235 "Could not pass"
6236 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
6237 }
6238 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
6239 }
6240
6241 if (probe_rsp_ie_len[2] > 0)
6242 {
6243 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
6244 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
6245 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
6246 probe_rsp_ie_len[2], NULL,
6247 eANI_BOOLEAN_FALSE)
6248 == eHAL_STATUS_FAILURE)
6249 {
6250 hddLog(LOGE,
6251 "Could not pass"
6252 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
6253 }
6254 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
6255 }
6256
6257 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6258 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6259 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6260 {
6261 hddLog(LOGE,
6262 "Could not pass"
6263 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
6264 }
6265 }
6266 else
6267 {
6268 // Reset WNI_CFG_PROBE_RSP Flags
6269 wlan_hdd_reset_prob_rspies(pAdapter);
6270
6271 hddLog(VOS_TRACE_LEVEL_INFO,
6272 "%s: No Probe Response IE received in set beacon",
6273 __func__);
6274 }
6275 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07006276 break;
6277 case DOT11F_EID_RSN:
6278 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
6279 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
6280 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
6281 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
6282 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
6283 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006284 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
6285 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306286 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006287 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306288 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006289 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306290
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006291 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6292 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006293 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6294 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006295 VOS_ASSERT(0);
6296 return -ENOMEM;
6297 }
6298 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6299 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306300
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006301 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6302 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6303 break;
6304 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006305#ifdef FEATURE_WLAN_WAPI
6306 case WLAN_EID_WAPI:
6307 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006308 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07006309 pAdapter->wapi_info.nWapiMode);
6310 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306311 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07006312 akmsuiteCount = WPA_GET_LE16(tmp);
6313 tmp = tmp + 1;
6314 akmlist = (int *)(tmp);
6315 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
6316 {
6317 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
6318 }
6319 else
6320 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006321 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 VOS_ASSERT(0);
6323 return -EINVAL;
6324 }
6325
6326 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
6327 {
6328 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006329 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006330 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306331 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006332 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306333 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006334 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006335 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006336 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
6337 }
6338 break;
6339#endif
6340 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306341 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006342 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006343 /* when Unknown IE is received we should break and continue
6344 * to the next IE in the buffer instead we were returning
6345 * so changing this to break */
6346 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006347 }
6348 genie += eLen;
6349 remLen -= eLen;
6350 }
6351 EXIT();
6352 return 0;
6353}
6354
6355/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05306356 * FUNCTION: hdd_isWPAIEPresent
6357 * Parse the received IE to find the WPA IE
6358 *
6359 */
6360static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
6361{
6362 v_U8_t eLen = 0;
6363 v_U16_t remLen = ie_len;
6364 v_U8_t elementId = 0;
6365
6366 while (remLen >= 2)
6367 {
6368 elementId = *ie++;
6369 eLen = *ie++;
6370 remLen -= 2;
6371 if (eLen > remLen)
6372 {
6373 hddLog(VOS_TRACE_LEVEL_ERROR,
6374 "%s: IE length is wrong %d", __func__, eLen);
6375 return FALSE;
6376 }
6377 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
6378 {
6379 /* OUI - 0x00 0X50 0XF2
6380 WPA Information Element - 0x01
6381 WPA version - 0x01*/
6382 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
6383 return TRUE;
6384 }
6385 ie += eLen;
6386 remLen -= eLen;
6387 }
6388 return FALSE;
6389}
6390
6391/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006392 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306393 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006394 * parameters during connect operation.
6395 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306396int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006397 struct cfg80211_connect_params *req
6398 )
6399{
6400 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306401 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006402 ENTER();
6403
6404 /*set wpa version*/
6405 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6406
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306407 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006408 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05306409 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006410 {
6411 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6412 }
6413 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
6414 {
6415 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6416 }
6417 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306418
6419 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006420 pWextState->wpaVersion);
6421
6422 /*set authentication type*/
6423 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
6424
6425 if (0 > status)
6426 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306427 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006428 "%s: failed to set authentication type ", __func__);
6429 return status;
6430 }
6431
6432 /*set key mgmt type*/
6433 if (req->crypto.n_akm_suites)
6434 {
6435 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
6436 if (0 > status)
6437 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306438 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07006439 __func__);
6440 return status;
6441 }
6442 }
6443
6444 /*set pairwise cipher type*/
6445 if (req->crypto.n_ciphers_pairwise)
6446 {
6447 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6448 req->crypto.ciphers_pairwise[0], true);
6449 if (0 > status)
6450 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306451 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006452 "%s: failed to set unicast cipher type", __func__);
6453 return status;
6454 }
6455 }
6456 else
6457 {
6458 /*Reset previous cipher suite to none*/
6459 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6460 if (0 > status)
6461 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306462 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006463 "%s: failed to set unicast cipher type", __func__);
6464 return status;
6465 }
6466 }
6467
6468 /*set group cipher type*/
6469 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6470 false);
6471
6472 if (0 > status)
6473 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306474 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006475 __func__);
6476 return status;
6477 }
6478
Chet Lanctot186b5732013-03-18 10:26:30 -07006479#ifdef WLAN_FEATURE_11W
6480 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6481#endif
6482
Jeff Johnson295189b2012-06-20 16:38:30 -07006483 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6484 if (req->ie_len)
6485 {
6486 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6487 if ( 0 > status)
6488 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306489 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006490 __func__);
6491 return status;
6492 }
6493 }
6494
6495 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306496 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006497 {
6498 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6499 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6500 )
6501 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306502 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006503 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6504 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306505 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006506 __func__);
6507 return -EOPNOTSUPP;
6508 }
6509 else
6510 {
6511 u8 key_len = req->key_len;
6512 u8 key_idx = req->key_idx;
6513
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306514 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006515 && (CSR_MAX_NUM_KEY > key_idx)
6516 )
6517 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306518 hddLog(VOS_TRACE_LEVEL_INFO,
6519 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006520 __func__, key_idx, key_len);
6521 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306522 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006523 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306524 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006525 (u8)key_len;
6526 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6527 }
6528 }
6529 }
6530 }
6531
6532 return status;
6533}
6534
6535/*
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306536 * FUNCTION: wlan_hdd_try_disconnect
6537 * This function is used to disconnect from previous
6538 * connection
6539 */
6540static int wlan_hdd_try_disconnect( hdd_adapter_t *pAdapter )
6541{
6542 long ret = 0;
6543 hdd_station_ctx_t *pHddStaCtx;
6544 eMib_dot11DesiredBssType connectedBssType;
6545
6546 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6547
6548 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
6549
6550 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
6551 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
6552 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
6553 {
6554 /* Issue disconnect to CSR */
6555 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6556 if( eHAL_STATUS_SUCCESS ==
6557 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6558 pAdapter->sessionId,
6559 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
6560 {
6561 ret = wait_for_completion_interruptible_timeout(
6562 &pAdapter->disconnect_comp_var,
6563 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6564 if (0 >= ret)
6565 {
6566 hddLog(LOGE, FL("Failed to receive disconnect event"));
6567 return -EALREADY;
6568 }
6569 }
6570 }
6571 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
6572 {
6573 ret = wait_for_completion_interruptible_timeout(
6574 &pAdapter->disconnect_comp_var,
6575 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6576 if (0 >= ret)
6577 {
6578 hddLog(LOGE, FL("Failed to receive disconnect event"));
6579 return -EALREADY;
6580 }
6581 }
6582
6583 return 0;
6584}
6585
6586/*
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306587 * FUNCTION: __wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306588 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006589 * parameters during connect operation.
6590 */
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306591static int __wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006592 struct net_device *ndev,
6593 struct cfg80211_connect_params *req
6594 )
6595{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306596 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306597 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006598 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006599 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006600
6601 ENTER();
6602
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306603 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6604 TRACE_CODE_HDD_CFG80211_CONNECT,
6605 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306606 hddLog(VOS_TRACE_LEVEL_INFO,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05306607 "%s: device_mode = %s (%d)", __func__,
6608 hdd_device_modetoString(pAdapter->device_mode),
6609 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006610
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306611 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006612 if (!pHddCtx)
6613 {
6614 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6615 "%s: HDD context is null", __func__);
6616 return VOS_STATUS_E_FAILURE;
6617 }
6618
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306619 status = wlan_hdd_validate_context(pHddCtx);
6620
6621 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306623 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6624 "%s: HDD context is not valid", __func__);
6625 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 }
6627
6628#ifdef WLAN_BTAMP_FEATURE
6629 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306630 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006631 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306632 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006633 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006634 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006635 }
6636#endif
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306637
6638 //If Device Mode is Station Concurrent Sessions Exit BMps
6639 //P2P Mode will be taken care in Open/close adapter
6640 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6641 (vos_concurrent_sessions_running()))
6642 {
6643 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
6644 }
6645
6646 /*Try disconnecting if already in connected state*/
6647 status = wlan_hdd_try_disconnect(pAdapter);
6648 if ( 0 > status)
6649 {
6650 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6651 " connection"));
6652 return -EALREADY;
6653 }
6654
Jeff Johnson295189b2012-06-20 16:38:30 -07006655 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306656 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006657
6658 if ( 0 > status)
6659 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306660 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006661 __func__);
6662 return status;
6663 }
6664
Mohit Khanna765234a2012-09-11 15:08:35 -07006665 if ( req->channel )
6666 {
6667 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6668 req->ssid_len, req->bssid,
6669 req->channel->hw_value);
6670 }
6671 else
6672 {
6673 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306674 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006675 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006676
6677 if (0 > status)
6678 {
6679 //ReEnable BMPS if disabled
6680 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6681 (NULL != pHddCtx))
6682 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306683 if (pHddCtx->hdd_wlan_suspended)
6684 {
6685 hdd_set_pwrparams(pHddCtx);
6686 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006687 //ReEnable Bmps and Imps back
6688 hdd_enable_bmps_imps(pHddCtx);
6689 }
6690
6691 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6692 return status;
6693 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306694 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 EXIT();
6696 return status;
6697}
6698
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306699static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
6700 struct net_device *ndev,
6701 struct cfg80211_connect_params *req)
6702{
6703 int ret;
6704 vos_ssr_protect(__func__);
6705 ret = __wlan_hdd_cfg80211_connect(wiphy, ndev, req);
6706 vos_ssr_unprotect(__func__);
6707
6708 return ret;
6709}
Jeff Johnson295189b2012-06-20 16:38:30 -07006710
6711/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306712 * FUNCTION: wlan_hdd_disconnect
6713 * This function is used to issue a disconnect request to SME
6714 */
6715int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6716{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306717 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306718 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306719 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6720
6721 status = wlan_hdd_validate_context(pHddCtx);
6722
6723 if (0 != status)
6724 {
6725 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6726 "%s: HDD context is not valid", __func__);
6727 return status;
6728 }
6729
6730 pHddCtx->isAmpAllowed = VOS_TRUE;
Vinay Krishna Erannab09d3e72014-03-26 21:23:55 +05306731 pHddStaCtx->conn_info.connState = eConnectionState_Disconnecting;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306732 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306733
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306734 /*issue disconnect*/
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05306735
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306736 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6737 pAdapter->sessionId, reason);
6738
6739 if ( 0 != status )
6740 {
6741 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006742 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306743 __func__, (int)status );
6744 return -EINVAL;
6745 }
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306746 status = wait_for_completion_interruptible_timeout(
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306747 &pAdapter->disconnect_comp_var,
6748 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306749 if (!status)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306750 {
6751 hddLog(VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306752 "%s: Failed to disconnect, timed out", __func__);
6753 return -ETIMEDOUT;
6754 }
6755 else if (status == -ERESTARTSYS)
6756 {
6757 hddLog(VOS_TRACE_LEVEL_ERROR,
6758 "%s: Failed to disconnect, wait interrupted", __func__);
6759 return status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306760 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306761 /*stop tx queues*/
6762 netif_tx_disable(pAdapter->dev);
6763 netif_carrier_off(pAdapter->dev);
Mahesh A Saptasagar05a357e2014-02-26 16:28:06 +05306764 return 0;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306765}
6766
6767
6768/*
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306769 * FUNCTION: __wlan_hdd_cfg80211_disconnect
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 * This function is used to issue a disconnect request to SME
6771 */
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306772static int __wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006773 struct net_device *dev,
6774 u16 reason
6775 )
6776{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306777 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6778 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006779 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306780 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006781 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006782 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306783#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006784 tANI_U8 staIdx;
6785#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306786
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306788
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05306789 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
6790 TRACE_CODE_HDD_CFG80211_DISCONNECT,
6791 pAdapter->sessionId, reason));
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05306792 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s(%d)",
6793 __func__, hdd_device_modetoString(pAdapter->device_mode),
6794 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006795
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306796 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6797 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006798
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306799 status = wlan_hdd_validate_context(pHddCtx);
6800
6801 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006802 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306803 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6804 "%s: HDD context is not valid", __func__);
6805 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006806 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306807
Jeff Johnson295189b2012-06-20 16:38:30 -07006808 if (NULL != pRoamProfile)
6809 {
6810 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306811 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6812 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006813 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306814 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006815 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306816 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006817 switch(reason)
6818 {
6819 case WLAN_REASON_MIC_FAILURE:
6820 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6821 break;
6822
6823 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6824 case WLAN_REASON_DISASSOC_AP_BUSY:
6825 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6826 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6827 break;
6828
6829 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6830 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
Abhishek Singhc3269a52014-05-21 17:22:24 +05306831 case WLAN_REASON_DEAUTH_LEAVING:
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6833 break;
6834
Jeff Johnson295189b2012-06-20 16:38:30 -07006835 default:
6836 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6837 break;
6838 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306839 pScanInfo = &pHddCtx->scan_info;
6840 if (pScanInfo->mScanPending)
6841 {
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306842 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306843 "Aborting Scan");
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306844 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId,
6845 eCSR_SCAN_ABORT_DEFAULT);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306846 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006847
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006848#ifdef FEATURE_WLAN_TDLS
6849 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006850 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006851 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006852 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6853 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006854 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006855 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006856 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006857 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006858 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006859 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006860 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006861 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006862 pAdapter->sessionId,
6863 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006864 }
6865 }
6866#endif
Arun Kumar Khandavalli94a2bb02013-12-28 19:17:25 +05306867 hddLog(LOG1, FL("Disconnecting with reasoncode:%u"), reasonCode);
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306868 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6869 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006870 {
6871 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006872 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006873 __func__, (int)status );
6874 return -EINVAL;
6875 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306877 else
6878 {
6879 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6880 "called while in %d state", __func__,
6881 pHddStaCtx->conn_info.connState);
6882 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006883 }
6884 else
6885 {
6886 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6887 }
6888
6889 return status;
6890}
6891
Mahesh A Saptasagarfafb7fe2014-05-16 13:19:37 +05306892static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
6893 struct net_device *dev,
6894 u16 reason
6895 )
6896{
6897 int ret;
6898 vos_ssr_protect(__func__);
6899 ret = __wlan_hdd_cfg80211_disconnect(wiphy, dev, reason);
6900 vos_ssr_unprotect(__func__);
6901
6902 return ret;
6903}
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306904
Jeff Johnson295189b2012-06-20 16:38:30 -07006905/*
6906 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306907 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006908 * settings in IBSS mode.
6909 */
6910static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306911 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006912 struct cfg80211_ibss_params *params
6913 )
6914{
6915 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306916 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006917 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6918 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306919
Jeff Johnson295189b2012-06-20 16:38:30 -07006920 ENTER();
6921
6922 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006923 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006924
6925 if (params->ie_len && ( NULL != params->ie) )
6926 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006927 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6928 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 {
6930 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6931 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6932 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006933 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006934 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006935 tDot11fIEWPA dot11WPAIE;
6936 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006937 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006938
Wilson Yang00256342013-10-10 23:13:38 -07006939 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006940 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6941 params->ie_len, DOT11F_EID_WPA);
6942 if ( NULL != ie )
6943 {
6944 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6945 // Unpack the WPA IE
6946 //Skip past the EID byte and length byte - and four byte WiFi OUI
6947 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6948 &ie[2+4],
6949 ie[1] - 4,
6950 &dot11WPAIE);
6951 /*Extract the multicast cipher, the encType for unicast
6952 cipher for wpa-none is none*/
6953 encryptionType =
6954 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6955 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006956 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006957
Jeff Johnson295189b2012-06-20 16:38:30 -07006958 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6959
6960 if (0 > status)
6961 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306962 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 __func__);
6964 return status;
6965 }
6966 }
6967
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306968 pWextState->roamProfile.AuthType.authType[0] =
6969 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6971
6972 if (params->privacy)
6973 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306974 /* Security enabled IBSS, At this time there is no information available
6975 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006976 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306977 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006978 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306979 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 *enable privacy bit in beacons */
6981
6982 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6983 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006984 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6985 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006986 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6987 pWextState->roamProfile.EncryptionType.numEntries = 1;
6988 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 return status;
6990}
6991
6992/*
6993 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306994 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006995 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306996static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006997 struct net_device *dev,
6998 struct cfg80211_ibss_params *params
6999 )
7000{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307001 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07007002 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
7003 tCsrRoamProfile *pRoamProfile;
7004 int status;
krunal sonie9002db2013-11-25 14:24:17 -08007005 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007006 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307007 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008
7009 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307010
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307011 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7012 TRACE_CODE_HDD_CFG80211_JOIN_IBSS,
7013 pAdapter->sessionId, pAdapter->device_mode));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307014 hddLog(VOS_TRACE_LEVEL_INFO,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05307015 "%s: device_mode = %s (%d)", __func__,
7016 hdd_device_modetoString(pAdapter->device_mode),
7017 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07007018
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307019 status = wlan_hdd_validate_context(pHddCtx);
7020
7021 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007022 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307023 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7024 "%s: HDD context is not valid", __func__);
7025 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007026 }
7027
7028 if (NULL == pWextState)
7029 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007030 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07007031 __func__);
7032 return -EIO;
7033 }
7034
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05307035 /*Try disconnecting if already in connected state*/
7036 status = wlan_hdd_try_disconnect(pAdapter);
7037 if ( 0 > status)
7038 {
7039 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
7040 " IBSS connection"));
7041 return -EALREADY;
7042 }
7043
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 pRoamProfile = &pWextState->roamProfile;
7045
7046 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
7047 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307048 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007049 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007050 return -EINVAL;
7051 }
7052
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07007053 /* BSSID is provided by upper layers hence no need to AUTO generate */
7054 if (NULL != params->bssid) {
7055 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
7056 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
7057 hddLog (VOS_TRACE_LEVEL_ERROR,
7058 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
7059 return -EIO;
7060 }
7061 }
krunal sonie9002db2013-11-25 14:24:17 -08007062 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
7063 {
7064 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
7065 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
7066 {
7067 hddLog (VOS_TRACE_LEVEL_ERROR,
7068 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
7069 return -EIO;
7070 }
7071 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
7072 if (!params->bssid)
7073 {
7074 hddLog (VOS_TRACE_LEVEL_ERROR,
7075 "%s:Failed memory allocation", __func__);
7076 return -EIO;
7077 }
7078 vos_mem_copy((v_U8_t *)params->bssid,
7079 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
7080 VOS_MAC_ADDR_SIZE);
7081 alloc_bssid = VOS_TRUE;
7082 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07007083
Jeff Johnson295189b2012-06-20 16:38:30 -07007084 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07007085 if (NULL !=
7086#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
7087 params->chandef.chan)
7088#else
7089 params->channel)
7090#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007091 {
7092 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007093 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7094 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7095 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7096 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007097
7098 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307099 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07007100 ieee80211_frequency_to_channel(
7101#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
7102 params->chandef.chan->center_freq);
7103#else
7104 params->channel->center_freq);
7105#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007106
7107 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7108 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07007109 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007110 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
7111 __func__);
7112 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07007113 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007114
7115 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007116 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007117 if (channelNum == validChan[indx])
7118 {
7119 break;
7120 }
7121 }
7122 if (indx >= numChans)
7123 {
7124 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07007125 __func__, channelNum);
7126 return -EINVAL;
7127 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007128 /* Set the Operational Channel */
7129 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
7130 channelNum);
7131 pRoamProfile->ChannelInfo.numOfChannels = 1;
7132 pHddStaCtx->conn_info.operationChannel = channelNum;
7133 pRoamProfile->ChannelInfo.ChannelList =
7134 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07007135 }
7136
7137 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307138 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07007139 if (status < 0)
7140 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307141 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07007142 __func__);
7143 return status;
7144 }
7145
7146 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307147 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07007148 params->ssid_len, params->bssid,
7149 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007150
7151 if (0 > status)
7152 {
7153 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
7154 return status;
7155 }
7156
krunal sonie9002db2013-11-25 14:24:17 -08007157 if (NULL != params->bssid &&
7158 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
7159 alloc_bssid == VOS_TRUE)
7160 {
7161 vos_mem_free(params->bssid);
7162 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007163 return 0;
7164}
7165
7166/*
7167 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307168 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07007169 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307170static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07007171 struct net_device *dev
7172 )
7173{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307174 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07007175 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
7176 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307177 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7178 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007179
7180 ENTER();
7181
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307182 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7183 TRACE_CODE_HDD_CFG80211_LEAVE_IBSS,
7184 pAdapter->sessionId, eCSR_DISCONNECT_REASON_IBSS_LEAVE));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307185 status = wlan_hdd_validate_context(pHddCtx);
7186
7187 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007188 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307189 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7190 "%s: HDD context is not valid", __func__);
7191 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007192 }
7193
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05307194 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %s (%d)", __func__,
7195 hdd_device_modetoString(pAdapter->device_mode),
7196 pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07007197 if (NULL == pWextState)
7198 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007199 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07007200 __func__);
7201 return -EIO;
7202 }
7203
7204 pRoamProfile = &pWextState->roamProfile;
7205
7206 /* Issue disconnect only if interface type is set to IBSS */
7207 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
7208 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307209 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07007210 __func__);
7211 return -EINVAL;
7212 }
7213
7214 /* Issue Disconnect request */
7215 INIT_COMPLETION(pAdapter->disconnect_comp_var);
7216 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7217 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
7218
7219 return 0;
7220}
7221
7222/*
7223 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
7224 * This function is used to set the phy parameters
7225 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
7226 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307227static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07007228 u32 changed)
7229{
7230 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
7231 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307232 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007233
7234 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307235 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7236 TRACE_CODE_HDD_CFG80211_SET_WIPHY_PARAMS,
7237 NO_SESSION, wiphy->rts_threshold));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307238 status = wlan_hdd_validate_context(pHddCtx);
7239
7240 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007241 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307242 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7243 "%s: HDD context is not valid", __func__);
7244 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007245 }
7246
Jeff Johnson295189b2012-06-20 16:38:30 -07007247 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
7248 {
7249 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
7250 WNI_CFG_RTS_THRESHOLD_STAMAX :
7251 wiphy->rts_threshold;
7252
7253 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307254 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07007255 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307256 hddLog(VOS_TRACE_LEVEL_ERROR,
7257 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007258 __func__, rts_threshold);
7259 return -EINVAL;
7260 }
7261
7262 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
7263 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307264 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007265 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307266 hddLog(VOS_TRACE_LEVEL_ERROR,
7267 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007268 __func__, rts_threshold);
7269 return -EIO;
7270 }
7271
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307272 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007273 rts_threshold);
7274 }
7275
7276 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
7277 {
7278 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
7279 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
7280 wiphy->frag_threshold;
7281
7282 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307283 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007284 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307285 hddLog(VOS_TRACE_LEVEL_ERROR,
7286 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007287 frag_threshold);
7288 return -EINVAL;
7289 }
7290
7291 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
7292 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307293 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007294 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307295 hddLog(VOS_TRACE_LEVEL_ERROR,
7296 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007297 __func__, frag_threshold);
7298 return -EIO;
7299 }
7300
7301 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
7302 frag_threshold);
7303 }
7304
7305 if ((changed & WIPHY_PARAM_RETRY_SHORT)
7306 || (changed & WIPHY_PARAM_RETRY_LONG))
7307 {
7308 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
7309 wiphy->retry_short :
7310 wiphy->retry_long;
7311
7312 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
7313 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
7314 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307315 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007316 __func__, retry_value);
7317 return -EINVAL;
7318 }
7319
7320 if (changed & WIPHY_PARAM_RETRY_SHORT)
7321 {
7322 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
7323 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307324 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007325 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307326 hddLog(VOS_TRACE_LEVEL_ERROR,
7327 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007328 __func__, retry_value);
7329 return -EIO;
7330 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307331 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007332 __func__, retry_value);
7333 }
7334 else if (changed & WIPHY_PARAM_RETRY_SHORT)
7335 {
7336 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
7337 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307338 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007339 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307340 hddLog(VOS_TRACE_LEVEL_ERROR,
7341 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007342 __func__, retry_value);
7343 return -EIO;
7344 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307345 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007346 __func__, retry_value);
7347 }
7348 }
7349
7350 return 0;
7351}
7352
7353/*
7354 * FUNCTION: wlan_hdd_cfg80211_set_txpower
7355 * This function is used to set the txpower
7356 */
7357static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07007358#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7359 struct wireless_dev *wdev,
7360#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007361#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307362 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007363#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307364 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007365#endif
7366 int dbm)
7367{
7368 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307369 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007370 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
7371 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307372 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007373
7374 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307375 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7376 TRACE_CODE_HDD_CFG80211_SET_TXPOWER,
7377 NO_SESSION, type ));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307378 status = wlan_hdd_validate_context(pHddCtx);
7379
7380 if (0 != status)
7381 {
7382 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7383 "%s: HDD context is not valid", __func__);
7384 return status;
7385 }
7386
7387 hHal = pHddCtx->hHal;
7388
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307389 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
7390 dbm, ccmCfgSetCallback,
7391 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007392 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307393 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007394 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
7395 return -EIO;
7396 }
7397
7398 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
7399 dbm);
7400
7401 switch(type)
7402 {
7403 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
7404 /* Fall through */
7405 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
7406 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
7407 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307408 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
7409 __func__);
7410 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07007411 }
7412 break;
7413 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307414 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07007415 __func__);
7416 return -EOPNOTSUPP;
7417 break;
7418 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307419 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
7420 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07007421 return -EIO;
7422 }
7423
7424 return 0;
7425}
7426
7427/*
7428 * FUNCTION: wlan_hdd_cfg80211_get_txpower
7429 * This function is used to read the txpower
7430 */
Yue Maf49ba872013-08-19 12:04:25 -07007431static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
7432#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7433 struct wireless_dev *wdev,
7434#endif
7435 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07007436{
7437
7438 hdd_adapter_t *pAdapter;
7439 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307440 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007441
Jeff Johnsone7245742012-09-05 17:12:55 -07007442 ENTER();
7443
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307444 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007445
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307446 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007447 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7449 "%s: HDD context is not valid", __func__);
7450 *dbm = 0;
7451 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007452 }
7453
Jeff Johnson295189b2012-06-20 16:38:30 -07007454 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
7455 if (NULL == pAdapter)
7456 {
7457 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
7458 return -ENOENT;
7459 }
7460
7461 wlan_hdd_get_classAstats(pAdapter);
7462 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
7463
Jeff Johnsone7245742012-09-05 17:12:55 -07007464 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007465 return 0;
7466}
7467
7468static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
7469 u8* mac, struct station_info *sinfo)
7470{
7471 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
7472 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7473 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
c_hpothu44ff4e02014-05-08 00:13:57 +05307474 tANI_U32 rate_flags;
Jeff Johnson295189b2012-06-20 16:38:30 -07007475
7476 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
7477 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07007478
7479 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
7480 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
7481 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
7482 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
7483 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
7484 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
7485 tANI_U16 maxRate = 0;
7486 tANI_U16 myRate;
7487 tANI_U16 currentRate = 0;
7488 tANI_U8 maxSpeedMCS = 0;
7489 tANI_U8 maxMCSIdx = 0;
7490 tANI_U8 rateFlag = 1;
7491 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07007492 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307493 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007494
Leo Chang6f8870f2013-03-26 18:11:36 -07007495#ifdef WLAN_FEATURE_11AC
7496 tANI_U32 vht_mcs_map;
7497 eDataRate11ACMaxMcs vhtMaxMcs;
7498#endif /* WLAN_FEATURE_11AC */
7499
Jeff Johnsone7245742012-09-05 17:12:55 -07007500 ENTER();
7501
Jeff Johnson295189b2012-06-20 16:38:30 -07007502 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
7503 (0 == ssidlen))
7504 {
7505 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
7506 " Invalid ssidlen, %d", __func__, ssidlen);
7507 /*To keep GUI happy*/
7508 return 0;
7509 }
7510
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307511 status = wlan_hdd_validate_context(pHddCtx);
7512
7513 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007514 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307515 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7516 "%s: HDD context is not valid", __func__);
7517 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007518 }
7519
Jeff Johnson295189b2012-06-20 16:38:30 -07007520
Kiet Lam3b17fc82013-09-27 05:24:08 +05307521 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
7522 sinfo->filled |= STATION_INFO_SIGNAL;
7523
c_hpothu44ff4e02014-05-08 00:13:57 +05307524 if ((eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed) ||
7525 (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed &&
7526 sinfo->signal >= pCfg->linkSpeedRssiHigh))
7527 {
7528 rate_flags = pAdapter->maxRateFlags;
7529 }
7530 else
7531 {
7532 wlan_hdd_get_station_stats(pAdapter);
7533 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
7534 }
7535
Jeff Johnson295189b2012-06-20 16:38:30 -07007536 //convert to the UI units of 100kbps
7537 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
7538
7539#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07007540 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 -07007541 sinfo->signal,
7542 pCfg->reportMaxLinkSpeed,
7543 myRate,
7544 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007545 (int) pCfg->linkSpeedRssiMid,
7546 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07007547 (int) rate_flags,
7548 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07007549#endif //LINKSPEED_DEBUG_ENABLED
7550
7551 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
7552 {
7553 // we do not want to necessarily report the current speed
7554 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
7555 {
7556 // report the max possible speed
7557 rssidx = 0;
7558 }
7559 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
7560 {
7561 // report the max possible speed with RSSI scaling
7562 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
7563 {
7564 // report the max possible speed
7565 rssidx = 0;
7566 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007567 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07007568 {
7569 // report middle speed
7570 rssidx = 1;
7571 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007572 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
7573 {
7574 // report middle speed
7575 rssidx = 2;
7576 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 else
7578 {
7579 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007580 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07007581 }
7582 }
7583 else
7584 {
7585 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
7586 hddLog(VOS_TRACE_LEVEL_ERROR,
7587 "%s: Invalid value for reportMaxLinkSpeed: %u",
7588 __func__, pCfg->reportMaxLinkSpeed);
7589 rssidx = 0;
7590 }
7591
7592 maxRate = 0;
7593
7594 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307595 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7596 OperationalRates, &ORLeng))
7597 {
7598 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7599 /*To keep GUI happy*/
7600 return 0;
7601 }
7602
Jeff Johnson295189b2012-06-20 16:38:30 -07007603 for (i = 0; i < ORLeng; i++)
7604 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007605 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007606 {
7607 /* Validate Rate Set */
7608 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7609 {
7610 currentRate = supported_data_rate[j].supported_rate[rssidx];
7611 break;
7612 }
7613 }
7614 /* Update MAX rate */
7615 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7616 }
7617
7618 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307619 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7620 ExtendedRates, &ERLeng))
7621 {
7622 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7623 /*To keep GUI happy*/
7624 return 0;
7625 }
7626
Jeff Johnson295189b2012-06-20 16:38:30 -07007627 for (i = 0; i < ERLeng; i++)
7628 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007629 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007630 {
7631 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7632 {
7633 currentRate = supported_data_rate[j].supported_rate[rssidx];
7634 break;
7635 }
7636 }
7637 /* Update MAX rate */
7638 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7639 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307640 /* Get MCS Rate Set --
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307641 Only if we are always reporting max speed (or)
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307642 if we have good rssi */
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307643 if ((0 == rssidx) ||
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307644 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007645 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307646 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7647 MCSRates, &MCSLeng))
7648 {
7649 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7650 /*To keep GUI happy*/
7651 return 0;
7652 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007653 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007654#ifdef WLAN_FEATURE_11AC
7655 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307656 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007657 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007658 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307659 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007660 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007661 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007662 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007663 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007664 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007665 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007666 maxMCSIdx = 7;
7667 }
7668 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7669 {
7670 maxMCSIdx = 8;
7671 }
7672 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7673 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307674 //VHT20 is supporting 0~8
7675 if (rate_flags & eHAL_TX_RATE_VHT20)
7676 maxMCSIdx = 8;
7677 else
7678 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007679 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307680
7681 if (rate_flags & eHAL_TX_RATE_VHT80)
7682 {
7683 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7684 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7685 }
7686 else if (rate_flags & eHAL_TX_RATE_VHT40)
7687 {
7688 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7689 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7690 }
7691 else if (rate_flags & eHAL_TX_RATE_VHT20)
7692 {
7693 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7694 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7695 }
7696
Leo Chang6f8870f2013-03-26 18:11:36 -07007697 maxSpeedMCS = 1;
7698 if (currentRate > maxRate)
7699 {
7700 maxRate = currentRate;
7701 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307702
Leo Chang6f8870f2013-03-26 18:11:36 -07007703 }
7704 else
7705#endif /* WLAN_FEATURE_11AC */
7706 {
7707 if (rate_flags & eHAL_TX_RATE_HT40)
7708 {
7709 rateFlag |= 1;
7710 }
7711 if (rate_flags & eHAL_TX_RATE_SGI)
7712 {
7713 rateFlag |= 2;
7714 }
7715
7716 for (i = 0; i < MCSLeng; i++)
7717 {
7718 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7719 for (j = 0; j < temp; j++)
7720 {
7721 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7722 {
7723 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7724 break;
7725 }
7726 }
7727 if ((j < temp) && (currentRate > maxRate))
7728 {
7729 maxRate = currentRate;
7730 maxSpeedMCS = 1;
7731 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7732 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007733 }
7734 }
7735 }
7736
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307737 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7738 {
7739 maxRate = myRate;
7740 maxSpeedMCS = 1;
7741 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7742 }
7743
Jeff Johnson295189b2012-06-20 16:38:30 -07007744 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007745 if (((maxRate < myRate) && (0 == rssidx)) ||
7746 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007747 {
7748 maxRate = myRate;
7749 if (rate_flags & eHAL_TX_RATE_LEGACY)
7750 {
7751 maxSpeedMCS = 0;
7752 }
7753 else
7754 {
7755 maxSpeedMCS = 1;
7756 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7757 }
7758 }
7759
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307760 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007761 {
7762 sinfo->txrate.legacy = maxRate;
7763#ifdef LINKSPEED_DEBUG_ENABLED
7764 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7765#endif //LINKSPEED_DEBUG_ENABLED
7766 }
7767 else
7768 {
7769 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007770#ifdef WLAN_FEATURE_11AC
7771 sinfo->txrate.nss = 1;
7772 if (rate_flags & eHAL_TX_RATE_VHT80)
7773 {
7774 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307775 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007776 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307777 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007778 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307779 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7780 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7781 }
7782 else if (rate_flags & eHAL_TX_RATE_VHT20)
7783 {
7784 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7785 }
7786#endif /* WLAN_FEATURE_11AC */
7787 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7788 {
7789 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7790 if (rate_flags & eHAL_TX_RATE_HT40)
7791 {
7792 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7793 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007794 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007795 if (rate_flags & eHAL_TX_RATE_SGI)
7796 {
7797 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7798 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307799
Jeff Johnson295189b2012-06-20 16:38:30 -07007800#ifdef LINKSPEED_DEBUG_ENABLED
7801 pr_info("Reporting MCS rate %d flags %x\n",
7802 sinfo->txrate.mcs,
7803 sinfo->txrate.flags );
7804#endif //LINKSPEED_DEBUG_ENABLED
7805 }
7806 }
7807 else
7808 {
7809 // report current rate instead of max rate
7810
7811 if (rate_flags & eHAL_TX_RATE_LEGACY)
7812 {
7813 //provide to the UI in units of 100kbps
7814 sinfo->txrate.legacy = myRate;
7815#ifdef LINKSPEED_DEBUG_ENABLED
7816 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7817#endif //LINKSPEED_DEBUG_ENABLED
7818 }
7819 else
7820 {
7821 //must be MCS
7822 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007823#ifdef WLAN_FEATURE_11AC
7824 sinfo->txrate.nss = 1;
7825 if (rate_flags & eHAL_TX_RATE_VHT80)
7826 {
7827 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7828 }
7829 else
7830#endif /* WLAN_FEATURE_11AC */
7831 {
7832 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7833 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007834 if (rate_flags & eHAL_TX_RATE_SGI)
7835 {
7836 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7837 }
7838 if (rate_flags & eHAL_TX_RATE_HT40)
7839 {
7840 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7841 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007842#ifdef WLAN_FEATURE_11AC
7843 else if (rate_flags & eHAL_TX_RATE_VHT80)
7844 {
7845 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7846 }
7847#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007848#ifdef LINKSPEED_DEBUG_ENABLED
7849 pr_info("Reporting actual MCS rate %d flags %x\n",
7850 sinfo->txrate.mcs,
7851 sinfo->txrate.flags );
7852#endif //LINKSPEED_DEBUG_ENABLED
7853 }
7854 }
7855 sinfo->filled |= STATION_INFO_TX_BITRATE;
7856
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007857 sinfo->tx_packets =
7858 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7859 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7860 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7861 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7862
7863 sinfo->tx_retries =
7864 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7865 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7866 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7867 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7868
7869 sinfo->tx_failed =
7870 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7871 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7872 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7873 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7874
7875 sinfo->filled |=
7876 STATION_INFO_TX_PACKETS |
7877 STATION_INFO_TX_RETRIES |
7878 STATION_INFO_TX_FAILED;
7879
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307880 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7881 TRACE_CODE_HDD_CFG80211_GET_STA,
7882 pAdapter->sessionId, maxRate));
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007883 EXIT();
7884 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007885}
7886
7887static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007888 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007889{
7890 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307891 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007892 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307893 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007894
Jeff Johnsone7245742012-09-05 17:12:55 -07007895 ENTER();
7896
Jeff Johnson295189b2012-06-20 16:38:30 -07007897 if (NULL == pAdapter)
7898 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007899 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007900 return -ENODEV;
7901 }
7902
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307903 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7904 TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT,
7905 pAdapter->sessionId, timeout));
7906
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307907 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307908 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307909
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307910 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307911 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307912 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7913 "%s: HDD context is not valid", __func__);
7914 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307915 }
7916
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307917 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7918 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7919 (pHddCtx->cfg_ini->fhostArpOffload) &&
7920 (eConnectionState_Associated ==
7921 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7922 {
Amar Singhald53568e2013-09-26 11:03:45 -07007923
7924 hddLog(VOS_TRACE_LEVEL_INFO,
7925 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307926 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307927 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7928 {
7929 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007930 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307931 __func__, vos_status);
7932 }
7933 }
7934
Jeff Johnson295189b2012-06-20 16:38:30 -07007935 /**The get power cmd from the supplicant gets updated by the nl only
7936 *on successful execution of the function call
7937 *we are oppositely mapped w.r.t mode in the driver
7938 **/
7939 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7940
Jeff Johnsone7245742012-09-05 17:12:55 -07007941 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007942 if (VOS_STATUS_E_FAILURE == vos_status)
7943 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307944 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7945 "%s: failed to enter bmps mode", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007946 return -EINVAL;
7947 }
7948 return 0;
7949}
7950
7951
7952#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7953static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7954 struct net_device *netdev,
7955 u8 key_index)
7956{
Jeff Johnsone7245742012-09-05 17:12:55 -07007957 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007958 return 0;
7959}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307960#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007961
7962#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7963static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7964 struct net_device *dev,
7965 struct ieee80211_txq_params *params)
7966{
Jeff Johnsone7245742012-09-05 17:12:55 -07007967 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007968 return 0;
7969}
7970#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7971static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7972 struct ieee80211_txq_params *params)
7973{
Jeff Johnsone7245742012-09-05 17:12:55 -07007974 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007975 return 0;
7976}
7977#endif //LINUX_VERSION_CODE
7978
7979static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7980 struct net_device *dev, u8 *mac)
7981{
7982 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307983 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007984 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307985 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007986 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007987
Jeff Johnsone7245742012-09-05 17:12:55 -07007988 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307989
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307990 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007991 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307992 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007993 return -EINVAL;
7994 }
7995
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05307996 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
7997 TRACE_CODE_HDD_CFG80211_DEL_STA,
7998 pAdapter->sessionId, pAdapter->device_mode));
7999
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308000 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8001 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07008002
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308003 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008004 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308005 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8006 "%s: HDD context is not valid", __func__);
8007 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008008 }
8009
Jeff Johnson295189b2012-06-20 16:38:30 -07008010 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07008011 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07008012 )
8013 {
8014 if( NULL == mac )
8015 {
8016 v_U16_t i;
8017 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
8018 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07008019 if ((pAdapter->aStaInfo[i].isUsed) &&
8020 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07008021 {
8022 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
8023 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08008024 "%s: Delete STA with MAC::"
8025 MAC_ADDRESS_STR,
8026 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07008027 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
8028 if (VOS_IS_STATUS_SUCCESS(vos_status))
8029 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07008030 }
8031 }
8032 }
8033 else
8034 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008035
8036 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
8037 if (!VOS_IS_STATUS_SUCCESS(vos_status))
8038 {
8039 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08008040 "%s: Skip this DEL STA as this is not used::"
8041 MAC_ADDRESS_STR,
8042 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008043 return -ENOENT;
8044 }
8045
8046 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
8047 {
8048 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08008049 "%s: Skip this DEL STA as deauth is in progress::"
8050 MAC_ADDRESS_STR,
8051 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008052 return -ENOENT;
8053 }
8054
8055 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
8056
Jeff Johnson295189b2012-06-20 16:38:30 -07008057 hddLog(VOS_TRACE_LEVEL_INFO,
8058 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008059 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07008060 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08008061 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008062
8063 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
8064 if (!VOS_IS_STATUS_SUCCESS(vos_status))
8065 {
8066 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
8067 hddLog(VOS_TRACE_LEVEL_INFO,
8068 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008069 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008070 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08008071 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08008072 return -ENOENT;
8073 }
8074
Jeff Johnson295189b2012-06-20 16:38:30 -07008075 }
8076 }
8077
8078 EXIT();
8079
8080 return 0;
8081}
8082
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008083static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
8084 struct net_device *dev, u8 *mac, struct station_parameters *params)
8085{
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308086 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008087 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008088#ifdef FEATURE_WLAN_TDLS
8089 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008090 ENTER();
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308091
8092 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8093 TRACE_CODE_HDD_CFG80211_ADD_STA,
8094 pAdapter->sessionId, params->listen_interval));
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008095 mask = params->sta_flags_mask;
8096
8097 set = params->sta_flags_set;
8098
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008099#ifdef WLAN_FEATURE_TDLS_DEBUG
8100 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8101 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
8102 __func__, mask, set, MAC_ADDR_ARRAY(mac));
8103#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008104
8105 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
8106 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08008107 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008108 }
8109 }
8110#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008111 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008112}
8113
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008114
8115#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07008116
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008117static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07008118 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008119{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308120 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008121 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308122 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008123 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308124 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308125 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008126 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308127 hdd_context_t *pHddCtx;
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008128 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
8129 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07008130
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308131 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308132 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008133 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308134 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008135 return -EINVAL;
8136 }
8137
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308138 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8139 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008140
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308141 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008142 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308143 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8144 "%s: HDD context is not valid", __func__);
8145 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008146 }
8147
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308148 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008149 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308150 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008151
Agarwal Ashish3da95242014-05-21 14:57:17 +05308152 for (j = 0; j < pHddStaCtx->PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008153 {
Agarwal Ashish3da95242014-05-21 14:57:17 +05308154 if (vos_mem_compare(pHddStaCtx->PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008155 pmksa->bssid, WNI_CFG_BSSID_LEN))
8156 {
8157 /* BSSID matched previous entry. Overwrite it. */
8158 BSSIDMatched = 1;
Agarwal Ashish3da95242014-05-21 14:57:17 +05308159 vos_mem_copy(pHddStaCtx->PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008160 pmksa->bssid, WNI_CFG_BSSID_LEN);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308161 vos_mem_copy(pHddStaCtx->PMKIDCache[j].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308162 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008163 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308164 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008165 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008166 dump_bssid(pmksa->bssid);
8167 dump_pmkid(halHandle, pmksa->pmkid);
8168 break;
8169 }
8170 }
8171
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07008172 /* Check we compared all entries,if then take the first slot now */
Agarwal Ashish3da95242014-05-21 14:57:17 +05308173 if (j == MAX_PMKSAIDS_IN_CACHE) pHddStaCtx->PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07008174
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008175 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308176 {
8177 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Agarwal Ashish3da95242014-05-21 14:57:17 +05308178 vos_mem_copy(pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308179 pmksa->bssid, ETHER_ADDR_LEN);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308180 vos_mem_copy(pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308181 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008182 CSR_RSN_PMKID_SIZE);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308183 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: Adding a new cache entry %d.",
8184 __func__, pHddStaCtx->PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008185 dump_bssid(pmksa->bssid);
8186 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308187 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008188 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Agarwal Ashish3da95242014-05-21 14:57:17 +05308189 if (pHddStaCtx->PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1))
8190 pHddStaCtx->PMKIDCacheIndex++;
8191 else
8192 pHddStaCtx->PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008193 }
8194
8195
8196 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Agarwal Ashish3da95242014-05-21 14:57:17 +05308197 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
8198 __func__, pHddStaCtx->PMKIDCacheIndex );
8199
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008200 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308201 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
Agarwal Ashish3da95242014-05-21 14:57:17 +05308202 pHddStaCtx->PMKIDCache,
8203 pHddStaCtx->PMKIDCacheIndex);
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308204 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8205 TRACE_CODE_HDD_CFG80211_SET_PMKSA,
8206 pAdapter->sessionId, result));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008207 return 0;
8208}
8209
8210
Wilson Yang6507c4e2013-10-01 20:11:19 -07008211
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008212static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07008213 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008214{
Wilson Yang6507c4e2013-10-01 20:11:19 -07008215 tANI_U32 j=0;
8216 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308217 hdd_station_ctx_t *pHddStaCtx;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008218 tHalHandle halHandle;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008219 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008220 hdd_context_t *pHddCtx;
Wilson Yangef657d32014-01-15 19:19:23 -08008221 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008222
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008223 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
8224 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07008225
8226 /* Validate pAdapter */
8227 if (NULL == pAdapter)
8228 {
8229 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
8230 return -EINVAL;
8231 }
8232
8233 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8234 status = wlan_hdd_validate_context(pHddCtx);
8235
8236 if (0 != status)
8237 {
8238 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8239 "%s: HDD context is not valid", __func__);
8240 return status;
8241 }
8242
8243 /*Retrieve halHandle*/
8244 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308245 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008246
8247 /*in case index is 0,no entry to delete*/
Agarwal Ashish3da95242014-05-21 14:57:17 +05308248 if (0 == pHddStaCtx->PMKIDCacheIndex)
Wilson Yang6507c4e2013-10-01 20:11:19 -07008249 {
Agarwal Ashish3da95242014-05-21 14:57:17 +05308250 hddLog(VOS_TRACE_LEVEL_INFO, FL("No entries to flush"));
8251 return 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008252 }
8253
8254 /*find the matching PMKSA entry from j=0 to (index-1),
8255 * and delete the matched one
8256 */
Agarwal Ashish3da95242014-05-21 14:57:17 +05308257 for (j = 0; j < pHddStaCtx->PMKIDCacheIndex; j++)
Wilson Yang6507c4e2013-10-01 20:11:19 -07008258 {
Agarwal Ashish3da95242014-05-21 14:57:17 +05308259 if (vos_mem_compare(pHddStaCtx->PMKIDCache[j].BSSID,
Wilson Yang6507c4e2013-10-01 20:11:19 -07008260 pmksa->bssid,
8261 WNI_CFG_BSSID_LEN))
8262 {
8263 /* BSSID matched entry */
8264 BSSIDMatched = 1;
Agarwal Ashish3da95242014-05-21 14:57:17 +05308265 if (j < pHddStaCtx->PMKIDCacheIndex-1)
Wilson Yang6507c4e2013-10-01 20:11:19 -07008266 {
8267 /*replace the matching entry with the last entry in HDD local cache*/
Agarwal Ashish3da95242014-05-21 14:57:17 +05308268 vos_mem_copy(pHddStaCtx->PMKIDCache[j].BSSID,
8269 pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex-1].BSSID,
8270 VOS_MAC_ADDR_SIZE);
8271 vos_mem_copy(pHddStaCtx->PMKIDCache[j].PMKID,
8272 pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex-1].PMKID,
8273 CSR_RSN_PMKID_SIZE);
8274 }
Wilson Yang6507c4e2013-10-01 20:11:19 -07008275
8276 /*clear the last entry in HDD cache ---[index-1]*/
Agarwal Ashish3da95242014-05-21 14:57:17 +05308277 vos_mem_zero(pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex-1].BSSID,
8278 VOS_MAC_ADDR_SIZE);
8279 vos_mem_zero(pHddStaCtx->PMKIDCache[pHddStaCtx->PMKIDCacheIndex-1].PMKID,
8280 CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008281 /*reduce the PMKID array index*/
Agarwal Ashish3da95242014-05-21 14:57:17 +05308282 pHddStaCtx->PMKIDCacheIndex--;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008283 /*delete the last PMKID cache in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008284 if (eHAL_STATUS_SUCCESS !=
8285 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008286 {
8287 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
Agarwal Ashish3da95242014-05-21 14:57:17 +05308288 __func__, pHddStaCtx->PMKIDCacheIndex);
Wilson Yangef657d32014-01-15 19:19:23 -08008289 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008290 }
8291
8292 dump_bssid(pmksa->bssid);
8293 dump_pmkid(halHandle,pmksa->pmkid);
8294
8295 break;
8296 }
8297 }
8298
8299 /* we compare all entries,but cannot find matching entry */
8300 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
8301 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008302 hddLog(VOS_TRACE_LEVEL_FATAL,
8303 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
8304 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07008305 dump_bssid(pmksa->bssid);
8306 dump_pmkid(halHandle, pmksa->pmkid);
8307 return -EINVAL;
8308 }
Wilson Yangef657d32014-01-15 19:19:23 -08008309 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008310}
8311
Wilson Yang6507c4e2013-10-01 20:11:19 -07008312
8313
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008314static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
8315{
Wilson Yang6507c4e2013-10-01 20:11:19 -07008316 tANI_U32 j=0;
8317 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308318 hdd_station_ctx_t *pHddStaCtx;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008319 tHalHandle halHandle;
8320 hdd_context_t *pHddCtx;
8321 tANI_U8 *pBSSId;
Wilson Yangef657d32014-01-15 19:19:23 -08008322 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008323
8324 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
8325
8326 /* Validate pAdapter */
8327 if (NULL == pAdapter)
8328 {
8329 hddLog(VOS_TRACE_LEVEL_ERROR,
8330 "%s: Invalid Adapter" ,__func__);
8331 return -EINVAL;
8332 }
8333
8334 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8335 status = wlan_hdd_validate_context(pHddCtx);
8336
8337 if (0 != status)
8338 {
8339 hddLog(VOS_TRACE_LEVEL_ERROR,
8340 "%s: HDD context is not valid", __func__);
8341 return status;
8342 }
8343
8344 /*Retrieve halHandle*/
8345 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Agarwal Ashish3da95242014-05-21 14:57:17 +05308346 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008347
8348 /*in case index is 0,no entry to delete*/
Agarwal Ashish3da95242014-05-21 14:57:17 +05308349 if (0 == pHddStaCtx->PMKIDCacheIndex)
Wilson Yang6507c4e2013-10-01 20:11:19 -07008350 {
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308351 hddLog(VOS_TRACE_LEVEL_ERROR, FL("No entries to flush"));
Agarwal Ashish3da95242014-05-21 14:57:17 +05308352 return 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008353 }
8354
8355 /*delete all the PMKSA one by one */
Agarwal Ashish3da95242014-05-21 14:57:17 +05308356 for (j = 0; j < pHddStaCtx->PMKIDCacheIndex; j++)
Wilson Yang6507c4e2013-10-01 20:11:19 -07008357 {
Agarwal Ashish3da95242014-05-21 14:57:17 +05308358 pBSSId =(tANI_U8 *)(pHddStaCtx->PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008359 /*delete the PMKID in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008360 if (eHAL_STATUS_SUCCESS !=
8361 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008362 {
8363 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
8364 __func__,j);
Wilson Yangef657d32014-01-15 19:19:23 -08008365 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008366 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05308367 /*clear the entry in HDD cache 0--index-1 */
Agarwal Ashish3da95242014-05-21 14:57:17 +05308368 vos_mem_zero(pHddStaCtx->PMKIDCache[j].BSSID, VOS_MAC_ADDR_SIZE);
8369 vos_mem_zero(pHddStaCtx->PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
8370 }
Wilson Yang6507c4e2013-10-01 20:11:19 -07008371
Agarwal Ashish3da95242014-05-21 14:57:17 +05308372 pHddStaCtx->PMKIDCacheIndex = 0;
Wilson Yangef657d32014-01-15 19:19:23 -08008373 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008374}
8375#endif
8376
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008377#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308378static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008379 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
8380{
8381 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8382 hdd_station_ctx_t *pHddStaCtx;
8383
8384 if (NULL == pAdapter)
8385 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008386 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008387 return -ENODEV;
8388 }
8389
8390 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8391
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308392 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8393 TRACE_CODE_HDD_CFG80211_UPDATE_FT_IES,
8394 pAdapter->sessionId, pHddStaCtx->conn_info.connState));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008395 // Added for debug on reception of Re-assoc Req.
8396 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
8397 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008398 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008399 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08008400 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008401 }
8402
8403#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08008404 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008405 ftie->ie_len);
8406#endif
8407
8408 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05308409 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
8410 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008411 ftie->ie_len);
8412 return 0;
8413}
8414#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008415
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308416#ifdef FEATURE_WLAN_SCAN_PNO
8417
8418void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
8419 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8420{
8421 int ret;
8422 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
8423 hdd_context_t *pHddCtx;
8424
Nirav Shah80830bf2013-12-31 16:35:12 +05308425 ENTER();
8426
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308427 if (NULL == pAdapter)
8428 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308429 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308430 "%s: HDD adapter is Null", __func__);
8431 return ;
8432 }
8433
8434 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8435 if (NULL == pHddCtx)
8436 {
8437 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8438 "%s: HDD context is Null!!!", __func__);
8439 return ;
8440 }
8441
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308442 spin_lock(&pHddCtx->schedScan_lock);
8443 if (TRUE == pHddCtx->isWiphySuspended)
8444 {
8445 pHddCtx->isSchedScanUpdatePending = TRUE;
8446 spin_unlock(&pHddCtx->schedScan_lock);
8447 hddLog(VOS_TRACE_LEVEL_INFO,
8448 "%s: Update cfg80211 scan database after it resume", __func__);
8449 return ;
8450 }
8451 spin_unlock(&pHddCtx->schedScan_lock);
8452
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308453 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
8454
8455 if (0 > ret)
8456 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
8457
8458 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308459 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8460 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308461}
8462
8463/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308464 * FUNCTION: wlan_hdd_is_pno_allowed
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308465 * Disallow pno if any session is active
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308466 */
8467static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
8468{
8469 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8470 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308471 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308472 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8473 int status = 0;
8474 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
8475
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308476 /* The current firmware design does not allow PNO during any
8477 * active sessions. Hence, determine the active sessions
8478 * and return a failure.
8479 */
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308480 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
8481 {
8482 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308483 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308484
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308485 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
8486 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
8487 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
8488 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
8489 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
8490 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308491 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308492 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308493 }
8494 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8495 pAdapterNode = pNext;
8496 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308497 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308498}
8499
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308500void hdd_cfg80211_sched_scan_start_status_cb(void *callbackContext, VOS_STATUS status)
8501{
8502 hdd_adapter_t *pAdapter = callbackContext;
8503 hdd_context_t *pHddCtx;
8504
8505 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
8506 {
8507 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8508 FL("Invalid adapter or adapter has invalid magic"));
8509 return;
8510 }
8511
8512 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8513 if (0 != wlan_hdd_validate_context(pHddCtx))
8514 {
8515 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8516 FL("HDD context is not valid"));
8517 return;
8518 }
8519
8520 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8521 FL("PNO enable response status = %d"), status);
8522
8523 pAdapter->pno_req_status = (status == VOS_STATUS_SUCCESS) ? 0 : -EBUSY;
8524 complete(&pAdapter->pno_comp_var);
8525}
8526
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308527/*
Mahesh A Saptasagar6cc38562014-05-23 21:22:17 +05308528 * FUNCTION: __wlan_hdd_cfg80211_sched_scan_start
8529 * Function to enable PNO
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308530 */
Mahesh A Saptasagar6cc38562014-05-23 21:22:17 +05308531static int __wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308532 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8533{
8534 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8535 tpSirPNOScanReq pPnoRequest = NULL;
8536 hdd_context_t *pHddCtx;
8537 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308538 v_U32_t i, indx, num_ch, tempInterval;
Sushant Kaushikd62d9782014-02-19 15:39:40 +05308539 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
8540 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308541 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8542 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308543 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308544
8545 if (NULL == pAdapter)
8546 {
8547 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8548 "%s: HDD adapter is Null", __func__);
8549 return -ENODEV;
8550 }
8551
8552 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308553 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308554
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308555 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308556 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308557 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8558 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308559 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308560 }
8561
8562 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8563 if (NULL == hHal)
8564 {
8565 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8566 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308567 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308568 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308569
Mahesh A Saptasagar2395ee62014-05-21 19:12:21 +05308570 ret = wlan_hdd_scan_abort(pAdapter);
8571 if (ret <= 0)
8572 {
8573 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8574 "%s: aborting the existing scan is unsuccessfull", __func__);
8575 return -EBUSY;
8576 }
8577
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308578 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308579 {
Vinay Krishna Erannacbf75f42014-02-26 17:35:20 +05308580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308581 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308582 return -EBUSY;
8583 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308584
c_hpothu37f21312014-04-09 21:49:54 +05308585 if (TRUE == pHddCtx->isPnoEnable)
8586 {
8587 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8588 FL("already PNO is enabled"));
8589 return -EBUSY;
8590 }
8591 pHddCtx->isPnoEnable = TRUE;
8592
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308593 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8594 if (NULL == pPnoRequest)
8595 {
8596 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8597 "%s: vos_mem_malloc failed", __func__);
c_hpothu37f21312014-04-09 21:49:54 +05308598 pHddCtx->isPnoEnable = FALSE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308599 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308600 }
8601
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05308602 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308603 pPnoRequest->enable = 1; /*Enable PNO */
8604 pPnoRequest->ucNetworksCount = request->n_match_sets;
8605
8606 if (( !pPnoRequest->ucNetworksCount ) ||
8607 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
8608 {
8609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik1e406c32014-05-09 15:57:52 +05308610 "%s: Network input is not correct %d Max Network supported is %d",
8611 __func__, pPnoRequest->ucNetworksCount,
8612 SIR_PNO_MAX_SUPP_NETWORKS);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308613 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308614 goto error;
8615 }
8616
8617 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
8618 {
8619 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308620 "%s: Incorrect number of channels %d",
8621 __func__, request->n_channels);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308622 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308623 goto error;
8624 }
8625
8626 /* Framework provides one set of channels(all)
8627 * common for all saved profile */
8628 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
8629 channels_allowed, &num_channels_allowed))
8630 {
8631 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8632 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308633 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308634 goto error;
8635 }
8636 /* Checking each channel against allowed channel list */
8637 num_ch = 0;
Nirav Shah80830bf2013-12-31 16:35:12 +05308638 if (request->n_channels)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308639 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308640 char chList [(request->n_channels*5)+1];
8641 int len;
8642 for (i = 0, len = 0; i < request->n_channels; i++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308643 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308644 for (indx = 0; indx < num_channels_allowed; indx++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308645 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308646 if (request->channels[i]->hw_value == channels_allowed[indx])
8647 {
8648 valid_ch[num_ch++] = request->channels[i]->hw_value;
8649 len += snprintf(chList+len, 5, "%d ",
8650 request->channels[i]->hw_value);
8651 break ;
8652 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308653 }
8654 }
Nirav Shah80830bf2013-12-31 16:35:12 +05308655 hddLog(VOS_TRACE_LEVEL_INFO,"Channel-List: %s ", chList);
8656 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308657
8658 /* Filling per profile params */
8659 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
8660 {
8661 pPnoRequest->aNetworks[i].ssId.length =
8662 request->match_sets[i].ssid.ssid_len;
8663
8664 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8665 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8666 {
8667 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308668 "%s: SSID Len %d is not correct for network %d",
8669 __func__, pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308670 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308671 goto error;
8672 }
8673
8674 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8675 request->match_sets[i].ssid.ssid,
8676 request->match_sets[i].ssid.ssid_len);
Sushant Kaushik1e406c32014-05-09 15:57:52 +05308677 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8678 "%s: SSID of network %d is %s ", __func__,
8679 i, pPnoRequest->aNetworks[i].ssId.ssId);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308680 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8681 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8682 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8683
8684 /*Copying list of valid channel into request */
8685 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8686 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8687
8688 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8689 }
8690
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308691 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008692 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308693 if ((0 < request->ie_len) && (NULL != request->ie))
8694 {
8695 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8696 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8697 pPnoRequest->us24GProbeTemplateLen);
8698
8699 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8700 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8701 pPnoRequest->us5GProbeTemplateLen);
8702 }
8703
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308704 /* Driver gets only one time interval which is hardcoded in
8705 * supplicant for 10000ms. Taking power consumption into account 6 timers
8706 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8707 * 80,160,320 secs. And number of scan cycle for each timer
8708 * is configurable through INI param gPNOScanTimerRepeatValue.
8709 * If it is set to 0 only one timer will be used and PNO scan cycle
8710 * will be repeated after each interval specified by supplicant
8711 * till PNO is disabled.
8712 */
8713 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8714 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8715 else
8716 pPnoRequest->scanTimers.ucScanTimersCount =
8717 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8718
8719 tempInterval = (request->interval)/1000;
8720 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8721 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8722 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8723 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8724 {
8725 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8726 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8727 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8728 tempInterval *= 2;
8729 }
8730 //Repeat last timer until pno disabled.
8731 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8732
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308733 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308734
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308735 INIT_COMPLETION(pAdapter->pno_comp_var);
8736 pPnoRequest->statusCallback = hdd_cfg80211_sched_scan_start_status_cb;
8737 pPnoRequest->callbackContext = pAdapter;
8738 pAdapter->pno_req_status = 0;
8739
Nirav Shah80830bf2013-12-31 16:35:12 +05308740 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8741 "SessionId %d, enable %d, modePNO %d, ucScanTimersCount %d",
8742 pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO,
8743 pPnoRequest->scanTimers.ucScanTimersCount);
8744
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308745 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8746 pPnoRequest, pAdapter->sessionId,
8747 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8748 if (eHAL_STATUS_SUCCESS != status)
8749 {
8750 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308751 "%s: Failed to enable PNO", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308752 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308753 goto error;
8754 }
8755
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308756 ret = wait_for_completion_timeout(
8757 &pAdapter->pno_comp_var,
8758 msecs_to_jiffies(WLAN_WAIT_TIME_PNO));
8759 if (0 >= ret)
8760 {
8761 // Did not receive the response for PNO enable in time.
8762 // Assuming the PNO enable was success.
8763 // Returning error from here, because we timeout, results
8764 // in side effect of Wifi (Wifi Setting) not to work.
8765 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8766 FL("Timed out waiting for PNO to be Enabled"));
8767 ret = 0;
8768 goto error;
8769 }
8770
8771 ret = pAdapter->pno_req_status;
c_hpothu37f21312014-04-09 21:49:54 +05308772 return ret;
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308773
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308774error:
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308775 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8776 FL("PNO scanRequest offloaded ret = %d"), ret);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308777 vos_mem_free(pPnoRequest);
c_hpothu37f21312014-04-09 21:49:54 +05308778 pHddCtx->isPnoEnable = FALSE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308779 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308780}
8781
8782/*
Mahesh A Saptasagar6cc38562014-05-23 21:22:17 +05308783 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
8784 * NL interface to enable PNO
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308785 */
Mahesh A Saptasagar6cc38562014-05-23 21:22:17 +05308786static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
8787 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8788{
8789 int ret;
8790
8791 vos_ssr_protect(__func__);
8792 ret = __wlan_hdd_cfg80211_sched_scan_start(wiphy, dev, request);
8793 vos_ssr_unprotect(__func__);
8794
8795 return ret;
8796}
8797
8798/*
8799 * FUNCTION: __wlan_hdd_cfg80211_sched_scan_stop
8800 * Function to disable PNO
8801 */
8802static int __wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308803 struct net_device *dev)
8804{
8805 eHalStatus status = eHAL_STATUS_FAILURE;
8806 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8807 hdd_context_t *pHddCtx;
8808 tHalHandle hHal;
8809 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308810 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308811
8812 ENTER();
8813
8814 if (NULL == pAdapter)
8815 {
8816 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8817 "%s: HDD adapter is Null", __func__);
8818 return -ENODEV;
8819 }
8820
8821 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308822
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308823 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308824 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308825 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308826 "%s: HDD context is Null", __func__);
8827 return -ENODEV;
8828 }
8829
8830 /* The return 0 is intentional when isLogpInProgress and
8831 * isLoadUnloadInProgress. We did observe a crash due to a return of
8832 * failure in sched_scan_stop , especially for a case where the unload
8833 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8834 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8835 * success. If it returns a failure , then its next invocation due to the
8836 * clean up of the second interface will have the dev pointer corresponding
8837 * to the first one leading to a crash.
8838 */
8839 if (pHddCtx->isLogpInProgress)
8840 {
8841 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8842 "%s: LOGP in Progress. Ignore!!!", __func__);
8843 return ret;
8844 }
8845
Mihir Shete18156292014-03-11 15:38:30 +05308846 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308847 {
8848 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8849 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8850 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308851 }
8852
8853 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8854 if (NULL == hHal)
8855 {
8856 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8857 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308858 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308859 }
8860
8861 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8862 if (NULL == pPnoRequest)
8863 {
8864 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8865 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308866 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308867 }
8868
8869 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8870 pPnoRequest->enable = 0; /* Disable PNO */
8871 pPnoRequest->ucNetworksCount = 0;
8872
8873 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8874 pAdapter->sessionId,
8875 NULL, pAdapter);
8876 if (eHAL_STATUS_SUCCESS != status)
8877 {
8878 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8879 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308880 ret = -EINVAL;
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308881 goto error;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308882 }
c_hpothu37f21312014-04-09 21:49:54 +05308883 pHddCtx->isPnoEnable = FALSE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308884
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308885error:
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308886 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Vinay Krishna Erannaf0e523b2014-03-01 21:00:16 +05308887 FL("PNO scan disabled ret = %d"), ret);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308888 vos_mem_free(pPnoRequest);
8889
8890 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308891 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308892}
8893
Mahesh A Saptasagar6cc38562014-05-23 21:22:17 +05308894/*
8895 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8896 * NL interface to disable PNO
8897 */
8898static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8899 struct net_device *dev)
8900{
8901 int ret;
8902
8903 vos_ssr_protect(__func__);
8904 ret = __wlan_hdd_cfg80211_sched_scan_stop(wiphy, dev);
8905 vos_ssr_unprotect(__func__);
8906
8907 return ret;
8908}
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308909#endif /*FEATURE_WLAN_SCAN_PNO*/
8910
8911
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008912#ifdef FEATURE_WLAN_TDLS
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308913#if TDLS_MGMT_VERSION2
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008914static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8915 u8 *peer, u8 action_code, u8 dialog_token,
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308916 u16 status_code, u32 peer_capability, const u8 *buf, size_t len)
8917#else
8918static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8919 u8 *peer, u8 action_code, u8 dialog_token,
8920 u16 status_code, const u8 *buf, size_t len)
8921#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008922{
8923
8924 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8925 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008926 u8 peerMac[6];
8927 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008928 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008929 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008930 long rc;
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05308931#if !(TDLS_MGMT_VERSION2)
8932 u32 peer_capability = 0;
8933#endif
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308934 tANI_U16 numCurrTdlsPeers;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008935
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05308936 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
8937 TRACE_CODE_HDD_CFG80211_TDLS_MGMT,
8938 pAdapter->sessionId, action_code));
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008939 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008940 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308941 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008942 "Invalid arguments");
8943 return -EINVAL;
8944 }
8945
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008946 if (pHddCtx->isLogpInProgress)
8947 {
8948 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8949 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008950 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008951 return -EBUSY;
8952 }
8953
Hoonki Lee27511902013-03-14 18:19:06 -07008954 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008955 {
Hoonki Lee27511902013-03-14 18:19:06 -07008956 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8957 "%s: TDLS mode is disabled OR not enabled in FW."
8958 MAC_ADDRESS_STR " action %d declined.",
8959 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008960 return -ENOTSUPP;
8961 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008962
Hoonki Lee27511902013-03-14 18:19:06 -07008963 /* other than teardown frame, other mgmt frames are not sent if disabled */
8964 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8965 {
8966 /* if tdls_mode is disabled to respond to peer's request */
8967 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8968 {
8969 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8970 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008971 " TDLS mode is disabled. action %d declined.",
8972 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008973
8974 return -ENOTSUPP;
8975 }
8976 }
8977
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008978 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8979 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308980 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008981 {
8982 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008983 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008984 " TDLS setup is ongoing. action %d declined.",
8985 __func__, MAC_ADDR_ARRAY(peer), action_code);
8986 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008987 }
8988 }
8989
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008990 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8991 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008992 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05308993 numCurrTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
8994 if (HDD_MAX_NUM_TDLS_STA <= numCurrTdlsPeers)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008995 {
8996 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8997 we return error code at 'add_station()'. Hence we have this
8998 check again in addtion to add_station().
8999 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009000 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08009001 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009002 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9003 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309004 " TDLS Max peer already connected. action (%d) declined. Num of peers (%d), Max allowed (%d).",
9005 __func__, MAC_ADDR_ARRAY(peer), action_code,
9006 numCurrTdlsPeers, HDD_MAX_NUM_TDLS_STA);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05309007 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08009008 }
9009 else
9010 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009011 /* maximum reached. tweak to send error code to peer and return
9012 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08009013 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009014 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9015 "%s: " MAC_ADDRESS_STR
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05309016 " TDLS Max peer already connected, send response status (%d). Num of peers (%d), Max allowed (%d).",
9017 __func__, MAC_ADDR_ARRAY(peer), status_code,
9018 numCurrTdlsPeers, HDD_MAX_NUM_TDLS_STA);
Gopichand Nakkala05922802013-03-14 12:23:19 -07009019 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009020 /* fall through to send setup resp with failure status
9021 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08009022 }
9023 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009024 else
9025 {
9026 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309027 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009028 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009029 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009030 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07009031 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
9032 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009033 return -EPERM;
9034 }
9035 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08009036 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009037 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009038
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009039#ifdef WLAN_FEATURE_TDLS_DEBUG
9040 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Kumar Khandavalli9fb625e2014-03-17 16:07:40 +05309041 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %zu",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009042 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
9043 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009044#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009045
Hoonki Leea34dd892013-02-05 22:56:02 -08009046 /*Except teardown responder will not be used so just make 0*/
9047 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08009048 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08009049 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07009050
9051 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05309052 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07009053
9054 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
9055 responder = pTdlsPeer->is_responder;
9056 else
Hoonki Leea34dd892013-02-05 22:56:02 -08009057 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07009058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arun Kumar Khandavalli9fb625e2014-03-17 16:07:40 +05309059 "%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 -07009060 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
9061 dialog_token, status_code, len);
9062 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08009063 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009064 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009065
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05309066 /* For explicit trigger of DIS_REQ come out of BMPS for
9067 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07009068 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05309069 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
9070 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07009071 {
9072 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
9073 {
9074 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05309075 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07009076 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
9077 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05309078 if (SIR_MAC_TDLS_DIS_REQ != action_code)
9079 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07009080 }
9081
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009082 /* make sure doesn't call send_mgmt() while it is pending */
9083 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
9084 {
9085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08009086 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009087 __func__, MAC_ADDR_ARRAY(peer), action_code);
9088 return -EBUSY;
9089 }
9090
9091 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009092 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
9093
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009094 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Pradeep Reddy POTTETIca171f82014-03-21 14:17:35 +05309095 peerMac, action_code, dialog_token, status_code, peer_capability, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009096
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009097 if (VOS_STATUS_SUCCESS != status)
9098 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009099 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9100 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009101 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07009102 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05309103 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009104 }
9105
Hoonki Leed37cbb32013-04-20 00:31:14 -07009106 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
9107 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
9108
9109 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009110 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07009111 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07009112 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07009113 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009114 pAdapter->mgmtTxCompletionStatus = FALSE;
Yue Ma4f55ef32014-01-23 16:45:33 -08009115
9116 if (pHddCtx->isLogpInProgress)
9117 {
9118 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9119 "%s: LOGP in Progress. Ignore!!!", __func__);
9120 return -EAGAIN;
9121 }
9122
Hoonki Leed37cbb32013-04-20 00:31:14 -07009123 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05309124 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009125 }
9126
Gopichand Nakkala05922802013-03-14 12:23:19 -07009127 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07009128 {
9129 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07009130 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07009131 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009132
Hoonki Leea34dd892013-02-05 22:56:02 -08009133 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
9134 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08009135 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08009136 }
9137 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
9138 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08009139 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08009140 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009141
9142 return 0;
9143}
9144
9145static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
9146 u8 *peer, enum nl80211_tdls_operation oper)
9147{
9148 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9149 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309150 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009151 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009152
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309153 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
9154 TRACE_CODE_HDD_CFG80211_TDLS_OPER,
9155 pAdapter->sessionId, oper));
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309156 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009157 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08009158 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07009159 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009160 return -EINVAL;
9161 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009162
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309163 status = wlan_hdd_validate_context(pHddCtx);
9164
9165 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08009166 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309167 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9168 "%s: HDD context is not valid", __func__);
9169 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08009170 }
9171
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009172
9173 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009174 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009175 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08009176 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07009177 "TDLS Disabled in INI OR not enabled in FW. "
9178 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009179 return -ENOTSUPP;
9180 }
9181
9182 switch (oper) {
9183 case NL80211_TDLS_ENABLE_LINK:
9184 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009185 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309186 long ret;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309187 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009188
Sunil Dutt41de4e22013-11-14 18:09:02 +05309189 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9190
9191 if ( NULL == pTdlsPeer ) {
9192 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
9193 " (oper %d) not exsting. ignored",
9194 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
9195 return -EINVAL;
9196 }
9197
9198 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9199 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
9200 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
9201 "NL80211_TDLS_ENABLE_LINK");
9202
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07009203 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
9204 {
9205 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
9206 MAC_ADDRESS_STR " failed",
9207 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
9208 return -EINVAL;
9209 }
9210
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009211 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009212 {
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309213 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05309214
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309215 if (0 != wlan_hdd_tdls_get_link_establish_params(
9216 pAdapter, peer,&tdlsLinkEstablishParams)) {
9217 return -EINVAL;
9218 }
9219 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309220
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05309221 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
9222 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
9223 /* Send TDLS peer UAPSD capabilities to the firmware and
9224 * register with the TL on after the response for this operation
9225 * is received .
9226 */
9227 ret = wait_for_completion_interruptible_timeout(
9228 &pAdapter->tdls_link_establish_req_comp,
9229 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
9230 if (ret <= 0)
9231 {
9232 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9233 "%s: Link Establish Request Faled Status %ld",
9234 __func__, ret);
9235 return -EINVAL;
9236 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309237 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009238 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05309239 /* Mark TDLS client Authenticated .*/
9240 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
9241 pTdlsPeer->staId,
9242 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009243 if (VOS_STATUS_SUCCESS == status)
9244 {
Hoonki Lee14621352013-04-16 17:51:19 -07009245 if (pTdlsPeer->is_responder == 0)
9246 {
9247 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
9248
9249 wlan_hdd_tdls_timer_restart(pAdapter,
9250 &pTdlsPeer->initiatorWaitTimeoutTimer,
9251 WAIT_TIME_TDLS_INITIATOR);
9252 /* suspend initiator TX until it receives direct packet from the
9253 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
9254 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
9255 &staId, NULL);
9256 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07009257 wlan_hdd_tdls_increment_peer_count(pAdapter);
9258 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009259 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309260
9261 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05309262 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
9263 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309264 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05309265 int ac;
9266 uint8 ucAc[4] = { WLANTL_AC_VO,
9267 WLANTL_AC_VI,
9268 WLANTL_AC_BK,
9269 WLANTL_AC_BE };
9270 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
9271 for(ac=0; ac < 4; ac++)
9272 {
9273 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
9274 pTdlsPeer->staId, ucAc[ac],
9275 tlTid[ac], tlTid[ac], 0, 0,
9276 WLANTL_BI_DIR );
9277 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05309278 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009279 }
9280
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009281 }
9282 break;
9283 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08009284 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05309285 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9286
9287 if ( NULL == pTdlsPeer ) {
9288 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
9289 " (oper %d) not exsting. ignored",
9290 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
9291 return -EINVAL;
9292 }
9293
9294 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9295 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
9296 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
9297 "NL80211_TDLS_DISABLE_LINK");
9298
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009299 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08009300 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009301 long status;
9302
9303 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
9304
Lee Hoonkic1262f22013-01-24 21:59:00 -08009305 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
9306 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009307
9308 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
9309 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
9310 if (status <= 0)
9311 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009312 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07009313 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9314 "%s: Del station failed status %ld",
9315 __func__, status);
9316 return -EPERM;
9317 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07009318 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08009319 }
9320 else
9321 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009322 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9323 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08009324 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08009325 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07009326 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009327 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05309328 {
9329 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9330 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
9331 __func__, MAC_ADDR_ARRAY(peer));
9332
9333 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
9334 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
9335
9336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9337 " %s TDLS External control and Implicit Trigger not enabled ",
9338 __func__);
9339 return -ENOTSUPP;
9340 }
9341
Sunil Dutt41de4e22013-11-14 18:09:02 +05309342
9343 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
9344
9345 if ( NULL == pTdlsPeer ) {
9346 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
9347 " peer not exsting",
9348 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309349 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309350 }
9351 else {
9352 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
9353 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
9354 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309355
9356 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
9357 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309358 break;
9359 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009360 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05309361 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309362 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309363 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9364 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
9365 __func__, MAC_ADDR_ARRAY(peer));
9366
9367 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
9368 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
9369
9370 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9371 " %s TDLS External control and Implicit Trigger not enabled ",
9372 __func__);
9373 return -ENOTSUPP;
9374 }
9375
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309376 /* To cater the requirement of establishing the TDLS link
9377 * irrespective of the data traffic , get an entry of TDLS peer.
9378 */
9379 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
9380 if (pTdlsPeer == NULL) {
9381 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9382 "%s: peer " MAC_ADDRESS_STR " not existing",
9383 __func__, MAC_ADDR_ARRAY(peer));
9384 return -EINVAL;
9385 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05309386
9387 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
9388
9389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9390 " %s TDLS Add Force Peer Failed",
9391 __func__);
9392 return -EINVAL;
9393 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05309394 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05309395 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009396 case NL80211_TDLS_DISCOVERY_REQ:
9397 /* We don't support in-driver setup/teardown/discovery */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309398 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9399 "%s: We don't support in-driver setup/teardown/discovery "
9400 ,__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009401 return -ENOTSUPP;
9402 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309403 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9404 "%s: unsupported event",__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009405 return -ENOTSUPP;
9406 }
9407 return 0;
9408}
Chilam NG571c65a2013-01-19 12:27:36 +05309409
9410int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
9411 struct net_device *dev, u8 *peer)
9412{
Arif Hussaina7c8e412013-11-20 11:06:42 -08009413 hddLog(VOS_TRACE_LEVEL_INFO,
9414 "tdls send discover req: "MAC_ADDRESS_STR,
9415 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05309416
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05309417#if TDLS_MGMT_VERSION2
9418 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
9419 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, 0, NULL, 0);
9420#else
Chilam NG571c65a2013-01-19 12:27:36 +05309421 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
9422 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
Sunil Dutt Undekarieacac6f2014-03-21 14:08:53 +05309423#endif
Chilam NG571c65a2013-01-19 12:27:36 +05309424}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009425#endif
9426
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309427#ifdef WLAN_FEATURE_GTK_OFFLOAD
9428/*
9429 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
9430 * Callback rountine called upon receiving response for
9431 * get offload info
9432 */
9433void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
9434 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
9435{
9436
9437 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309438 tANI_U8 tempReplayCounter[8];
9439 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309440
9441 ENTER();
9442
9443 if (NULL == pAdapter)
9444 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05309445 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309446 "%s: HDD adapter is Null", __func__);
9447 return ;
9448 }
9449
9450 if (NULL == pGtkOffloadGetInfoRsp)
9451 {
9452 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9453 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
9454 return ;
9455 }
9456
9457 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
9458 {
9459 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9460 "%s: wlan Failed to get replay counter value",
9461 __func__);
9462 return ;
9463 }
9464
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309465 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9466 /* Update replay counter */
9467 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
9468 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9469
9470 {
9471 /* changing from little to big endian since supplicant
9472 * works on big endian format
9473 */
9474 int i;
9475 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9476
9477 for (i = 0; i < 8; i++)
9478 {
9479 tempReplayCounter[7-i] = (tANI_U8)p[i];
9480 }
9481 }
9482
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309483 /* Update replay counter to NL */
9484 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309485 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309486}
9487
9488/*
9489 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
9490 * This function is used to offload GTK rekeying job to the firmware.
9491 */
9492int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
9493 struct cfg80211_gtk_rekey_data *data)
9494{
9495 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9496 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9497 hdd_station_ctx_t *pHddStaCtx;
9498 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309499 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309500 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309501 eHalStatus status = eHAL_STATUS_FAILURE;
9502
9503 ENTER();
9504
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309505
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309506 if (NULL == pAdapter)
9507 {
9508 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9509 "%s: HDD adapter is Null", __func__);
9510 return -ENODEV;
9511 }
9512
Sushant Kaushik4b7cb302014-01-06 17:45:01 +05309513 MTRACE(vos_trace(VOS_MODULE_ID_HDD,
9514 TRACE_CODE_HDD_CFG80211_SET_REKEY_DATA,
9515 pAdapter->sessionId, pAdapter->device_mode));
9516
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309517 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309518
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309519 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309520 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309521 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9522 "%s: HDD context is not valid", __func__);
9523 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309524 }
9525
9526 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9527 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9528 if (NULL == hHal)
9529 {
9530 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9531 "%s: HAL context is Null!!!", __func__);
9532 return -EAGAIN;
9533 }
9534
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309535 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
9536 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
9537 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
9538 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309539 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309540 {
9541 /* changing from big to little endian since driver
9542 * works on little endian format
9543 */
9544 tANI_U8 *p =
9545 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
9546 int i;
9547
9548 for (i = 0; i < 8; i++)
9549 {
9550 p[7-i] = data->replay_ctr[i];
9551 }
9552 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309553
9554 if (TRUE == pHddCtx->hdd_wlan_suspended)
9555 {
9556 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309557 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
9558 sizeof (tSirGtkOffloadParams));
9559 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309560 pAdapter->sessionId);
9561
9562 if (eHAL_STATUS_SUCCESS != status)
9563 {
9564 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9565 "%s: sme_SetGTKOffload failed, returned %d",
9566 __func__, status);
9567 return status;
9568 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309569 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9570 "%s: sme_SetGTKOffload successfull", __func__);
9571 }
9572 else
9573 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309574 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9575 "%s: wlan not suspended GTKOffload request is stored",
9576 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309577 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309578
9579 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309580}
9581#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
9582
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309583/*
9584 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
9585 * This function is used to set access control policy
9586 */
9587static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
9588 struct net_device *dev, const struct cfg80211_acl_data *params)
9589{
9590 int i;
9591 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9592 hdd_hostapd_state_t *pHostapdState;
9593 tsap_Config_t *pConfig;
9594 v_CONTEXT_t pVosContext = NULL;
9595 hdd_context_t *pHddCtx;
9596 int status;
9597
9598 ENTER();
9599
9600 if (NULL == pAdapter)
9601 {
9602 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9603 "%s: HDD adapter is Null", __func__);
9604 return -ENODEV;
9605 }
9606
9607 if (NULL == params)
9608 {
9609 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9610 "%s: params is Null", __func__);
9611 return -EINVAL;
9612 }
9613
9614 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9615 status = wlan_hdd_validate_context(pHddCtx);
9616
9617 if (0 != status)
9618 {
9619 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9620 "%s: HDD context is not valid", __func__);
9621 return status;
9622 }
9623
9624 pVosContext = pHddCtx->pvosContext;
9625 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9626
9627 if (NULL == pHostapdState)
9628 {
9629 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9630 "%s: pHostapdState is Null", __func__);
9631 return -EINVAL;
9632 }
9633
9634 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
9635 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
9636
9637 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
9638 {
9639 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
9640
9641 /* default value */
9642 pConfig->num_accept_mac = 0;
9643 pConfig->num_deny_mac = 0;
9644
9645 /**
9646 * access control policy
9647 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
9648 * listed in hostapd.deny file.
9649 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
9650 * listed in hostapd.accept file.
9651 */
9652 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
9653 {
9654 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
9655 }
9656 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
9657 {
9658 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
9659 }
9660 else
9661 {
9662 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9663 "%s:Acl Policy : %d is not supported",
9664 __func__, params->acl_policy);
9665 return -ENOTSUPP;
9666 }
9667
9668 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
9669 {
9670 pConfig->num_accept_mac = params->n_acl_entries;
9671 for (i = 0; i < params->n_acl_entries; i++)
9672 {
9673 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9674 "** Add ACL MAC entry %i in WhiletList :"
9675 MAC_ADDRESS_STR, i,
9676 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9677
9678 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
9679 sizeof(qcmacaddr));
9680 }
9681 }
9682 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
9683 {
9684 pConfig->num_deny_mac = params->n_acl_entries;
9685 for (i = 0; i < params->n_acl_entries; i++)
9686 {
9687 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9688 "** Add ACL MAC entry %i in BlackList :"
9689 MAC_ADDRESS_STR, i,
9690 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9691
9692 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
9693 sizeof(qcmacaddr));
9694 }
9695 }
9696
9697 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
9698 {
9699 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9700 "%s: SAP Set Mac Acl fail", __func__);
9701 return -EINVAL;
9702 }
9703 }
9704 else
9705 {
9706 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Sushant Kaushik8bc7df22014-04-09 17:55:29 +05309707 "%s: Invalid device_mode = %s (%d)",
9708 __func__, hdd_device_modetoString(pAdapter->device_mode),
9709 pAdapter->device_mode);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309710 return -EINVAL;
9711 }
9712
9713 return 0;
9714}
9715
Leo Chang9056f462013-08-01 19:21:11 -07009716#ifdef WLAN_NL80211_TESTMODE
9717#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07009718void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07009719(
9720 void *pAdapter,
9721 void *indCont
9722)
9723{
Leo Changd9df8aa2013-09-26 13:32:26 -07009724 tSirLPHBInd *lphbInd;
9725 struct sk_buff *skb;
c_hpothu73f35e62014-04-18 13:40:08 +05309726 hdd_context_t *pHddCtxt;
Leo Chang9056f462013-08-01 19:21:11 -07009727
9728 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009729 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07009730
c_hpothu73f35e62014-04-18 13:40:08 +05309731 if (pAdapter == NULL)
9732 {
9733 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9734 "%s: pAdapter is NULL\n",__func__);
9735 return;
9736 }
9737
Leo Chang9056f462013-08-01 19:21:11 -07009738 if (NULL == indCont)
9739 {
9740 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009741 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07009742 return;
9743 }
9744
c_hpothu73f35e62014-04-18 13:40:08 +05309745 pHddCtxt = (hdd_context_t *)pAdapter;
Leo Changd9df8aa2013-09-26 13:32:26 -07009746 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07009747 skb = cfg80211_testmode_alloc_event_skb(
c_hpothu73f35e62014-04-18 13:40:08 +05309748 pHddCtxt->wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07009749 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07009750 GFP_ATOMIC);
9751 if (!skb)
9752 {
9753 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9754 "LPHB timeout, NL buffer alloc fail");
9755 return;
9756 }
9757
Leo Changac3ba772013-10-07 09:47:04 -07009758 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07009759 {
9760 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9761 "WLAN_HDD_TM_ATTR_CMD put fail");
9762 goto nla_put_failure;
9763 }
Leo Changac3ba772013-10-07 09:47:04 -07009764 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07009765 {
9766 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9767 "WLAN_HDD_TM_ATTR_TYPE put fail");
9768 goto nla_put_failure;
9769 }
Leo Changac3ba772013-10-07 09:47:04 -07009770 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07009771 sizeof(tSirLPHBInd), lphbInd))
9772 {
9773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9774 "WLAN_HDD_TM_ATTR_DATA put fail");
9775 goto nla_put_failure;
9776 }
Leo Chang9056f462013-08-01 19:21:11 -07009777 cfg80211_testmode_event(skb, GFP_ATOMIC);
9778 return;
9779
9780nla_put_failure:
9781 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9782 "NLA Put fail");
9783 kfree_skb(skb);
9784
9785 return;
9786}
9787#endif /* FEATURE_WLAN_LPHB */
9788
9789static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9790{
9791 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9792 int err = 0;
9793#ifdef FEATURE_WLAN_LPHB
9794 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009795 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009796#endif /* FEATURE_WLAN_LPHB */
9797
9798 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9799 if (err)
9800 {
9801 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9802 "%s Testmode INV ATTR", __func__);
9803 return err;
9804 }
9805
9806 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9807 {
9808 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9809 "%s Testmode INV CMD", __func__);
9810 return -EINVAL;
9811 }
9812
9813 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9814 {
9815#ifdef FEATURE_WLAN_LPHB
9816 /* Low Power Heartbeat configuration request */
9817 case WLAN_HDD_TM_CMD_WLAN_HB:
9818 {
9819 int buf_len;
9820 void *buf;
9821 tSirLPHBReq *hb_params = NULL;
Amar Singhal05852702014-02-04 14:40:00 -08009822 tSirLPHBReq *hb_params_temp = NULL;
Leo Chang9056f462013-08-01 19:21:11 -07009823
9824 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9825 {
9826 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9827 "%s Testmode INV DATA", __func__);
9828 return -EINVAL;
9829 }
9830
9831 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9832 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
Amar Singhal05852702014-02-04 14:40:00 -08009833
9834 hb_params_temp =(tSirLPHBReq *)buf;
9835 if ((hb_params_temp->cmd == LPHB_SET_TCP_PARAMS_INDID) &&
9836 (hb_params_temp->params.lphbTcpParamReq.timePeriodSec == 0))
9837 return -EINVAL;
9838
Leo Chang9056f462013-08-01 19:21:11 -07009839 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9840 if (NULL == hb_params)
9841 {
9842 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9843 "%s Request Buffer Alloc Fail", __func__);
9844 return -EINVAL;
9845 }
9846
9847 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009848 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9849 hb_params,
9850 wlan_hdd_cfg80211_lphb_ind_handler);
9851 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009852 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9854 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009855 vos_mem_free(hb_params);
9856 }
Leo Chang9056f462013-08-01 19:21:11 -07009857 return 0;
9858 }
9859#endif /* FEATURE_WLAN_LPHB */
9860 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309861 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9862 "%s: unsupported event",__func__);
Leo Chang9056f462013-08-01 19:21:11 -07009863 return -EOPNOTSUPP;
9864 }
9865
9866 return err;
9867}
9868#endif /* CONFIG_NL80211_TESTMODE */
9869
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309870static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9871 struct net_device *dev,
9872 int idx, struct survey_info *survey)
9873{
9874 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9875 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309876 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309877 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309878 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309879 v_S7_t snr,rssi;
9880 int status, i, j, filled = 0;
9881
9882 ENTER();
9883
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309884 if (NULL == pAdapter)
9885 {
9886 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9887 "%s: HDD adapter is Null", __func__);
9888 return -ENODEV;
9889 }
9890
9891 if (NULL == wiphy)
9892 {
9893 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9894 "%s: wiphy is Null", __func__);
9895 return -ENODEV;
9896 }
9897
9898 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9899 status = wlan_hdd_validate_context(pHddCtx);
9900
9901 if (0 != status)
9902 {
9903 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9904 "%s: HDD context is not valid", __func__);
9905 return status;
9906 }
9907
Mihir Sheted9072e02013-08-21 17:02:29 +05309908 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9909
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309910 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309911 0 != pAdapter->survey_idx ||
9912 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309913 {
9914 /* The survey dump ops when implemented completely is expected to
9915 * return a survey of all channels and the ops is called by the
9916 * kernel with incremental values of the argument 'idx' till it
9917 * returns -ENONET. But we can only support the survey for the
9918 * operating channel for now. survey_idx is used to track
9919 * that the ops is called only once and then return -ENONET for
9920 * the next iteration
9921 */
9922 pAdapter->survey_idx = 0;
9923 return -ENONET;
9924 }
9925
9926 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9927
9928 wlan_hdd_get_snr(pAdapter, &snr);
9929 wlan_hdd_get_rssi(pAdapter, &rssi);
9930
9931 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9932 hdd_wlan_get_freq(channel, &freq);
9933
9934
9935 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9936 {
9937 if (NULL == wiphy->bands[i])
9938 {
9939 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9940 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9941 continue;
9942 }
9943
9944 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9945 {
9946 struct ieee80211_supported_band *band = wiphy->bands[i];
9947
9948 if (band->channels[j].center_freq == (v_U16_t)freq)
9949 {
9950 survey->channel = &band->channels[j];
9951 /* The Rx BDs contain SNR values in dB for the received frames
9952 * while the supplicant expects noise. So we calculate and
9953 * return the value of noise (dBm)
9954 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9955 */
9956 survey->noise = rssi - snr;
9957 survey->filled = SURVEY_INFO_NOISE_DBM;
9958 filled = 1;
9959 }
9960 }
9961 }
9962
9963 if (filled)
9964 pAdapter->survey_idx = 1;
9965 else
9966 {
9967 pAdapter->survey_idx = 0;
9968 return -ENONET;
9969 }
9970
9971 return 0;
9972}
9973
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309974/*
9975 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9976 * this is called when cfg80211 driver resume
9977 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9978 */
9979int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9980{
9981 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9982 hdd_adapter_t *pAdapter;
9983 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9984 VOS_STATUS status = VOS_STATUS_SUCCESS;
9985
9986 ENTER();
9987
9988 if ( NULL == pHddCtx )
9989 {
9990 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9991 "%s: HddCtx validation failed", __func__);
9992 return 0;
9993 }
9994
9995 if (pHddCtx->isLogpInProgress)
9996 {
9997 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9998 "%s: LOGP in Progress. Ignore!!!", __func__);
9999 return 0;
10000 }
10001
Mihir Shete18156292014-03-11 15:38:30 +053010002 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010003 {
10004 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
10005 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
10006 return 0;
10007 }
10008
10009 spin_lock(&pHddCtx->schedScan_lock);
10010 pHddCtx->isWiphySuspended = FALSE;
10011 if (TRUE != pHddCtx->isSchedScanUpdatePending)
10012 {
10013 spin_unlock(&pHddCtx->schedScan_lock);
10014 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10015 "%s: Return resume is not due to PNO indication", __func__);
10016 return 0;
10017 }
10018 // Reset flag to avoid updatating cfg80211 data old results again
10019 pHddCtx->isSchedScanUpdatePending = FALSE;
10020 spin_unlock(&pHddCtx->schedScan_lock);
10021
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +053010022
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010023 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
10024
10025 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
10026 {
10027 pAdapter = pAdapterNode->pAdapter;
10028 if ( (NULL != pAdapter) &&
10029 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
10030 {
10031 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +053010032 {
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010033 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
10034 "%s: NO SCAN result", __func__);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +053010035 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010036 else
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +053010037 {
10038 /* Acquire wakelock to handle the case where APP's tries to
10039 * suspend immediately after updating the scan results. Whis
10040 * results in app's is in suspended state and not able to
10041 * process the connect request to AP
10042 */
10043 hdd_prevent_suspend_timeout(2000);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010044 cfg80211_sched_scan_results(pHddCtx->wiphy);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +053010045 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010046
10047 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10048 "%s : cfg80211 scan result database updated", __func__);
10049
10050 return 0;
10051
10052 }
10053 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
10054 pAdapterNode = pNext;
10055 }
10056
10057 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
10058 "%s: Failed to find Adapter", __func__);
10059 return 0;
10060}
10061
10062/*
10063 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
10064 * this is called when cfg80211 driver suspends
10065 */
10066int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
10067 struct cfg80211_wowlan *wow)
10068{
10069 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
10070
10071 ENTER();
10072 if (NULL == pHddCtx)
10073 {
10074 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
10075 "%s: HddCtx validation failed", __func__);
10076 return 0;
10077 }
10078
10079 pHddCtx->isWiphySuspended = TRUE;
10080
10081 EXIT();
10082
10083 return 0;
10084}
10085
Jeff Johnson295189b2012-06-20 16:38:30 -070010086/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +053010087static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -070010088{
10089 .add_virtual_intf = wlan_hdd_add_virtual_intf,
10090 .del_virtual_intf = wlan_hdd_del_virtual_intf,
10091 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
10092 .change_station = wlan_hdd_change_station,
10093#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
10094 .add_beacon = wlan_hdd_cfg80211_add_beacon,
10095 .del_beacon = wlan_hdd_cfg80211_del_beacon,
10096 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -070010097#else
10098 .start_ap = wlan_hdd_cfg80211_start_ap,
10099 .change_beacon = wlan_hdd_cfg80211_change_beacon,
10100 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -070010101#endif
10102 .change_bss = wlan_hdd_cfg80211_change_bss,
10103 .add_key = wlan_hdd_cfg80211_add_key,
10104 .get_key = wlan_hdd_cfg80211_get_key,
10105 .del_key = wlan_hdd_cfg80211_del_key,
10106 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -080010107#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -070010108 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -080010109#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010110 .scan = wlan_hdd_cfg80211_scan,
10111 .connect = wlan_hdd_cfg80211_connect,
10112 .disconnect = wlan_hdd_cfg80211_disconnect,
10113 .join_ibss = wlan_hdd_cfg80211_join_ibss,
10114 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
10115 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
10116 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
10117 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -070010118 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
10119 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
DARAM SUDHA39eede62014-02-12 11:16:40 +053010120 .mgmt_tx = wlan_hdd_mgmt_tx,
Jeff Johnson295189b2012-06-20 16:38:30 -070010121#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
10122 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
10123 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
10124 .set_txq_params = wlan_hdd_set_txq_params,
10125#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070010126 .get_station = wlan_hdd_cfg80211_get_station,
10127 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
10128 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -070010129 .add_station = wlan_hdd_cfg80211_add_station,
10130#ifdef FEATURE_WLAN_LFR
10131 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
10132 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
10133 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
10134#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -070010135#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
10136 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
10137#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -080010138#ifdef FEATURE_WLAN_TDLS
10139 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
10140 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
10141#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +053010142#ifdef WLAN_FEATURE_GTK_OFFLOAD
10143 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
10144#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +053010145#ifdef FEATURE_WLAN_SCAN_PNO
10146 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
10147 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
10148#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +053010149 .resume = wlan_hdd_cfg80211_resume_wlan,
10150 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +053010151 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -070010152#ifdef WLAN_NL80211_TESTMODE
10153 .testmode_cmd = wlan_hdd_cfg80211_testmode,
10154#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +053010155 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -070010156};
10157