blob: ee8ec0b100bc89470e9e97497b855bf823670e73 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Wilson Yangef657d32014-01-15 19:19:23 -08002 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303 *
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*/
Jeff Johnson295189b2012-06-20 16:38:30 -070021
22/**========================================================================
23
24 \file wlan_hdd_cfg80211.c
25
26 \brief WLAN Host Device Driver implementation
27
Gopichand Nakkala747461f2013-04-24 19:24:45 +053028 Copyright 2008 (c) Qualcomm Technologies, Inc. All Rights Reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070029
Gopichand Nakkala747461f2013-04-24 19:24:45 +053030 Qualcomm Technologies Confidential and Proprietary.
Jeff Johnson295189b2012-06-20 16:38:30 -070031
32 ========================================================================*/
33
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070034/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070036 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070039 This section contains comments describing changes made to the module.
40 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070044
45
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070046 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070047 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070048 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
50 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070051 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070052 ==========================================================================*/
53
Jeff Johnson295189b2012-06-20 16:38:30 -070054
55#include <linux/version.h>
56#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
59#include <linux/wireless.h>
60#include <wlan_hdd_includes.h>
61#include <net/arp.h>
62#include <net/cfg80211.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_wowl.h>
65#include <aniGlobal.h>
66#include "ccmApi.h"
67#include "sirParams.h"
68#include "dot11f.h"
69#include "wlan_hdd_assoc.h"
70#include "wlan_hdd_wext.h"
71#include "sme_Api.h"
72#include "wlan_hdd_p2p.h"
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_hostapd.h"
75#include "sapInternal.h"
76#include "wlan_hdd_softap_tx_rx.h"
77#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053078#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053079#include "wlan_hdd_power.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070080#ifdef WLAN_BTAMP_FEATURE
81#include "bap_hdd_misc.h"
82#endif
83#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080084#ifdef FEATURE_WLAN_TDLS
85#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053086#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053087#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080088#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053089#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070090#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070091
92#define g_mode_rates_size (12)
93#define a_mode_rates_size (8)
94#define FREQ_BASE_80211G (2407)
95#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070096#define MAX_SCAN_SSID 9
Kiet Lamac06e2c2013-10-23 16:25:07 +053097#define MAX_PENDING_LOG 5
Jeff Johnson295189b2012-06-20 16:38:30 -070098#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
99 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
100
101#define HDD2GHZCHAN(freq, chan, flag) { \
102 .band = IEEE80211_BAND_2GHZ, \
103 .center_freq = (freq), \
104 .hw_value = (chan),\
105 .flags = (flag), \
106 .max_antenna_gain = 0 ,\
107 .max_power = 30, \
108}
109
110#define HDD5GHZCHAN(freq, chan, flag) { \
111 .band = IEEE80211_BAND_5GHZ, \
112 .center_freq = (freq), \
113 .hw_value = (chan),\
114 .flags = (flag), \
115 .max_antenna_gain = 0 ,\
116 .max_power = 30, \
117}
118
119#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
120{\
121 .bitrate = rate, \
122 .hw_value = rate_id, \
123 .flags = flag, \
124}
125
Lee Hoonkic1262f22013-01-24 21:59:00 -0800126#ifndef WLAN_FEATURE_TDLS_DEBUG
127#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
128#else
129#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
130#endif
131
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530132#ifdef WLAN_FEATURE_VOWIFI_11R
133#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
134#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
135#endif
136
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530137static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700138{
139 WLAN_CIPHER_SUITE_WEP40,
140 WLAN_CIPHER_SUITE_WEP104,
141 WLAN_CIPHER_SUITE_TKIP,
142#ifdef FEATURE_WLAN_CCX
143#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
144 WLAN_CIPHER_SUITE_KRK,
145 WLAN_CIPHER_SUITE_CCMP,
146#else
147 WLAN_CIPHER_SUITE_CCMP,
148#endif
149#ifdef FEATURE_WLAN_WAPI
150 WLAN_CIPHER_SUITE_SMS4,
151#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700152#ifdef WLAN_FEATURE_11W
153 WLAN_CIPHER_SUITE_AES_CMAC,
154#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700155};
156
157static inline int is_broadcast_ether_addr(const u8 *addr)
158{
159 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
160 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
161}
162
163static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530164{
Jeff Johnson295189b2012-06-20 16:38:30 -0700165 HDD2GHZCHAN(2412, 1, 0) ,
166 HDD2GHZCHAN(2417, 2, 0) ,
167 HDD2GHZCHAN(2422, 3, 0) ,
168 HDD2GHZCHAN(2427, 4, 0) ,
169 HDD2GHZCHAN(2432, 5, 0) ,
170 HDD2GHZCHAN(2437, 6, 0) ,
171 HDD2GHZCHAN(2442, 7, 0) ,
172 HDD2GHZCHAN(2447, 8, 0) ,
173 HDD2GHZCHAN(2452, 9, 0) ,
174 HDD2GHZCHAN(2457, 10, 0) ,
175 HDD2GHZCHAN(2462, 11, 0) ,
176 HDD2GHZCHAN(2467, 12, 0) ,
177 HDD2GHZCHAN(2472, 13, 0) ,
178 HDD2GHZCHAN(2484, 14, 0) ,
179};
180
Jeff Johnson295189b2012-06-20 16:38:30 -0700181static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
182{
183 HDD2GHZCHAN(2412, 1, 0) ,
184 HDD2GHZCHAN(2437, 6, 0) ,
185 HDD2GHZCHAN(2462, 11, 0) ,
186};
Jeff Johnson295189b2012-06-20 16:38:30 -0700187
188static struct ieee80211_channel hdd_channels_5_GHZ[] =
189{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700190 HDD5GHZCHAN(4920, 240, 0) ,
191 HDD5GHZCHAN(4940, 244, 0) ,
192 HDD5GHZCHAN(4960, 248, 0) ,
193 HDD5GHZCHAN(4980, 252, 0) ,
194 HDD5GHZCHAN(5040, 208, 0) ,
195 HDD5GHZCHAN(5060, 212, 0) ,
196 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700197 HDD5GHZCHAN(5180, 36, 0) ,
198 HDD5GHZCHAN(5200, 40, 0) ,
199 HDD5GHZCHAN(5220, 44, 0) ,
200 HDD5GHZCHAN(5240, 48, 0) ,
201 HDD5GHZCHAN(5260, 52, 0) ,
202 HDD5GHZCHAN(5280, 56, 0) ,
203 HDD5GHZCHAN(5300, 60, 0) ,
204 HDD5GHZCHAN(5320, 64, 0) ,
205 HDD5GHZCHAN(5500,100, 0) ,
206 HDD5GHZCHAN(5520,104, 0) ,
207 HDD5GHZCHAN(5540,108, 0) ,
208 HDD5GHZCHAN(5560,112, 0) ,
209 HDD5GHZCHAN(5580,116, 0) ,
210 HDD5GHZCHAN(5600,120, 0) ,
211 HDD5GHZCHAN(5620,124, 0) ,
212 HDD5GHZCHAN(5640,128, 0) ,
213 HDD5GHZCHAN(5660,132, 0) ,
214 HDD5GHZCHAN(5680,136, 0) ,
215 HDD5GHZCHAN(5700,140, 0) ,
Leo Chang80de3c22013-11-26 10:52:12 -0800216#ifdef FEATURE_WLAN_CH144
217 HDD5GHZCHAN(5720,144, 0) ,
218#endif /* FEATURE_WLAN_CH144 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700219 HDD5GHZCHAN(5745,149, 0) ,
220 HDD5GHZCHAN(5765,153, 0) ,
221 HDD5GHZCHAN(5785,157, 0) ,
222 HDD5GHZCHAN(5805,161, 0) ,
223 HDD5GHZCHAN(5825,165, 0) ,
224};
225
226static struct ieee80211_rate g_mode_rates[] =
227{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530228 HDD_G_MODE_RATETAB(10, 0x1, 0),
229 HDD_G_MODE_RATETAB(20, 0x2, 0),
230 HDD_G_MODE_RATETAB(55, 0x4, 0),
231 HDD_G_MODE_RATETAB(110, 0x8, 0),
232 HDD_G_MODE_RATETAB(60, 0x10, 0),
233 HDD_G_MODE_RATETAB(90, 0x20, 0),
234 HDD_G_MODE_RATETAB(120, 0x40, 0),
235 HDD_G_MODE_RATETAB(180, 0x80, 0),
236 HDD_G_MODE_RATETAB(240, 0x100, 0),
237 HDD_G_MODE_RATETAB(360, 0x200, 0),
238 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530240};
Jeff Johnson295189b2012-06-20 16:38:30 -0700241
242static struct ieee80211_rate a_mode_rates[] =
243{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530244 HDD_G_MODE_RATETAB(60, 0x10, 0),
245 HDD_G_MODE_RATETAB(90, 0x20, 0),
246 HDD_G_MODE_RATETAB(120, 0x40, 0),
247 HDD_G_MODE_RATETAB(180, 0x80, 0),
248 HDD_G_MODE_RATETAB(240, 0x100, 0),
249 HDD_G_MODE_RATETAB(360, 0x200, 0),
250 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700251 HDD_G_MODE_RATETAB(540, 0x800, 0),
252};
253
254static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
255{
256 .channels = hdd_channels_2_4_GHZ,
257 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
258 .band = IEEE80211_BAND_2GHZ,
259 .bitrates = g_mode_rates,
260 .n_bitrates = g_mode_rates_size,
261 .ht_cap.ht_supported = 1,
262 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
263 | IEEE80211_HT_CAP_GRN_FLD
264 | IEEE80211_HT_CAP_DSSSCCK40
265 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
266 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
267 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
268 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
269 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
270 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
271};
272
Jeff Johnson295189b2012-06-20 16:38:30 -0700273static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
274{
275 .channels = hdd_social_channels_2_4_GHZ,
276 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
277 .band = IEEE80211_BAND_2GHZ,
278 .bitrates = g_mode_rates,
279 .n_bitrates = g_mode_rates_size,
280 .ht_cap.ht_supported = 1,
281 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
282 | IEEE80211_HT_CAP_GRN_FLD
283 | IEEE80211_HT_CAP_DSSSCCK40
284 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
285 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
286 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
287 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
288 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
289 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
290};
Jeff Johnson295189b2012-06-20 16:38:30 -0700291
292static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
293{
294 .channels = hdd_channels_5_GHZ,
295 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
296 .band = IEEE80211_BAND_5GHZ,
297 .bitrates = a_mode_rates,
298 .n_bitrates = a_mode_rates_size,
299 .ht_cap.ht_supported = 1,
300 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
301 | IEEE80211_HT_CAP_GRN_FLD
302 | IEEE80211_HT_CAP_DSSSCCK40
303 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
304 | IEEE80211_HT_CAP_SGI_40
305 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
306 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
307 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
308 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
309 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
310 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
311};
312
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530313/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 TX/RX direction for each kind of interface */
315static const struct ieee80211_txrx_stypes
316wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
317 [NL80211_IFTYPE_STATION] = {
318 .tx = 0xffff,
319 .rx = BIT(SIR_MAC_MGMT_ACTION) |
320 BIT(SIR_MAC_MGMT_PROBE_REQ),
321 },
322 [NL80211_IFTYPE_AP] = {
323 .tx = 0xffff,
324 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
325 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
326 BIT(SIR_MAC_MGMT_PROBE_REQ) |
327 BIT(SIR_MAC_MGMT_DISASSOC) |
328 BIT(SIR_MAC_MGMT_AUTH) |
329 BIT(SIR_MAC_MGMT_DEAUTH) |
330 BIT(SIR_MAC_MGMT_ACTION),
331 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700332 [NL80211_IFTYPE_ADHOC] = {
333 .tx = 0xffff,
334 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
335 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
336 BIT(SIR_MAC_MGMT_PROBE_REQ) |
337 BIT(SIR_MAC_MGMT_DISASSOC) |
338 BIT(SIR_MAC_MGMT_AUTH) |
339 BIT(SIR_MAC_MGMT_DEAUTH) |
340 BIT(SIR_MAC_MGMT_ACTION),
341 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700342 [NL80211_IFTYPE_P2P_CLIENT] = {
343 .tx = 0xffff,
344 .rx = BIT(SIR_MAC_MGMT_ACTION) |
345 BIT(SIR_MAC_MGMT_PROBE_REQ),
346 },
347 [NL80211_IFTYPE_P2P_GO] = {
348 /* This is also same as for SoftAP */
349 .tx = 0xffff,
350 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
351 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
352 BIT(SIR_MAC_MGMT_PROBE_REQ) |
353 BIT(SIR_MAC_MGMT_DISASSOC) |
354 BIT(SIR_MAC_MGMT_AUTH) |
355 BIT(SIR_MAC_MGMT_DEAUTH) |
356 BIT(SIR_MAC_MGMT_ACTION),
357 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700358};
359
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800360#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800361static const struct ieee80211_iface_limit
362wlan_hdd_iface_limit[] = {
363 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800364 /* max = 3 ; Our driver create two interfaces during driver init
365 * wlan0 and p2p0 interfaces. p2p0 is considered as station
366 * interface until a group is formed. In JB architecture, once the
367 * group is formed, interface type of p2p0 is changed to P2P GO or
368 * Client.
369 * When supplicant remove the group, it first issue a set interface
370 * cmd to change the mode back to Station. In JB this works fine as
371 * we advertize two station type interface during driver init.
372 * Some vendors create separate interface for P2P GO/Client,
373 * after group formation(Third one). But while group remove
374 * supplicant first tries to change the mode(3rd interface) to STATION
375 * But as we advertized only two sta type interfaces nl80211 was
376 * returning error for the third one which was leading to failure in
377 * delete interface. Ideally while removing the group, supplicant
378 * should not try to change the 3rd interface mode to Station type.
379 * Till we get a fix in wpa_supplicant, we advertize max STA
380 * interface type to 3
381 */
382 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800383 .types = BIT(NL80211_IFTYPE_STATION),
384 },
385 {
386 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700387 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800388 },
389 {
390 .max = 1,
391 .types = BIT(NL80211_IFTYPE_P2P_GO) |
392 BIT(NL80211_IFTYPE_P2P_CLIENT),
393 },
394};
395
396/* By default, only single channel concurrency is allowed */
397static struct ieee80211_iface_combination
398wlan_hdd_iface_combination = {
399 .limits = wlan_hdd_iface_limit,
400 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800401 /*
402 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
403 * and p2p0 interfaces during driver init
404 * Some vendors create separate interface for P2P operations.
405 * wlan0: STA interface
406 * p2p0: P2P Device interface, action frames goes
407 * through this interface.
408 * p2p-xx: P2P interface, After GO negotiation this interface is
409 * created for p2p operations(GO/CLIENT interface).
410 */
411 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800412 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
413 .beacon_int_infra_match = false,
414};
415#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800416
Jeff Johnson295189b2012-06-20 16:38:30 -0700417static struct cfg80211_ops wlan_hdd_cfg80211_ops;
418
419/* Data rate 100KBPS based on IE Index */
420struct index_data_rate_type
421{
422 v_U8_t beacon_rate_index;
423 v_U16_t supported_rate[4];
424};
425
426/* 11B, 11G Rate table include Basic rate and Extended rate
427 The IDX field is the rate index
428 The HI field is the rate when RSSI is strong or being ignored
429 (in this case we report actual rate)
430 The MID field is the rate when RSSI is moderate
431 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
432 The LO field is the rate when RSSI is low
433 (in this case we don't report rates, actual current rate used)
434 */
435static const struct
436{
437 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700438 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700439} supported_data_rate[] =
440{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700441/* IDX HI HM LM LO (RSSI-based index */
442 {2, { 10, 10, 10, 0}},
443 {4, { 20, 20, 10, 0}},
444 {11, { 55, 20, 10, 0}},
445 {12, { 60, 55, 20, 0}},
446 {18, { 90, 55, 20, 0}},
447 {22, {110, 55, 20, 0}},
448 {24, {120, 90, 60, 0}},
449 {36, {180, 120, 60, 0}},
450 {44, {220, 180, 60, 0}},
451 {48, {240, 180, 90, 0}},
452 {66, {330, 180, 90, 0}},
453 {72, {360, 240, 90, 0}},
454 {96, {480, 240, 120, 0}},
455 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700456};
457
458/* MCS Based rate table */
459static struct index_data_rate_type supported_mcs_rate[] =
460{
461/* MCS L20 L40 S20 S40 */
462 {0, {65, 135, 72, 150}},
463 {1, {130, 270, 144, 300}},
464 {2, {195, 405, 217, 450}},
465 {3, {260, 540, 289, 600}},
466 {4, {390, 810, 433, 900}},
467 {5, {520, 1080, 578, 1200}},
468 {6, {585, 1215, 650, 1350}},
469 {7, {650, 1350, 722, 1500}}
470};
471
Leo Chang6f8870f2013-03-26 18:11:36 -0700472#ifdef WLAN_FEATURE_11AC
473
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530474#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700475
476struct index_vht_data_rate_type
477{
478 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530479 v_U16_t supported_VHT80_rate[2];
480 v_U16_t supported_VHT40_rate[2];
481 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700482};
483
484typedef enum
485{
486 DATA_RATE_11AC_MAX_MCS_7,
487 DATA_RATE_11AC_MAX_MCS_8,
488 DATA_RATE_11AC_MAX_MCS_9,
489 DATA_RATE_11AC_MAX_MCS_NA
490} eDataRate11ACMaxMcs;
491
492/* MCS Based VHT rate table */
493static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
494{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530495/* MCS L80 S80 L40 S40 L20 S40*/
496 {0, {293, 325}, {135, 150}, {65, 72}},
497 {1, {585, 650}, {270, 300}, {130, 144}},
498 {2, {878, 975}, {405, 450}, {195, 217}},
499 {3, {1170, 1300}, {540, 600}, {260, 289}},
500 {4, {1755, 1950}, {810, 900}, {390, 433}},
501 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
502 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
503 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
504 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
505 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700506};
507#endif /* WLAN_FEATURE_11AC */
508
Jeff Johnson295189b2012-06-20 16:38:30 -0700509extern struct net_device_ops net_ops_struct;
510
Leo Chang9056f462013-08-01 19:21:11 -0700511#ifdef WLAN_NL80211_TESTMODE
512enum wlan_hdd_tm_attr
513{
514 WLAN_HDD_TM_ATTR_INVALID = 0,
515 WLAN_HDD_TM_ATTR_CMD = 1,
516 WLAN_HDD_TM_ATTR_DATA = 2,
517 WLAN_HDD_TM_ATTR_TYPE = 3,
518 /* keep last */
519 WLAN_HDD_TM_ATTR_AFTER_LAST,
520 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
521};
522
523enum wlan_hdd_tm_cmd
524{
525 WLAN_HDD_TM_CMD_WLAN_HB = 1,
526};
527
528#define WLAN_HDD_TM_DATA_MAX_LEN 5000
529
530static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
531{
532 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
533 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
534 .len = WLAN_HDD_TM_DATA_MAX_LEN },
535};
536#endif /* WLAN_NL80211_TESTMODE */
537
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800538#ifdef FEATURE_WLAN_CH_AVOID
539/*
540 * FUNCTION: wlan_hdd_send_avoid_freq_event
541 * This is called when wlan driver needs to send vendor specific
542 * avoid frequency range event to userspace
543 */
544int wlan_hdd_send_avoid_freq_event(hdd_context_t *pHddCtx,
545 tHddAvoidFreqList *pAvoidFreqList)
546{
547 struct sk_buff *vendor_event;
548
549 ENTER();
550
551 if (!pHddCtx)
552 {
553 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
554 "%s: HDD context is null", __func__);
555 return -1;
556 }
557
558 if (!pAvoidFreqList)
559 {
560 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
561 "%s: pAvoidFreqList is null", __func__);
562 return -1;
563 }
564
565 vendor_event = cfg80211_vendor_event_alloc(pHddCtx->wiphy,
566 sizeof(tHddAvoidFreqList),
567 QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX,
568 GFP_KERNEL);
569 if (!vendor_event)
570 {
571 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
572 "%s: cfg80211_vendor_event_alloc failed", __func__);
573 return -1;
574 }
575
576 memcpy(skb_put(vendor_event, sizeof(tHddAvoidFreqList)),
577 (void *)pAvoidFreqList, sizeof(tHddAvoidFreqList));
578
579 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
580
581 EXIT();
582 return 0;
583}
584#endif /* FEATURE_WLAN_CH_AVOID */
585
586/* vendor specific events */
587static const struct nl80211_vendor_cmd_info wlan_hdd_cfg80211_vendor_events[] =
588{
589#ifdef FEATURE_WLAN_CH_AVOID
590 {
591 .vendor_id = QCOM_NL80211_VENDOR_ID,
592 .subcmd = QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY
593 },
594#endif /* FEATURE_WLAN_CH_AVOID */
595};
596
Jeff Johnson295189b2012-06-20 16:38:30 -0700597/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530598 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530599 * This function is called by hdd_wlan_startup()
600 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530601 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700602 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530603struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700604{
605 struct wiphy *wiphy;
606 ENTER();
607
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530608 /*
609 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700610 */
611 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
612
613 if (!wiphy)
614 {
615 /* Print error and jump into err label and free the memory */
616 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
617 return NULL;
618 }
619
620 return wiphy;
621}
622
623/*
624 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530625 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 * private ioctl to change the band value
627 */
628int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
629{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530630 int i, j;
631 eNVChannelEnabledType channelEnabledState;
632
Jeff Johnsone7245742012-09-05 17:12:55 -0700633 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530634 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700635 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530636
637 if (NULL == wiphy->bands[i])
638 {
639 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
640 __func__, i);
641 continue;
642 }
643
644 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
645 {
646 struct ieee80211_supported_band *band = wiphy->bands[i];
647
648 channelEnabledState = vos_nv_getChannelEnabledState(
649 band->channels[j].hw_value);
650
651 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
652 {
653 // Enable Social channels for P2P
654 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
655 NV_CHANNEL_ENABLE == channelEnabledState)
656 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
657 else
658 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
659 continue;
660 }
661 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
662 {
663 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
664 continue;
665 }
666
667 if (NV_CHANNEL_DISABLE == channelEnabledState ||
668 NV_CHANNEL_INVALID == channelEnabledState)
669 {
670 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
671 }
672 else if (NV_CHANNEL_DFS == channelEnabledState)
673 {
674 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
675 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
676 }
677 else
678 {
679 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
680 |IEEE80211_CHAN_RADAR);
681 }
682 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700683 }
684 return 0;
685}
686/*
687 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530688 * This function is called by hdd_wlan_startup()
689 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700690 * This function is used to initialize and register wiphy structure.
691 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530692int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700693 struct wiphy *wiphy,
694 hdd_config_t *pCfg
695 )
696{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530697 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700698 ENTER();
699
Jeff Johnson295189b2012-06-20 16:38:30 -0700700 /* Now bind the underlying wlan device with wiphy */
701 set_wiphy_dev(wiphy, dev);
702
703 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700704
Kiet Lam6c583332013-10-14 05:37:09 +0530705#ifndef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -0700706 /* the flag for the other case would be initialzed in
707 vos_init_wiphy_from_nv_bin */
Amar Singhal0a402232013-10-11 20:57:16 -0700708 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
Kiet Lam6c583332013-10-14 05:37:09 +0530709#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700710
Amar Singhalfddc28c2013-09-05 13:03:40 -0700711 /* This will disable updating of NL channels from passive to
712 * active if a beacon is received on passive channel. */
713 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700714
Amar Singhalfddc28c2013-09-05 13:03:40 -0700715
Amar Singhala49cbc52013-10-08 18:37:44 -0700716
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700717#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700718 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
719 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
720 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700721 | WIPHY_FLAG_OFFCHAN_TX;
Kiet Lam6c583332013-10-14 05:37:09 +0530722 wiphy->country_ie_pref = NL80211_COUNTRY_IE_IGNORE_CORE;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700723#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700724
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700725#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
726 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800727#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700728 || pCfg->isFastRoamIniFeatureEnabled
729#endif
730#ifdef FEATURE_WLAN_CCX
731 || pCfg->isCcxIniFeatureEnabled
732#endif
733 )
734 {
735 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
736 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800737#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800738#ifdef FEATURE_WLAN_TDLS
739 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
740 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
741#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530742#ifdef FEATURE_WLAN_SCAN_PNO
Hardik Kantilal Patel3dfd8792013-11-13 20:34:57 +0530743 if (pCfg->configPNOScanSupport)
744 {
745 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
746 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
747 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
748 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
749 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530750#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800751
Amar Singhalfddc28c2013-09-05 13:03:40 -0700752#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700753 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
754 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700755 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700756 driver need to determine what to do with both
757 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700758
759 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700760#else
761 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700762#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700763
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530764 wiphy->max_scan_ssids = MAX_SCAN_SSID;
765
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530766 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700767
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530768 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
769
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530771 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 | BIT(NL80211_IFTYPE_P2P_CLIENT)
774 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700775 | BIT(NL80211_IFTYPE_AP);
776
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800777#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800778 if( pCfg->enableMCC )
779 {
780 /* Currently, supports up to two channels */
781 wlan_hdd_iface_combination.num_different_channels = 2;
782
783 if( !pCfg->allowMCCGODiffBI )
784 wlan_hdd_iface_combination.beacon_int_infra_match = true;
785
786 }
787 wiphy->iface_combinations = &wlan_hdd_iface_combination;
788 wiphy->n_iface_combinations = 1;
789#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800790
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 /* Before registering we need to update the ht capabilitied based
792 * on ini values*/
793 if( !pCfg->ShortGI20MhzEnable )
794 {
795 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
796 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
797 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
798 }
799
800 if( !pCfg->ShortGI40MhzEnable )
801 {
802 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
803 }
804
805 if( !pCfg->nChannelBondingMode5GHz )
806 {
807 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
808 }
809
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530810 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
811 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
812
813 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
814 {
815
816 if (NULL == wiphy->bands[i])
817 {
818 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
819 __func__, i);
820 continue;
821 }
822
823 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
824 {
825 struct ieee80211_supported_band *band = wiphy->bands[i];
826
827 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
828 {
829 // Enable social channels for P2P
830 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
831 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
832 else
833 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
834 continue;
835 }
836 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
837 {
838 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
839 continue;
840 }
841 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700842 }
843 /*Initialise the supported cipher suite details*/
844 wiphy->cipher_suites = hdd_cipher_suites;
845 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
846
847 /*signal strength in mBm (100*dBm) */
848 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
849
850#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700851 wiphy->max_remain_on_channel_duration = 1000;
852#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700853
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800854 wiphy->n_vendor_commands = 0;
855 wiphy->vendor_events = wlan_hdd_cfg80211_vendor_events;
856 wiphy->n_vendor_events = ARRAY_SIZE(wlan_hdd_cfg80211_vendor_events);
857
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530858 EXIT();
859 return 0;
860}
861
862/* In this function we are registering wiphy. */
863int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
864{
865 ENTER();
866 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700867 if (0 > wiphy_register(wiphy))
868 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530869 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
871 return -EIO;
872 }
873
874 EXIT();
875 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530876}
Jeff Johnson295189b2012-06-20 16:38:30 -0700877
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530878/* In this function we are updating channel list when,
879 regulatory domain is FCC and country code is US.
880 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
881 As per FCC smart phone is not a indoor device.
882 GO should not opeate on indoor channels */
883void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
884{
885 int j;
886 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
887 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
888 //Default counrtycode from NV at the time of wiphy initialization.
889 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
890 &defaultCountryCode[0]))
891 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -0700892 hddLog(LOGE, FL("Failed to get default country code from NV"));
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530893 }
894 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
895 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530896 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
897 {
898 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
899 return;
900 }
901 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
902 {
903 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
904 // Mark UNII -1 band channel as passive
905 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
906 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
907 }
908 }
909}
910
Jeff Johnson295189b2012-06-20 16:38:30 -0700911/* In this function we will do all post VOS start initialization.
912 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530913 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700914*/
915void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
916{
Jeff Johnson295189b2012-06-20 16:38:30 -0700917 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
918 /* Register for all P2P action, public action etc frames */
919 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
920
Jeff Johnsone7245742012-09-05 17:12:55 -0700921 ENTER();
922
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 /* Right now we are registering these frame when driver is getting
924 initialized. Once we will move to 2.6.37 kernel, in which we have
925 frame register ops, we will move this code as a part of that */
926 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530927 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700928 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
929
930 /* GAS Initial Response */
931 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
932 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530933
Jeff Johnson295189b2012-06-20 16:38:30 -0700934 /* GAS Comeback Request */
935 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
936 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
937
938 /* GAS Comeback Response */
939 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
940 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
941
942 /* P2P Public Action */
943 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530944 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 P2P_PUBLIC_ACTION_FRAME_SIZE );
946
947 /* P2P Action */
948 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
949 (v_U8_t*)P2P_ACTION_FRAME,
950 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700951
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530952 /* WNM BSS Transition Request frame */
953 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
954 (v_U8_t*)WNM_BSS_ACTION_FRAME,
955 WNM_BSS_ACTION_FRAME_SIZE );
956
Chet Lanctot186b5732013-03-18 10:26:30 -0700957#ifdef WLAN_FEATURE_11W
958 /* SA Query Response Action Frame */
959 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
960 (v_U8_t*)SA_QUERY_FRAME_RSP,
961 SA_QUERY_FRAME_RSP_SIZE );
962#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700963}
964
965void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
966{
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
968 /* Register for all P2P action, public action etc frames */
969 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
970
Jeff Johnsone7245742012-09-05 17:12:55 -0700971 ENTER();
972
Jeff Johnson295189b2012-06-20 16:38:30 -0700973 /* Right now we are registering these frame when driver is getting
974 initialized. Once we will move to 2.6.37 kernel, in which we have
975 frame register ops, we will move this code as a part of that */
976 /* GAS Initial Request */
977
978 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
979 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
980
981 /* GAS Initial Response */
982 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
983 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530984
Jeff Johnson295189b2012-06-20 16:38:30 -0700985 /* GAS Comeback Request */
986 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
987 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
988
989 /* GAS Comeback Response */
990 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
991 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
992
993 /* P2P Public Action */
994 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530995 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700996 P2P_PUBLIC_ACTION_FRAME_SIZE );
997
998 /* P2P Action */
999 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1000 (v_U8_t*)P2P_ACTION_FRAME,
1001 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -07001002
1003#ifdef WLAN_FEATURE_11W
1004 /* SA Query Response Action Frame */
1005 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1006 (v_U8_t*)SA_QUERY_FRAME_RSP,
1007 SA_QUERY_FRAME_RSP_SIZE );
1008#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -07001009}
1010
1011#ifdef FEATURE_WLAN_WAPI
1012void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
1013 const u8 *mac_addr, u8 *key , int key_Len)
1014{
1015 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1016 tCsrRoamSetKey setKey;
1017 v_BOOL_t isConnected = TRUE;
1018 int status = 0;
1019 v_U32_t roamId= 0xFF;
1020 tANI_U8 *pKeyPtr = NULL;
1021 int n = 0;
1022
Arif Hussain6d2a3322013-11-17 19:50:10 -08001023 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07001024 __func__,pAdapter->device_mode);
1025
Gopichand Nakkalae7480202013-02-11 15:24:22 +05301026 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07001027 setKey.keyId = key_index; // Store Key ID
1028 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
1029 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
1030 setKey.paeRole = 0 ; // the PAE role
1031 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
1032 {
1033 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
1034 }
1035 else
1036 {
1037 isConnected = hdd_connIsConnected(pHddStaCtx);
1038 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
1039 }
1040 setKey.keyLength = key_Len;
1041 pKeyPtr = setKey.Key;
1042 memcpy( pKeyPtr, key, key_Len);
1043
Arif Hussain6d2a3322013-11-17 19:50:10 -08001044 hddLog(VOS_TRACE_LEVEL_INFO,"%s: WAPI KEY LENGTH:0x%04x",
Jeff Johnson295189b2012-06-20 16:38:30 -07001045 __func__, key_Len);
1046 for (n = 0 ; n < key_Len; n++)
1047 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
1048 __func__,n,setKey.Key[n]);
1049
1050 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
1051 if ( isConnected )
1052 {
1053 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
1054 pAdapter->sessionId, &setKey, &roamId );
1055 }
1056 if ( status != 0 )
1057 {
1058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1059 "[%4d] sme_RoamSetKey returned ERROR status= %d",
1060 __LINE__, status );
1061 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
1062 }
1063}
1064#endif /* FEATURE_WLAN_WAPI*/
1065
1066#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301067int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07001068 beacon_data_t **ppBeacon,
1069 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001070#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301071int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001072 beacon_data_t **ppBeacon,
1073 struct cfg80211_beacon_data *params,
1074 int dtim_period)
1075#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301076{
Jeff Johnson295189b2012-06-20 16:38:30 -07001077 int size;
1078 beacon_data_t *beacon = NULL;
1079 beacon_data_t *old = NULL;
1080 int head_len,tail_len;
1081
Jeff Johnsone7245742012-09-05 17:12:55 -07001082 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001083 if (params->head && !params->head_len)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301084 {
1085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1086 FL("head_len is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301088 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001089
1090 old = pAdapter->sessionCtx.ap.beacon;
1091
1092 if (!params->head && !old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301093 {
1094 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1095 FL("session(%d) old and new heads points to NULL"),
1096 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07001097 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301098 }
1099
1100 if (params->tail && !params->tail_len)
1101 {
1102 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1103 FL("tail_len is zero but tail is not NULL"));
1104 return -EINVAL;
1105 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001106
Jeff Johnson295189b2012-06-20 16:38:30 -07001107#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1108 /* Kernel 3.0 is not updating dtim_period for set beacon */
1109 if (!params->dtim_period)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301110 {
1111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1112 FL("dtim period is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001113 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301114 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001115#endif
1116
1117 if(params->head)
1118 head_len = params->head_len;
1119 else
1120 head_len = old->head_len;
1121
1122 if(params->tail || !old)
1123 tail_len = params->tail_len;
1124 else
1125 tail_len = old->tail_len;
1126
1127 size = sizeof(beacon_data_t) + head_len + tail_len;
1128
1129 beacon = kzalloc(size, GFP_KERNEL);
1130
1131 if( beacon == NULL )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301132 {
1133 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1134 FL("Mem allocation for beacon failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 return -ENOMEM;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301136 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001137
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001138#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001139 if(params->dtim_period || !old )
1140 beacon->dtim_period = params->dtim_period;
1141 else
1142 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001143#else
1144 if(dtim_period || !old )
1145 beacon->dtim_period = dtim_period;
1146 else
1147 beacon->dtim_period = old->dtim_period;
1148#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301149
Jeff Johnson295189b2012-06-20 16:38:30 -07001150 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1151 beacon->tail = beacon->head + head_len;
1152 beacon->head_len = head_len;
1153 beacon->tail_len = tail_len;
1154
1155 if(params->head) {
1156 memcpy (beacon->head,params->head,beacon->head_len);
1157 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301158 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001159 if(old)
1160 memcpy (beacon->head,old->head,beacon->head_len);
1161 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301162
Jeff Johnson295189b2012-06-20 16:38:30 -07001163 if(params->tail) {
1164 memcpy (beacon->tail,params->tail,beacon->tail_len);
1165 }
1166 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301167 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001168 memcpy (beacon->tail,old->tail,beacon->tail_len);
1169 }
1170
1171 *ppBeacon = beacon;
1172
1173 kfree(old);
1174
1175 return 0;
1176
1177}
Jeff Johnson295189b2012-06-20 16:38:30 -07001178
1179v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1180{
1181 int left = length;
1182 v_U8_t *ptr = pIes;
1183 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301184
Jeff Johnson295189b2012-06-20 16:38:30 -07001185 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301186 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001187 elem_id = ptr[0];
1188 elem_len = ptr[1];
1189 left -= 2;
1190 if(elem_len > left)
1191 {
1192 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001193 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 eid,elem_len,left);
1195 return NULL;
1196 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301197 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001198 {
1199 return ptr;
1200 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301201
Jeff Johnson295189b2012-06-20 16:38:30 -07001202 left -= elem_len;
1203 ptr += (elem_len + 2);
1204 }
1205 return NULL;
1206}
1207
Jeff Johnson295189b2012-06-20 16:38:30 -07001208/* Check if rate is 11g rate or not */
1209static int wlan_hdd_rate_is_11g(u8 rate)
1210{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001211 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001212 u8 i;
1213 for (i = 0; i < 8; i++)
1214 {
1215 if(rate == gRateArray[i])
1216 return TRUE;
1217 }
1218 return FALSE;
1219}
1220
1221/* Check for 11g rate and set proper 11g only mode */
1222static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1223 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1224{
1225 u8 i, num_rates = pIe[0];
1226
1227 pIe += 1;
1228 for ( i = 0; i < num_rates; i++)
1229 {
1230 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1231 {
1232 /* If rate set have 11g rate than change the mode to 11G */
1233 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1234 if (pIe[i] & BASIC_RATE_MASK)
1235 {
1236 /* If we have 11g rate as basic rate, it means mode
1237 is 11g only mode.
1238 */
1239 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1240 *pCheckRatesfor11g = FALSE;
1241 }
1242 }
1243 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1244 {
1245 *require_ht = TRUE;
1246 }
1247 }
1248 return;
1249}
1250
1251static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1252{
1253 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1254 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1255 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1256 u8 checkRatesfor11g = TRUE;
1257 u8 require_ht = FALSE;
1258 u8 *pIe=NULL;
1259
1260 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1261
1262 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1263 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1264 if (pIe != NULL)
1265 {
1266 pIe += 1;
1267 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1268 &pConfig->SapHw_mode);
1269 }
1270
1271 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1272 WLAN_EID_EXT_SUPP_RATES);
1273 if (pIe != NULL)
1274 {
1275
1276 pIe += 1;
1277 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1278 &pConfig->SapHw_mode);
1279 }
1280
1281 if( pConfig->channel > 14 )
1282 {
1283 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1284 }
1285
1286 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1287 WLAN_EID_HT_CAPABILITY);
1288
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301289 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001290 {
1291 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1292 if(require_ht)
1293 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1294 }
1295}
1296
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301297static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1298 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1299{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001300 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301301 v_U8_t *pIe = NULL;
1302 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1303
1304 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1305 pBeacon->tail, pBeacon->tail_len);
1306
1307 if (pIe)
1308 {
1309 ielen = pIe[1] + 2;
1310 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1311 {
1312 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1313 }
1314 else
1315 {
1316 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1317 return -EINVAL;
1318 }
1319 *total_ielen += ielen;
1320 }
1321 return 0;
1322}
1323
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001324static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1325 v_U8_t *genie, v_U8_t *total_ielen)
1326{
1327 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1328 int left = pBeacon->tail_len;
1329 v_U8_t *ptr = pBeacon->tail;
1330 v_U8_t elem_id, elem_len;
1331 v_U16_t ielen = 0;
1332
1333 if ( NULL == ptr || 0 == left )
1334 return;
1335
1336 while (left >= 2)
1337 {
1338 elem_id = ptr[0];
1339 elem_len = ptr[1];
1340 left -= 2;
1341 if (elem_len > left)
1342 {
1343 hddLog( VOS_TRACE_LEVEL_ERROR,
1344 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1345 elem_id, elem_len, left);
1346 return;
1347 }
1348 if (IE_EID_VENDOR == elem_id)
1349 {
1350 /* skipping the VSIE's which we don't want to include or
1351 * it will be included by existing code
1352 */
1353 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1354#ifdef WLAN_FEATURE_WFD
1355 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1356#endif
1357 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1358 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1359 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1360 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1361 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1362 {
1363 ielen = ptr[1] + 2;
1364 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1365 {
1366 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1367 *total_ielen += ielen;
1368 }
1369 else
1370 {
1371 hddLog( VOS_TRACE_LEVEL_ERROR,
1372 "IE Length is too big "
1373 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1374 elem_id, elem_len, *total_ielen);
1375 }
1376 }
1377 }
1378
1379 left -= elem_len;
1380 ptr += (elem_len + 2);
1381 }
1382 return;
1383}
1384
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001385#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001386static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1387 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001388#else
1389static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1390 struct cfg80211_beacon_data *params)
1391#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001392{
1393 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301394 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001396 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001397
1398 genie = vos_mem_malloc(MAX_GENIE_LEN);
1399
1400 if(genie == NULL) {
1401
1402 return -ENOMEM;
1403 }
1404
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301405 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1406 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301408 hddLog(LOGE,
1409 FL("Adding WPS IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301410 ret = -EINVAL;
1411 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001412 }
1413
1414#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301415 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1416 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1417 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301418 hddLog(LOGE,
1419 FL("Adding WFD IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301420 ret = -EINVAL;
1421 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001422 }
1423#endif
1424
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301425 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1426 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001427 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301428 hddLog(LOGE,
1429 FL("Adding P2P IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301430 ret = -EINVAL;
1431 goto done;
1432 }
1433
1434 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1435 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001436 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001438
1439 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1440 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1441 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1442 {
1443 hddLog(LOGE,
1444 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001445 ret = -EINVAL;
1446 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001447 }
1448
1449 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1450 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1451 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1452 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1453 ==eHAL_STATUS_FAILURE)
1454 {
1455 hddLog(LOGE,
1456 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001457 ret = -EINVAL;
1458 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001459 }
1460
1461 // Added for ProResp IE
1462 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1463 {
1464 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1465 u8 probe_rsp_ie_len[3] = {0};
1466 u8 counter = 0;
1467 /* Check Probe Resp Length if it is greater then 255 then Store
1468 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1469 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1470 Store More then 255 bytes into One Variable.
1471 */
1472 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1473 {
1474 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1475 {
1476 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1477 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1478 }
1479 else
1480 {
1481 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1482 rem_probe_resp_ie_len = 0;
1483 }
1484 }
1485
1486 rem_probe_resp_ie_len = 0;
1487
1488 if (probe_rsp_ie_len[0] > 0)
1489 {
1490 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1491 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1492 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1493 probe_rsp_ie_len[0], NULL,
1494 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1495 {
1496 hddLog(LOGE,
1497 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001498 ret = -EINVAL;
1499 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001500 }
1501 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1502 }
1503
1504 if (probe_rsp_ie_len[1] > 0)
1505 {
1506 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1507 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1508 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1509 probe_rsp_ie_len[1], NULL,
1510 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1511 {
1512 hddLog(LOGE,
1513 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001514 ret = -EINVAL;
1515 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001516 }
1517 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1518 }
1519
1520 if (probe_rsp_ie_len[2] > 0)
1521 {
1522 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1523 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1524 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1525 probe_rsp_ie_len[2], NULL,
1526 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1527 {
1528 hddLog(LOGE,
1529 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001530 ret = -EINVAL;
1531 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001532 }
1533 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1534 }
1535
1536 if (probe_rsp_ie_len[1] == 0 )
1537 {
1538 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1539 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1540 eANI_BOOLEAN_FALSE) )
1541 {
1542 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001543 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001544 }
1545 }
1546
1547 if (probe_rsp_ie_len[2] == 0 )
1548 {
1549 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1550 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1551 eANI_BOOLEAN_FALSE) )
1552 {
1553 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001554 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 }
1556 }
1557
1558 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1559 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1560 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1561 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1562 == eHAL_STATUS_FAILURE)
1563 {
1564 hddLog(LOGE,
1565 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001566 ret = -EINVAL;
1567 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001568 }
1569 }
1570 else
1571 {
1572 // Reset WNI_CFG_PROBE_RSP Flags
1573 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1574
1575 hddLog(VOS_TRACE_LEVEL_INFO,
1576 "%s: No Probe Response IE received in set beacon",
1577 __func__);
1578 }
1579
1580 // Added for AssocResp IE
1581 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1582 {
1583 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1584 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1585 params->assocresp_ies_len, NULL,
1586 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1587 {
1588 hddLog(LOGE,
1589 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001590 ret = -EINVAL;
1591 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001592 }
1593
1594 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1595 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1596 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1597 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1598 == eHAL_STATUS_FAILURE)
1599 {
1600 hddLog(LOGE,
1601 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001602 ret = -EINVAL;
1603 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001604 }
1605 }
1606 else
1607 {
1608 hddLog(VOS_TRACE_LEVEL_INFO,
1609 "%s: No Assoc Response IE received in set beacon",
1610 __func__);
1611
1612 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1613 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1614 eANI_BOOLEAN_FALSE) )
1615 {
1616 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001617 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 }
1619 }
1620
Jeff Johnsone7245742012-09-05 17:12:55 -07001621done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001622 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301623 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001624}
Jeff Johnson295189b2012-06-20 16:38:30 -07001625
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301626/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 * FUNCTION: wlan_hdd_validate_operation_channel
1628 * called by wlan_hdd_cfg80211_start_bss() and
1629 * wlan_hdd_cfg80211_set_channel()
1630 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301631 * channel list.
1632 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001633VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001634{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301635
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 v_U32_t num_ch = 0;
1637 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1638 u32 indx = 0;
1639 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301640 v_U8_t fValidChannel = FALSE, count = 0;
1641 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301642
Jeff Johnson295189b2012-06-20 16:38:30 -07001643 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1644
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301645 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001646 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301647 /* Validate the channel */
1648 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001649 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301650 if ( channel == rfChannels[count].channelNum )
1651 {
1652 fValidChannel = TRUE;
1653 break;
1654 }
1655 }
1656 if (fValidChannel != TRUE)
1657 {
1658 hddLog(VOS_TRACE_LEVEL_ERROR,
1659 "%s: Invalid Channel [%d]", __func__, channel);
1660 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 }
1662 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301663 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001664 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301665 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1666 valid_ch, &num_ch))
1667 {
1668 hddLog(VOS_TRACE_LEVEL_ERROR,
1669 "%s: failed to get valid channel list", __func__);
1670 return VOS_STATUS_E_FAILURE;
1671 }
1672 for (indx = 0; indx < num_ch; indx++)
1673 {
1674 if (channel == valid_ch[indx])
1675 {
1676 break;
1677 }
1678 }
1679
1680 if (indx >= num_ch)
1681 {
1682 hddLog(VOS_TRACE_LEVEL_ERROR,
1683 "%s: Invalid Channel [%d]", __func__, channel);
1684 return VOS_STATUS_E_FAILURE;
1685 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001686 }
1687 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301688
Jeff Johnson295189b2012-06-20 16:38:30 -07001689}
1690
Viral Modi3a32cc52013-02-08 11:14:52 -08001691/**
1692 * FUNCTION: wlan_hdd_cfg80211_set_channel
1693 * This function is used to set the channel number
1694 */
1695static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1696 struct ieee80211_channel *chan,
1697 enum nl80211_channel_type channel_type
1698 )
1699{
1700 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001701 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001702 hdd_adapter_t *pAdapter = NULL;
1703 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301704 hdd_context_t *pHddCtx;
1705 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001706
1707 ENTER();
1708
1709 if( NULL == dev )
1710 {
1711 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001712 "%s: Called with dev = NULL.", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001713 return -ENODEV;
1714 }
1715 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1716
1717 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001718 "%s: device_mode = %d freq = %d", __func__,
Viral Modi3a32cc52013-02-08 11:14:52 -08001719 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301720
1721 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1722 status = wlan_hdd_validate_context(pHddCtx);
1723
1724 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001725 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301726 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1727 "%s: HDD context is not valid", __func__);
1728 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001729 }
1730
1731 /*
1732 * Do freq to chan conversion
1733 * TODO: for 11a
1734 */
1735
1736 channel = ieee80211_frequency_to_channel(freq);
1737
1738 /* Check freq range */
1739 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1740 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1741 {
1742 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001743 "%s: Channel [%d] is outside valid range from %d to %d",
Viral Modi3a32cc52013-02-08 11:14:52 -08001744 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1745 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1746 return -EINVAL;
1747 }
1748
1749 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1750
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301751 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1752 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001753 {
1754 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1755 {
1756 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001757 "%s: Invalid Channel [%d]", __func__, channel);
Viral Modi3a32cc52013-02-08 11:14:52 -08001758 return -EINVAL;
1759 }
1760 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1761 "%s: set channel to [%d] for device mode =%d",
1762 __func__, channel,pAdapter->device_mode);
1763 }
1764 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001765 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001766 )
1767 {
1768 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1769 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1770 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1771
1772 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1773 {
1774 /* Link is up then return cant set channel*/
1775 hddLog( VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001776 "%s: IBSS Associated, can't set the channel", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001777 return -EINVAL;
1778 }
1779
1780 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1781 pHddStaCtx->conn_info.operationChannel = channel;
1782 pRoamProfile->ChannelInfo.ChannelList =
1783 &pHddStaCtx->conn_info.operationChannel;
1784 }
1785 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001786 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001787 )
1788 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301789 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1790 {
1791 if(VOS_STATUS_SUCCESS !=
1792 wlan_hdd_validate_operation_channel(pAdapter,channel))
1793 {
1794 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001795 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301796 return -EINVAL;
1797 }
1798 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1799 }
1800 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001801 {
1802 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1803
1804 /* If auto channel selection is configured as enable/ 1 then ignore
1805 channel set by supplicant
1806 */
1807 if ( cfg_param->apAutoChannelSelection )
1808 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301809 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1810 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001811 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1812 "%s: set channel to auto channel (0) for device mode =%d",
1813 __func__, pAdapter->device_mode);
1814 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301815 else
1816 {
1817 if(VOS_STATUS_SUCCESS !=
1818 wlan_hdd_validate_operation_channel(pAdapter,channel))
1819 {
1820 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001821 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301822 return -EINVAL;
1823 }
1824 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1825 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001826 }
1827 }
1828 else
1829 {
1830 hddLog(VOS_TRACE_LEVEL_FATAL,
1831 "%s: Invalid device mode failed to set valid channel", __func__);
1832 return -EINVAL;
1833 }
1834 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301835 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001836}
1837
Jeff Johnson295189b2012-06-20 16:38:30 -07001838#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1839static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1840 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001841#else
1842static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1843 struct cfg80211_beacon_data *params,
1844 const u8 *ssid, size_t ssid_len,
1845 enum nl80211_hidden_ssid hidden_ssid)
1846#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001847{
1848 tsap_Config_t *pConfig;
1849 beacon_data_t *pBeacon = NULL;
1850 struct ieee80211_mgmt *pMgmt_frame;
1851 v_U8_t *pIe=NULL;
1852 v_U16_t capab_info;
1853 eCsrAuthType RSNAuthType;
1854 eCsrEncryptionType RSNEncryptType;
1855 eCsrEncryptionType mcRSNEncryptType;
1856 int status = VOS_STATUS_SUCCESS;
1857 tpWLAN_SAPEventCB pSapEventCallback;
1858 hdd_hostapd_state_t *pHostapdState;
1859 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1860 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301861 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001862 struct qc_mac_acl_entry *acl_entry = NULL;
1863 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001864 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001865
1866 ENTER();
1867
1868 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1869
1870 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1871
1872 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1873
1874 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1875
1876 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1877
1878 //channel is already set in the set_channel Call back
1879 //pConfig->channel = pCommitConfig->channel;
1880
1881 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301882 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001883 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1884
1885 pConfig->dtim_period = pBeacon->dtim_period;
1886
Arif Hussain6d2a3322013-11-17 19:50:10 -08001887 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***",
Jeff Johnson295189b2012-06-20 16:38:30 -07001888 pConfig->dtim_period);
1889
1890
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001891 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001892 {
1893 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001894 WLAN_EID_COUNTRY);
Kiet Lam083504c2013-11-25 14:17:45 +05301895 if(memcmp(pHddCtx->cfg_ini->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0)
1896 {
1897 tANI_BOOLEAN restartNeeded;
1898 pConfig->ieee80211d = 1;
1899 vos_mem_copy(pConfig->countryCode, pHddCtx->cfg_ini->apCntryCode, 3);
1900 sme_setRegInfo(hHal, pConfig->countryCode);
1901 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
1902 }
1903 else if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001904 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001905 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001906 pConfig->ieee80211d = 1;
1907 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1908 sme_setRegInfo(hHal, pConfig->countryCode);
1909 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001911 else
1912 {
1913 pConfig->ieee80211d = 0;
1914 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301915 /*
1916 * If auto channel is configured i.e. channel is 0,
1917 * so skip channel validation.
1918 */
1919 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1920 {
1921 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1922 {
1923 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001924 "%s: Invalid Channel [%d]", __func__, pConfig->channel);
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301925 return -EINVAL;
1926 }
1927 }
1928 else
1929 {
1930 if(1 != pHddCtx->is_dynamic_channel_range_set)
1931 {
1932 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1933 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1934 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1935 }
1936 pHddCtx->is_dynamic_channel_range_set = 0;
1937 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001938 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001939 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001940 {
1941 pConfig->ieee80211d = 0;
1942 }
1943 pConfig->authType = eSAP_AUTO_SWITCH;
1944
1945 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301946
1947 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1949
1950 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1951
1952 /*Set wps station to configured*/
1953 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1954
1955 if(pIe)
1956 {
1957 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1958 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08001959 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***");
Jeff Johnson295189b2012-06-20 16:38:30 -07001960 return -EINVAL;
1961 }
1962 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1963 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001964 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001965 /* Check 15 bit of WPS IE as it contain information for wps state
1966 * WPS state
1967 */
1968 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1969 {
1970 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1971 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1972 {
1973 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1974 }
1975 }
1976 }
1977 else
1978 {
1979 pConfig->wps_state = SAP_WPS_DISABLED;
1980 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301981 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001982
1983 pConfig->RSNWPAReqIELength = 0;
1984 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301985 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001986 WLAN_EID_RSN);
1987 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301988 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001989 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1990 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1991 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301992 /* The actual processing may eventually be more extensive than
1993 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 * by the app.
1995 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301996 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001997 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1998 &RSNEncryptType,
1999 &mcRSNEncryptType,
2000 &RSNAuthType,
2001 pConfig->pRSNWPAReqIE[1]+2,
2002 pConfig->pRSNWPAReqIE );
2003
2004 if( VOS_STATUS_SUCCESS == status )
2005 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302006 /* Now copy over all the security attributes you have
2007 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 * */
2009 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2010 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2011 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2012 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302013 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002014 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002015 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2016 }
2017 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302018
Jeff Johnson295189b2012-06-20 16:38:30 -07002019 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2020 pBeacon->tail, pBeacon->tail_len);
2021
2022 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
2023 {
2024 if (pConfig->pRSNWPAReqIE)
2025 {
2026 /*Mixed mode WPA/WPA2*/
2027 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
2028 pConfig->RSNWPAReqIELength += pIe[1] + 2;
2029 }
2030 else
2031 {
2032 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2033 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2034 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302035 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002036 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2037 &RSNEncryptType,
2038 &mcRSNEncryptType,
2039 &RSNAuthType,
2040 pConfig->pRSNWPAReqIE[1]+2,
2041 pConfig->pRSNWPAReqIE );
2042
2043 if( VOS_STATUS_SUCCESS == status )
2044 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302045 /* Now copy over all the security attributes you have
2046 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002047 * */
2048 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2049 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2050 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2051 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302052 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002053 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002054 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2055 }
2056 }
2057 }
2058
Jeff Johnson4416a782013-03-25 14:17:50 -07002059 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
2060 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
2061 return -EINVAL;
2062 }
2063
Jeff Johnson295189b2012-06-20 16:38:30 -07002064 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
2065
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002066#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002067 if (params->ssid != NULL)
2068 {
2069 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
2070 pConfig->SSIDinfo.ssid.length = params->ssid_len;
2071 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2072 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2073 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002074#else
2075 if (ssid != NULL)
2076 {
2077 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
2078 pConfig->SSIDinfo.ssid.length = ssid_len;
2079 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2080 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2081 }
2082#endif
2083
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302084 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302086
Jeff Johnson295189b2012-06-20 16:38:30 -07002087 /* default value */
2088 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
2089 pConfig->num_accept_mac = 0;
2090 pConfig->num_deny_mac = 0;
2091
2092 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2093 pBeacon->tail, pBeacon->tail_len);
2094
2095 /* pIe for black list is following form:
2096 type : 1 byte
2097 length : 1 byte
2098 OUI : 4 bytes
2099 acl type : 1 byte
2100 no of mac addr in black list: 1 byte
2101 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302102 */
2103 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002104 {
2105 pConfig->SapMacaddr_acl = pIe[6];
2106 pConfig->num_deny_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002107 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002108 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302109 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2110 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002111 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2112 for (i = 0; i < pConfig->num_deny_mac; i++)
2113 {
2114 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2115 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302116 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002117 }
2118 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2119 pBeacon->tail, pBeacon->tail_len);
2120
2121 /* pIe for white list is following form:
2122 type : 1 byte
2123 length : 1 byte
2124 OUI : 4 bytes
2125 acl type : 1 byte
2126 no of mac addr in white list: 1 byte
2127 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302128 */
2129 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002130 {
2131 pConfig->SapMacaddr_acl = pIe[6];
2132 pConfig->num_accept_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002133 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002134 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302135 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2136 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002137 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2138 for (i = 0; i < pConfig->num_accept_mac; i++)
2139 {
2140 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2141 acl_entry++;
2142 }
2143 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302144
Jeff Johnson295189b2012-06-20 16:38:30 -07002145 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2146
Jeff Johnsone7245742012-09-05 17:12:55 -07002147#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002148 /* Overwrite the hostapd setting for HW mode only for 11ac.
Kiet Lam0f320422013-11-21 19:29:17 +05302149 * This is valid only if mode is set to 11n in hostapd, either AUTO or
2150 * 11ac in .ini and 11ac is supported by both host and firmware.
2151 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode)
2152 */
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002153 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2154 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302155 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002156 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
Kiet Lam0f320422013-11-21 19:29:17 +05302157 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) &&
2158 (sme_IsFeatureSupportedByDriver(DOT11AC)) && (sme_IsFeatureSupportedByFW(DOT11AC)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002159 {
2160 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002161
2162 /* Disable VHT support in 2.4 GHz band */
2163 if (pConfig->channel <= 14 &&
2164 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2165 {
2166 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2167 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002168 }
2169#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302170
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002171 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2172 {
2173 sme_SelectCBMode(hHal,
2174 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2175 pConfig->channel);
2176 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002177 // ht_capab is not what the name conveys,this is used for protection bitmap
2178 pConfig->ht_capab =
2179 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2180
2181 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2182 {
2183 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2184 return -EINVAL;
2185 }
2186
2187 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302188 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002189 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2190 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302191 pConfig->obssProtEnabled =
2192 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002193
Arif Hussain6d2a3322013-11-17 19:50:10 -08002194 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR),
Jeff Johnson295189b2012-06-20 16:38:30 -07002195 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002196 hddLog(LOGW,FL("ssid =%s, beaconint=%d, channel=%d"),
2197 pConfig->SSIDinfo.ssid.ssId, (int)pConfig->beacon_int,
2198 (int)pConfig->channel);
2199 hddLog(LOGW,FL("hw_mode=%x, privacy=%d, authType=%d"),
2200 pConfig->SapHw_mode, pConfig->privacy,
2201 pConfig->authType);
2202 hddLog(LOGW,FL("RSN/WPALen=%d, Uapsd = %d"),
2203 (int)pConfig->RSNWPAReqIELength, pConfig->UapsdEnable);
2204 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d"),
2205 pConfig->protEnabled, pConfig->obssProtEnabled);
Jeff Johnson295189b2012-06-20 16:38:30 -07002206
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302207 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002208 {
2209 //Bss already started. just return.
2210 //TODO Probably it should update some beacon params.
2211 hddLog( LOGE, "Bss Already started...Ignore the request");
2212 EXIT();
2213 return 0;
2214 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302215
Jeff Johnson295189b2012-06-20 16:38:30 -07002216 pConfig->persona = pHostapdAdapter->device_mode;
2217
2218 pSapEventCallback = hdd_hostapd_SAPEventCB;
2219 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2220 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2221 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002222 hddLog(LOGE,FL("SAP Start Bss fail"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002223 return -EINVAL;
2224 }
2225
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302226 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002227 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2228
2229 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302230
Jeff Johnson295189b2012-06-20 16:38:30 -07002231 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302232 {
2233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002234 ("ERROR: HDD vos wait for single_event failed!!"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002235 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002236 VOS_ASSERT(0);
2237 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302238
Jeff Johnson295189b2012-06-20 16:38:30 -07002239 //Succesfully started Bss update the state bit.
2240 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2241
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002242#ifdef WLAN_FEATURE_P2P_DEBUG
2243 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2244 {
2245 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2246 {
2247 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2248 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002249 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002250 }
2251 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2252 {
2253 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2254 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002255 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002256 }
2257 }
2258#endif
2259
Jeff Johnson295189b2012-06-20 16:38:30 -07002260 pHostapdState->bCommit = TRUE;
2261 EXIT();
2262
2263 return 0;
2264}
2265
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002266#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302267static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2268 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002269 struct beacon_parameters *params)
2270{
2271 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302272 hdd_context_t *pHddCtx;
2273 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002274
2275 ENTER();
2276
Arif Hussain6d2a3322013-11-17 19:50:10 -08002277 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d",pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002278
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302279 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2280 status = wlan_hdd_validate_context(pHddCtx);
2281
2282 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002283 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302284 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2285 "%s: HDD context is not valid", __func__);
2286 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002287 }
2288
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302289 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002290 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002291 )
2292 {
2293 beacon_data_t *old,*new;
2294
2295 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302296
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302298 {
2299 hddLog(VOS_TRACE_LEVEL_WARN,
2300 FL("already beacon info added to session(%d)"),
2301 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002302 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302303 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002304
2305 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2306
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302307 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002308 {
2309 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002310 "%s:Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002311 return -EINVAL;
2312 }
2313
2314 pAdapter->sessionCtx.ap.beacon = new;
2315
2316 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2317 }
2318
2319 EXIT();
2320 return status;
2321}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302322
2323static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002324 struct net_device *dev,
2325 struct beacon_parameters *params)
2326{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302327 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302328 hdd_context_t *pHddCtx;
2329 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002330
2331 ENTER();
2332
Arif Hussain6d2a3322013-11-17 19:50:10 -08002333 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002334 __func__,pAdapter->device_mode);
2335
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302336 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2337 status = wlan_hdd_validate_context(pHddCtx);
2338
2339 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002340 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302341 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2342 "%s: HDD context is not valid", __func__);
2343 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002344 }
2345
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302346 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002347 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302348 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002349 {
2350 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302351
Jeff Johnson295189b2012-06-20 16:38:30 -07002352 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302353
Jeff Johnson295189b2012-06-20 16:38:30 -07002354 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302355 {
2356 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2357 FL("session(%d) old and new heads points to NULL"),
2358 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002359 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302360 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002361
2362 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2363
2364 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302365 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002366 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002367 return -EINVAL;
2368 }
2369
2370 pAdapter->sessionCtx.ap.beacon = new;
2371
2372 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2373 }
2374
2375 EXIT();
2376 return status;
2377}
2378
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002379#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2380
2381#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002382static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2383 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002384#else
2385static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2386 struct net_device *dev)
2387#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002388{
2389 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002390 hdd_context_t *pHddCtx = NULL;
2391 hdd_scaninfo_t *pScanInfo = NULL;
2392 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302393 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002394
2395 ENTER();
2396
2397 if (NULL == pAdapter)
2398 {
2399 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002400 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002401 return -ENODEV;
2402 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002403
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302404 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2405 status = wlan_hdd_validate_context(pHddCtx);
2406
2407 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002408 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302409 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2410 "%s: HDD context is not valid", __func__);
2411 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002412 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002413
2414 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2415 if (NULL == staAdapter)
2416 {
2417 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2418 if (NULL == staAdapter)
2419 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002420 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2421 "%s: HDD adapter context for STA/P2P-CLI is Null",
2422 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002423 }
2424 }
2425
2426 pScanInfo = &pHddCtx->scan_info;
2427
Arif Hussain6d2a3322013-11-17 19:50:10 -08002428 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002429 __func__,pAdapter->device_mode);
2430
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002431 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002432 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302433 long ret;
2434
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002435 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05302436 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId,
2437 eCSR_SCAN_ABORT_DEFAULT);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302438 ret = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002439 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002440 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302441 if (ret <= 0)
Jeff Johnsone7245742012-09-05 17:12:55 -07002442 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302444 FL("Timeout occurred while waiting for abortscan %ld"),
2445 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002446
2447 if (pHddCtx->isLogpInProgress)
2448 {
2449 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2450 "%s: LOGP in Progress. Ignore!!!", __func__);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302451
2452 VOS_ASSERT(pScanInfo->mScanPending);
Yue Ma4f55ef32014-01-23 16:45:33 -08002453 return -EAGAIN;
2454 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002455 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002456 }
2457 }
2458
Arun Kumar Khandavallia3bd8002014-01-17 16:21:19 +05302459 hdd_hostapd_stop(dev);
2460
Jeff Johnson295189b2012-06-20 16:38:30 -07002461 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002462 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002463 )
2464 {
2465 beacon_data_t *old;
2466
2467 old = pAdapter->sessionCtx.ap.beacon;
2468
2469 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302470 {
2471 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2472 FL("session(%d) beacon data points to NULL"),
2473 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002474 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302475 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002476
Jeff Johnson295189b2012-06-20 16:38:30 -07002477 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002478
2479 mutex_lock(&pHddCtx->sap_lock);
2480 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2481 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002482 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002483 {
2484 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2485
2486 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2487
2488 if (!VOS_IS_STATUS_SUCCESS(status))
2489 {
2490 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002491 ("ERROR: HDD vos wait for single_event failed!!"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002492 VOS_ASSERT(0);
2493 }
2494 }
2495 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2496 }
2497 mutex_unlock(&pHddCtx->sap_lock);
2498
2499 if(status != VOS_STATUS_SUCCESS)
2500 {
2501 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002502 "%s:Error!!! Stopping the BSS",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002503 return -EINVAL;
2504 }
2505
Jeff Johnson4416a782013-03-25 14:17:50 -07002506 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002507 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2508 ==eHAL_STATUS_FAILURE)
2509 {
2510 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002511 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002512 }
2513
Jeff Johnson4416a782013-03-25 14:17:50 -07002514 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002515 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2516 eANI_BOOLEAN_FALSE) )
2517 {
2518 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002519 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002520 }
2521
2522 // Reset WNI_CFG_PROBE_RSP Flags
2523 wlan_hdd_reset_prob_rspies(pAdapter);
2524
2525 pAdapter->sessionCtx.ap.beacon = NULL;
2526 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002527#ifdef WLAN_FEATURE_P2P_DEBUG
2528 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2529 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2530 {
2531 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2532 "GO got removed");
2533 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2534 }
2535#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002536 }
2537 EXIT();
2538 return status;
2539}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002540
2541#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2542
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302543static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2544 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002545 struct cfg80211_ap_settings *params)
2546{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302547 hdd_adapter_t *pAdapter;
2548 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302549 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002550
2551 ENTER();
2552
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302553 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002554 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302555 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302556 "%s: Device is Null", __func__);
2557 return -ENODEV;
2558 }
2559
2560 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2561 if (NULL == pAdapter)
2562 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302564 "%s: HDD adapter is Null", __func__);
2565 return -ENODEV;
2566 }
2567
2568 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2569 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302570 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302571 "%s: HDD adapter magic is invalid", __func__);
2572 return -ENODEV;
2573 }
2574
2575 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302576 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302577
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302578 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302579 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302580 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2581 "%s: HDD context is not valid", __func__);
2582 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302583 }
2584
2585 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2586 __func__, pAdapter->device_mode);
2587
2588 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002589 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002590 )
2591 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302592 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002593
2594 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302595
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002596 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302597 {
2598 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2599 FL("already beacon info added to session(%d)"),
2600 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002601 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302602 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002603
2604 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2605
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302606 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002607 {
2608 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302609 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002610 return -EINVAL;
2611 }
2612 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002613#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002614 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2615#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2616 params->channel, params->channel_type);
2617#else
2618 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2619#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002620#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002621 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2622 params->ssid_len, params->hidden_ssid);
2623 }
2624
2625 EXIT();
2626 return status;
2627}
2628
2629
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302630static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002631 struct net_device *dev,
2632 struct cfg80211_beacon_data *params)
2633{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302634 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302635 hdd_context_t *pHddCtx;
2636 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002637
2638 ENTER();
2639
Arif Hussain6d2a3322013-11-17 19:50:10 -08002640 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002641 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302642
2643 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2644 status = wlan_hdd_validate_context(pHddCtx);
2645
2646 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002647 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302648 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2649 "%s: HDD context is not valid", __func__);
2650 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002651 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002652
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302653 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002654 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302655 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002656 {
2657 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302658
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002659 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302660
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002661 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302662 {
2663 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2664 FL("session(%d) beacon data points to NULL"),
2665 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002666 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302667 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002668
2669 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2670
2671 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302672 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002673 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002674 return -EINVAL;
2675 }
2676
2677 pAdapter->sessionCtx.ap.beacon = new;
2678
2679 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2680 }
2681
2682 EXIT();
2683 return status;
2684}
2685
2686#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2687
Jeff Johnson295189b2012-06-20 16:38:30 -07002688
2689static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2690 struct net_device *dev,
2691 struct bss_parameters *params)
2692{
2693 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2694
2695 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302696
Arif Hussain6d2a3322013-11-17 19:50:10 -08002697 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002698 __func__,pAdapter->device_mode);
2699
2700 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002701 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302702 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002703 {
2704 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2705 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302706 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002707 {
2708 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002710 }
2711
2712 EXIT();
2713 return 0;
2714}
2715
Kiet Lam10841362013-11-01 11:36:50 +05302716/* FUNCTION: wlan_hdd_change_country_code_cd
2717* to wait for contry code completion
2718*/
2719void* wlan_hdd_change_country_code_cb(void *pAdapter)
2720{
2721 hdd_adapter_t *call_back_pAdapter = pAdapter;
2722 complete(&call_back_pAdapter->change_country_code);
2723 return NULL;
2724}
2725
Jeff Johnson295189b2012-06-20 16:38:30 -07002726/*
2727 * FUNCTION: wlan_hdd_cfg80211_change_iface
2728 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2729 */
2730int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2731 struct net_device *ndev,
2732 enum nl80211_iftype type,
2733 u32 *flags,
2734 struct vif_params *params
2735 )
2736{
2737 struct wireless_dev *wdev;
2738 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002739 hdd_context_t *pHddCtx;
Mohit Khanna0f232092012-09-11 14:46:08 -07002740 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002741 tCsrRoamProfile *pRoamProfile = NULL;
2742 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302743 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002744 eMib_dot11DesiredBssType connectedBssType;
2745 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302746 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07002747
2748 ENTER();
2749
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002750 if (!pAdapter)
2751 {
2752 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2753 "%s: Adapter context is null", __func__);
2754 return VOS_STATUS_E_FAILURE;
2755 }
2756
2757 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2758 if (!pHddCtx)
2759 {
2760 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2761 "%s: HDD context is null", __func__);
2762 return VOS_STATUS_E_FAILURE;
2763 }
2764
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302765 status = wlan_hdd_validate_context(pHddCtx);
2766
2767 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002768 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302769 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2770 "%s: HDD context is not valid", __func__);
2771 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002772 }
2773
2774 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2775 __func__, pAdapter->device_mode);
2776
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302777 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002778 wdev = ndev->ieee80211_ptr;
2779
2780#ifdef WLAN_BTAMP_FEATURE
2781 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2782 (NL80211_IFTYPE_ADHOC == type)||
2783 (NL80211_IFTYPE_AP == type)||
2784 (NL80211_IFTYPE_P2P_GO == type))
2785 {
2786 pHddCtx->isAmpAllowed = VOS_FALSE;
2787 // stop AMP traffic
2788 status = WLANBAP_StopAmp();
2789 if(VOS_STATUS_SUCCESS != status )
2790 {
2791 pHddCtx->isAmpAllowed = VOS_TRUE;
2792 hddLog(VOS_TRACE_LEVEL_FATAL,
2793 "%s: Failed to stop AMP", __func__);
2794 return -EINVAL;
2795 }
2796 }
2797#endif //WLAN_BTAMP_FEATURE
2798 /* Reset the current device mode bit mask*/
2799 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2800
2801 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002802 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002803 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002804 )
2805 {
2806 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002807 if (!pWextState)
2808 {
2809 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2810 "%s: pWextState is null", __func__);
2811 return VOS_STATUS_E_FAILURE;
2812 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002813 pRoamProfile = &pWextState->roamProfile;
2814 LastBSSType = pRoamProfile->BSSType;
2815
2816 switch (type)
2817 {
2818 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002819 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002820 hddLog(VOS_TRACE_LEVEL_INFO,
2821 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2822 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002823#ifdef WLAN_FEATURE_11AC
2824 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2825 {
2826 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2827 }
2828#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302829 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002830 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002831 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002832 //Check for sub-string p2p to confirm its a p2p interface
2833 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302834 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002835 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2836 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2837 }
2838 else
2839 {
2840 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002841 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002842 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302843#ifdef FEATURE_WLAN_TDLS
2844 /* The open adapter for the p2p shall skip initializations in
2845 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2846 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2847 * tdls_init when the change_iface sets the device mode to
2848 * WLAN_HDD_P2P_CLIENT.
2849 */
2850
2851 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2852 {
2853 if (0 != wlan_hdd_tdls_init (pAdapter))
2854 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302855 hddLog(VOS_TRACE_LEVEL_ERROR,
2856 "%s: tdls initialization failed", __func__);
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302857 return -EINVAL;
2858 }
2859 }
2860#endif
2861
Jeff Johnson295189b2012-06-20 16:38:30 -07002862 break;
2863 case NL80211_IFTYPE_ADHOC:
2864 hddLog(VOS_TRACE_LEVEL_INFO,
2865 "%s: setting interface Type to ADHOC", __func__);
2866 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2867 pRoamProfile->phyMode =
2868 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002869 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002870 wdev->iftype = type;
2871 break;
2872
2873 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002874 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002875 {
2876 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2877 "%s: setting interface Type to %s", __func__,
2878 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2879
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002880 //Cancel any remain on channel for GO mode
2881 if (NL80211_IFTYPE_P2P_GO == type)
2882 {
2883 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2884 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002885 if (NL80211_IFTYPE_AP == type)
2886 {
2887 /* As Loading WLAN Driver one interface being created for p2p device
2888 * address. This will take one HW STA and the max number of clients
2889 * that can connect to softAP will be reduced by one. so while changing
2890 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2891 * interface as it is not required in SoftAP mode.
2892 */
2893
2894 // Get P2P Adapter
2895 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2896
2897 if (pP2pAdapter)
2898 {
2899 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2900 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2901 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2902 }
2903 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302904#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002905
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302906 /* A Mutex Lock is introduced while changing the mode to
2907 * protect the concurrent access for the Adapters by TDLS
2908 * module.
2909 */
2910 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2911 {
2912 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2913 "%s: unable to lock list", __func__);
2914 return -EINVAL;
2915 }
2916#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002917 //De-init the adapter.
2918 hdd_stop_adapter( pHddCtx, pAdapter );
2919 hdd_deinit_adapter( pHddCtx, pAdapter );
2920 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002921 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2922 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302923#ifdef FEATURE_WLAN_TDLS
2924 mutex_unlock(&pHddCtx->tdls_lock);
2925#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002926
2927 //Disable BMPS and IMPS if enabled
2928 //before starting Go
2929 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2930 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302931 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002932 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2933 {
2934 //Fail to Exit BMPS
2935 VOS_ASSERT(0);
2936 }
2937 }
2938
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002939 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2940 (pConfig->apRandomBssidEnabled))
2941 {
2942 /* To meet Android requirements create a randomized
2943 MAC address of the form 02:1A:11:Fx:xx:xx */
2944 get_random_bytes(&ndev->dev_addr[3], 3);
2945 ndev->dev_addr[0] = 0x02;
2946 ndev->dev_addr[1] = 0x1A;
2947 ndev->dev_addr[2] = 0x11;
2948 ndev->dev_addr[3] |= 0xF0;
2949 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2950 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08002951 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
2952 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002953 }
2954
Jeff Johnson295189b2012-06-20 16:38:30 -07002955 hdd_set_ap_ops( pAdapter->dev );
2956
Kiet Lam10841362013-11-01 11:36:50 +05302957 /* This is for only SAP mode where users can
2958 * control country through ini.
2959 * P2P GO follows station country code
2960 * acquired during the STA scanning. */
2961 if((NL80211_IFTYPE_AP == type) &&
2962 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2963 {
2964 int status = 0;
2965 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2966 "%s: setting country code from INI ", __func__);
2967 init_completion(&pAdapter->change_country_code);
2968 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2969 (void *)(tSmeChangeCountryCallback)
2970 wlan_hdd_change_country_code_cb,
2971 pConfig->apCntryCode, pAdapter,
2972 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05302973 eSIR_FALSE,
2974 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05302975 if (eHAL_STATUS_SUCCESS == status)
2976 {
2977 /* Wait for completion */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302978 ret = wait_for_completion_interruptible_timeout(
Kiet Lam10841362013-11-01 11:36:50 +05302979 &pAdapter->change_country_code,
2980 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302981 if (ret <= 0)
Kiet Lam10841362013-11-01 11:36:50 +05302982 {
2983 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302984 FL("SME Timed out while setting country code %ld"),
2985 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002986
2987 if (pHddCtx->isLogpInProgress)
2988 {
2989 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2990 "%s: LOGP in Progress. Ignore!!!", __func__);
2991 return -EAGAIN;
2992 }
Kiet Lam10841362013-11-01 11:36:50 +05302993 }
2994 }
2995 else
2996 {
2997 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002998 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05302999 return -EINVAL;
3000 }
3001 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003002 status = hdd_init_ap_mode(pAdapter);
3003 if(status != VOS_STATUS_SUCCESS)
3004 {
3005 hddLog(VOS_TRACE_LEVEL_FATAL,
3006 "%s: Error initializing the ap mode", __func__);
3007 return -EINVAL;
3008 }
3009 hdd_set_conparam(1);
3010
Jeff Johnson295189b2012-06-20 16:38:30 -07003011 /*interface type changed update in wiphy structure*/
3012 if(wdev)
3013 {
3014 wdev->iftype = type;
3015 pHddCtx->change_iface = type;
3016 }
3017 else
3018 {
3019 hddLog(VOS_TRACE_LEVEL_ERROR,
3020 "%s: ERROR !!!! Wireless dev is NULL", __func__);
3021 return -EINVAL;
3022 }
3023 goto done;
3024 }
3025
3026 default:
3027 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3028 __func__);
3029 return -EOPNOTSUPP;
3030 }
3031 }
3032 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003033 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003034 )
3035 {
3036 switch(type)
3037 {
3038 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07003039 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07003040 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303041#ifdef FEATURE_WLAN_TDLS
3042
3043 /* A Mutex Lock is introduced while changing the mode to
3044 * protect the concurrent access for the Adapters by TDLS
3045 * module.
3046 */
3047 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
3048 {
3049 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3050 "%s: unable to lock list", __func__);
3051 return -EINVAL;
3052 }
3053#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07003054 hdd_stop_adapter( pHddCtx, pAdapter );
3055 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003056 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08003057 //Check for sub-string p2p to confirm its a p2p interface
3058 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003059 {
3060 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
3061 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
3062 }
3063 else
3064 {
3065 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07003066 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003067 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003068 hdd_set_conparam(0);
3069 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003070 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
3071 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303072#ifdef FEATURE_WLAN_TDLS
3073 mutex_unlock(&pHddCtx->tdls_lock);
3074#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05303075 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003076 if( VOS_STATUS_SUCCESS != status )
3077 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07003078 /* In case of JB, for P2P-GO, only change interface will be called,
3079 * This is the right place to enable back bmps_imps()
3080 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05303081 if (pHddCtx->hdd_wlan_suspended)
3082 {
3083 hdd_set_pwrparams(pHddCtx);
3084 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003085 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003086 goto done;
3087 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07003089 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003090 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3091 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 goto done;
3093 default:
3094 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3095 __func__);
3096 return -EOPNOTSUPP;
3097
3098 }
3099
3100 }
3101 else
3102 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303103 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: unsupported device mode(%d)",
3104 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003105 return -EOPNOTSUPP;
3106 }
3107
3108
3109 if(pRoamProfile)
3110 {
3111 if ( LastBSSType != pRoamProfile->BSSType )
3112 {
3113 /*interface type changed update in wiphy structure*/
3114 wdev->iftype = type;
3115
3116 /*the BSS mode changed, We need to issue disconnect
3117 if connected or in IBSS disconnect state*/
3118 if ( hdd_connGetConnectedBssType(
3119 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
3120 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
3121 {
3122 /*need to issue a disconnect to CSR.*/
3123 INIT_COMPLETION(pAdapter->disconnect_comp_var);
3124 if( eHAL_STATUS_SUCCESS ==
3125 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
3126 pAdapter->sessionId,
3127 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
3128 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303129 ret = wait_for_completion_interruptible_timeout(
3130 &pAdapter->disconnect_comp_var,
3131 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
3132 if (ret <= 0)
3133 {
3134 hddLog(VOS_TRACE_LEVEL_ERROR,
3135 FL("wait on disconnect_comp_var failed %ld"), ret);
3136 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003137 }
3138 }
3139 }
3140 }
3141
3142done:
3143 /*set bitmask based on updated value*/
3144 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07003145
3146 /* Only STA mode support TM now
3147 * all other mode, TM feature should be disabled */
3148 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
3149 (~VOS_STA & pHddCtx->concurrency_mode) )
3150 {
3151 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
3152 }
3153
Jeff Johnson295189b2012-06-20 16:38:30 -07003154#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303155 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003156 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
3157 {
3158 //we are ok to do AMP
3159 pHddCtx->isAmpAllowed = VOS_TRUE;
3160 }
3161#endif //WLAN_BTAMP_FEATURE
3162 EXIT();
3163 return 0;
3164}
3165
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003166#ifdef FEATURE_WLAN_TDLS
3167static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
3168 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
3169{
3170 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3171 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3172 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003173 hddTdlsPeer_t *pTdlsPeer;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303174 long ret;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003175
3176 ENTER();
3177
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303178 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003179 {
3180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3181 "Invalid arguments");
3182 return -EINVAL;
3183 }
Hoonki Lee27511902013-03-14 18:19:06 -07003184
3185 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3186 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3187 {
3188 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3189 "%s: TDLS mode is disabled OR not enabled in FW."
3190 MAC_ADDRESS_STR " Request declined.",
3191 __func__, MAC_ADDR_ARRAY(mac));
3192 return -ENOTSUPP;
3193 }
3194
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003195 if (pHddCtx->isLogpInProgress)
3196 {
3197 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3198 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003199 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003200 return -EBUSY;
3201 }
3202
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303203 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003204
3205 if ( NULL == pTdlsPeer ) {
3206 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3207 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3208 __func__, MAC_ADDR_ARRAY(mac), update);
3209 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003210 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003211
3212 /* in add station, we accept existing valid staId if there is */
3213 if ((0 == update) &&
3214 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3215 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003216 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003217 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003218 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003219 " link_status %d. staId %d. add station ignored.",
3220 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3221 return 0;
3222 }
3223 /* in change station, we accept only when staId is valid */
3224 if ((1 == update) &&
3225 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3226 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3227 {
3228 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3229 "%s: " MAC_ADDRESS_STR
3230 " link status %d. staId %d. change station %s.",
3231 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3232 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3233 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003234 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003235
3236 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303237 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003238 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003239 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3240 "%s: " MAC_ADDRESS_STR
3241 " TDLS setup is ongoing. Request declined.",
3242 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003243 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003244 }
3245
3246 /* first to check if we reached to maximum supported TDLS peer.
3247 TODO: for now, return -EPERM looks working fine,
3248 but need to check if any other errno fit into this category.*/
3249 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3250 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003251 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3252 "%s: " MAC_ADDRESS_STR
3253 " TDLS Max peer already connected. Request declined.",
3254 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003255 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003256 }
3257 else
3258 {
3259 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303260 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003261 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003262 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003263 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3264 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3265 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003266 return -EPERM;
3267 }
3268 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003269 if (0 == update)
3270 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003271
Jeff Johnsond75fe012013-04-06 10:53:06 -07003272 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303273 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003274 {
3275 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3276 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003277 if(StaParams->htcap_present)
3278 {
3279 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3280 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3281 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3282 "ht_capa->extended_capabilities: %0x",
3283 StaParams->HTCap.extendedHtCapInfo);
3284 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003285 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3286 "params->capability: %0x",StaParams->capability);
3287 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003288 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003289 if(StaParams->vhtcap_present)
3290 {
3291 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3292 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3293 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3294 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3295 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003296 {
3297 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003298 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003299 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3300 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3301 "[%d]: %x ", i, StaParams->supported_rates[i]);
3302 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003303 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303304 else if ((1 == update) && (NULL == StaParams))
3305 {
3306 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3307 "%s : update is true, but staParams is NULL. Error!", __func__);
3308 return -EPERM;
3309 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003310
3311 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3312
3313 if (!update)
3314 {
3315 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3316 pAdapter->sessionId, mac);
3317 }
3318 else
3319 {
3320 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3321 pAdapter->sessionId, mac, StaParams);
3322 }
3323
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303324 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003325 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3326
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303327 if (ret <= 0)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003328 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003329 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303330 "%s: timeout waiting for tdls add station indication %ld",
3331 __func__, ret);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003332 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003333 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303334
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003335 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3336 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003337 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003338 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003339 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003340 }
3341
3342 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003343
3344error:
3345 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3346 return -EPERM;
3347
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003348}
3349#endif
3350
Jeff Johnson295189b2012-06-20 16:38:30 -07003351static int wlan_hdd_change_station(struct wiphy *wiphy,
3352 struct net_device *dev,
3353 u8 *mac,
3354 struct station_parameters *params)
3355{
3356 VOS_STATUS status = VOS_STATUS_SUCCESS;
3357 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303358 hdd_context_t *pHddCtx;
3359 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003360 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003361#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003362 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003363 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003364#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003365 ENTER();
3366
Gopichand Nakkala29149562013-05-10 21:43:41 +05303367 if ((NULL == pAdapter))
3368 {
3369 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3370 "invalid adapter ");
3371 return -EINVAL;
3372 }
3373
3374 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3375 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3376
3377 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3378 {
3379 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3380 "invalid HDD state or HDD station context");
3381 return -EINVAL;
3382 }
3383
3384 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003385 {
3386 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3387 "%s:LOGP in Progress. Ignore!!!", __func__);
3388 return -EAGAIN;
3389 }
3390
Jeff Johnson295189b2012-06-20 16:38:30 -07003391 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3392
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003393 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3394 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003395 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003396 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003397 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303398 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003399 WLANTL_STA_AUTHENTICATED);
3400
Gopichand Nakkala29149562013-05-10 21:43:41 +05303401 if (status != VOS_STATUS_SUCCESS)
3402 {
3403 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3404 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3405 return -EINVAL;
3406 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003407 }
3408 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003409 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3410 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303411#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003412 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3413 StaParams.capability = params->capability;
3414 StaParams.uapsd_queues = params->uapsd_queues;
3415 StaParams.max_sp = params->max_sp;
3416
3417 if (0 != params->ext_capab_len)
3418 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3419 sizeof(StaParams.extn_capability));
3420
3421 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003422 {
3423 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003424 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003425 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003426
3427 StaParams.supported_rates_len = params->supported_rates_len;
3428
3429 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3430 * The supported_rates array , for all the structures propogating till Add Sta
3431 * to the firmware has to be modified , if the supplicant (ieee80211) is
3432 * modified to send more rates.
3433 */
3434
3435 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3436 */
3437 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3438 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3439
3440 if (0 != StaParams.supported_rates_len) {
3441 int i = 0;
3442 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3443 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003444 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003445 "Supported Rates with Length %d", StaParams.supported_rates_len);
3446 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003447 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003448 "[%d]: %0x", i, StaParams.supported_rates[i]);
3449 }
3450
3451 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003452 {
3453 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003454 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003455 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003456
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003457 if (0 != params->ext_capab_len ) {
3458 /*Define A Macro : TODO Sunil*/
3459 if ((1<<4) & StaParams.extn_capability[3]) {
3460 isBufSta = 1;
3461 }
3462 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303463 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3464 params->max_sp, isBufSta);
3465 if (VOS_STATUS_SUCCESS != status) {
3466 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3467 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3468 return -EINVAL;
3469 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003470 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3471
3472 if (VOS_STATUS_SUCCESS != status) {
3473 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3474 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3475 return -EINVAL;
3476 }
3477 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003478#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303479 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003480 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003481 return status;
3482}
3483
3484/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003485 * FUNCTION: wlan_hdd_cfg80211_add_key
3486 * This function is used to initialize the key information
3487 */
3488#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003489static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003490 struct net_device *ndev,
3491 u8 key_index, bool pairwise,
3492 const u8 *mac_addr,
3493 struct key_params *params
3494 )
3495#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003496static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003497 struct net_device *ndev,
3498 u8 key_index, const u8 *mac_addr,
3499 struct key_params *params
3500 )
3501#endif
3502{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003503 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003504 tCsrRoamSetKey setKey;
3505 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303506 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003507 v_U32_t roamId= 0xFF;
3508 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003509 hdd_hostapd_state_t *pHostapdState;
3510 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003511 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303512 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003513
3514 ENTER();
3515
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303516 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3517 status = wlan_hdd_validate_context(pHddCtx);
3518
3519 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003520 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303521 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3522 "%s: HDD context is not valid", __func__);
3523 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003524 }
3525
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003526 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3527 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003528
3529 if (CSR_MAX_NUM_KEY <= key_index)
3530 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003531 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 key_index);
3533
3534 return -EINVAL;
3535 }
3536
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003537 if (CSR_MAX_KEY_LEN < params->key_len)
3538 {
3539 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3540 params->key_len);
3541
3542 return -EINVAL;
3543 }
3544
3545 hddLog(VOS_TRACE_LEVEL_INFO,
3546 "%s: called with key index = %d & key length %d",
3547 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003548
3549 /*extract key idx, key len and key*/
3550 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3551 setKey.keyId = key_index;
3552 setKey.keyLength = params->key_len;
3553 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3554
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003555 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003556 {
3557 case WLAN_CIPHER_SUITE_WEP40:
3558 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3559 break;
3560
3561 case WLAN_CIPHER_SUITE_WEP104:
3562 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3563 break;
3564
3565 case WLAN_CIPHER_SUITE_TKIP:
3566 {
3567 u8 *pKey = &setKey.Key[0];
3568 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3569
3570 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3571
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003572 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003573
3574 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003575 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003576 |--------------|----------|----------|
3577 <---16bytes---><--8bytes--><--8bytes-->
3578
3579 */
3580 /*Sme expects the 32 bytes key to be in the below order
3581
3582 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003583 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003584 |--------------|----------|----------|
3585 <---16bytes---><--8bytes--><--8bytes-->
3586 */
3587 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003588 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003589
3590 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003591 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003592
3593 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003594 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003595
3596
3597 break;
3598 }
3599
3600 case WLAN_CIPHER_SUITE_CCMP:
3601 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3602 break;
3603
3604#ifdef FEATURE_WLAN_WAPI
3605 case WLAN_CIPHER_SUITE_SMS4:
3606 {
3607 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3608 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3609 params->key, params->key_len);
3610 return 0;
3611 }
3612#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003613
Jeff Johnson295189b2012-06-20 16:38:30 -07003614#ifdef FEATURE_WLAN_CCX
3615 case WLAN_CIPHER_SUITE_KRK:
3616 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3617 break;
3618#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003619
3620#ifdef WLAN_FEATURE_11W
3621 case WLAN_CIPHER_SUITE_AES_CMAC:
3622 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003623 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003624#endif
3625
Jeff Johnson295189b2012-06-20 16:38:30 -07003626 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003627 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003628 __func__, params->cipher);
3629 return -EOPNOTSUPP;
3630 }
3631
3632 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3633 __func__, setKey.encType);
3634
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003635 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003636#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3637 (!pairwise)
3638#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003639 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003640#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003641 )
3642 {
3643 /* set group key*/
3644 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3645 "%s- %d: setting Broadcast key",
3646 __func__, __LINE__);
3647 setKey.keyDirection = eSIR_RX_ONLY;
3648 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3649 }
3650 else
3651 {
3652 /* set pairwise key*/
3653 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3654 "%s- %d: setting pairwise key",
3655 __func__, __LINE__);
3656 setKey.keyDirection = eSIR_TX_RX;
3657 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3658 }
3659 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3660 {
3661 setKey.keyDirection = eSIR_TX_RX;
3662 /*Set the group key*/
3663 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3664 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003665
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003666 if ( 0 != status )
3667 {
3668 hddLog(VOS_TRACE_LEVEL_ERROR,
3669 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3670 return -EINVAL;
3671 }
3672 /*Save the keys here and call sme_RoamSetKey for setting
3673 the PTK after peer joins the IBSS network*/
3674 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3675 &setKey, sizeof(tCsrRoamSetKey));
3676 return status;
3677 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303678 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3679 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3680 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003681 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003682 if( pHostapdState->bssState == BSS_START )
3683 {
c_hpothu7c55da62014-01-23 18:34:02 +05303684 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3685 vos_status = wlan_hdd_check_ula_done(pAdapter);
3686
3687 if ( vos_status != VOS_STATUS_SUCCESS )
3688 {
3689 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3690 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3691 __LINE__, vos_status );
3692
3693 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3694
3695 return -EINVAL;
3696 }
3697
Jeff Johnson295189b2012-06-20 16:38:30 -07003698 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3699
3700 if ( status != eHAL_STATUS_SUCCESS )
3701 {
3702 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3703 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3704 __LINE__, status );
3705 }
3706 }
3707
3708 /* Saving WEP keys */
3709 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3710 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3711 {
3712 //Save the wep key in ap context. Issue setkey after the BSS is started.
3713 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3714 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3715 }
3716 else
3717 {
3718 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003719 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003720 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3721 }
3722 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003723 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3724 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003725 {
3726 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3727 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3728
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303729#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3730 if (!pairwise)
3731#else
3732 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3733#endif
3734 {
3735 /* set group key*/
3736 if (pHddStaCtx->roam_info.deferKeyComplete)
3737 {
3738 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3739 "%s- %d: Perform Set key Complete",
3740 __func__, __LINE__);
3741 hdd_PerformRoamSetKeyComplete(pAdapter);
3742 }
3743 }
3744
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3746
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003747 pWextState->roamProfile.Keys.defaultIndex = key_index;
3748
3749
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003750 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003751 params->key, params->key_len);
3752
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303753
Jeff Johnson295189b2012-06-20 16:38:30 -07003754 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3755
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303756 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003757 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303758 __func__, setKey.peerMac[0], setKey.peerMac[1],
3759 setKey.peerMac[2], setKey.peerMac[3],
3760 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003761 setKey.keyDirection);
3762
3763 vos_status = wlan_hdd_check_ula_done(pAdapter);
3764
3765 if ( vos_status != VOS_STATUS_SUCCESS )
3766 {
3767 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3768 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3769 __LINE__, vos_status );
3770
3771 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3772
3773 return -EINVAL;
3774
3775 }
3776
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003777#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303778 /* The supplicant may attempt to set the PTK once pre-authentication
3779 is done. Save the key in the UMAC and include it in the ADD BSS
3780 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003781 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303782 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003783 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303784 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3785 "%s: Update PreAuth Key success", __func__);
3786 return 0;
3787 }
3788 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3789 {
3790 hddLog(VOS_TRACE_LEVEL_ERROR,
3791 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303792 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003793 }
3794#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003795
3796 /* issue set key request to SME*/
3797 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3798 pAdapter->sessionId, &setKey, &roamId );
3799
3800 if ( 0 != status )
3801 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303802 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003803 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3804 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3805 return -EINVAL;
3806 }
3807
3808
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303809 /* in case of IBSS as there was no information available about WEP keys during
3810 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003811 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303812 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3813 !( ( IW_AUTH_KEY_MGMT_802_1X
3814 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003815 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3816 )
3817 &&
3818 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3819 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3820 )
3821 )
3822 {
3823 setKey.keyDirection = eSIR_RX_ONLY;
3824 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3825
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303826 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003827 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303828 __func__, setKey.peerMac[0], setKey.peerMac[1],
3829 setKey.peerMac[2], setKey.peerMac[3],
3830 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003831 setKey.keyDirection);
3832
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303833 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003834 pAdapter->sessionId, &setKey, &roamId );
3835
3836 if ( 0 != status )
3837 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303838 hddLog(VOS_TRACE_LEVEL_ERROR,
3839 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003840 __func__, status);
3841 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3842 return -EINVAL;
3843 }
3844 }
3845 }
3846
3847 return 0;
3848}
3849
3850/*
3851 * FUNCTION: wlan_hdd_cfg80211_get_key
3852 * This function is used to get the key information
3853 */
3854#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303855static int wlan_hdd_cfg80211_get_key(
3856 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003857 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303858 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003859 const u8 *mac_addr, void *cookie,
3860 void (*callback)(void *cookie, struct key_params*)
3861 )
3862#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303863static int wlan_hdd_cfg80211_get_key(
3864 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003865 struct net_device *ndev,
3866 u8 key_index, const u8 *mac_addr, void *cookie,
3867 void (*callback)(void *cookie, struct key_params*)
3868 )
3869#endif
3870{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303871 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003872 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3873 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3874 struct key_params params;
3875
3876 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303877
Arif Hussain6d2a3322013-11-17 19:50:10 -08003878 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003879 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303880
Jeff Johnson295189b2012-06-20 16:38:30 -07003881 memset(&params, 0, sizeof(params));
3882
3883 if (CSR_MAX_NUM_KEY <= key_index)
3884 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303885 hddLog(VOS_TRACE_LEVEL_ERROR, FL("invalid key index %d"), key_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07003886 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303887 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003888
3889 switch(pRoamProfile->EncryptionType.encryptionType[0])
3890 {
3891 case eCSR_ENCRYPT_TYPE_NONE:
3892 params.cipher = IW_AUTH_CIPHER_NONE;
3893 break;
3894
3895 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3896 case eCSR_ENCRYPT_TYPE_WEP40:
3897 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3898 break;
3899
3900 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3901 case eCSR_ENCRYPT_TYPE_WEP104:
3902 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3903 break;
3904
3905 case eCSR_ENCRYPT_TYPE_TKIP:
3906 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3907 break;
3908
3909 case eCSR_ENCRYPT_TYPE_AES:
3910 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3911 break;
3912
3913 default:
3914 params.cipher = IW_AUTH_CIPHER_NONE;
3915 break;
3916 }
3917
3918 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3919 params.seq_len = 0;
3920 params.seq = NULL;
3921 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3922 callback(cookie, &params);
3923 return 0;
3924}
3925
3926/*
3927 * FUNCTION: wlan_hdd_cfg80211_del_key
3928 * This function is used to delete the key information
3929 */
3930#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303931static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003932 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303933 u8 key_index,
3934 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003935 const u8 *mac_addr
3936 )
3937#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303938static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003939 struct net_device *ndev,
3940 u8 key_index,
3941 const u8 *mac_addr
3942 )
3943#endif
3944{
3945 int status = 0;
3946
3947 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303948 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003949 //it is observed that this is invalidating peer
3950 //key index whenever re-key is done. This is affecting data link.
3951 //It should be ok to ignore del_key.
3952#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303953 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3954 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003955 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3956 tCsrRoamSetKey setKey;
3957 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303958
Jeff Johnson295189b2012-06-20 16:38:30 -07003959 ENTER();
3960
3961 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3962 __func__,pAdapter->device_mode);
3963
3964 if (CSR_MAX_NUM_KEY <= key_index)
3965 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303966 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003967 key_index);
3968
3969 return -EINVAL;
3970 }
3971
3972 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3973 setKey.keyId = key_index;
3974
3975 if (mac_addr)
3976 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3977 else
3978 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3979
3980 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3981
3982 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003983 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303984 )
3985 {
3986
3987 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003988 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3989 if( pHostapdState->bssState == BSS_START)
3990 {
3991 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303992
Jeff Johnson295189b2012-06-20 16:38:30 -07003993 if ( status != eHAL_STATUS_SUCCESS )
3994 {
3995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3996 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3997 __LINE__, status );
3998 }
3999 }
4000 }
4001 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304002 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07004003 )
4004 {
4005 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4006
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304007 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
4008
4009 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07004010 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304011 __func__, setKey.peerMac[0], setKey.peerMac[1],
4012 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07004013 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304014 if(pAdapter->sessionCtx.station.conn_info.connState ==
4015 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07004016 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304017 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004018 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304019
Jeff Johnson295189b2012-06-20 16:38:30 -07004020 if ( 0 != status )
4021 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304022 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004023 "%s: sme_RoamSetKey failure, returned %d",
4024 __func__, status);
4025 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
4026 return -EINVAL;
4027 }
4028 }
4029 }
4030#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07004031 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004032 return status;
4033}
4034
4035/*
4036 * FUNCTION: wlan_hdd_cfg80211_set_default_key
4037 * This function is used to set the default tx key index
4038 */
4039#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
4040static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4041 struct net_device *ndev,
4042 u8 key_index,
4043 bool unicast, bool multicast)
4044#else
4045static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4046 struct net_device *ndev,
4047 u8 key_index)
4048#endif
4049{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304050 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304051 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05304052 hdd_wext_state_t *pWextState;
4053 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304054 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004055
4056 ENTER();
4057
Gopichand Nakkala29149562013-05-10 21:43:41 +05304058 if ((NULL == pAdapter))
4059 {
4060 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4061 "invalid adapter");
4062 return -EINVAL;
4063 }
4064
4065 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4066 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4067
4068 if ((NULL == pWextState) || (NULL == pHddStaCtx))
4069 {
4070 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4071 "invalid Wext state or HDD context");
4072 return -EINVAL;
4073 }
4074
Arif Hussain6d2a3322013-11-17 19:50:10 -08004075 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004076 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304077
Jeff Johnson295189b2012-06-20 16:38:30 -07004078 if (CSR_MAX_NUM_KEY <= key_index)
4079 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304080 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004081 key_index);
4082
4083 return -EINVAL;
4084 }
4085
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304086 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4087 status = wlan_hdd_validate_context(pHddCtx);
4088
4089 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004090 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304091 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4092 "%s: HDD context is not valid", __func__);
4093 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004094 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304095
Jeff Johnson295189b2012-06-20 16:38:30 -07004096 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07004097 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304098 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004099 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05304100 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08004101 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304102 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08004103 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07004104 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304105 {
4106 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304108
Jeff Johnson295189b2012-06-20 16:38:30 -07004109 tCsrRoamSetKey setKey;
4110 v_U32_t roamId= 0xFF;
4111 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304112
4113 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004114 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304115
Jeff Johnson295189b2012-06-20 16:38:30 -07004116 Keys->defaultIndex = (u8)key_index;
4117 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4118 setKey.keyId = key_index;
4119 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304120
4121 vos_mem_copy(&setKey.Key[0],
4122 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07004123 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304124
Gopichand Nakkala29149562013-05-10 21:43:41 +05304125 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304126
4127 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07004128 &pHddStaCtx->conn_info.bssId[0],
4129 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304130
Gopichand Nakkala29149562013-05-10 21:43:41 +05304131 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
4132 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4133 eCSR_ENCRYPT_TYPE_WEP104)
4134 {
4135 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
4136 even though ap is configured for WEP-40 encryption. In this canse the key length
4137 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
4138 type(104) and switching encryption type to 40*/
4139 pWextState->roamProfile.EncryptionType.encryptionType[0] =
4140 eCSR_ENCRYPT_TYPE_WEP40;
4141 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
4142 eCSR_ENCRYPT_TYPE_WEP40;
4143 }
4144
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304145 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07004146 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304147
Jeff Johnson295189b2012-06-20 16:38:30 -07004148 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304149 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004150 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304151
Jeff Johnson295189b2012-06-20 16:38:30 -07004152 if ( 0 != status )
4153 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304154 hddLog(VOS_TRACE_LEVEL_ERROR,
4155 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004156 status);
4157 return -EINVAL;
4158 }
4159 }
4160 }
4161
4162 /* In SoftAp mode setting key direction for default mode */
4163 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
4164 {
4165 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
4166 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
4167 (eCSR_ENCRYPT_TYPE_AES !=
4168 pWextState->roamProfile.EncryptionType.encryptionType[0])
4169 )
4170 {
4171 /* Saving key direction for default key index to TX default */
4172 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
4173 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
4174 }
4175 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304176
Jeff Johnson295189b2012-06-20 16:38:30 -07004177 return status;
4178}
4179
Jeff Johnson295189b2012-06-20 16:38:30 -07004180/*
4181 * FUNCTION: wlan_hdd_cfg80211_inform_bss
4182 * This function is used to inform the BSS details to nl80211 interface.
4183 */
4184static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
4185 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
4186{
4187 struct net_device *dev = pAdapter->dev;
4188 struct wireless_dev *wdev = dev->ieee80211_ptr;
4189 struct wiphy *wiphy = wdev->wiphy;
4190 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4191 int chan_no;
4192 int ie_length;
4193 const char *ie;
4194 unsigned int freq;
4195 struct ieee80211_channel *chan;
4196 int rssi = 0;
4197 struct cfg80211_bss *bss = NULL;
4198
4199 ENTER();
4200
4201 if( NULL == pBssDesc )
4202 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004203 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004204 return bss;
4205 }
4206
4207 chan_no = pBssDesc->channelId;
4208 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4209 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4210
4211 if( NULL == ie )
4212 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004213 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004214 return bss;
4215 }
4216
4217#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4218 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4219 {
4220 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4221 }
4222 else
4223 {
4224 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4225 }
4226#else
4227 freq = ieee80211_channel_to_frequency(chan_no);
4228#endif
4229
4230 chan = __ieee80211_get_channel(wiphy, freq);
4231
4232 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4233 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4234 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4235 if (bss == NULL)
4236 {
4237 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4238
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304239 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4240 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004241 pBssDesc->capabilityInfo,
4242 pBssDesc->beaconInterval, ie, ie_length,
4243 rssi, GFP_KERNEL ));
4244}
4245 else
4246 {
4247 return bss;
4248 }
4249}
4250
4251
4252
4253/*
4254 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4255 * This function is used to inform the BSS details to nl80211 interface.
4256 */
4257struct cfg80211_bss*
4258wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4259 tSirBssDescription *bss_desc
4260 )
4261{
4262 /*
4263 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4264 already exists in bss data base of cfg80211 for that particular BSS ID.
4265 Using cfg80211_inform_bss_frame to update the bss entry instead of
4266 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4267 now there is no possibility to get the mgmt(probe response) frame from PE,
4268 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4269 cfg80211_inform_bss_frame.
4270 */
4271 struct net_device *dev = pAdapter->dev;
4272 struct wireless_dev *wdev = dev->ieee80211_ptr;
4273 struct wiphy *wiphy = wdev->wiphy;
4274 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004275#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4276 qcom_ie_age *qie_age = NULL;
4277 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4278#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004279 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004280#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004281 const char *ie =
4282 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4283 unsigned int freq;
4284 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304285 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004286 struct cfg80211_bss *bss_status = NULL;
4287 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4288 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004289 hdd_context_t *pHddCtx;
4290 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004291#ifdef WLAN_OPEN_SOURCE
4292 struct timespec ts;
4293#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004294
Wilson Yangf80a0542013-10-07 13:02:37 -07004295 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4296 status = wlan_hdd_validate_context(pHddCtx);
4297
4298 /*bss_update is not allowed during wlan driver loading or unloading*/
4299 if (pHddCtx->isLoadUnloadInProgress)
4300 {
4301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4302 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4303 return NULL;
4304 }
4305
4306
4307 if (0 != status)
4308 {
4309 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4310 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004311 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004312 }
4313
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304314 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004315 if (!mgmt)
4316 {
4317 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4318 "%s: memory allocation failed ", __func__);
4319 return NULL;
4320 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004321
Jeff Johnson295189b2012-06-20 16:38:30 -07004322 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004323
4324#ifdef WLAN_OPEN_SOURCE
4325 /* Android does not want the timestamp from the frame.
4326 Instead it wants a monotonic increasing value */
4327 get_monotonic_boottime(&ts);
4328 mgmt->u.probe_resp.timestamp =
4329 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4330#else
4331 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004332 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4333 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004334
4335#endif
4336
Jeff Johnson295189b2012-06-20 16:38:30 -07004337 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4338 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004339
4340#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4341 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4342 /* Assuming this is the last IE, copy at the end */
4343 ie_length -=sizeof(qcom_ie_age);
4344 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4345 qie_age->element_id = QCOM_VENDOR_IE_ID;
4346 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4347 qie_age->oui_1 = QCOM_OUI1;
4348 qie_age->oui_2 = QCOM_OUI2;
4349 qie_age->oui_3 = QCOM_OUI3;
4350 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4351 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4352#endif
4353
Jeff Johnson295189b2012-06-20 16:38:30 -07004354 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304355 if (bss_desc->fProbeRsp)
4356 {
4357 mgmt->frame_control |=
4358 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4359 }
4360 else
4361 {
4362 mgmt->frame_control |=
4363 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4364 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004365
4366#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304367 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004368 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4369 {
4370 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4371 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304372 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004373 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4374
4375 {
4376 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4377 }
4378 else
4379 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304380 hddLog(VOS_TRACE_LEVEL_ERROR, "%s Invalid chan_no:%d",
4381 __func__, chan_no);
Jeff Johnson295189b2012-06-20 16:38:30 -07004382 kfree(mgmt);
4383 return NULL;
4384 }
4385#else
4386 freq = ieee80211_channel_to_frequency(chan_no);
4387#endif
4388 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004389 /*when the band is changed on the fly using the GUI, three things are done
4390 * 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)
4391 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4392 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4393 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4394 * and discards the channels correponding to previous band and calls back with zero bss results.
4395 * 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
4396 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4397 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4398 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4399 * So drop the bss and continue to next bss.
4400 */
4401 if(chan == NULL)
4402 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304403 hddLog(VOS_TRACE_LEVEL_ERROR, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004404 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004405 return NULL;
4406 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004407 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304408 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004409 * */
4410 if (( eConnectionState_Associated ==
4411 pAdapter->sessionCtx.station.conn_info.connState ) &&
4412 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4413 pAdapter->sessionCtx.station.conn_info.bssId,
4414 WNI_CFG_BSSID_LEN)))
4415 {
4416 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4417 rssi = (pAdapter->rssi * 100);
4418 }
4419 else
4420 {
4421 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4422 }
4423
Nirav Shah20ac06f2013-12-12 18:14:06 +05304424 hddLog(VOS_TRACE_LEVEL_INFO, "%s: BSSID:" MAC_ADDRESS_STR " Channel:%d"
4425 "RSSI:%d", __func__, MAC_ADDR_ARRAY(mgmt->bssid),
4426 chan->center_freq, (int)(rssi/100));
4427
Jeff Johnson295189b2012-06-20 16:38:30 -07004428 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4429 frame_len, rssi, GFP_KERNEL);
4430 kfree(mgmt);
4431 return bss_status;
4432}
4433
4434/*
4435 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4436 * This function is used to update the BSS data base of CFG8011
4437 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304438struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004439 tCsrRoamInfo *pRoamInfo
4440 )
4441{
4442 tCsrRoamConnectedProfile roamProfile;
4443 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4444 struct cfg80211_bss *bss = NULL;
4445
4446 ENTER();
4447
4448 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4449 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4450
4451 if (NULL != roamProfile.pBssDesc)
4452 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304453 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004454 &roamProfile);
4455
4456 if (NULL == bss)
4457 {
4458 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4459 __func__);
4460 }
4461
4462 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4463 }
4464 else
4465 {
4466 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4467 __func__);
4468 }
4469 return bss;
4470}
4471
4472/*
4473 * FUNCTION: wlan_hdd_cfg80211_update_bss
4474 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304475static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4476 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004477 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304478{
Jeff Johnson295189b2012-06-20 16:38:30 -07004479 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4480 tCsrScanResultInfo *pScanResult;
4481 eHalStatus status = 0;
4482 tScanResultHandle pResult;
4483 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004484 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004485
4486 ENTER();
4487
Wilson Yangf80a0542013-10-07 13:02:37 -07004488 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4489
4490 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004491 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004492 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4493 "%s:LOGP in Progress. Ignore!!!",__func__);
4494 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004495 }
4496
Wilson Yangf80a0542013-10-07 13:02:37 -07004497
4498 /*bss_update is not allowed during wlan driver loading or unloading*/
4499 if (pHddCtx->isLoadUnloadInProgress)
4500 {
4501 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4502 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4503 return VOS_STATUS_E_PERM;
4504 }
4505
4506
Jeff Johnson295189b2012-06-20 16:38:30 -07004507 /*
4508 * start getting scan results and populate cgf80211 BSS database
4509 */
4510 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4511
4512 /* no scan results */
4513 if (NULL == pResult)
4514 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304515 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result Status %d",
4516 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 return status;
4518 }
4519
4520 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4521
4522 while (pScanResult)
4523 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304524 /*
4525 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4526 * entry already exists in bss data base of cfg80211 for that
4527 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4528 * bss entry instead of cfg80211_inform_bss, But this call expects
4529 * mgmt packet as input. As of now there is no possibility to get
4530 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004531 * ieee80211_mgmt(probe response) and passing to c
4532 * fg80211_inform_bss_frame.
4533 * */
4534
4535 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4536 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304537
Jeff Johnson295189b2012-06-20 16:38:30 -07004538
4539 if (NULL == bss_status)
4540 {
4541 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004542 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004543 }
4544 else
4545 {
Yue Maf49ba872013-08-19 12:04:25 -07004546 cfg80211_put_bss(
4547#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4548 wiphy,
4549#endif
4550 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004551 }
4552
4553 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4554 }
4555
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304556 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004557
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304558 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004559}
4560
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004561void
4562hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4563{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304564 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004565 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004566} /****** end hddPrintMacAddr() ******/
4567
4568void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004569hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004570{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304571 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004572 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004573 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4574 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4575 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004576} /****** end hddPrintPmkId() ******/
4577
4578//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4579//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4580
4581//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4582//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4583
4584#define dump_bssid(bssid) \
4585 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004586 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4587 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004588 }
4589
4590#define dump_pmkid(pMac, pmkid) \
4591 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004592 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4593 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004594 }
4595
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004596#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004597/*
4598 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4599 * This function is used to notify the supplicant of a new PMKSA candidate.
4600 */
4601int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304602 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004603 int index, bool preauth )
4604{
Jeff Johnsone7245742012-09-05 17:12:55 -07004605#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004606 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004607 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004608
4609 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004610 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004611
4612 if( NULL == pRoamInfo )
4613 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004614 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004615 return -EINVAL;
4616 }
4617
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004618 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4619 {
4620 dump_bssid(pRoamInfo->bssid);
4621 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004622 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004623 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004624#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304625 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004626}
4627#endif //FEATURE_WLAN_LFR
4628
Yue Maef608272013-04-08 23:09:17 -07004629#ifdef FEATURE_WLAN_LFR_METRICS
4630/*
4631 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4632 * 802.11r/LFR metrics reporting function to report preauth initiation
4633 *
4634 */
4635#define MAX_LFR_METRICS_EVENT_LENGTH 100
4636VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4637 tCsrRoamInfo *pRoamInfo)
4638{
4639 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4640 union iwreq_data wrqu;
4641
4642 ENTER();
4643
4644 if (NULL == pAdapter)
4645 {
4646 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4647 return VOS_STATUS_E_FAILURE;
4648 }
4649
4650 /* create the event */
4651 memset(&wrqu, 0, sizeof(wrqu));
4652 memset(metrics_notification, 0, sizeof(metrics_notification));
4653
4654 wrqu.data.pointer = metrics_notification;
4655 wrqu.data.length = scnprintf(metrics_notification,
4656 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4657 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4658
4659 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4660
4661 EXIT();
4662
4663 return VOS_STATUS_SUCCESS;
4664}
4665
4666/*
4667 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4668 * 802.11r/LFR metrics reporting function to report preauth completion
4669 * or failure
4670 */
4671VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4672 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4673{
4674 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4675 union iwreq_data wrqu;
4676
4677 ENTER();
4678
4679 if (NULL == pAdapter)
4680 {
4681 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4682 return VOS_STATUS_E_FAILURE;
4683 }
4684
4685 /* create the event */
4686 memset(&wrqu, 0, sizeof(wrqu));
4687 memset(metrics_notification, 0, sizeof(metrics_notification));
4688
4689 scnprintf(metrics_notification, sizeof(metrics_notification),
4690 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4691 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4692
4693 if (1 == preauth_status)
4694 strncat(metrics_notification, " TRUE", 5);
4695 else
4696 strncat(metrics_notification, " FALSE", 6);
4697
4698 wrqu.data.pointer = metrics_notification;
4699 wrqu.data.length = strlen(metrics_notification);
4700
4701 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4702
4703 EXIT();
4704
4705 return VOS_STATUS_SUCCESS;
4706}
4707
4708/*
4709 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4710 * 802.11r/LFR metrics reporting function to report handover initiation
4711 *
4712 */
4713VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4714 tCsrRoamInfo *pRoamInfo)
4715{
4716 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4717 union iwreq_data wrqu;
4718
4719 ENTER();
4720
4721 if (NULL == pAdapter)
4722 {
4723 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4724 return VOS_STATUS_E_FAILURE;
4725 }
4726
4727 /* create the event */
4728 memset(&wrqu, 0, sizeof(wrqu));
4729 memset(metrics_notification, 0, sizeof(metrics_notification));
4730
4731 wrqu.data.pointer = metrics_notification;
4732 wrqu.data.length = scnprintf(metrics_notification,
4733 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4734 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4735
4736 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4737
4738 EXIT();
4739
4740 return VOS_STATUS_SUCCESS;
4741}
4742#endif
4743
Jeff Johnson295189b2012-06-20 16:38:30 -07004744/*
4745 * FUNCTION: hdd_cfg80211_scan_done_callback
4746 * scanning callback function, called after finishing scan
4747 *
4748 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304749static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004750 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4751{
4752 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304753 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004754 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004755 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4756 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004757 struct cfg80211_scan_request *req = NULL;
4758 int ret = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304759 long waitRet = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004760
4761 ENTER();
4762
4763 hddLog(VOS_TRACE_LEVEL_INFO,
4764 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004765 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004766 __func__, halHandle, pContext, (int) scanId, (int) status);
4767
Kiet Lamac06e2c2013-10-23 16:25:07 +05304768 pScanInfo->mScanPendingCounter = 0;
4769
Jeff Johnson295189b2012-06-20 16:38:30 -07004770 //Block on scan req completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304771 waitRet = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07004772 &pScanInfo->scan_req_completion_event,
4773 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304774 if (waitRet <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07004775 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304776 hddLog(VOS_TRACE_LEVEL_ERROR,
4777 "%s wait on scan_req_completion_event failed %ld",__func__, waitRet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004778 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004779 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004780 }
4781
Yue Maef608272013-04-08 23:09:17 -07004782 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004783 {
4784 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004785 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004786 }
4787
4788 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304789 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004790 {
4791 hddLog(VOS_TRACE_LEVEL_INFO,
4792 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004793 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004794 (int) scanId);
4795 }
4796
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304797 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004798 pAdapter);
4799
4800 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304801 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004802
4803
4804 /* If any client wait scan result through WEXT
4805 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004806 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004807 {
4808 /* The other scan request waiting for current scan finish
4809 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004810 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004811 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004812 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004813 }
4814 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004815 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004816 {
4817 struct net_device *dev = pAdapter->dev;
4818 union iwreq_data wrqu;
4819 int we_event;
4820 char *msg;
4821
4822 memset(&wrqu, '\0', sizeof(wrqu));
4823 we_event = SIOCGIWSCAN;
4824 msg = NULL;
4825 wireless_send_event(dev, we_event, &wrqu, msg);
4826 }
4827 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004828 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004829
4830 /* Get the Scan Req */
4831 req = pAdapter->request;
4832
4833 if (!req)
4834 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004835 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004836 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004837 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004838 }
4839
4840 /*
4841 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304842 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004843 req->n_ssids = 0;
4844 req->n_channels = 0;
4845 req->ie = 0;
4846
Jeff Johnson295189b2012-06-20 16:38:30 -07004847 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004848 /* Scan is no longer pending */
4849 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004850
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004851 /*
4852 * cfg80211_scan_done informing NL80211 about completion
4853 * of scanning
4854 */
4855 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004856 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004857
Jeff Johnsone7245742012-09-05 17:12:55 -07004858allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004859 /* release the wake lock at the end of the scan*/
4860 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004861
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004862 /* Acquire wakelock to handle the case where APP's tries to suspend
4863 * immediatly after the driver gets connect request(i.e after scan)
4864 * from supplicant, this result in app's is suspending and not able
4865 * to process the connect request to AP */
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05304866 hdd_prevent_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004867
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004868#ifdef FEATURE_WLAN_TDLS
4869 wlan_hdd_tdls_scan_done_callback(pAdapter);
4870#endif
4871
Jeff Johnson295189b2012-06-20 16:38:30 -07004872 EXIT();
4873 return 0;
4874}
4875
4876/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004877 * FUNCTION: hdd_isScanAllowed
4878 * Go through each adapter and check if scan allowed
4879 *
4880 */
4881v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4882{
4883 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4884 hdd_station_ctx_t *pHddStaCtx = NULL;
4885 hdd_adapter_t *pAdapter = NULL;
4886 VOS_STATUS status = 0;
4887 v_U8_t staId = 0;
4888 v_U8_t *staMac = NULL;
4889
c_hpothu9b781ba2013-12-30 20:57:45 +05304890 if (TRUE == pHddCtx->btCoexModeSet)
4891 {
4892 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4893 FL("BTCoex Mode operation in progress, Do not allow scan"));
4894 return VOS_FALSE;
4895 }
4896
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004897 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4898
4899 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4900 {
4901 pAdapter = pAdapterNode->pAdapter;
4902
4903 if( pAdapter )
4904 {
4905 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304906 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004907 __func__, pAdapter->device_mode);
4908 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4909 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4910 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4911 {
4912 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4913 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4914 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4915 {
4916 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4917 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004918 "%s: client " MAC_ADDRESS_STR
4919 " is in the middle of WPS/EAPOL exchange.", __func__,
4920 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004921 return VOS_FALSE;
4922 }
4923 }
4924 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4925 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4926 {
4927 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4928 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304929 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004930 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4931 {
4932 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4933
4934 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004935 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
4936 "middle of WPS/EAPOL exchange.", __func__,
4937 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004938 return VOS_FALSE;
4939 }
4940 }
4941 }
4942 }
4943 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4944 pAdapterNode = pNext;
4945 }
4946 hddLog(VOS_TRACE_LEVEL_INFO,
4947 "%s: Scan allowed", __func__);
4948 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304949}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004950
4951/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004952 * FUNCTION: wlan_hdd_cfg80211_scan
4953 * this scan respond to scan trigger and update cfg80211 scan database
4954 * later, scan dump command can be used to recieve scan results
4955 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004956int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4957#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4958 struct net_device *dev,
4959#endif
4960 struct cfg80211_scan_request *request)
4961{
4962#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4963 struct net_device *dev = request->wdev->netdev;
4964#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304965 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004966 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4967 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304968 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004969 tCsrScanRequest scanRequest;
4970 tANI_U8 *channelList = NULL, i;
4971 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304972 int status;
4973 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004974 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004975
4976 ENTER();
4977
Arif Hussain6d2a3322013-11-17 19:50:10 -08004978 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004979 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004980
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304981 status = wlan_hdd_validate_context(pHddCtx);
4982
4983 if (0 != status)
4984 {
4985 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4986 "%s: HDD context is not valid", __func__);
4987 return status;
4988 }
4989
4990 cfg_param = pHddCtx->cfg_ini;
4991 pScanInfo = &pHddCtx->scan_info;
4992
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004993 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004994 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004995 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004996 {
4997 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004998 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4999 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005000 return -EBUSY;
5001 }
5002
Jeff Johnson295189b2012-06-20 16:38:30 -07005003#ifdef WLAN_BTAMP_FEATURE
5004 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005005 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07005006 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005007 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005008 "%s: No scanning when AMP is on", __func__);
5009 return -EOPNOTSUPP;
5010 }
5011#endif
5012 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005013 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07005014 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005015 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005016 "%s: Not scanning on device_mode = %d",
5017 __func__, pAdapter->device_mode);
5018 return -EOPNOTSUPP;
5019 }
5020
5021 if (TRUE == pScanInfo->mScanPending)
5022 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305023 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
5024 {
5025 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
5026 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005027 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005028 }
5029
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305030 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07005031 //Channel and action frame is pending
5032 //Otherwise Cancel Remain On Channel and allow Scan
5033 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005034 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07005035 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305036 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005037 return -EBUSY;
5038 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005039#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005040 /* if tdls disagree scan right now, return immediately.
5041 tdls will schedule the scan when scan is allowed. (return SUCCESS)
5042 or will reject the scan if any TDLS is in progress. (return -EBUSY)
5043 */
5044 status = wlan_hdd_tdls_scan_callback (pAdapter,
5045 wiphy,
5046#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5047 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07005048#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005049 request);
5050 if(status <= 0)
5051 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305052 if(!status)
5053 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS in progress."
5054 "scan rejected %d", __func__, status);
5055 else
5056 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS teardown is ongoing %d",
5057 __func__, status);
5058
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005059 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005060 }
5061#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07005062
Jeff Johnson295189b2012-06-20 16:38:30 -07005063 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
5064 {
5065 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08005066 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005067 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305068 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005069 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
5070 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305071 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005072 "%s: MAX TM Level Scan not allowed", __func__);
5073 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305074 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005075 }
5076 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
5077
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005078 /* Check if scan is allowed at this point of time.
5079 */
5080 if (!hdd_isScanAllowed(pHddCtx))
5081 {
5082 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
5083 return -EBUSY;
5084 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305085
Jeff Johnson295189b2012-06-20 16:38:30 -07005086 vos_mem_zero( &scanRequest, sizeof(scanRequest));
5087
5088 if (NULL != request)
5089 {
5090 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305091 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07005092
5093 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
5094 * Becasue of this, driver is assuming that this is not wildcard scan and so
5095 * is not aging out the scan results.
5096 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07005097 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07005098 {
5099 request->n_ssids = 0;
5100 }
5101
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07005102 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07005103 {
5104 tCsrSSIDInfo *SsidInfo;
5105 int j;
5106 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
5107 /* Allocate num_ssid tCsrSSIDInfo structure */
5108 SsidInfo = scanRequest.SSIDs.SSIDList =
5109 ( tCsrSSIDInfo *)vos_mem_malloc(
5110 request->n_ssids*sizeof(tCsrSSIDInfo));
5111
5112 if(NULL == scanRequest.SSIDs.SSIDList)
5113 {
5114 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305115 "%s: memory alloc failed SSIDInfo buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005116 return -ENOMEM;
5117 }
5118
5119 /* copy all the ssid's and their length */
5120 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
5121 {
5122 /* get the ssid length */
5123 SsidInfo->SSID.length = request->ssids[j].ssid_len;
5124 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
5125 SsidInfo->SSID.length);
5126 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
Nirav Shah20ac06f2013-12-12 18:14:06 +05305127 hddLog(VOS_TRACE_LEVEL_INFO, "SSID number %d: %s",
Jeff Johnson295189b2012-06-20 16:38:30 -07005128 j, SsidInfo->SSID.ssId);
5129 }
5130 /* set the scan type to active */
5131 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5132 }
5133 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
5134 {
5135 /* set the scan type to active */
5136 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5137 }
5138 else
5139 {
5140 /*Set the scan type to default type, in this case it is ACTIVE*/
5141 scanRequest.scanType = pScanInfo->scan_mode;
5142 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305143 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07005144 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
5145 }
5146 else
5147 {
5148 /* set the scan type to active */
5149 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5150 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
5151
5152 /* set min and max channel time to zero */
5153 scanRequest.minChnTime = 0;
5154 scanRequest.maxChnTime = 0;
5155 }
5156
5157 /* set BSSType to default type */
5158 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
5159
5160 /*TODO: scan the requested channels only*/
5161
5162 /*Right now scanning all the channels */
5163 if( request )
5164 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305165 hddLog(VOS_TRACE_LEVEL_INFO,
5166 "No of Scan Channels: %d", request->n_channels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005167 if( request->n_channels )
5168 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305169 char chList [(request->n_channels*5)+1];
5170 int len;
Jeff Johnson295189b2012-06-20 16:38:30 -07005171 channelList = vos_mem_malloc( request->n_channels );
5172 if( NULL == channelList )
5173 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305174 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305175 "%s: memory alloc failed channelList", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005176 status = -ENOMEM;
5177 goto free_mem;
5178 }
5179
Nirav Shah20ac06f2013-12-12 18:14:06 +05305180 for( i = 0, len = 0; i < request->n_channels ; i++ )
5181 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 channelList[i] = request->channels[i]->hw_value;
Nirav Shah20ac06f2013-12-12 18:14:06 +05305183 len += snprintf(chList+len, 5, "%d ", channelList[i]);
5184 }
5185
5186 hddLog(VOS_TRACE_LEVEL_INFO,
5187 "Channel-List: %s ", chList);
Jeff Johnson295189b2012-06-20 16:38:30 -07005188 }
5189
5190 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
5191 scanRequest.ChannelInfo.ChannelList = channelList;
5192
5193 /* set requestType to full scan */
5194 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305195
5196 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005197 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305198 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005199 */
5200
5201 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305202 * and in that case driver shoudnt flush scan results. If
5203 * driver flushes the scan results here and unfortunately if
5204 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005205 * fails which is not desired
5206 */
5207
5208 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
5209 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305210 hddLog(VOS_TRACE_LEVEL_DEBUG, "Flushing P2P Results");
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005211 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
5212 pAdapter->sessionId );
5213 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005214
5215 if( request->ie_len )
5216 {
5217 /* save this for future association (join requires this) */
Agarwal Ashish4f616132013-12-30 23:32:50 +05305218 /*TODO: Array needs to be converted to dynamic allocation,
5219 * as multiple ie.s can be sent in cfg80211_scan_request structure
5220 * CR 597966
5221 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005222 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5223 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5224 pScanInfo->scanAddIE.length = request->ie_len;
5225
Agarwal Ashish4f616132013-12-30 23:32:50 +05305226 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07005227 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
Agarwal Ashish4f616132013-12-30 23:32:50 +05305228 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005229 {
Agarwal Ashish4f616132013-12-30 23:32:50 +05305230 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
5231 {
5232 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5233 memcpy( pwextBuf->roamProfile.addIEScan,
5234 request->ie, request->ie_len);
5235 }
5236 else
5237 {
5238 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
5239 "%d", request->ie_len);
5240 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005241
Agarwal Ashish4f616132013-12-30 23:32:50 +05305242 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005243 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5244 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5245
Jeff Johnson295189b2012-06-20 16:38:30 -07005246 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5247 request->ie_len);
5248 if (pP2pIe != NULL)
5249 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005250#ifdef WLAN_FEATURE_P2P_DEBUG
5251 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5252 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5253 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5254 {
5255 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5256 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5257 "Go nego completed to Connection is started");
5258 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5259 "for 8way Handshake");
5260 }
5261 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5262 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5263 {
5264 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5265 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5266 "Disconnected state to Connection is started");
5267 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5268 "for 4way Handshake");
5269 }
5270#endif
5271
Jeff Johnsone7245742012-09-05 17:12:55 -07005272 /* no_cck will be set during p2p find to disable 11b rates */
5273 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005275 hddLog(VOS_TRACE_LEVEL_INFO,
5276 "%s: This is a P2P Search", __func__);
5277 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005278
Jeff Johnsone7245742012-09-05 17:12:55 -07005279 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5280 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005281 /* set requestType to P2P Discovery */
5282 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005283 }
5284
5285 /*
5286 Skip Dfs Channel in case of P2P Search
5287 if it is set in ini file
5288 */
5289 if(cfg_param->skipDfsChnlInP2pSearch)
5290 {
5291 scanRequest.skipDfsChnlInP2pSearch = 1;
5292 }
5293 else
5294 {
5295 scanRequest.skipDfsChnlInP2pSearch = 0;
5296 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005297
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 }
5299 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005300 }
5301 }
5302
5303 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5304
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005305 /* acquire the wakelock to avoid the apps suspend during the scan. To
5306 * address the following issues.
5307 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5308 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5309 * for long time, this result in apps running at full power for long time.
5310 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5311 * be stuck in full power because of resume BMPS
5312 */
5313 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005314
Nirav Shah20ac06f2013-12-12 18:14:06 +05305315 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
5316 "requestType %d, scanType %d, minChnTime %d, maxChnTime %d,"
5317 "p2pSearch %d, skipDfsChnlInP2pSearch %d", scanRequest.requestType,
5318 scanRequest.scanType, scanRequest.minChnTime, scanRequest.maxChnTime,
5319 scanRequest.p2pSearch, scanRequest.skipDfsChnlInP2pSearch);
5320
Jeff Johnsone7245742012-09-05 17:12:55 -07005321 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005322 pAdapter->sessionId, &scanRequest, &scanId,
5323 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005324
Jeff Johnson295189b2012-06-20 16:38:30 -07005325 if (eHAL_STATUS_SUCCESS != status)
5326 {
5327 hddLog(VOS_TRACE_LEVEL_ERROR,
5328 "%s: sme_ScanRequest returned error %d", __func__, status);
5329 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005330 if(eHAL_STATUS_RESOURCES == status)
5331 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305332 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: HO is in progress."
5333 "So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005334 status = -EBUSY;
5335 } else {
5336 status = -EIO;
5337 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005338 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005339 goto free_mem;
5340 }
5341
5342 pScanInfo->mScanPending = TRUE;
5343 pAdapter->request = request;
5344 pScanInfo->scanId = scanId;
5345
5346 complete(&pScanInfo->scan_req_completion_event);
5347
5348free_mem:
5349 if( scanRequest.SSIDs.SSIDList )
5350 {
5351 vos_mem_free(scanRequest.SSIDs.SSIDList);
5352 }
5353
5354 if( channelList )
5355 vos_mem_free( channelList );
5356
5357 EXIT();
5358
5359 return status;
5360}
5361
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005362
5363void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5364{
5365 v_U8_t iniDot11Mode =
5366 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5367 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5368
5369 switch ( iniDot11Mode )
5370 {
5371 case eHDD_DOT11_MODE_AUTO:
5372 case eHDD_DOT11_MODE_11ac:
5373 case eHDD_DOT11_MODE_11ac_ONLY:
5374#ifdef WLAN_FEATURE_11AC
5375 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5376#else
5377 hddDot11Mode = eHDD_DOT11_MODE_11n;
5378#endif
5379 break;
5380 case eHDD_DOT11_MODE_11n:
5381 case eHDD_DOT11_MODE_11n_ONLY:
5382 hddDot11Mode = eHDD_DOT11_MODE_11n;
5383 break;
5384 default:
5385 hddDot11Mode = iniDot11Mode;
5386 break;
5387 }
5388 /* This call decides required channel bonding mode */
5389 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5390 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5391 operationChannel);
5392}
5393
Jeff Johnson295189b2012-06-20 16:38:30 -07005394/*
5395 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305396 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305398int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005399 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005400{
5401 int status = 0;
5402 hdd_wext_state_t *pWextState;
5403 v_U32_t roamId;
5404 tCsrRoamProfile *pRoamProfile;
Jeff Johnson295189b2012-06-20 16:38:30 -07005405 eCsrAuthType RSNAuthType;
5406
5407 ENTER();
5408
5409 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305410
Jeff Johnson295189b2012-06-20 16:38:30 -07005411 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5412 {
5413 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5414 return -EINVAL;
5415 }
5416
5417 pRoamProfile = &pWextState->roamProfile;
5418
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305419 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005420 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005421 hdd_station_ctx_t *pHddStaCtx;
5422 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005423
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305424 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005425 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5426 {
5427 /*QoS not enabled in cfg file*/
5428 pRoamProfile->uapsd_mask = 0;
5429 }
5430 else
5431 {
5432 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305433 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5435 }
5436
5437 pRoamProfile->SSIDs.numOfSSIDs = 1;
5438 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5439 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305440 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005441 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5442 ssid, ssid_len);
5443
5444 if (bssid)
5445 {
5446 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5447 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5448 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305449 /* Save BSSID in seperate variable as well, as RoamProfile
5450 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005451 case of join failure we should send valid BSSID to supplicant
5452 */
5453 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5454 WNI_CFG_BSSID_LEN);
5455 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005456 else
5457 {
5458 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5459 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005460
5461 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5462 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305463 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005464 /*set gen ie*/
5465 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5466 /*set auth*/
5467 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5468 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005469#ifdef FEATURE_WLAN_WAPI
5470 if (pAdapter->wapi_info.nWapiMode)
5471 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005472 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005473 switch (pAdapter->wapi_info.wapiAuthMode)
5474 {
5475 case WAPI_AUTH_MODE_PSK:
5476 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005477 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005478 pAdapter->wapi_info.wapiAuthMode);
5479 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5480 break;
5481 }
5482 case WAPI_AUTH_MODE_CERT:
5483 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005484 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005485 pAdapter->wapi_info.wapiAuthMode);
5486 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5487 break;
5488 }
5489 } // End of switch
5490 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5491 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5492 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005493 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 pRoamProfile->AuthType.numEntries = 1;
5495 pRoamProfile->EncryptionType.numEntries = 1;
5496 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5497 pRoamProfile->mcEncryptionType.numEntries = 1;
5498 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5499 }
5500 }
5501#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305502#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305503 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305504 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5505 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5506 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305507 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5508 sizeof (tSirGtkOffloadParams));
5509 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305510 }
5511#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005512 pRoamProfile->csrPersona = pAdapter->device_mode;
5513
Jeff Johnson32d95a32012-09-10 13:15:23 -07005514 if( operatingChannel )
5515 {
5516 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5517 pRoamProfile->ChannelInfo.numOfChannels = 1;
5518 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005519 else
5520 {
5521 pRoamProfile->ChannelInfo.ChannelList = NULL;
5522 pRoamProfile->ChannelInfo.numOfChannels = 0;
5523 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005524 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5525 {
5526 hdd_select_cbmode(pAdapter,operatingChannel);
5527 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005528 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5529 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305530 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005531 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005532 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5533 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305534 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5535 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005536 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5537 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305538
5539 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005540 pAdapter->sessionId, pRoamProfile, &roamId);
5541
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305542 if ((eHAL_STATUS_SUCCESS != status) &&
5543 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5544 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305545
5546 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005547 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5548 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5549 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305550 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005551 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305552 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005553
5554 pRoamProfile->ChannelInfo.ChannelList = NULL;
5555 pRoamProfile->ChannelInfo.numOfChannels = 0;
5556
Jeff Johnson295189b2012-06-20 16:38:30 -07005557 }
5558 else
5559 {
5560 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5561 return -EINVAL;
5562 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005563 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005564 return status;
5565}
5566
5567/*
5568 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5569 * This function is used to set the authentication type (OPEN/SHARED).
5570 *
5571 */
5572static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5573 enum nl80211_auth_type auth_type)
5574{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305575 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005576 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5577
5578 ENTER();
5579
5580 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305581 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005583 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305584 hddLog(VOS_TRACE_LEVEL_INFO,
5585 "%s: set authentication type to AUTOSWITCH", __func__);
5586 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5587 break;
5588
5589 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005590#ifdef WLAN_FEATURE_VOWIFI_11R
5591 case NL80211_AUTHTYPE_FT:
5592#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305593 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005594 "%s: set authentication type to OPEN", __func__);
5595 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5596 break;
5597
5598 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305599 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005600 "%s: set authentication type to SHARED", __func__);
5601 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5602 break;
5603#ifdef FEATURE_WLAN_CCX
5604 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305605 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005606 "%s: set authentication type to CCKM WPA", __func__);
5607 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5608 break;
5609#endif
5610
5611
5612 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305613 hddLog(VOS_TRACE_LEVEL_ERROR,
5614 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005615 auth_type);
5616 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5617 return -EINVAL;
5618 }
5619
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305620 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005621 pHddStaCtx->conn_info.authType;
5622 return 0;
5623}
5624
5625/*
5626 * FUNCTION: wlan_hdd_set_akm_suite
5627 * This function is used to set the key mgmt type(PSK/8021x).
5628 *
5629 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305630static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005631 u32 key_mgmt
5632 )
5633{
5634 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5635 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305636
Jeff Johnson295189b2012-06-20 16:38:30 -07005637 /*set key mgmt type*/
5638 switch(key_mgmt)
5639 {
5640 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305641#ifdef WLAN_FEATURE_VOWIFI_11R
5642 case WLAN_AKM_SUITE_FT_PSK:
5643#endif
5644 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005645 __func__);
5646 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5647 break;
5648
5649 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305650#ifdef WLAN_FEATURE_VOWIFI_11R
5651 case WLAN_AKM_SUITE_FT_8021X:
5652#endif
5653 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 __func__);
5655 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5656 break;
5657#ifdef FEATURE_WLAN_CCX
5658#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5659#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5660 case WLAN_AKM_SUITE_CCKM:
5661 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5662 __func__);
5663 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5664 break;
5665#endif
5666
5667 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305668 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005669 __func__, key_mgmt);
5670 return -EINVAL;
5671
5672 }
5673 return 0;
5674}
5675
5676/*
5677 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305678 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005679 * (NONE/WEP40/WEP104/TKIP/CCMP).
5680 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305681static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5682 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 bool ucast
5684 )
5685{
5686 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305687 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005688 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5689
5690 ENTER();
5691
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305692 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005693 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305694 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005695 __func__, cipher);
5696 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5697 }
5698 else
5699 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305700
Jeff Johnson295189b2012-06-20 16:38:30 -07005701 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305702 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005703 {
5704 case IW_AUTH_CIPHER_NONE:
5705 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5706 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305707
Jeff Johnson295189b2012-06-20 16:38:30 -07005708 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305709 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305711
Jeff Johnson295189b2012-06-20 16:38:30 -07005712 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305713 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005714 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305715
Jeff Johnson295189b2012-06-20 16:38:30 -07005716 case WLAN_CIPHER_SUITE_TKIP:
5717 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5718 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305719
Jeff Johnson295189b2012-06-20 16:38:30 -07005720 case WLAN_CIPHER_SUITE_CCMP:
5721 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5722 break;
5723#ifdef FEATURE_WLAN_WAPI
5724 case WLAN_CIPHER_SUITE_SMS4:
5725 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5726 break;
5727#endif
5728
5729#ifdef FEATURE_WLAN_CCX
5730 case WLAN_CIPHER_SUITE_KRK:
5731 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5732 break;
5733#endif
5734 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305735 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005736 __func__, cipher);
5737 return -EOPNOTSUPP;
5738 }
5739 }
5740
5741 if (ucast)
5742 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305743 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005744 __func__, encryptionType);
5745 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5746 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305747 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005748 encryptionType;
5749 }
5750 else
5751 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305752 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005753 __func__, encryptionType);
5754 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5755 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5756 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5757 }
5758
5759 return 0;
5760}
5761
5762
5763/*
5764 * FUNCTION: wlan_hdd_cfg80211_set_ie
5765 * This function is used to parse WPA/RSN IE's.
5766 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305767int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5768 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005769 size_t ie_len
5770 )
5771{
5772 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5773 u8 *genie = ie;
5774 v_U16_t remLen = ie_len;
5775#ifdef FEATURE_WLAN_WAPI
5776 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5777 u16 *tmp;
5778 v_U16_t akmsuiteCount;
5779 int *akmlist;
5780#endif
5781 ENTER();
5782
5783 /* clear previous assocAddIE */
5784 pWextState->assocAddIE.length = 0;
5785 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5786
5787 while (remLen >= 2)
5788 {
5789 v_U16_t eLen = 0;
5790 v_U8_t elementId;
5791 elementId = *genie++;
5792 eLen = *genie++;
5793 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305794
Arif Hussain6d2a3322013-11-17 19:50:10 -08005795 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005796 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305797
5798 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005799 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305800 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005801 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 -07005802 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305803 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005804 "%s: Invalid WPA IE", __func__);
5805 return -EINVAL;
5806 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305807 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005808 {
5809 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305810 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005811 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305812
Jeff Johnson295189b2012-06-20 16:38:30 -07005813 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5814 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005815 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5816 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005817 VOS_ASSERT(0);
5818 return -ENOMEM;
5819 }
5820 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5821 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5822 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305823
Jeff Johnson295189b2012-06-20 16:38:30 -07005824 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5825 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5826 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5827 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305828 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5829 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005830 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5831 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5832 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5833 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5834 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5835 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305836 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05305837 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005838 {
5839 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305840 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005841 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305842
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5844 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005845 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5846 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005847 VOS_ASSERT(0);
5848 return -ENOMEM;
5849 }
5850 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5851 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5852 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305853
Jeff Johnson295189b2012-06-20 16:38:30 -07005854 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5855 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5856 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005857#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305858 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5859 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005860 /*Consider WFD IE, only for P2P Client */
5861 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5862 {
5863 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305864 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005865 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305866
Jeff Johnson295189b2012-06-20 16:38:30 -07005867 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5868 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005869 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5870 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005871 VOS_ASSERT(0);
5872 return -ENOMEM;
5873 }
5874 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5875 // WPS IE + P2P IE + WFD IE
5876 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5877 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305878
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5880 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5881 }
5882#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005883 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305884 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005885 HS20_OUI_TYPE_SIZE)) )
5886 {
5887 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305888 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005889 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005890
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005891 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5892 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005893 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5894 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005895 VOS_ASSERT(0);
5896 return -ENOMEM;
5897 }
5898 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5899 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005900
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005901 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5902 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5903 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005904
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005905 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5906
5907 /* populating as ADDIE in beacon frames */
5908 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5909 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5910 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5911 {
5912 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5913 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5914 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5915 {
5916 hddLog(LOGE,
5917 "Coldn't pass "
5918 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5919 }
5920 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5921 else
5922 hddLog(LOGE,
5923 "Could not pass on "
5924 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5925
5926 /* IBSS mode doesn't contain params->proberesp_ies still
5927 beaconIE's need to be populated in probe response frames */
5928 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5929 {
5930 u16 rem_probe_resp_ie_len = eLen + 2;
5931 u8 probe_rsp_ie_len[3] = {0};
5932 u8 counter = 0;
5933
5934 /* Check Probe Resp Length if it is greater then 255 then
5935 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5936 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5937 not able Store More then 255 bytes into One Variable */
5938
5939 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5940 {
5941 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5942 {
5943 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5944 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5945 }
5946 else
5947 {
5948 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5949 rem_probe_resp_ie_len = 0;
5950 }
5951 }
5952
5953 rem_probe_resp_ie_len = 0;
5954
5955 if (probe_rsp_ie_len[0] > 0)
5956 {
5957 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5958 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5959 (tANI_U8*)(genie - 2),
5960 probe_rsp_ie_len[0], NULL,
5961 eANI_BOOLEAN_FALSE)
5962 == eHAL_STATUS_FAILURE)
5963 {
5964 hddLog(LOGE,
5965 "Could not pass"
5966 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5967 }
5968 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5969 }
5970
5971 if (probe_rsp_ie_len[1] > 0)
5972 {
5973 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5974 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5975 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5976 probe_rsp_ie_len[1], NULL,
5977 eANI_BOOLEAN_FALSE)
5978 == eHAL_STATUS_FAILURE)
5979 {
5980 hddLog(LOGE,
5981 "Could not pass"
5982 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5983 }
5984 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5985 }
5986
5987 if (probe_rsp_ie_len[2] > 0)
5988 {
5989 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5990 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5991 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5992 probe_rsp_ie_len[2], NULL,
5993 eANI_BOOLEAN_FALSE)
5994 == eHAL_STATUS_FAILURE)
5995 {
5996 hddLog(LOGE,
5997 "Could not pass"
5998 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5999 }
6000 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
6001 }
6002
6003 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6004 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6005 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6006 {
6007 hddLog(LOGE,
6008 "Could not pass"
6009 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
6010 }
6011 }
6012 else
6013 {
6014 // Reset WNI_CFG_PROBE_RSP Flags
6015 wlan_hdd_reset_prob_rspies(pAdapter);
6016
6017 hddLog(VOS_TRACE_LEVEL_INFO,
6018 "%s: No Probe Response IE received in set beacon",
6019 __func__);
6020 }
6021 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07006022 break;
6023 case DOT11F_EID_RSN:
6024 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
6025 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
6026 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
6027 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
6028 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
6029 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006030 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
6031 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306032 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006033 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306034 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006035 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306036
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006037 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6038 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006039 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6040 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006041 VOS_ASSERT(0);
6042 return -ENOMEM;
6043 }
6044 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6045 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306046
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006047 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6048 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6049 break;
6050 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006051#ifdef FEATURE_WLAN_WAPI
6052 case WLAN_EID_WAPI:
6053 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006054 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07006055 pAdapter->wapi_info.nWapiMode);
6056 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306057 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 akmsuiteCount = WPA_GET_LE16(tmp);
6059 tmp = tmp + 1;
6060 akmlist = (int *)(tmp);
6061 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
6062 {
6063 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
6064 }
6065 else
6066 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006067 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07006068 VOS_ASSERT(0);
6069 return -EINVAL;
6070 }
6071
6072 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
6073 {
6074 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006075 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006076 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306077 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006078 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306079 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006080 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006081 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
6083 }
6084 break;
6085#endif
6086 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306087 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006089 /* when Unknown IE is received we should break and continue
6090 * to the next IE in the buffer instead we were returning
6091 * so changing this to break */
6092 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006093 }
6094 genie += eLen;
6095 remLen -= eLen;
6096 }
6097 EXIT();
6098 return 0;
6099}
6100
6101/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05306102 * FUNCTION: hdd_isWPAIEPresent
6103 * Parse the received IE to find the WPA IE
6104 *
6105 */
6106static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
6107{
6108 v_U8_t eLen = 0;
6109 v_U16_t remLen = ie_len;
6110 v_U8_t elementId = 0;
6111
6112 while (remLen >= 2)
6113 {
6114 elementId = *ie++;
6115 eLen = *ie++;
6116 remLen -= 2;
6117 if (eLen > remLen)
6118 {
6119 hddLog(VOS_TRACE_LEVEL_ERROR,
6120 "%s: IE length is wrong %d", __func__, eLen);
6121 return FALSE;
6122 }
6123 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
6124 {
6125 /* OUI - 0x00 0X50 0XF2
6126 WPA Information Element - 0x01
6127 WPA version - 0x01*/
6128 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
6129 return TRUE;
6130 }
6131 ie += eLen;
6132 remLen -= eLen;
6133 }
6134 return FALSE;
6135}
6136
6137/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006138 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306139 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006140 * parameters during connect operation.
6141 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306142int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006143 struct cfg80211_connect_params *req
6144 )
6145{
6146 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306147 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006148 ENTER();
6149
6150 /*set wpa version*/
6151 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6152
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306153 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006154 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05306155 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006156 {
6157 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6158 }
6159 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
6160 {
6161 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6162 }
6163 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306164
6165 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006166 pWextState->wpaVersion);
6167
6168 /*set authentication type*/
6169 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
6170
6171 if (0 > status)
6172 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306173 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 "%s: failed to set authentication type ", __func__);
6175 return status;
6176 }
6177
6178 /*set key mgmt type*/
6179 if (req->crypto.n_akm_suites)
6180 {
6181 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
6182 if (0 > status)
6183 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306184 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07006185 __func__);
6186 return status;
6187 }
6188 }
6189
6190 /*set pairwise cipher type*/
6191 if (req->crypto.n_ciphers_pairwise)
6192 {
6193 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6194 req->crypto.ciphers_pairwise[0], true);
6195 if (0 > status)
6196 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306197 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006198 "%s: failed to set unicast cipher type", __func__);
6199 return status;
6200 }
6201 }
6202 else
6203 {
6204 /*Reset previous cipher suite to none*/
6205 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6206 if (0 > status)
6207 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306208 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006209 "%s: failed to set unicast cipher type", __func__);
6210 return status;
6211 }
6212 }
6213
6214 /*set group cipher type*/
6215 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6216 false);
6217
6218 if (0 > status)
6219 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306220 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006221 __func__);
6222 return status;
6223 }
6224
Chet Lanctot186b5732013-03-18 10:26:30 -07006225#ifdef WLAN_FEATURE_11W
6226 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6227#endif
6228
Jeff Johnson295189b2012-06-20 16:38:30 -07006229 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6230 if (req->ie_len)
6231 {
6232 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6233 if ( 0 > status)
6234 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306235 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006236 __func__);
6237 return status;
6238 }
6239 }
6240
6241 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306242 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 {
6244 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6245 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6246 )
6247 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306248 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6250 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306251 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006252 __func__);
6253 return -EOPNOTSUPP;
6254 }
6255 else
6256 {
6257 u8 key_len = req->key_len;
6258 u8 key_idx = req->key_idx;
6259
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306260 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006261 && (CSR_MAX_NUM_KEY > key_idx)
6262 )
6263 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306264 hddLog(VOS_TRACE_LEVEL_INFO,
6265 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006266 __func__, key_idx, key_len);
6267 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306268 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006269 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306270 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006271 (u8)key_len;
6272 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6273 }
6274 }
6275 }
6276 }
6277
6278 return status;
6279}
6280
6281/*
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306282 * FUNCTION: wlan_hdd_try_disconnect
6283 * This function is used to disconnect from previous
6284 * connection
6285 */
6286static int wlan_hdd_try_disconnect( hdd_adapter_t *pAdapter )
6287{
6288 long ret = 0;
6289 hdd_station_ctx_t *pHddStaCtx;
6290 eMib_dot11DesiredBssType connectedBssType;
6291
6292 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6293
6294 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
6295
6296 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
6297 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
6298 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
6299 {
6300 /* Issue disconnect to CSR */
6301 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6302 if( eHAL_STATUS_SUCCESS ==
6303 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6304 pAdapter->sessionId,
6305 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
6306 {
6307 ret = wait_for_completion_interruptible_timeout(
6308 &pAdapter->disconnect_comp_var,
6309 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6310 if (0 >= ret)
6311 {
6312 hddLog(LOGE, FL("Failed to receive disconnect event"));
6313 return -EALREADY;
6314 }
6315 }
6316 }
6317 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
6318 {
6319 ret = wait_for_completion_interruptible_timeout(
6320 &pAdapter->disconnect_comp_var,
6321 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6322 if (0 >= ret)
6323 {
6324 hddLog(LOGE, FL("Failed to receive disconnect event"));
6325 return -EALREADY;
6326 }
6327 }
6328
6329 return 0;
6330}
6331
6332/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006333 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306334 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006335 * parameters during connect operation.
6336 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306337static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006338 struct net_device *ndev,
6339 struct cfg80211_connect_params *req
6340 )
6341{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306342 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306343 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006344 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006345 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006346
6347 ENTER();
6348
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006349 if (!pAdapter)
6350 {
6351 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6352 "%s: Adapter context is null", __func__);
6353 return VOS_STATUS_E_FAILURE;
6354 }
6355
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306356 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006357 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006358
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306359 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006360 if (!pHddCtx)
6361 {
6362 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6363 "%s: HDD context is null", __func__);
6364 return VOS_STATUS_E_FAILURE;
6365 }
6366
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306367 status = wlan_hdd_validate_context(pHddCtx);
6368
6369 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006370 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306371 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6372 "%s: HDD context is not valid", __func__);
6373 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006374 }
6375
6376#ifdef WLAN_BTAMP_FEATURE
6377 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306378 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006379 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306380 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006381 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006382 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006383 }
6384#endif
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306385
6386 //If Device Mode is Station Concurrent Sessions Exit BMps
6387 //P2P Mode will be taken care in Open/close adapter
6388 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6389 (vos_concurrent_sessions_running()))
6390 {
6391 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
6392 }
6393
6394 /*Try disconnecting if already in connected state*/
6395 status = wlan_hdd_try_disconnect(pAdapter);
6396 if ( 0 > status)
6397 {
6398 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6399 " connection"));
6400 return -EALREADY;
6401 }
6402
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306404 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006405
6406 if ( 0 > status)
6407 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306408 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 __func__);
6410 return status;
6411 }
6412
Mohit Khanna765234a2012-09-11 15:08:35 -07006413 if ( req->channel )
6414 {
6415 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6416 req->ssid_len, req->bssid,
6417 req->channel->hw_value);
6418 }
6419 else
6420 {
6421 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306422 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006423 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006424
6425 if (0 > status)
6426 {
6427 //ReEnable BMPS if disabled
6428 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6429 (NULL != pHddCtx))
6430 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306431 if (pHddCtx->hdd_wlan_suspended)
6432 {
6433 hdd_set_pwrparams(pHddCtx);
6434 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006435 //ReEnable Bmps and Imps back
6436 hdd_enable_bmps_imps(pHddCtx);
6437 }
6438
6439 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6440 return status;
6441 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306442 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006443 EXIT();
6444 return status;
6445}
6446
6447
6448/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306449 * FUNCTION: wlan_hdd_disconnect
6450 * This function is used to issue a disconnect request to SME
6451 */
6452int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6453{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306454 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306455 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306456 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306457 long ret;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306458
6459 status = wlan_hdd_validate_context(pHddCtx);
6460
6461 if (0 != status)
6462 {
6463 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6464 "%s: HDD context is not valid", __func__);
6465 return status;
6466 }
6467
6468 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306469 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306470 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306471
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306472 /*issue disconnect*/
6473 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6474 pAdapter->sessionId, reason);
6475
6476 if ( 0 != status )
6477 {
6478 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006479 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306480 __func__, (int)status );
6481 return -EINVAL;
6482 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306483 ret = wait_for_completion_interruptible_timeout(
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306484 &pAdapter->disconnect_comp_var,
6485 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306486 if (ret <= 0)
6487 {
6488 hddLog(VOS_TRACE_LEVEL_ERROR,
6489 FL("wait on disconnect_comp_var failed %ld"), ret);
6490 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306491 /*stop tx queues*/
6492 netif_tx_disable(pAdapter->dev);
6493 netif_carrier_off(pAdapter->dev);
6494 return status;
6495}
6496
6497
6498/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006499 * FUNCTION: wlan_hdd_cfg80211_disconnect
6500 * This function is used to issue a disconnect request to SME
6501 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306502static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006503 struct net_device *dev,
6504 u16 reason
6505 )
6506{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306507 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6508 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006509 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306510 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006511 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006512 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306513#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006514 tANI_U8 staIdx;
6515#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306516
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306518
Arif Hussain6d2a3322013-11-17 19:50:10 -08006519 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006520 __func__,pAdapter->device_mode);
6521
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306522 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6523 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006524
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306525 status = wlan_hdd_validate_context(pHddCtx);
6526
6527 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006528 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306529 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6530 "%s: HDD context is not valid", __func__);
6531 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006532 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306533
Jeff Johnson295189b2012-06-20 16:38:30 -07006534 if (NULL != pRoamProfile)
6535 {
6536 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306537 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6538 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006539 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306540 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006541 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306542 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006543 switch(reason)
6544 {
6545 case WLAN_REASON_MIC_FAILURE:
6546 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6547 break;
6548
6549 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6550 case WLAN_REASON_DISASSOC_AP_BUSY:
6551 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6552 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6553 break;
6554
6555 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6556 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6557 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6558 break;
6559
6560 case WLAN_REASON_DEAUTH_LEAVING:
6561 default:
6562 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6563 break;
6564 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306565 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6566 pScanInfo = &pHddCtx->scan_info;
6567 if (pScanInfo->mScanPending)
6568 {
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306569 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306570 "Aborting Scan");
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05306571 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId,
6572 eCSR_SCAN_ABORT_DEFAULT);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306573 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006574
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006575#ifdef FEATURE_WLAN_TDLS
6576 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006577 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006578 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006579 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6580 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006581 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006582 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006583 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006584 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006585 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006586 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006587 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006588 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006589 pAdapter->sessionId,
6590 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006591 }
6592 }
6593#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306594 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6595 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006596 {
6597 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006598 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006599 __func__, (int)status );
6600 return -EINVAL;
6601 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006602 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306603 else
6604 {
6605 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6606 "called while in %d state", __func__,
6607 pHddStaCtx->conn_info.connState);
6608 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006609 }
6610 else
6611 {
6612 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6613 }
6614
6615 return status;
6616}
6617
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306618
Jeff Johnson295189b2012-06-20 16:38:30 -07006619/*
6620 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306621 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 * settings in IBSS mode.
6623 */
6624static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306625 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 struct cfg80211_ibss_params *params
6627 )
6628{
6629 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306630 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006631 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6632 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306633
Jeff Johnson295189b2012-06-20 16:38:30 -07006634 ENTER();
6635
6636 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006637 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006638
6639 if (params->ie_len && ( NULL != params->ie) )
6640 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006641 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6642 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006643 {
6644 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6645 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6646 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006647 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006648 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006649 tDot11fIEWPA dot11WPAIE;
6650 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006651 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006652
Wilson Yang00256342013-10-10 23:13:38 -07006653 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006654 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6655 params->ie_len, DOT11F_EID_WPA);
6656 if ( NULL != ie )
6657 {
6658 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6659 // Unpack the WPA IE
6660 //Skip past the EID byte and length byte - and four byte WiFi OUI
6661 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6662 &ie[2+4],
6663 ie[1] - 4,
6664 &dot11WPAIE);
6665 /*Extract the multicast cipher, the encType for unicast
6666 cipher for wpa-none is none*/
6667 encryptionType =
6668 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6669 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006670 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006671
Jeff Johnson295189b2012-06-20 16:38:30 -07006672 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6673
6674 if (0 > status)
6675 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306676 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006677 __func__);
6678 return status;
6679 }
6680 }
6681
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306682 pWextState->roamProfile.AuthType.authType[0] =
6683 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006684 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6685
6686 if (params->privacy)
6687 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306688 /* Security enabled IBSS, At this time there is no information available
6689 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006690 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306691 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006692 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306693 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006694 *enable privacy bit in beacons */
6695
6696 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6697 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006698 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6699 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006700 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6701 pWextState->roamProfile.EncryptionType.numEntries = 1;
6702 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006703 return status;
6704}
6705
6706/*
6707 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306708 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006709 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306710static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006711 struct net_device *dev,
6712 struct cfg80211_ibss_params *params
6713 )
6714{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306715 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006716 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6717 tCsrRoamProfile *pRoamProfile;
6718 int status;
krunal sonie9002db2013-11-25 14:24:17 -08006719 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006720 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306721 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006722
6723 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306724
6725 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006726 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006727
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306728 status = wlan_hdd_validate_context(pHddCtx);
6729
6730 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006731 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306732 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6733 "%s: HDD context is not valid", __func__);
6734 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006735 }
6736
6737 if (NULL == pWextState)
6738 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006739 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006740 __func__);
6741 return -EIO;
6742 }
6743
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306744 /*Try disconnecting if already in connected state*/
6745 status = wlan_hdd_try_disconnect(pAdapter);
6746 if ( 0 > status)
6747 {
6748 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6749 " IBSS connection"));
6750 return -EALREADY;
6751 }
6752
Jeff Johnson295189b2012-06-20 16:38:30 -07006753 pRoamProfile = &pWextState->roamProfile;
6754
6755 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6756 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306757 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006758 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006759 return -EINVAL;
6760 }
6761
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006762 /* BSSID is provided by upper layers hence no need to AUTO generate */
6763 if (NULL != params->bssid) {
6764 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6765 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
6766 hddLog (VOS_TRACE_LEVEL_ERROR,
6767 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6768 return -EIO;
6769 }
6770 }
krunal sonie9002db2013-11-25 14:24:17 -08006771 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
6772 {
6773 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6774 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
6775 {
6776 hddLog (VOS_TRACE_LEVEL_ERROR,
6777 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6778 return -EIO;
6779 }
6780 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
6781 if (!params->bssid)
6782 {
6783 hddLog (VOS_TRACE_LEVEL_ERROR,
6784 "%s:Failed memory allocation", __func__);
6785 return -EIO;
6786 }
6787 vos_mem_copy((v_U8_t *)params->bssid,
6788 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
6789 VOS_MAC_ADDR_SIZE);
6790 alloc_bssid = VOS_TRUE;
6791 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006792
Jeff Johnson295189b2012-06-20 16:38:30 -07006793 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006794 if (NULL !=
6795#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6796 params->chandef.chan)
6797#else
6798 params->channel)
6799#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006800 {
6801 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006802 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6803 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6804 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6805 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006806
6807 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306808 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006809 ieee80211_frequency_to_channel(
6810#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6811 params->chandef.chan->center_freq);
6812#else
6813 params->channel->center_freq);
6814#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006815
6816 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6817 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006818 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006819 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6820 __func__);
6821 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006822 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006823
6824 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006825 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006826 if (channelNum == validChan[indx])
6827 {
6828 break;
6829 }
6830 }
6831 if (indx >= numChans)
6832 {
6833 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 __func__, channelNum);
6835 return -EINVAL;
6836 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006837 /* Set the Operational Channel */
6838 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6839 channelNum);
6840 pRoamProfile->ChannelInfo.numOfChannels = 1;
6841 pHddStaCtx->conn_info.operationChannel = channelNum;
6842 pRoamProfile->ChannelInfo.ChannelList =
6843 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006844 }
6845
6846 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306847 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006848 if (status < 0)
6849 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306850 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006851 __func__);
6852 return status;
6853 }
6854
6855 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306856 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006857 params->ssid_len, params->bssid,
6858 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006859
6860 if (0 > status)
6861 {
6862 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6863 return status;
6864 }
6865
krunal sonie9002db2013-11-25 14:24:17 -08006866 if (NULL != params->bssid &&
6867 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
6868 alloc_bssid == VOS_TRUE)
6869 {
6870 vos_mem_free(params->bssid);
6871 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006872 return 0;
6873}
6874
6875/*
6876 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306877 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306879static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006880 struct net_device *dev
6881 )
6882{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306883 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6885 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306886 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6887 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006888
6889 ENTER();
6890
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306891 status = wlan_hdd_validate_context(pHddCtx);
6892
6893 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006894 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306895 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6896 "%s: HDD context is not valid", __func__);
6897 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006898 }
6899
Arif Hussain6d2a3322013-11-17 19:50:10 -08006900 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006901 if (NULL == pWextState)
6902 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006903 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006904 __func__);
6905 return -EIO;
6906 }
6907
6908 pRoamProfile = &pWextState->roamProfile;
6909
6910 /* Issue disconnect only if interface type is set to IBSS */
6911 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6912 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306913 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 __func__);
6915 return -EINVAL;
6916 }
6917
6918 /* Issue Disconnect request */
6919 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6920 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6921 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6922
6923 return 0;
6924}
6925
6926/*
6927 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6928 * This function is used to set the phy parameters
6929 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6930 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306931static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006932 u32 changed)
6933{
6934 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6935 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306936 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006937
6938 ENTER();
6939
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306940 status = wlan_hdd_validate_context(pHddCtx);
6941
6942 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006943 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306944 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6945 "%s: HDD context is not valid", __func__);
6946 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006947 }
6948
Jeff Johnson295189b2012-06-20 16:38:30 -07006949 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6950 {
6951 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6952 WNI_CFG_RTS_THRESHOLD_STAMAX :
6953 wiphy->rts_threshold;
6954
6955 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306956 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006957 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306958 hddLog(VOS_TRACE_LEVEL_ERROR,
6959 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006960 __func__, rts_threshold);
6961 return -EINVAL;
6962 }
6963
6964 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6965 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306966 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006967 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306968 hddLog(VOS_TRACE_LEVEL_ERROR,
6969 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 __func__, rts_threshold);
6971 return -EIO;
6972 }
6973
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306974 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006975 rts_threshold);
6976 }
6977
6978 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6979 {
6980 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6981 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6982 wiphy->frag_threshold;
6983
6984 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306985 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006986 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306987 hddLog(VOS_TRACE_LEVEL_ERROR,
6988 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 frag_threshold);
6990 return -EINVAL;
6991 }
6992
6993 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6994 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306995 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006996 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306997 hddLog(VOS_TRACE_LEVEL_ERROR,
6998 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006999 __func__, frag_threshold);
7000 return -EIO;
7001 }
7002
7003 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
7004 frag_threshold);
7005 }
7006
7007 if ((changed & WIPHY_PARAM_RETRY_SHORT)
7008 || (changed & WIPHY_PARAM_RETRY_LONG))
7009 {
7010 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
7011 wiphy->retry_short :
7012 wiphy->retry_long;
7013
7014 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
7015 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
7016 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307017 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 __func__, retry_value);
7019 return -EINVAL;
7020 }
7021
7022 if (changed & WIPHY_PARAM_RETRY_SHORT)
7023 {
7024 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
7025 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307026 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307028 hddLog(VOS_TRACE_LEVEL_ERROR,
7029 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007030 __func__, retry_value);
7031 return -EIO;
7032 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307033 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007034 __func__, retry_value);
7035 }
7036 else if (changed & WIPHY_PARAM_RETRY_SHORT)
7037 {
7038 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
7039 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307040 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007041 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307042 hddLog(VOS_TRACE_LEVEL_ERROR,
7043 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 __func__, retry_value);
7045 return -EIO;
7046 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307047 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007048 __func__, retry_value);
7049 }
7050 }
7051
7052 return 0;
7053}
7054
7055/*
7056 * FUNCTION: wlan_hdd_cfg80211_set_txpower
7057 * This function is used to set the txpower
7058 */
7059static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07007060#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7061 struct wireless_dev *wdev,
7062#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007063#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307064 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007065#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307066 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007067#endif
7068 int dbm)
7069{
7070 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307071 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007072 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
7073 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307074 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007075
7076 ENTER();
7077
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307078 status = wlan_hdd_validate_context(pHddCtx);
7079
7080 if (0 != status)
7081 {
7082 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7083 "%s: HDD context is not valid", __func__);
7084 return status;
7085 }
7086
7087 hHal = pHddCtx->hHal;
7088
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307089 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
7090 dbm, ccmCfgSetCallback,
7091 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307093 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007094 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
7095 return -EIO;
7096 }
7097
7098 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
7099 dbm);
7100
7101 switch(type)
7102 {
7103 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
7104 /* Fall through */
7105 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
7106 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
7107 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307108 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
7109 __func__);
7110 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07007111 }
7112 break;
7113 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307114 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07007115 __func__);
7116 return -EOPNOTSUPP;
7117 break;
7118 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307119 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
7120 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07007121 return -EIO;
7122 }
7123
7124 return 0;
7125}
7126
7127/*
7128 * FUNCTION: wlan_hdd_cfg80211_get_txpower
7129 * This function is used to read the txpower
7130 */
Yue Maf49ba872013-08-19 12:04:25 -07007131static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
7132#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7133 struct wireless_dev *wdev,
7134#endif
7135 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07007136{
7137
7138 hdd_adapter_t *pAdapter;
7139 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307140 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007141
Jeff Johnsone7245742012-09-05 17:12:55 -07007142 ENTER();
7143
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307144 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007145
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307146 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007147 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7149 "%s: HDD context is not valid", __func__);
7150 *dbm = 0;
7151 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007152 }
7153
Jeff Johnson295189b2012-06-20 16:38:30 -07007154 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
7155 if (NULL == pAdapter)
7156 {
7157 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
7158 return -ENOENT;
7159 }
7160
7161 wlan_hdd_get_classAstats(pAdapter);
7162 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
7163
Jeff Johnsone7245742012-09-05 17:12:55 -07007164 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007165 return 0;
7166}
7167
7168static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
7169 u8* mac, struct station_info *sinfo)
7170{
7171 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
7172 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7173 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
7174 tANI_U8 rate_flags;
7175
7176 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
7177 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07007178
7179 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
7180 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
7181 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
7182 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
7183 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
7184 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
7185 tANI_U16 maxRate = 0;
7186 tANI_U16 myRate;
7187 tANI_U16 currentRate = 0;
7188 tANI_U8 maxSpeedMCS = 0;
7189 tANI_U8 maxMCSIdx = 0;
7190 tANI_U8 rateFlag = 1;
7191 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07007192 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307193 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007194
Leo Chang6f8870f2013-03-26 18:11:36 -07007195#ifdef WLAN_FEATURE_11AC
7196 tANI_U32 vht_mcs_map;
7197 eDataRate11ACMaxMcs vhtMaxMcs;
7198#endif /* WLAN_FEATURE_11AC */
7199
Jeff Johnsone7245742012-09-05 17:12:55 -07007200 ENTER();
7201
Jeff Johnson295189b2012-06-20 16:38:30 -07007202 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
7203 (0 == ssidlen))
7204 {
7205 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
7206 " Invalid ssidlen, %d", __func__, ssidlen);
7207 /*To keep GUI happy*/
7208 return 0;
7209 }
7210
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307211 status = wlan_hdd_validate_context(pHddCtx);
7212
7213 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007214 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7216 "%s: HDD context is not valid", __func__);
7217 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007218 }
7219
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007220 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007221 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
7222
Kiet Lam3b17fc82013-09-27 05:24:08 +05307223 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
7224 sinfo->filled |= STATION_INFO_SIGNAL;
7225
Jeff Johnson295189b2012-06-20 16:38:30 -07007226 //convert to the UI units of 100kbps
7227 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
7228
7229#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07007230 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 -07007231 sinfo->signal,
7232 pCfg->reportMaxLinkSpeed,
7233 myRate,
7234 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007235 (int) pCfg->linkSpeedRssiMid,
7236 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07007237 (int) rate_flags,
7238 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07007239#endif //LINKSPEED_DEBUG_ENABLED
7240
7241 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
7242 {
7243 // we do not want to necessarily report the current speed
7244 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
7245 {
7246 // report the max possible speed
7247 rssidx = 0;
7248 }
7249 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
7250 {
7251 // report the max possible speed with RSSI scaling
7252 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
7253 {
7254 // report the max possible speed
7255 rssidx = 0;
7256 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007257 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07007258 {
7259 // report middle speed
7260 rssidx = 1;
7261 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007262 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
7263 {
7264 // report middle speed
7265 rssidx = 2;
7266 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007267 else
7268 {
7269 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007270 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 }
7272 }
7273 else
7274 {
7275 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
7276 hddLog(VOS_TRACE_LEVEL_ERROR,
7277 "%s: Invalid value for reportMaxLinkSpeed: %u",
7278 __func__, pCfg->reportMaxLinkSpeed);
7279 rssidx = 0;
7280 }
7281
7282 maxRate = 0;
7283
7284 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307285 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7286 OperationalRates, &ORLeng))
7287 {
7288 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7289 /*To keep GUI happy*/
7290 return 0;
7291 }
7292
Jeff Johnson295189b2012-06-20 16:38:30 -07007293 for (i = 0; i < ORLeng; i++)
7294 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007295 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007296 {
7297 /* Validate Rate Set */
7298 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7299 {
7300 currentRate = supported_data_rate[j].supported_rate[rssidx];
7301 break;
7302 }
7303 }
7304 /* Update MAX rate */
7305 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7306 }
7307
7308 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307309 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7310 ExtendedRates, &ERLeng))
7311 {
7312 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7313 /*To keep GUI happy*/
7314 return 0;
7315 }
7316
Jeff Johnson295189b2012-06-20 16:38:30 -07007317 for (i = 0; i < ERLeng; i++)
7318 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007319 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007320 {
7321 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7322 {
7323 currentRate = supported_data_rate[j].supported_rate[rssidx];
7324 break;
7325 }
7326 }
7327 /* Update MAX rate */
7328 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7329 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307330 /* Get MCS Rate Set --
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307331 Only if we are always reporting max speed (or)
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307332 if we have good rssi */
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307333 if ((0 == rssidx) ||
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307334 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007335 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307336 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7337 MCSRates, &MCSLeng))
7338 {
7339 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7340 /*To keep GUI happy*/
7341 return 0;
7342 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007343 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007344#ifdef WLAN_FEATURE_11AC
7345 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307346 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007347 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007348 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307349 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007350 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007351 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007352 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007354 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007355 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007356 maxMCSIdx = 7;
7357 }
7358 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7359 {
7360 maxMCSIdx = 8;
7361 }
7362 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7363 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307364 //VHT20 is supporting 0~8
7365 if (rate_flags & eHAL_TX_RATE_VHT20)
7366 maxMCSIdx = 8;
7367 else
7368 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007369 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307370
7371 if (rate_flags & eHAL_TX_RATE_VHT80)
7372 {
7373 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7374 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7375 }
7376 else if (rate_flags & eHAL_TX_RATE_VHT40)
7377 {
7378 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7379 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7380 }
7381 else if (rate_flags & eHAL_TX_RATE_VHT20)
7382 {
7383 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7384 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7385 }
7386
Leo Chang6f8870f2013-03-26 18:11:36 -07007387 maxSpeedMCS = 1;
7388 if (currentRate > maxRate)
7389 {
7390 maxRate = currentRate;
7391 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307392
Leo Chang6f8870f2013-03-26 18:11:36 -07007393 }
7394 else
7395#endif /* WLAN_FEATURE_11AC */
7396 {
7397 if (rate_flags & eHAL_TX_RATE_HT40)
7398 {
7399 rateFlag |= 1;
7400 }
7401 if (rate_flags & eHAL_TX_RATE_SGI)
7402 {
7403 rateFlag |= 2;
7404 }
7405
7406 for (i = 0; i < MCSLeng; i++)
7407 {
7408 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7409 for (j = 0; j < temp; j++)
7410 {
7411 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7412 {
7413 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7414 break;
7415 }
7416 }
7417 if ((j < temp) && (currentRate > maxRate))
7418 {
7419 maxRate = currentRate;
7420 maxSpeedMCS = 1;
7421 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7422 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007423 }
7424 }
7425 }
7426
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307427 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7428 {
7429 maxRate = myRate;
7430 maxSpeedMCS = 1;
7431 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7432 }
7433
Jeff Johnson295189b2012-06-20 16:38:30 -07007434 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007435 if (((maxRate < myRate) && (0 == rssidx)) ||
7436 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007437 {
7438 maxRate = myRate;
7439 if (rate_flags & eHAL_TX_RATE_LEGACY)
7440 {
7441 maxSpeedMCS = 0;
7442 }
7443 else
7444 {
7445 maxSpeedMCS = 1;
7446 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7447 }
7448 }
7449
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307450 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007451 {
7452 sinfo->txrate.legacy = maxRate;
7453#ifdef LINKSPEED_DEBUG_ENABLED
7454 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7455#endif //LINKSPEED_DEBUG_ENABLED
7456 }
7457 else
7458 {
7459 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007460#ifdef WLAN_FEATURE_11AC
7461 sinfo->txrate.nss = 1;
7462 if (rate_flags & eHAL_TX_RATE_VHT80)
7463 {
7464 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307465 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007466 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307467 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007468 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307469 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7470 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7471 }
7472 else if (rate_flags & eHAL_TX_RATE_VHT20)
7473 {
7474 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7475 }
7476#endif /* WLAN_FEATURE_11AC */
7477 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7478 {
7479 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7480 if (rate_flags & eHAL_TX_RATE_HT40)
7481 {
7482 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7483 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007484 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007485 if (rate_flags & eHAL_TX_RATE_SGI)
7486 {
7487 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7488 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307489
Jeff Johnson295189b2012-06-20 16:38:30 -07007490#ifdef LINKSPEED_DEBUG_ENABLED
7491 pr_info("Reporting MCS rate %d flags %x\n",
7492 sinfo->txrate.mcs,
7493 sinfo->txrate.flags );
7494#endif //LINKSPEED_DEBUG_ENABLED
7495 }
7496 }
7497 else
7498 {
7499 // report current rate instead of max rate
7500
7501 if (rate_flags & eHAL_TX_RATE_LEGACY)
7502 {
7503 //provide to the UI in units of 100kbps
7504 sinfo->txrate.legacy = myRate;
7505#ifdef LINKSPEED_DEBUG_ENABLED
7506 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7507#endif //LINKSPEED_DEBUG_ENABLED
7508 }
7509 else
7510 {
7511 //must be MCS
7512 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007513#ifdef WLAN_FEATURE_11AC
7514 sinfo->txrate.nss = 1;
7515 if (rate_flags & eHAL_TX_RATE_VHT80)
7516 {
7517 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7518 }
7519 else
7520#endif /* WLAN_FEATURE_11AC */
7521 {
7522 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7523 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007524 if (rate_flags & eHAL_TX_RATE_SGI)
7525 {
7526 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7527 }
7528 if (rate_flags & eHAL_TX_RATE_HT40)
7529 {
7530 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7531 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007532#ifdef WLAN_FEATURE_11AC
7533 else if (rate_flags & eHAL_TX_RATE_VHT80)
7534 {
7535 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7536 }
7537#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007538#ifdef LINKSPEED_DEBUG_ENABLED
7539 pr_info("Reporting actual MCS rate %d flags %x\n",
7540 sinfo->txrate.mcs,
7541 sinfo->txrate.flags );
7542#endif //LINKSPEED_DEBUG_ENABLED
7543 }
7544 }
7545 sinfo->filled |= STATION_INFO_TX_BITRATE;
7546
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007547 sinfo->tx_packets =
7548 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7549 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7550 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7551 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7552
7553 sinfo->tx_retries =
7554 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7555 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7556 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7557 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7558
7559 sinfo->tx_failed =
7560 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7561 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7562 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7563 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7564
7565 sinfo->filled |=
7566 STATION_INFO_TX_PACKETS |
7567 STATION_INFO_TX_RETRIES |
7568 STATION_INFO_TX_FAILED;
7569
7570 EXIT();
7571 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007572}
7573
7574static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007575 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007576{
7577 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307578 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007579 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307580 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007581
Jeff Johnsone7245742012-09-05 17:12:55 -07007582 ENTER();
7583
Jeff Johnson295189b2012-06-20 16:38:30 -07007584 if (NULL == pAdapter)
7585 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007586 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007587 return -ENODEV;
7588 }
7589
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307590 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307591 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307592
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307593 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307594 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307595 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7596 "%s: HDD context is not valid", __func__);
7597 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307598 }
7599
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307600 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7601 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7602 (pHddCtx->cfg_ini->fhostArpOffload) &&
7603 (eConnectionState_Associated ==
7604 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7605 {
Amar Singhald53568e2013-09-26 11:03:45 -07007606
7607 hddLog(VOS_TRACE_LEVEL_INFO,
7608 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307609 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307610 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7611 {
7612 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007613 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307614 __func__, vos_status);
7615 }
7616 }
7617
Jeff Johnson295189b2012-06-20 16:38:30 -07007618 /**The get power cmd from the supplicant gets updated by the nl only
7619 *on successful execution of the function call
7620 *we are oppositely mapped w.r.t mode in the driver
7621 **/
7622 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7623
Jeff Johnsone7245742012-09-05 17:12:55 -07007624 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007625 if (VOS_STATUS_E_FAILURE == vos_status)
7626 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307627 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7628 "%s: failed to enter bmps mode", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007629 return -EINVAL;
7630 }
7631 return 0;
7632}
7633
7634
7635#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7636static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7637 struct net_device *netdev,
7638 u8 key_index)
7639{
Jeff Johnsone7245742012-09-05 17:12:55 -07007640 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007641 return 0;
7642}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307643#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007644
7645#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7646static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7647 struct net_device *dev,
7648 struct ieee80211_txq_params *params)
7649{
Jeff Johnsone7245742012-09-05 17:12:55 -07007650 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007651 return 0;
7652}
7653#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7654static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7655 struct ieee80211_txq_params *params)
7656{
Jeff Johnsone7245742012-09-05 17:12:55 -07007657 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007658 return 0;
7659}
7660#endif //LINUX_VERSION_CODE
7661
7662static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7663 struct net_device *dev, u8 *mac)
7664{
7665 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307666 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007667 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307668 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007669 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007670
Jeff Johnsone7245742012-09-05 17:12:55 -07007671 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307672 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007673 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307674 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007675 return -EINVAL;
7676 }
7677
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307678 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7679 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007680
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307681 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007682 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307683 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7684 "%s: HDD context is not valid", __func__);
7685 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007686 }
7687
Jeff Johnson295189b2012-06-20 16:38:30 -07007688 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007689 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007690 )
7691 {
7692 if( NULL == mac )
7693 {
7694 v_U16_t i;
7695 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7696 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007697 if ((pAdapter->aStaInfo[i].isUsed) &&
7698 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007699 {
7700 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7701 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007702 "%s: Delete STA with MAC::"
7703 MAC_ADDRESS_STR,
7704 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007705 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7706 if (VOS_IS_STATUS_SUCCESS(vos_status))
7707 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007708 }
7709 }
7710 }
7711 else
7712 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007713
7714 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7715 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7716 {
7717 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007718 "%s: Skip this DEL STA as this is not used::"
7719 MAC_ADDRESS_STR,
7720 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007721 return -ENOENT;
7722 }
7723
7724 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7725 {
7726 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007727 "%s: Skip this DEL STA as deauth is in progress::"
7728 MAC_ADDRESS_STR,
7729 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007730 return -ENOENT;
7731 }
7732
7733 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7734
Jeff Johnson295189b2012-06-20 16:38:30 -07007735 hddLog(VOS_TRACE_LEVEL_INFO,
7736 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007737 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007738 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007739 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007740
7741 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7742 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7743 {
7744 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7745 hddLog(VOS_TRACE_LEVEL_INFO,
7746 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007747 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007748 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007749 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007750 return -ENOENT;
7751 }
7752
Jeff Johnson295189b2012-06-20 16:38:30 -07007753 }
7754 }
7755
7756 EXIT();
7757
7758 return 0;
7759}
7760
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007761static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7762 struct net_device *dev, u8 *mac, struct station_parameters *params)
7763{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007764 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007765#ifdef FEATURE_WLAN_TDLS
7766 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007767 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007768 mask = params->sta_flags_mask;
7769
7770 set = params->sta_flags_set;
7771
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007772#ifdef WLAN_FEATURE_TDLS_DEBUG
7773 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7774 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7775 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7776#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007777
7778 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7779 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007780 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007781 }
7782 }
7783#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007784 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007785}
7786
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007787
7788#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007789#define MAX_PMKSAIDS_IN_CACHE 8
7790
7791static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7792static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7793
7794
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007795static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007796 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007797{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307798 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007799 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7800 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307801 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307802 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007803 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307804 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307805
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007806 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
7807 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07007808
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307809 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307810 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007811 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307812 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007813 return -EINVAL;
7814 }
7815
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307816 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7817 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007818
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307819 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007820 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307821 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7822 "%s: HDD context is not valid", __func__);
7823 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007824 }
7825
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307826 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007827 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7828
Wilson Yang6507c4e2013-10-01 20:11:19 -07007829 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007830 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307831 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007832 pmksa->bssid, WNI_CFG_BSSID_LEN))
7833 {
7834 /* BSSID matched previous entry. Overwrite it. */
7835 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307836 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007837 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307838 vos_mem_copy(PMKIDCache[j].PMKID,
7839 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007840 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307841 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007842 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007843 dump_bssid(pmksa->bssid);
7844 dump_pmkid(halHandle, pmksa->pmkid);
7845 break;
7846 }
7847 }
7848
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007849 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007850 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007851
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007852 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307853 {
7854 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007855 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307856 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007857 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307858 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007859 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307860 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007861 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007862 dump_bssid(pmksa->bssid);
7863 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307864 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007865 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007866 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007867 }
7868
7869
7870 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307871 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007872 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307873 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007874 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007875 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307876 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7877 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007878 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007879 return 0;
7880}
7881
7882
Wilson Yang6507c4e2013-10-01 20:11:19 -07007883
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007884static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007885 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007886{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007887 tANI_U32 j=0;
7888 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7889 tHalHandle halHandle;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007890 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007891 hdd_context_t *pHddCtx;
Wilson Yangef657d32014-01-15 19:19:23 -08007892 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007893
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007894 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
7895 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007896
7897 /* Validate pAdapter */
7898 if (NULL == pAdapter)
7899 {
7900 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7901 return -EINVAL;
7902 }
7903
7904 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7905 status = wlan_hdd_validate_context(pHddCtx);
7906
7907 if (0 != status)
7908 {
7909 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7910 "%s: HDD context is not valid", __func__);
7911 return status;
7912 }
7913
7914 /*Retrieve halHandle*/
7915 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7916
7917 /*in case index is 0,no entry to delete*/
7918 if (0 == PMKIDCacheIndex)
7919 {
7920 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7921 __func__);
7922 return -EINVAL;
7923 }
7924
7925 /*find the matching PMKSA entry from j=0 to (index-1),
7926 * and delete the matched one
7927 */
7928 for (j = 0; j<PMKIDCacheIndex; j++)
7929 {
7930 if (vos_mem_compare(PMKIDCache[j].BSSID,
7931 pmksa->bssid,
7932 WNI_CFG_BSSID_LEN))
7933 {
7934 /* BSSID matched entry */
7935 BSSIDMatched = 1;
7936
7937 if (j<PMKIDCacheIndex-1)
7938 {
7939 /*replace the matching entry with the last entry in HDD local cache*/
7940 vos_mem_copy(PMKIDCache[j].BSSID,
7941 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7942 WNI_CFG_BSSID_LEN);
7943 vos_mem_copy(PMKIDCache[j].PMKID,
7944 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7945 CSR_RSN_PMKID_SIZE);
7946 }
7947
7948 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07007949 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7950 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7951
7952 /*reduce the PMKID array index*/
7953 PMKIDCacheIndex--;
7954
7955 /*delete the last PMKID cache in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08007956 if (eHAL_STATUS_SUCCESS !=
7957 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid))
Wilson Yang6507c4e2013-10-01 20:11:19 -07007958 {
7959 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7960 __func__,PMKIDCacheIndex);
Wilson Yangef657d32014-01-15 19:19:23 -08007961 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007962 }
7963
7964 dump_bssid(pmksa->bssid);
7965 dump_pmkid(halHandle,pmksa->pmkid);
7966
7967 break;
7968 }
7969 }
7970
7971 /* we compare all entries,but cannot find matching entry */
7972 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7973 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007974 hddLog(VOS_TRACE_LEVEL_FATAL,
7975 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
7976 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007977 dump_bssid(pmksa->bssid);
7978 dump_pmkid(halHandle, pmksa->pmkid);
7979 return -EINVAL;
7980 }
Wilson Yangef657d32014-01-15 19:19:23 -08007981 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007982}
7983
Wilson Yang6507c4e2013-10-01 20:11:19 -07007984
7985
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007986static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7987{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007988 tANI_U32 j=0;
7989 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7990 tHalHandle halHandle;
7991 hdd_context_t *pHddCtx;
7992 tANI_U8 *pBSSId;
Wilson Yangef657d32014-01-15 19:19:23 -08007993 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007994
7995 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7996
7997 /* Validate pAdapter */
7998 if (NULL == pAdapter)
7999 {
8000 hddLog(VOS_TRACE_LEVEL_ERROR,
8001 "%s: Invalid Adapter" ,__func__);
8002 return -EINVAL;
8003 }
8004
8005 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8006 status = wlan_hdd_validate_context(pHddCtx);
8007
8008 if (0 != status)
8009 {
8010 hddLog(VOS_TRACE_LEVEL_ERROR,
8011 "%s: HDD context is not valid", __func__);
8012 return status;
8013 }
8014
8015 /*Retrieve halHandle*/
8016 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8017
8018 /*in case index is 0,no entry to delete*/
8019 if (0 == PMKIDCacheIndex)
8020 {
8021 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
8022 __func__);
8023 return -EINVAL;
8024 }
8025
8026 /*delete all the PMKSA one by one */
8027 for (j = 0; j<PMKIDCacheIndex; j++)
8028 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07008029 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008030
8031 /*delete the PMKID in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008032 if (eHAL_STATUS_SUCCESS !=
8033 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008034 {
8035 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
8036 __func__,j);
Wilson Yangef657d32014-01-15 19:19:23 -08008037 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008038 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05308039 /*clear the entry in HDD cache 0--index-1 */
8040 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
8041 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008042 }
8043
8044 PMKIDCacheIndex = 0;
Wilson Yangef657d32014-01-15 19:19:23 -08008045 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008046}
8047#endif
8048
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008049#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308050static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008051 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
8052{
8053 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8054 hdd_station_ctx_t *pHddStaCtx;
8055
8056 if (NULL == pAdapter)
8057 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008058 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008059 return -ENODEV;
8060 }
8061
8062 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8063
8064 // Added for debug on reception of Re-assoc Req.
8065 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
8066 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008067 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008068 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08008069 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008070 }
8071
8072#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08008073 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008074 ftie->ie_len);
8075#endif
8076
8077 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05308078 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
8079 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008080 ftie->ie_len);
8081 return 0;
8082}
8083#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008084
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308085#ifdef FEATURE_WLAN_SCAN_PNO
8086
8087void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
8088 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8089{
8090 int ret;
8091 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
8092 hdd_context_t *pHddCtx;
8093
Nirav Shah80830bf2013-12-31 16:35:12 +05308094 ENTER();
8095
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308096 if (NULL == pAdapter)
8097 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308098 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308099 "%s: HDD adapter is Null", __func__);
8100 return ;
8101 }
8102
8103 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8104 if (NULL == pHddCtx)
8105 {
8106 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8107 "%s: HDD context is Null!!!", __func__);
8108 return ;
8109 }
8110
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308111 spin_lock(&pHddCtx->schedScan_lock);
8112 if (TRUE == pHddCtx->isWiphySuspended)
8113 {
8114 pHddCtx->isSchedScanUpdatePending = TRUE;
8115 spin_unlock(&pHddCtx->schedScan_lock);
8116 hddLog(VOS_TRACE_LEVEL_INFO,
8117 "%s: Update cfg80211 scan database after it resume", __func__);
8118 return ;
8119 }
8120 spin_unlock(&pHddCtx->schedScan_lock);
8121
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308122 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
8123
8124 if (0 > ret)
8125 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
8126
8127 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308128 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8129 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308130}
8131
8132/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308133 * FUNCTION: wlan_hdd_is_pno_allowed
8134 * To check is there any P2P GO/SAP or P2P Client/STA
8135 * session is active
8136 */
8137static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
8138{
8139 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8140 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308141 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308142 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8143 int status = 0;
8144 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
8145
8146 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
8147 {
8148 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308149 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308150
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308151 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
8152 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
8153 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
8154 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
8155 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
8156 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308157 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308158 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308159 }
8160 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8161 pAdapterNode = pNext;
8162 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308163 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308164}
8165
8166/*
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308167 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
8168 * NL interface to enable PNO
8169 */
8170static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
8171 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8172{
8173 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8174 tpSirPNOScanReq pPnoRequest = NULL;
8175 hdd_context_t *pHddCtx;
8176 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308177 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308178 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8179 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8180 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8181 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308182 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308183
8184 if (NULL == pAdapter)
8185 {
8186 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8187 "%s: HDD adapter is Null", __func__);
8188 return -ENODEV;
8189 }
8190
8191 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308192 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308193
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308194 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308195 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308196 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8197 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308198 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308199 }
8200
8201 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8202 if (NULL == hHal)
8203 {
8204 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8205 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308206 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308207 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308208
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308209 /* The current firmware design for PNO does not consider concurrent
8210 * active sessions.Hence , determine the concurrent active sessions
8211 * and return a failure to the framework on a request for schedule
8212 * scan.
8213 */
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308214 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308215 {
8216 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308217 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308218 return -EBUSY;
8219 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308220
8221 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8222 if (NULL == pPnoRequest)
8223 {
8224 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8225 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308226 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308227 }
8228
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05308229 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308230 pPnoRequest->enable = 1; /*Enable PNO */
8231 pPnoRequest->ucNetworksCount = request->n_match_sets;
8232
8233 if (( !pPnoRequest->ucNetworksCount ) ||
8234 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
8235 {
8236 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308237 "%s: Network input is not correct %d",
8238 __func__, pPnoRequest->ucNetworksCount);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308239 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308240 goto error;
8241 }
8242
8243 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
8244 {
8245 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308246 "%s: Incorrect number of channels %d",
8247 __func__, request->n_channels);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308248 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308249 goto error;
8250 }
8251
8252 /* Framework provides one set of channels(all)
8253 * common for all saved profile */
8254 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
8255 channels_allowed, &num_channels_allowed))
8256 {
8257 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8258 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308259 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308260 goto error;
8261 }
8262 /* Checking each channel against allowed channel list */
8263 num_ch = 0;
Nirav Shah80830bf2013-12-31 16:35:12 +05308264 if (request->n_channels)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308265 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308266 char chList [(request->n_channels*5)+1];
8267 int len;
8268 for (i = 0, len = 0; i < request->n_channels; i++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308269 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308270 for (indx = 0; indx < num_channels_allowed; indx++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308271 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308272 if (request->channels[i]->hw_value == channels_allowed[indx])
8273 {
8274 valid_ch[num_ch++] = request->channels[i]->hw_value;
8275 len += snprintf(chList+len, 5, "%d ",
8276 request->channels[i]->hw_value);
8277 break ;
8278 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308279 }
8280 }
Nirav Shah80830bf2013-12-31 16:35:12 +05308281 hddLog(VOS_TRACE_LEVEL_INFO,"Channel-List: %s ", chList);
8282 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308283
8284 /* Filling per profile params */
8285 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
8286 {
8287 pPnoRequest->aNetworks[i].ssId.length =
8288 request->match_sets[i].ssid.ssid_len;
8289
8290 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8291 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8292 {
8293 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308294 "%s: SSID Len %d is not correct for network %d",
8295 __func__, pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308296 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308297 goto error;
8298 }
8299
8300 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8301 request->match_sets[i].ssid.ssid,
8302 request->match_sets[i].ssid.ssid_len);
8303 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8304 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8305 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8306
8307 /*Copying list of valid channel into request */
8308 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8309 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8310
8311 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8312 }
8313
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308314 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008315 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308316 if ((0 < request->ie_len) && (NULL != request->ie))
8317 {
8318 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8319 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8320 pPnoRequest->us24GProbeTemplateLen);
8321
8322 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8323 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8324 pPnoRequest->us5GProbeTemplateLen);
8325 }
8326
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308327 /* Driver gets only one time interval which is hardcoded in
8328 * supplicant for 10000ms. Taking power consumption into account 6 timers
8329 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8330 * 80,160,320 secs. And number of scan cycle for each timer
8331 * is configurable through INI param gPNOScanTimerRepeatValue.
8332 * If it is set to 0 only one timer will be used and PNO scan cycle
8333 * will be repeated after each interval specified by supplicant
8334 * till PNO is disabled.
8335 */
8336 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8337 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8338 else
8339 pPnoRequest->scanTimers.ucScanTimersCount =
8340 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8341
8342 tempInterval = (request->interval)/1000;
8343 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8344 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8345 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8346 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8347 {
8348 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8349 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8350 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8351 tempInterval *= 2;
8352 }
8353 //Repeat last timer until pno disabled.
8354 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8355
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308356 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308357
Nirav Shah80830bf2013-12-31 16:35:12 +05308358 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8359 "SessionId %d, enable %d, modePNO %d, ucScanTimersCount %d",
8360 pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO,
8361 pPnoRequest->scanTimers.ucScanTimersCount);
8362
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308363 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8364 pPnoRequest, pAdapter->sessionId,
8365 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8366 if (eHAL_STATUS_SUCCESS != status)
8367 {
8368 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308369 "%s: Failed to enable PNO", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308370 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308371 goto error;
8372 }
8373
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308374 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8375 "PNO scanRequest offloaded");
8376
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308377error:
8378 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308379 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308380}
8381
8382/*
8383 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8384 * NL interface to disable PNO
8385 */
8386static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8387 struct net_device *dev)
8388{
8389 eHalStatus status = eHAL_STATUS_FAILURE;
8390 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8391 hdd_context_t *pHddCtx;
8392 tHalHandle hHal;
8393 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308394 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308395
8396 ENTER();
8397
8398 if (NULL == pAdapter)
8399 {
8400 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8401 "%s: HDD adapter is Null", __func__);
8402 return -ENODEV;
8403 }
8404
8405 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308406
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308407 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308408 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308409 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308410 "%s: HDD context is Null", __func__);
8411 return -ENODEV;
8412 }
8413
8414 /* The return 0 is intentional when isLogpInProgress and
8415 * isLoadUnloadInProgress. We did observe a crash due to a return of
8416 * failure in sched_scan_stop , especially for a case where the unload
8417 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8418 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8419 * success. If it returns a failure , then its next invocation due to the
8420 * clean up of the second interface will have the dev pointer corresponding
8421 * to the first one leading to a crash.
8422 */
8423 if (pHddCtx->isLogpInProgress)
8424 {
8425 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8426 "%s: LOGP in Progress. Ignore!!!", __func__);
8427 return ret;
8428 }
8429
8430 if (pHddCtx->isLoadUnloadInProgress)
8431 {
8432 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8433 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8434 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308435 }
8436
8437 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8438 if (NULL == hHal)
8439 {
8440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8441 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308442 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308443 }
8444
8445 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8446 if (NULL == pPnoRequest)
8447 {
8448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8449 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308450 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308451 }
8452
8453 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8454 pPnoRequest->enable = 0; /* Disable PNO */
8455 pPnoRequest->ucNetworksCount = 0;
8456
8457 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8458 pAdapter->sessionId,
8459 NULL, pAdapter);
8460 if (eHAL_STATUS_SUCCESS != status)
8461 {
8462 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8463 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308464 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308465 }
8466
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8468 "%s: PNO scan disabled", __func__);
8469
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308470 vos_mem_free(pPnoRequest);
8471
8472 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308473 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308474}
8475
8476#endif /*FEATURE_WLAN_SCAN_PNO*/
8477
8478
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008479#ifdef FEATURE_WLAN_TDLS
8480static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8481 u8 *peer, u8 action_code, u8 dialog_token,
8482 u16 status_code, const u8 *buf, size_t len)
8483{
8484
8485 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8486 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008487 u8 peerMac[6];
8488 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008489 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008490 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008491 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008492
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008493 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008494 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308495 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008496 "Invalid arguments");
8497 return -EINVAL;
8498 }
8499
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008500 if (pHddCtx->isLogpInProgress)
8501 {
8502 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8503 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008504 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008505 return -EBUSY;
8506 }
8507
Hoonki Lee27511902013-03-14 18:19:06 -07008508 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008509 {
Hoonki Lee27511902013-03-14 18:19:06 -07008510 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8511 "%s: TDLS mode is disabled OR not enabled in FW."
8512 MAC_ADDRESS_STR " action %d declined.",
8513 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008514 return -ENOTSUPP;
8515 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008516
Hoonki Lee27511902013-03-14 18:19:06 -07008517 /* other than teardown frame, other mgmt frames are not sent if disabled */
8518 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8519 {
8520 /* if tdls_mode is disabled to respond to peer's request */
8521 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8522 {
8523 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8524 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008525 " TDLS mode is disabled. action %d declined.",
8526 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008527
8528 return -ENOTSUPP;
8529 }
8530 }
8531
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008532 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8533 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308534 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008535 {
8536 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008537 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008538 " TDLS setup is ongoing. action %d declined.",
8539 __func__, MAC_ADDR_ARRAY(peer), action_code);
8540 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008541 }
8542 }
8543
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008544 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8545 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008546 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008547 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008548 {
8549 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8550 we return error code at 'add_station()'. Hence we have this
8551 check again in addtion to add_station().
8552 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008553 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008554 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008555 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8556 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008557 " TDLS Max peer already connected. action %d declined.",
8558 __func__, MAC_ADDR_ARRAY(peer), action_code);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308559 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008560 }
8561 else
8562 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008563 /* maximum reached. tweak to send error code to peer and return
8564 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008565 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008566 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8567 "%s: " MAC_ADDRESS_STR
8568 " TDLS Max peer already connected send response status %d",
8569 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008570 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008571 /* fall through to send setup resp with failure status
8572 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008573 }
8574 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008575 else
8576 {
8577 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308578 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008579 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008580 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008581 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008582 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8583 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008584 return -EPERM;
8585 }
8586 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008587 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008588 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008589
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008590#ifdef WLAN_FEATURE_TDLS_DEBUG
8591 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008592 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8593 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8594 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008595#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008596
Hoonki Leea34dd892013-02-05 22:56:02 -08008597 /*Except teardown responder will not be used so just make 0*/
8598 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008599 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008600 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008601
8602 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308603 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008604
8605 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8606 responder = pTdlsPeer->is_responder;
8607 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008608 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008609 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8610 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8611 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8612 dialog_token, status_code, len);
8613 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008614 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008615 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008616
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308617 /* For explicit trigger of DIS_REQ come out of BMPS for
8618 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008619 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308620 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8621 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008622 {
8623 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8624 {
8625 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308626 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008627 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8628 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308629 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8630 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008631 }
8632
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008633 /* make sure doesn't call send_mgmt() while it is pending */
8634 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8635 {
8636 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008637 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008638 __func__, MAC_ADDR_ARRAY(peer), action_code);
8639 return -EBUSY;
8640 }
8641
8642 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008643 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8644
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008645 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008646 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008647
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008648 if (VOS_STATUS_SUCCESS != status)
8649 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008650 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8651 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008652 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008653 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308654 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008655 }
8656
Hoonki Leed37cbb32013-04-20 00:31:14 -07008657 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8658 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8659
8660 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008661 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008662 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008663 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008664 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008665 pAdapter->mgmtTxCompletionStatus = FALSE;
Yue Ma4f55ef32014-01-23 16:45:33 -08008666
8667 if (pHddCtx->isLogpInProgress)
8668 {
8669 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8670 "%s: LOGP in Progress. Ignore!!!", __func__);
8671 return -EAGAIN;
8672 }
8673
Hoonki Leed37cbb32013-04-20 00:31:14 -07008674 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308675 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008676 }
8677
Gopichand Nakkala05922802013-03-14 12:23:19 -07008678 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008679 {
8680 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008681 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008682 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008683
Hoonki Leea34dd892013-02-05 22:56:02 -08008684 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8685 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008686 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008687 }
8688 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8689 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008690 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008691 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008692
8693 return 0;
8694}
8695
8696static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8697 u8 *peer, enum nl80211_tdls_operation oper)
8698{
8699 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8700 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308701 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008702 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008703
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308704 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008705 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008706 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008707 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008708 return -EINVAL;
8709 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008710
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308711 status = wlan_hdd_validate_context(pHddCtx);
8712
8713 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008714 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308715 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8716 "%s: HDD context is not valid", __func__);
8717 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008718 }
8719
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008720
8721 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008722 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008723 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008724 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008725 "TDLS Disabled in INI OR not enabled in FW. "
8726 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008727 return -ENOTSUPP;
8728 }
8729
8730 switch (oper) {
8731 case NL80211_TDLS_ENABLE_LINK:
8732 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008733 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308734 long ret;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308735 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008736
Sunil Dutt41de4e22013-11-14 18:09:02 +05308737 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8738
8739 if ( NULL == pTdlsPeer ) {
8740 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8741 " (oper %d) not exsting. ignored",
8742 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8743 return -EINVAL;
8744 }
8745
8746 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8747 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8748 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8749 "NL80211_TDLS_ENABLE_LINK");
8750
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008751 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8752 {
8753 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8754 MAC_ADDRESS_STR " failed",
8755 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8756 return -EINVAL;
8757 }
8758
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008759 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008760 {
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308761 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308762
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308763 if (0 != wlan_hdd_tdls_get_link_establish_params(
8764 pAdapter, peer,&tdlsLinkEstablishParams)) {
8765 return -EINVAL;
8766 }
8767 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308768
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308769 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8770 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8771 /* Send TDLS peer UAPSD capabilities to the firmware and
8772 * register with the TL on after the response for this operation
8773 * is received .
8774 */
8775 ret = wait_for_completion_interruptible_timeout(
8776 &pAdapter->tdls_link_establish_req_comp,
8777 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8778 if (ret <= 0)
8779 {
8780 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8781 "%s: Link Establish Request Faled Status %ld",
8782 __func__, ret);
8783 return -EINVAL;
8784 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308785 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008786 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308787 /* Mark TDLS client Authenticated .*/
8788 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8789 pTdlsPeer->staId,
8790 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008791 if (VOS_STATUS_SUCCESS == status)
8792 {
Hoonki Lee14621352013-04-16 17:51:19 -07008793 if (pTdlsPeer->is_responder == 0)
8794 {
8795 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8796
8797 wlan_hdd_tdls_timer_restart(pAdapter,
8798 &pTdlsPeer->initiatorWaitTimeoutTimer,
8799 WAIT_TIME_TDLS_INITIATOR);
8800 /* suspend initiator TX until it receives direct packet from the
8801 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8802 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8803 &staId, NULL);
8804 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008805 wlan_hdd_tdls_increment_peer_count(pAdapter);
8806 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008807 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308808
8809 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308810 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8811 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308812 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308813 int ac;
8814 uint8 ucAc[4] = { WLANTL_AC_VO,
8815 WLANTL_AC_VI,
8816 WLANTL_AC_BK,
8817 WLANTL_AC_BE };
8818 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8819 for(ac=0; ac < 4; ac++)
8820 {
8821 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8822 pTdlsPeer->staId, ucAc[ac],
8823 tlTid[ac], tlTid[ac], 0, 0,
8824 WLANTL_BI_DIR );
8825 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308826 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008827 }
8828
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008829 }
8830 break;
8831 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008832 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05308833 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8834
8835 if ( NULL == pTdlsPeer ) {
8836 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8837 " (oper %d) not exsting. ignored",
8838 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8839 return -EINVAL;
8840 }
8841
8842 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8843 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8844 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8845 "NL80211_TDLS_DISABLE_LINK");
8846
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008847 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008848 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008849 long status;
8850
8851 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8852
Lee Hoonkic1262f22013-01-24 21:59:00 -08008853 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8854 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008855
8856 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8857 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8858 if (status <= 0)
8859 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008860 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008861 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8862 "%s: Del station failed status %ld",
8863 __func__, status);
8864 return -EPERM;
8865 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008866 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008867 }
8868 else
8869 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008870 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8871 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008872 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008873 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008874 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008875 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308876 {
8877 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8878 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
8879 __func__, MAC_ADDR_ARRAY(peer));
8880
8881 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8882 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8883
8884 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8885 " %s TDLS External control and Implicit Trigger not enabled ",
8886 __func__);
8887 return -ENOTSUPP;
8888 }
8889
Sunil Dutt41de4e22013-11-14 18:09:02 +05308890
8891 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8892
8893 if ( NULL == pTdlsPeer ) {
8894 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
8895 " peer not exsting",
8896 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308897 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308898 }
8899 else {
8900 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
8901 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
8902 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308903
8904 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
8905 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308906 break;
8907 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008908 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308909 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308910 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308911 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8912 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
8913 __func__, MAC_ADDR_ARRAY(peer));
8914
8915 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8916 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8917
8918 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8919 " %s TDLS External control and Implicit Trigger not enabled ",
8920 __func__);
8921 return -ENOTSUPP;
8922 }
8923
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308924 /* To cater the requirement of establishing the TDLS link
8925 * irrespective of the data traffic , get an entry of TDLS peer.
8926 */
8927 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
8928 if (pTdlsPeer == NULL) {
8929 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8930 "%s: peer " MAC_ADDRESS_STR " not existing",
8931 __func__, MAC_ADDR_ARRAY(peer));
8932 return -EINVAL;
8933 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308934
8935 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
8936
8937 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8938 " %s TDLS Add Force Peer Failed",
8939 __func__);
8940 return -EINVAL;
8941 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308942 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308943 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008944 case NL80211_TDLS_DISCOVERY_REQ:
8945 /* We don't support in-driver setup/teardown/discovery */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308946 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8947 "%s: We don't support in-driver setup/teardown/discovery "
8948 ,__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008949 return -ENOTSUPP;
8950 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308951 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8952 "%s: unsupported event",__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008953 return -ENOTSUPP;
8954 }
8955 return 0;
8956}
Chilam NG571c65a2013-01-19 12:27:36 +05308957
8958int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8959 struct net_device *dev, u8 *peer)
8960{
Arif Hussaina7c8e412013-11-20 11:06:42 -08008961 hddLog(VOS_TRACE_LEVEL_INFO,
8962 "tdls send discover req: "MAC_ADDRESS_STR,
8963 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05308964
8965 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8966 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8967}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008968#endif
8969
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308970#ifdef WLAN_FEATURE_GTK_OFFLOAD
8971/*
8972 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8973 * Callback rountine called upon receiving response for
8974 * get offload info
8975 */
8976void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8977 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8978{
8979
8980 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308981 tANI_U8 tempReplayCounter[8];
8982 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308983
8984 ENTER();
8985
8986 if (NULL == pAdapter)
8987 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308988 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308989 "%s: HDD adapter is Null", __func__);
8990 return ;
8991 }
8992
8993 if (NULL == pGtkOffloadGetInfoRsp)
8994 {
8995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8996 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8997 return ;
8998 }
8999
9000 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
9001 {
9002 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9003 "%s: wlan Failed to get replay counter value",
9004 __func__);
9005 return ;
9006 }
9007
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309008 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9009 /* Update replay counter */
9010 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
9011 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9012
9013 {
9014 /* changing from little to big endian since supplicant
9015 * works on big endian format
9016 */
9017 int i;
9018 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9019
9020 for (i = 0; i < 8; i++)
9021 {
9022 tempReplayCounter[7-i] = (tANI_U8)p[i];
9023 }
9024 }
9025
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309026 /* Update replay counter to NL */
9027 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309028 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309029}
9030
9031/*
9032 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
9033 * This function is used to offload GTK rekeying job to the firmware.
9034 */
9035int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
9036 struct cfg80211_gtk_rekey_data *data)
9037{
9038 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9039 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9040 hdd_station_ctx_t *pHddStaCtx;
9041 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309042 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309043 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309044 eHalStatus status = eHAL_STATUS_FAILURE;
9045
9046 ENTER();
9047
9048 if (NULL == pAdapter)
9049 {
9050 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9051 "%s: HDD adapter is Null", __func__);
9052 return -ENODEV;
9053 }
9054
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309055 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309056
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309057 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309058 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309059 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9060 "%s: HDD context is not valid", __func__);
9061 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309062 }
9063
9064 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9065 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9066 if (NULL == hHal)
9067 {
9068 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9069 "%s: HAL context is Null!!!", __func__);
9070 return -EAGAIN;
9071 }
9072
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309073 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
9074 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
9075 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
9076 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309077 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309078 {
9079 /* changing from big to little endian since driver
9080 * works on little endian format
9081 */
9082 tANI_U8 *p =
9083 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
9084 int i;
9085
9086 for (i = 0; i < 8; i++)
9087 {
9088 p[7-i] = data->replay_ctr[i];
9089 }
9090 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309091
9092 if (TRUE == pHddCtx->hdd_wlan_suspended)
9093 {
9094 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309095 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
9096 sizeof (tSirGtkOffloadParams));
9097 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309098 pAdapter->sessionId);
9099
9100 if (eHAL_STATUS_SUCCESS != status)
9101 {
9102 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9103 "%s: sme_SetGTKOffload failed, returned %d",
9104 __func__, status);
9105 return status;
9106 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9108 "%s: sme_SetGTKOffload successfull", __func__);
9109 }
9110 else
9111 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309112 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9113 "%s: wlan not suspended GTKOffload request is stored",
9114 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309115 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309116
9117 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309118}
9119#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
9120
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309121/*
9122 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
9123 * This function is used to set access control policy
9124 */
9125static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
9126 struct net_device *dev, const struct cfg80211_acl_data *params)
9127{
9128 int i;
9129 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9130 hdd_hostapd_state_t *pHostapdState;
9131 tsap_Config_t *pConfig;
9132 v_CONTEXT_t pVosContext = NULL;
9133 hdd_context_t *pHddCtx;
9134 int status;
9135
9136 ENTER();
9137
9138 if (NULL == pAdapter)
9139 {
9140 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9141 "%s: HDD adapter is Null", __func__);
9142 return -ENODEV;
9143 }
9144
9145 if (NULL == params)
9146 {
9147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9148 "%s: params is Null", __func__);
9149 return -EINVAL;
9150 }
9151
9152 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9153 status = wlan_hdd_validate_context(pHddCtx);
9154
9155 if (0 != status)
9156 {
9157 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9158 "%s: HDD context is not valid", __func__);
9159 return status;
9160 }
9161
9162 pVosContext = pHddCtx->pvosContext;
9163 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9164
9165 if (NULL == pHostapdState)
9166 {
9167 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9168 "%s: pHostapdState is Null", __func__);
9169 return -EINVAL;
9170 }
9171
9172 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
9173 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
9174
9175 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
9176 {
9177 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
9178
9179 /* default value */
9180 pConfig->num_accept_mac = 0;
9181 pConfig->num_deny_mac = 0;
9182
9183 /**
9184 * access control policy
9185 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
9186 * listed in hostapd.deny file.
9187 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
9188 * listed in hostapd.accept file.
9189 */
9190 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
9191 {
9192 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
9193 }
9194 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
9195 {
9196 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
9197 }
9198 else
9199 {
9200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9201 "%s:Acl Policy : %d is not supported",
9202 __func__, params->acl_policy);
9203 return -ENOTSUPP;
9204 }
9205
9206 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
9207 {
9208 pConfig->num_accept_mac = params->n_acl_entries;
9209 for (i = 0; i < params->n_acl_entries; i++)
9210 {
9211 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9212 "** Add ACL MAC entry %i in WhiletList :"
9213 MAC_ADDRESS_STR, i,
9214 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9215
9216 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
9217 sizeof(qcmacaddr));
9218 }
9219 }
9220 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
9221 {
9222 pConfig->num_deny_mac = params->n_acl_entries;
9223 for (i = 0; i < params->n_acl_entries; i++)
9224 {
9225 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9226 "** Add ACL MAC entry %i in BlackList :"
9227 MAC_ADDRESS_STR, i,
9228 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9229
9230 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
9231 sizeof(qcmacaddr));
9232 }
9233 }
9234
9235 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
9236 {
9237 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9238 "%s: SAP Set Mac Acl fail", __func__);
9239 return -EINVAL;
9240 }
9241 }
9242 else
9243 {
9244 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9245 "%s: Invalid device_mode = %d",
9246 __func__, pAdapter->device_mode);
9247 return -EINVAL;
9248 }
9249
9250 return 0;
9251}
9252
Leo Chang9056f462013-08-01 19:21:11 -07009253#ifdef WLAN_NL80211_TESTMODE
9254#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07009255void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07009256(
9257 void *pAdapter,
9258 void *indCont
9259)
9260{
Leo Changd9df8aa2013-09-26 13:32:26 -07009261 tSirLPHBInd *lphbInd;
9262 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07009263
9264 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009265 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07009266
9267 if (NULL == indCont)
9268 {
9269 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009270 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07009271 return;
9272 }
9273
Leo Changd9df8aa2013-09-26 13:32:26 -07009274 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07009275 skb = cfg80211_testmode_alloc_event_skb(
9276 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07009277 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07009278 GFP_ATOMIC);
9279 if (!skb)
9280 {
9281 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9282 "LPHB timeout, NL buffer alloc fail");
9283 return;
9284 }
9285
Leo Changac3ba772013-10-07 09:47:04 -07009286 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07009287 {
9288 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9289 "WLAN_HDD_TM_ATTR_CMD put fail");
9290 goto nla_put_failure;
9291 }
Leo Changac3ba772013-10-07 09:47:04 -07009292 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07009293 {
9294 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9295 "WLAN_HDD_TM_ATTR_TYPE put fail");
9296 goto nla_put_failure;
9297 }
Leo Changac3ba772013-10-07 09:47:04 -07009298 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07009299 sizeof(tSirLPHBInd), lphbInd))
9300 {
9301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9302 "WLAN_HDD_TM_ATTR_DATA put fail");
9303 goto nla_put_failure;
9304 }
Leo Chang9056f462013-08-01 19:21:11 -07009305 cfg80211_testmode_event(skb, GFP_ATOMIC);
9306 return;
9307
9308nla_put_failure:
9309 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9310 "NLA Put fail");
9311 kfree_skb(skb);
9312
9313 return;
9314}
9315#endif /* FEATURE_WLAN_LPHB */
9316
9317static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9318{
9319 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9320 int err = 0;
9321#ifdef FEATURE_WLAN_LPHB
9322 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009323 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009324#endif /* FEATURE_WLAN_LPHB */
9325
9326 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9327 if (err)
9328 {
9329 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9330 "%s Testmode INV ATTR", __func__);
9331 return err;
9332 }
9333
9334 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9335 {
9336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9337 "%s Testmode INV CMD", __func__);
9338 return -EINVAL;
9339 }
9340
9341 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9342 {
9343#ifdef FEATURE_WLAN_LPHB
9344 /* Low Power Heartbeat configuration request */
9345 case WLAN_HDD_TM_CMD_WLAN_HB:
9346 {
9347 int buf_len;
9348 void *buf;
9349 tSirLPHBReq *hb_params = NULL;
Amar Singhal9cff0482014-02-04 14:40:00 -08009350 tSirLPHBReq *hb_params_temp = NULL;
Leo Chang9056f462013-08-01 19:21:11 -07009351
9352 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9353 {
9354 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9355 "%s Testmode INV DATA", __func__);
9356 return -EINVAL;
9357 }
9358
9359 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9360 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
Amar Singhal9cff0482014-02-04 14:40:00 -08009361
9362 hb_params_temp =(tSirLPHBReq *)buf;
9363 if ((hb_params_temp->cmd == LPHB_SET_TCP_PARAMS_INDID) &&
9364 (hb_params_temp->params.lphbTcpParamReq.timePeriodSec == 0))
9365 return -EINVAL;
9366
Leo Chang9056f462013-08-01 19:21:11 -07009367 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9368 if (NULL == hb_params)
9369 {
9370 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9371 "%s Request Buffer Alloc Fail", __func__);
9372 return -EINVAL;
9373 }
9374
9375 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009376 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9377 hb_params,
9378 wlan_hdd_cfg80211_lphb_ind_handler);
9379 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009380 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009381 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9382 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009383 vos_mem_free(hb_params);
9384 }
Leo Chang9056f462013-08-01 19:21:11 -07009385 return 0;
9386 }
9387#endif /* FEATURE_WLAN_LPHB */
9388 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9390 "%s: unsupported event",__func__);
Leo Chang9056f462013-08-01 19:21:11 -07009391 return -EOPNOTSUPP;
9392 }
9393
9394 return err;
9395}
9396#endif /* CONFIG_NL80211_TESTMODE */
9397
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309398static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9399 struct net_device *dev,
9400 int idx, struct survey_info *survey)
9401{
9402 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9403 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309404 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309405 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309406 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309407 v_S7_t snr,rssi;
9408 int status, i, j, filled = 0;
9409
9410 ENTER();
9411
9412
9413 if (NULL == pAdapter)
9414 {
9415 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9416 "%s: HDD adapter is Null", __func__);
9417 return -ENODEV;
9418 }
9419
9420 if (NULL == wiphy)
9421 {
9422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9423 "%s: wiphy is Null", __func__);
9424 return -ENODEV;
9425 }
9426
9427 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9428 status = wlan_hdd_validate_context(pHddCtx);
9429
9430 if (0 != status)
9431 {
9432 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9433 "%s: HDD context is not valid", __func__);
9434 return status;
9435 }
9436
Mihir Sheted9072e02013-08-21 17:02:29 +05309437 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9438
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309439 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309440 0 != pAdapter->survey_idx ||
9441 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309442 {
9443 /* The survey dump ops when implemented completely is expected to
9444 * return a survey of all channels and the ops is called by the
9445 * kernel with incremental values of the argument 'idx' till it
9446 * returns -ENONET. But we can only support the survey for the
9447 * operating channel for now. survey_idx is used to track
9448 * that the ops is called only once and then return -ENONET for
9449 * the next iteration
9450 */
9451 pAdapter->survey_idx = 0;
9452 return -ENONET;
9453 }
9454
9455 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9456
9457 wlan_hdd_get_snr(pAdapter, &snr);
9458 wlan_hdd_get_rssi(pAdapter, &rssi);
9459
9460 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9461 hdd_wlan_get_freq(channel, &freq);
9462
9463
9464 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9465 {
9466 if (NULL == wiphy->bands[i])
9467 {
9468 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9469 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9470 continue;
9471 }
9472
9473 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9474 {
9475 struct ieee80211_supported_band *band = wiphy->bands[i];
9476
9477 if (band->channels[j].center_freq == (v_U16_t)freq)
9478 {
9479 survey->channel = &band->channels[j];
9480 /* The Rx BDs contain SNR values in dB for the received frames
9481 * while the supplicant expects noise. So we calculate and
9482 * return the value of noise (dBm)
9483 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9484 */
9485 survey->noise = rssi - snr;
9486 survey->filled = SURVEY_INFO_NOISE_DBM;
9487 filled = 1;
9488 }
9489 }
9490 }
9491
9492 if (filled)
9493 pAdapter->survey_idx = 1;
9494 else
9495 {
9496 pAdapter->survey_idx = 0;
9497 return -ENONET;
9498 }
9499
9500 return 0;
9501}
9502
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309503/*
9504 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9505 * this is called when cfg80211 driver resume
9506 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9507 */
9508int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9509{
9510 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9511 hdd_adapter_t *pAdapter;
9512 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9513 VOS_STATUS status = VOS_STATUS_SUCCESS;
9514
9515 ENTER();
9516
9517 if ( NULL == pHddCtx )
9518 {
9519 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9520 "%s: HddCtx validation failed", __func__);
9521 return 0;
9522 }
9523
9524 if (pHddCtx->isLogpInProgress)
9525 {
9526 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9527 "%s: LOGP in Progress. Ignore!!!", __func__);
9528 return 0;
9529 }
9530
9531 if (pHddCtx->isLoadUnloadInProgress)
9532 {
9533 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9534 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9535 return 0;
9536 }
9537
9538 spin_lock(&pHddCtx->schedScan_lock);
9539 pHddCtx->isWiphySuspended = FALSE;
9540 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9541 {
9542 spin_unlock(&pHddCtx->schedScan_lock);
9543 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9544 "%s: Return resume is not due to PNO indication", __func__);
9545 return 0;
9546 }
9547 // Reset flag to avoid updatating cfg80211 data old results again
9548 pHddCtx->isSchedScanUpdatePending = FALSE;
9549 spin_unlock(&pHddCtx->schedScan_lock);
9550
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309551
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309552 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9553
9554 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9555 {
9556 pAdapter = pAdapterNode->pAdapter;
9557 if ( (NULL != pAdapter) &&
9558 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9559 {
9560 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309561 {
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9563 "%s: NO SCAN result", __func__);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309564 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309565 else
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309566 {
9567 /* Acquire wakelock to handle the case where APP's tries to
9568 * suspend immediately after updating the scan results. Whis
9569 * results in app's is in suspended state and not able to
9570 * process the connect request to AP
9571 */
9572 hdd_prevent_suspend_timeout(2000);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309573 cfg80211_sched_scan_results(pHddCtx->wiphy);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309574 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309575
9576 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9577 "%s : cfg80211 scan result database updated", __func__);
9578
9579 return 0;
9580
9581 }
9582 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9583 pAdapterNode = pNext;
9584 }
9585
9586 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9587 "%s: Failed to find Adapter", __func__);
9588 return 0;
9589}
9590
9591/*
9592 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9593 * this is called when cfg80211 driver suspends
9594 */
9595int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9596 struct cfg80211_wowlan *wow)
9597{
9598 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9599
9600 ENTER();
9601 if (NULL == pHddCtx)
9602 {
9603 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9604 "%s: HddCtx validation failed", __func__);
9605 return 0;
9606 }
9607
9608 pHddCtx->isWiphySuspended = TRUE;
9609
9610 EXIT();
9611
9612 return 0;
9613}
9614
Jeff Johnson295189b2012-06-20 16:38:30 -07009615/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309616static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009617{
9618 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9619 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9620 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9621 .change_station = wlan_hdd_change_station,
9622#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9623 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9624 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9625 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009626#else
9627 .start_ap = wlan_hdd_cfg80211_start_ap,
9628 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9629 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009630#endif
9631 .change_bss = wlan_hdd_cfg80211_change_bss,
9632 .add_key = wlan_hdd_cfg80211_add_key,
9633 .get_key = wlan_hdd_cfg80211_get_key,
9634 .del_key = wlan_hdd_cfg80211_del_key,
9635 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009636#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009637 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009638#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009639 .scan = wlan_hdd_cfg80211_scan,
9640 .connect = wlan_hdd_cfg80211_connect,
9641 .disconnect = wlan_hdd_cfg80211_disconnect,
9642 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9643 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9644 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9645 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9646 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009647 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9648 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9649 .mgmt_tx = wlan_hdd_action,
9650#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9651 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9652 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9653 .set_txq_params = wlan_hdd_set_txq_params,
9654#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009655 .get_station = wlan_hdd_cfg80211_get_station,
9656 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9657 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009658 .add_station = wlan_hdd_cfg80211_add_station,
9659#ifdef FEATURE_WLAN_LFR
9660 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9661 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9662 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9663#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009664#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9665 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9666#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009667#ifdef FEATURE_WLAN_TDLS
9668 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9669 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9670#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309671#ifdef WLAN_FEATURE_GTK_OFFLOAD
9672 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9673#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309674#ifdef FEATURE_WLAN_SCAN_PNO
9675 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9676 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9677#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309678 .resume = wlan_hdd_cfg80211_resume_wlan,
9679 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309680 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009681#ifdef WLAN_NL80211_TESTMODE
9682 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9683#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309684 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009685};
9686