blob: c06d2cadd842c41d4e22315062765c8c5750ff43 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20*/
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
Jeff Johnson295189b2012-06-20 16:38:30 -0700538/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530539 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530540 * This function is called by hdd_wlan_startup()
541 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530542 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700543 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530544struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700545{
546 struct wiphy *wiphy;
547 ENTER();
548
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530549 /*
550 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700551 */
552 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
553
554 if (!wiphy)
555 {
556 /* Print error and jump into err label and free the memory */
557 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
558 return NULL;
559 }
560
561 return wiphy;
562}
563
564/*
565 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530566 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700567 * private ioctl to change the band value
568 */
569int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
570{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530571 int i, j;
572 eNVChannelEnabledType channelEnabledState;
573
Jeff Johnsone7245742012-09-05 17:12:55 -0700574 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530575 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700576 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530577
578 if (NULL == wiphy->bands[i])
579 {
580 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
581 __func__, i);
582 continue;
583 }
584
585 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
586 {
587 struct ieee80211_supported_band *band = wiphy->bands[i];
588
589 channelEnabledState = vos_nv_getChannelEnabledState(
590 band->channels[j].hw_value);
591
592 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
593 {
594 // Enable Social channels for P2P
595 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
596 NV_CHANNEL_ENABLE == channelEnabledState)
597 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
598 else
599 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
600 continue;
601 }
602 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
603 {
604 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
605 continue;
606 }
607
608 if (NV_CHANNEL_DISABLE == channelEnabledState ||
609 NV_CHANNEL_INVALID == channelEnabledState)
610 {
611 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
612 }
613 else if (NV_CHANNEL_DFS == channelEnabledState)
614 {
615 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
616 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
617 }
618 else
619 {
620 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
621 |IEEE80211_CHAN_RADAR);
622 }
623 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700624 }
625 return 0;
626}
627/*
628 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530629 * This function is called by hdd_wlan_startup()
630 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700631 * This function is used to initialize and register wiphy structure.
632 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530633int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700634 struct wiphy *wiphy,
635 hdd_config_t *pCfg
636 )
637{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530638 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700639 ENTER();
640
Jeff Johnson295189b2012-06-20 16:38:30 -0700641 /* Now bind the underlying wlan device with wiphy */
642 set_wiphy_dev(wiphy, dev);
643
644 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700645
Kiet Lam6c583332013-10-14 05:37:09 +0530646#ifndef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -0700647 /* the flag for the other case would be initialzed in
648 vos_init_wiphy_from_nv_bin */
Amar Singhal0a402232013-10-11 20:57:16 -0700649 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
Kiet Lam6c583332013-10-14 05:37:09 +0530650#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700651
Amar Singhalfddc28c2013-09-05 13:03:40 -0700652 /* This will disable updating of NL channels from passive to
653 * active if a beacon is received on passive channel. */
654 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700655
Amar Singhalfddc28c2013-09-05 13:03:40 -0700656
Amar Singhala49cbc52013-10-08 18:37:44 -0700657
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700658#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700659 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
660 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
661 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700662 | WIPHY_FLAG_OFFCHAN_TX;
Kiet Lam6c583332013-10-14 05:37:09 +0530663 wiphy->country_ie_pref = NL80211_COUNTRY_IE_IGNORE_CORE;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700664#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700665
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700666#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
667 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800668#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700669 || pCfg->isFastRoamIniFeatureEnabled
670#endif
671#ifdef FEATURE_WLAN_CCX
672 || pCfg->isCcxIniFeatureEnabled
673#endif
674 )
675 {
676 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
677 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800678#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800679#ifdef FEATURE_WLAN_TDLS
680 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
681 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
682#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530683#ifdef FEATURE_WLAN_SCAN_PNO
Hardik Kantilal Patel3dfd8792013-11-13 20:34:57 +0530684 if (pCfg->configPNOScanSupport)
685 {
686 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
687 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
688 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
689 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
690 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530691#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800692
Amar Singhalfddc28c2013-09-05 13:03:40 -0700693#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700694 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
695 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700696 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700697 driver need to determine what to do with both
698 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700699
700 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700701#else
702 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700703#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700704
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530705 wiphy->max_scan_ssids = MAX_SCAN_SSID;
706
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530707 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700708
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530709 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
710
Jeff Johnson295189b2012-06-20 16:38:30 -0700711 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530712 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700713 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700714 | BIT(NL80211_IFTYPE_P2P_CLIENT)
715 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700716 | BIT(NL80211_IFTYPE_AP);
717
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800718#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800719 if( pCfg->enableMCC )
720 {
721 /* Currently, supports up to two channels */
722 wlan_hdd_iface_combination.num_different_channels = 2;
723
724 if( !pCfg->allowMCCGODiffBI )
725 wlan_hdd_iface_combination.beacon_int_infra_match = true;
726
727 }
728 wiphy->iface_combinations = &wlan_hdd_iface_combination;
729 wiphy->n_iface_combinations = 1;
730#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800731
Jeff Johnson295189b2012-06-20 16:38:30 -0700732 /* Before registering we need to update the ht capabilitied based
733 * on ini values*/
734 if( !pCfg->ShortGI20MhzEnable )
735 {
736 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
737 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
738 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
739 }
740
741 if( !pCfg->ShortGI40MhzEnable )
742 {
743 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
744 }
745
746 if( !pCfg->nChannelBondingMode5GHz )
747 {
748 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
749 }
750
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530751 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
752 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
753
754 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
755 {
756
757 if (NULL == wiphy->bands[i])
758 {
759 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
760 __func__, i);
761 continue;
762 }
763
764 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
765 {
766 struct ieee80211_supported_band *band = wiphy->bands[i];
767
768 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
769 {
770 // Enable social channels for P2P
771 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
772 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
773 else
774 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
775 continue;
776 }
777 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
778 {
779 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
780 continue;
781 }
782 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700783 }
784 /*Initialise the supported cipher suite details*/
785 wiphy->cipher_suites = hdd_cipher_suites;
786 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
787
788 /*signal strength in mBm (100*dBm) */
789 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
790
791#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700792 wiphy->max_remain_on_channel_duration = 1000;
793#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700794
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530795 EXIT();
796 return 0;
797}
798
799/* In this function we are registering wiphy. */
800int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
801{
802 ENTER();
803 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700804 if (0 > wiphy_register(wiphy))
805 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530806 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700807 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
808 return -EIO;
809 }
810
811 EXIT();
812 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530813}
Jeff Johnson295189b2012-06-20 16:38:30 -0700814
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530815/* In this function we are updating channel list when,
816 regulatory domain is FCC and country code is US.
817 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
818 As per FCC smart phone is not a indoor device.
819 GO should not opeate on indoor channels */
820void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
821{
822 int j;
823 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
824 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
825 //Default counrtycode from NV at the time of wiphy initialization.
826 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
827 &defaultCountryCode[0]))
828 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -0700829 hddLog(LOGE, FL("Failed to get default country code from NV"));
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530830 }
831 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
832 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530833 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
834 {
835 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
836 return;
837 }
838 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
839 {
840 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
841 // Mark UNII -1 band channel as passive
842 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
843 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
844 }
845 }
846}
847
Jeff Johnson295189b2012-06-20 16:38:30 -0700848/* In this function we will do all post VOS start initialization.
849 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530850 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700851*/
852void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
853{
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
855 /* Register for all P2P action, public action etc frames */
856 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
857
Jeff Johnsone7245742012-09-05 17:12:55 -0700858 ENTER();
859
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 /* Right now we are registering these frame when driver is getting
861 initialized. Once we will move to 2.6.37 kernel, in which we have
862 frame register ops, we will move this code as a part of that */
863 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530864 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700865 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
866
867 /* GAS Initial Response */
868 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
869 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530870
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 /* GAS Comeback Request */
872 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
873 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
874
875 /* GAS Comeback Response */
876 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
877 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
878
879 /* P2P Public Action */
880 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530881 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 P2P_PUBLIC_ACTION_FRAME_SIZE );
883
884 /* P2P Action */
885 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
886 (v_U8_t*)P2P_ACTION_FRAME,
887 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700888
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530889 /* WNM BSS Transition Request frame */
890 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
891 (v_U8_t*)WNM_BSS_ACTION_FRAME,
892 WNM_BSS_ACTION_FRAME_SIZE );
893
Chet Lanctot186b5732013-03-18 10:26:30 -0700894#ifdef WLAN_FEATURE_11W
895 /* SA Query Response Action Frame */
896 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
897 (v_U8_t*)SA_QUERY_FRAME_RSP,
898 SA_QUERY_FRAME_RSP_SIZE );
899#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700900}
901
902void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
903{
Jeff Johnson295189b2012-06-20 16:38:30 -0700904 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
905 /* Register for all P2P action, public action etc frames */
906 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
907
Jeff Johnsone7245742012-09-05 17:12:55 -0700908 ENTER();
909
Jeff Johnson295189b2012-06-20 16:38:30 -0700910 /* Right now we are registering these frame when driver is getting
911 initialized. Once we will move to 2.6.37 kernel, in which we have
912 frame register ops, we will move this code as a part of that */
913 /* GAS Initial Request */
914
915 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
916 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
917
918 /* GAS Initial Response */
919 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
920 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530921
Jeff Johnson295189b2012-06-20 16:38:30 -0700922 /* GAS Comeback Request */
923 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
924 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
925
926 /* GAS Comeback Response */
927 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
928 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
929
930 /* P2P Public Action */
931 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530932 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700933 P2P_PUBLIC_ACTION_FRAME_SIZE );
934
935 /* P2P Action */
936 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
937 (v_U8_t*)P2P_ACTION_FRAME,
938 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700939
940#ifdef WLAN_FEATURE_11W
941 /* SA Query Response Action Frame */
942 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
943 (v_U8_t*)SA_QUERY_FRAME_RSP,
944 SA_QUERY_FRAME_RSP_SIZE );
945#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700946}
947
948#ifdef FEATURE_WLAN_WAPI
949void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
950 const u8 *mac_addr, u8 *key , int key_Len)
951{
952 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
953 tCsrRoamSetKey setKey;
954 v_BOOL_t isConnected = TRUE;
955 int status = 0;
956 v_U32_t roamId= 0xFF;
957 tANI_U8 *pKeyPtr = NULL;
958 int n = 0;
959
Arif Hussain6d2a3322013-11-17 19:50:10 -0800960 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -0700961 __func__,pAdapter->device_mode);
962
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530963 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 setKey.keyId = key_index; // Store Key ID
965 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
966 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
967 setKey.paeRole = 0 ; // the PAE role
968 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
969 {
970 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
971 }
972 else
973 {
974 isConnected = hdd_connIsConnected(pHddStaCtx);
975 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
976 }
977 setKey.keyLength = key_Len;
978 pKeyPtr = setKey.Key;
979 memcpy( pKeyPtr, key, key_Len);
980
Arif Hussain6d2a3322013-11-17 19:50:10 -0800981 hddLog(VOS_TRACE_LEVEL_INFO,"%s: WAPI KEY LENGTH:0x%04x",
Jeff Johnson295189b2012-06-20 16:38:30 -0700982 __func__, key_Len);
983 for (n = 0 ; n < key_Len; n++)
984 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
985 __func__,n,setKey.Key[n]);
986
987 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
988 if ( isConnected )
989 {
990 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
991 pAdapter->sessionId, &setKey, &roamId );
992 }
993 if ( status != 0 )
994 {
995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
996 "[%4d] sme_RoamSetKey returned ERROR status= %d",
997 __LINE__, status );
998 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
999 }
1000}
1001#endif /* FEATURE_WLAN_WAPI*/
1002
1003#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301004int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07001005 beacon_data_t **ppBeacon,
1006 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001007#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301008int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001009 beacon_data_t **ppBeacon,
1010 struct cfg80211_beacon_data *params,
1011 int dtim_period)
1012#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301013{
Jeff Johnson295189b2012-06-20 16:38:30 -07001014 int size;
1015 beacon_data_t *beacon = NULL;
1016 beacon_data_t *old = NULL;
1017 int head_len,tail_len;
1018
Jeff Johnsone7245742012-09-05 17:12:55 -07001019 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001020 if (params->head && !params->head_len)
1021 return -EINVAL;
1022
1023 old = pAdapter->sessionCtx.ap.beacon;
1024
1025 if (!params->head && !old)
1026 return -EINVAL;
1027
Jeff Johnson295189b2012-06-20 16:38:30 -07001028#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1029 /* Kernel 3.0 is not updating dtim_period for set beacon */
1030 if (!params->dtim_period)
1031 return -EINVAL;
1032#endif
1033
1034 if(params->head)
1035 head_len = params->head_len;
1036 else
1037 head_len = old->head_len;
1038
1039 if(params->tail || !old)
1040 tail_len = params->tail_len;
1041 else
1042 tail_len = old->tail_len;
1043
1044 size = sizeof(beacon_data_t) + head_len + tail_len;
1045
1046 beacon = kzalloc(size, GFP_KERNEL);
1047
1048 if( beacon == NULL )
1049 return -ENOMEM;
1050
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001051#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001052 if(params->dtim_period || !old )
1053 beacon->dtim_period = params->dtim_period;
1054 else
1055 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001056#else
1057 if(dtim_period || !old )
1058 beacon->dtim_period = dtim_period;
1059 else
1060 beacon->dtim_period = old->dtim_period;
1061#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301062
Jeff Johnson295189b2012-06-20 16:38:30 -07001063 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1064 beacon->tail = beacon->head + head_len;
1065 beacon->head_len = head_len;
1066 beacon->tail_len = tail_len;
1067
1068 if(params->head) {
1069 memcpy (beacon->head,params->head,beacon->head_len);
1070 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301071 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001072 if(old)
1073 memcpy (beacon->head,old->head,beacon->head_len);
1074 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301075
Jeff Johnson295189b2012-06-20 16:38:30 -07001076 if(params->tail) {
1077 memcpy (beacon->tail,params->tail,beacon->tail_len);
1078 }
1079 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301080 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001081 memcpy (beacon->tail,old->tail,beacon->tail_len);
1082 }
1083
1084 *ppBeacon = beacon;
1085
1086 kfree(old);
1087
1088 return 0;
1089
1090}
Jeff Johnson295189b2012-06-20 16:38:30 -07001091
1092v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1093{
1094 int left = length;
1095 v_U8_t *ptr = pIes;
1096 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301097
Jeff Johnson295189b2012-06-20 16:38:30 -07001098 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301099 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001100 elem_id = ptr[0];
1101 elem_len = ptr[1];
1102 left -= 2;
1103 if(elem_len > left)
1104 {
1105 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001106 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 eid,elem_len,left);
1108 return NULL;
1109 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301110 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 {
1112 return ptr;
1113 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301114
Jeff Johnson295189b2012-06-20 16:38:30 -07001115 left -= elem_len;
1116 ptr += (elem_len + 2);
1117 }
1118 return NULL;
1119}
1120
Jeff Johnson295189b2012-06-20 16:38:30 -07001121/* Check if rate is 11g rate or not */
1122static int wlan_hdd_rate_is_11g(u8 rate)
1123{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001124 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001125 u8 i;
1126 for (i = 0; i < 8; i++)
1127 {
1128 if(rate == gRateArray[i])
1129 return TRUE;
1130 }
1131 return FALSE;
1132}
1133
1134/* Check for 11g rate and set proper 11g only mode */
1135static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1136 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1137{
1138 u8 i, num_rates = pIe[0];
1139
1140 pIe += 1;
1141 for ( i = 0; i < num_rates; i++)
1142 {
1143 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1144 {
1145 /* If rate set have 11g rate than change the mode to 11G */
1146 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1147 if (pIe[i] & BASIC_RATE_MASK)
1148 {
1149 /* If we have 11g rate as basic rate, it means mode
1150 is 11g only mode.
1151 */
1152 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1153 *pCheckRatesfor11g = FALSE;
1154 }
1155 }
1156 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1157 {
1158 *require_ht = TRUE;
1159 }
1160 }
1161 return;
1162}
1163
1164static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1165{
1166 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1167 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1168 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1169 u8 checkRatesfor11g = TRUE;
1170 u8 require_ht = FALSE;
1171 u8 *pIe=NULL;
1172
1173 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1174
1175 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1176 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1177 if (pIe != NULL)
1178 {
1179 pIe += 1;
1180 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1181 &pConfig->SapHw_mode);
1182 }
1183
1184 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1185 WLAN_EID_EXT_SUPP_RATES);
1186 if (pIe != NULL)
1187 {
1188
1189 pIe += 1;
1190 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1191 &pConfig->SapHw_mode);
1192 }
1193
1194 if( pConfig->channel > 14 )
1195 {
1196 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1197 }
1198
1199 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1200 WLAN_EID_HT_CAPABILITY);
1201
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301202 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001203 {
1204 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1205 if(require_ht)
1206 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1207 }
1208}
1209
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301210static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1211 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1212{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001213 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301214 v_U8_t *pIe = NULL;
1215 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1216
1217 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1218 pBeacon->tail, pBeacon->tail_len);
1219
1220 if (pIe)
1221 {
1222 ielen = pIe[1] + 2;
1223 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1224 {
1225 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1226 }
1227 else
1228 {
1229 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1230 return -EINVAL;
1231 }
1232 *total_ielen += ielen;
1233 }
1234 return 0;
1235}
1236
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001237static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1238 v_U8_t *genie, v_U8_t *total_ielen)
1239{
1240 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1241 int left = pBeacon->tail_len;
1242 v_U8_t *ptr = pBeacon->tail;
1243 v_U8_t elem_id, elem_len;
1244 v_U16_t ielen = 0;
1245
1246 if ( NULL == ptr || 0 == left )
1247 return;
1248
1249 while (left >= 2)
1250 {
1251 elem_id = ptr[0];
1252 elem_len = ptr[1];
1253 left -= 2;
1254 if (elem_len > left)
1255 {
1256 hddLog( VOS_TRACE_LEVEL_ERROR,
1257 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1258 elem_id, elem_len, left);
1259 return;
1260 }
1261 if (IE_EID_VENDOR == elem_id)
1262 {
1263 /* skipping the VSIE's which we don't want to include or
1264 * it will be included by existing code
1265 */
1266 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1267#ifdef WLAN_FEATURE_WFD
1268 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1269#endif
1270 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1271 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1272 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1273 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1274 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1275 {
1276 ielen = ptr[1] + 2;
1277 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1278 {
1279 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1280 *total_ielen += ielen;
1281 }
1282 else
1283 {
1284 hddLog( VOS_TRACE_LEVEL_ERROR,
1285 "IE Length is too big "
1286 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1287 elem_id, elem_len, *total_ielen);
1288 }
1289 }
1290 }
1291
1292 left -= elem_len;
1293 ptr += (elem_len + 2);
1294 }
1295 return;
1296}
1297
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001298#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001299static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1300 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001301#else
1302static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1303 struct cfg80211_beacon_data *params)
1304#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001305{
1306 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301307 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001308 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001309 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001310
1311 genie = vos_mem_malloc(MAX_GENIE_LEN);
1312
1313 if(genie == NULL) {
1314
1315 return -ENOMEM;
1316 }
1317
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301318 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1319 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001320 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301321 ret = -EINVAL;
1322 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001323 }
1324
1325#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301326 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1327 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1328 {
1329 ret = -EINVAL;
1330 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001331 }
1332#endif
1333
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301334 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1335 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301337 ret = -EINVAL;
1338 goto done;
1339 }
1340
1341 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1342 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001343 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001344 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001345
1346 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1347 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1348 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1349 {
1350 hddLog(LOGE,
1351 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001352 ret = -EINVAL;
1353 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001354 }
1355
1356 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1357 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1358 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1359 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1360 ==eHAL_STATUS_FAILURE)
1361 {
1362 hddLog(LOGE,
1363 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001364 ret = -EINVAL;
1365 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 }
1367
1368 // Added for ProResp IE
1369 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1370 {
1371 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1372 u8 probe_rsp_ie_len[3] = {0};
1373 u8 counter = 0;
1374 /* Check Probe Resp Length if it is greater then 255 then Store
1375 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1376 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1377 Store More then 255 bytes into One Variable.
1378 */
1379 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1380 {
1381 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1382 {
1383 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1384 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1385 }
1386 else
1387 {
1388 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1389 rem_probe_resp_ie_len = 0;
1390 }
1391 }
1392
1393 rem_probe_resp_ie_len = 0;
1394
1395 if (probe_rsp_ie_len[0] > 0)
1396 {
1397 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1398 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1399 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1400 probe_rsp_ie_len[0], NULL,
1401 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1402 {
1403 hddLog(LOGE,
1404 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001405 ret = -EINVAL;
1406 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 }
1408 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1409 }
1410
1411 if (probe_rsp_ie_len[1] > 0)
1412 {
1413 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1414 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1415 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1416 probe_rsp_ie_len[1], NULL,
1417 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1418 {
1419 hddLog(LOGE,
1420 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001421 ret = -EINVAL;
1422 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001423 }
1424 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1425 }
1426
1427 if (probe_rsp_ie_len[2] > 0)
1428 {
1429 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1430 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1431 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1432 probe_rsp_ie_len[2], NULL,
1433 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1434 {
1435 hddLog(LOGE,
1436 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001437 ret = -EINVAL;
1438 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001439 }
1440 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1441 }
1442
1443 if (probe_rsp_ie_len[1] == 0 )
1444 {
1445 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1446 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1447 eANI_BOOLEAN_FALSE) )
1448 {
1449 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001450 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001451 }
1452 }
1453
1454 if (probe_rsp_ie_len[2] == 0 )
1455 {
1456 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1457 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1458 eANI_BOOLEAN_FALSE) )
1459 {
1460 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001461 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001462 }
1463 }
1464
1465 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1466 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1467 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1468 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1469 == eHAL_STATUS_FAILURE)
1470 {
1471 hddLog(LOGE,
1472 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001473 ret = -EINVAL;
1474 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001475 }
1476 }
1477 else
1478 {
1479 // Reset WNI_CFG_PROBE_RSP Flags
1480 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1481
1482 hddLog(VOS_TRACE_LEVEL_INFO,
1483 "%s: No Probe Response IE received in set beacon",
1484 __func__);
1485 }
1486
1487 // Added for AssocResp IE
1488 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1489 {
1490 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1491 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1492 params->assocresp_ies_len, NULL,
1493 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1494 {
1495 hddLog(LOGE,
1496 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001497 ret = -EINVAL;
1498 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001499 }
1500
1501 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1502 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1503 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1504 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1505 == eHAL_STATUS_FAILURE)
1506 {
1507 hddLog(LOGE,
1508 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001509 ret = -EINVAL;
1510 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001511 }
1512 }
1513 else
1514 {
1515 hddLog(VOS_TRACE_LEVEL_INFO,
1516 "%s: No Assoc Response IE received in set beacon",
1517 __func__);
1518
1519 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1520 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1521 eANI_BOOLEAN_FALSE) )
1522 {
1523 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001524 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001525 }
1526 }
1527
Jeff Johnsone7245742012-09-05 17:12:55 -07001528done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001529 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301530 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001531}
Jeff Johnson295189b2012-06-20 16:38:30 -07001532
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301533/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001534 * FUNCTION: wlan_hdd_validate_operation_channel
1535 * called by wlan_hdd_cfg80211_start_bss() and
1536 * wlan_hdd_cfg80211_set_channel()
1537 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301538 * channel list.
1539 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001540VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001541{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301542
Jeff Johnson295189b2012-06-20 16:38:30 -07001543 v_U32_t num_ch = 0;
1544 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1545 u32 indx = 0;
1546 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301547 v_U8_t fValidChannel = FALSE, count = 0;
1548 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301549
Jeff Johnson295189b2012-06-20 16:38:30 -07001550 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1551
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301552 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001553 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301554 /* Validate the channel */
1555 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001556 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301557 if ( channel == rfChannels[count].channelNum )
1558 {
1559 fValidChannel = TRUE;
1560 break;
1561 }
1562 }
1563 if (fValidChannel != TRUE)
1564 {
1565 hddLog(VOS_TRACE_LEVEL_ERROR,
1566 "%s: Invalid Channel [%d]", __func__, channel);
1567 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001568 }
1569 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301570 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001571 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301572 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1573 valid_ch, &num_ch))
1574 {
1575 hddLog(VOS_TRACE_LEVEL_ERROR,
1576 "%s: failed to get valid channel list", __func__);
1577 return VOS_STATUS_E_FAILURE;
1578 }
1579 for (indx = 0; indx < num_ch; indx++)
1580 {
1581 if (channel == valid_ch[indx])
1582 {
1583 break;
1584 }
1585 }
1586
1587 if (indx >= num_ch)
1588 {
1589 hddLog(VOS_TRACE_LEVEL_ERROR,
1590 "%s: Invalid Channel [%d]", __func__, channel);
1591 return VOS_STATUS_E_FAILURE;
1592 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001593 }
1594 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301595
Jeff Johnson295189b2012-06-20 16:38:30 -07001596}
1597
Viral Modi3a32cc52013-02-08 11:14:52 -08001598/**
1599 * FUNCTION: wlan_hdd_cfg80211_set_channel
1600 * This function is used to set the channel number
1601 */
1602static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1603 struct ieee80211_channel *chan,
1604 enum nl80211_channel_type channel_type
1605 )
1606{
1607 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001608 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001609 hdd_adapter_t *pAdapter = NULL;
1610 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301611 hdd_context_t *pHddCtx;
1612 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001613
1614 ENTER();
1615
1616 if( NULL == dev )
1617 {
1618 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001619 "%s: Called with dev = NULL.", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001620 return -ENODEV;
1621 }
1622 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1623
1624 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001625 "%s: device_mode = %d freq = %d", __func__,
Viral Modi3a32cc52013-02-08 11:14:52 -08001626 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301627
1628 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1629 status = wlan_hdd_validate_context(pHddCtx);
1630
1631 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001632 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301633 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1634 "%s: HDD context is not valid", __func__);
1635 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001636 }
1637
1638 /*
1639 * Do freq to chan conversion
1640 * TODO: for 11a
1641 */
1642
1643 channel = ieee80211_frequency_to_channel(freq);
1644
1645 /* Check freq range */
1646 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1647 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1648 {
1649 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001650 "%s: Channel [%d] is outside valid range from %d to %d",
Viral Modi3a32cc52013-02-08 11:14:52 -08001651 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1652 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1653 return -EINVAL;
1654 }
1655
1656 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1657
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301658 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1659 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001660 {
1661 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1662 {
1663 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001664 "%s: Invalid Channel [%d]", __func__, channel);
Viral Modi3a32cc52013-02-08 11:14:52 -08001665 return -EINVAL;
1666 }
1667 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1668 "%s: set channel to [%d] for device mode =%d",
1669 __func__, channel,pAdapter->device_mode);
1670 }
1671 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001672 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001673 )
1674 {
1675 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1676 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1677 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1678
1679 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1680 {
1681 /* Link is up then return cant set channel*/
1682 hddLog( VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001683 "%s: IBSS Associated, can't set the channel", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001684 return -EINVAL;
1685 }
1686
1687 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1688 pHddStaCtx->conn_info.operationChannel = channel;
1689 pRoamProfile->ChannelInfo.ChannelList =
1690 &pHddStaCtx->conn_info.operationChannel;
1691 }
1692 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001693 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001694 )
1695 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301696 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1697 {
1698 if(VOS_STATUS_SUCCESS !=
1699 wlan_hdd_validate_operation_channel(pAdapter,channel))
1700 {
1701 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001702 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301703 return -EINVAL;
1704 }
1705 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1706 }
1707 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001708 {
1709 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1710
1711 /* If auto channel selection is configured as enable/ 1 then ignore
1712 channel set by supplicant
1713 */
1714 if ( cfg_param->apAutoChannelSelection )
1715 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301716 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1717 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001718 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1719 "%s: set channel to auto channel (0) for device mode =%d",
1720 __func__, pAdapter->device_mode);
1721 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301722 else
1723 {
1724 if(VOS_STATUS_SUCCESS !=
1725 wlan_hdd_validate_operation_channel(pAdapter,channel))
1726 {
1727 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001728 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301729 return -EINVAL;
1730 }
1731 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1732 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001733 }
1734 }
1735 else
1736 {
1737 hddLog(VOS_TRACE_LEVEL_FATAL,
1738 "%s: Invalid device mode failed to set valid channel", __func__);
1739 return -EINVAL;
1740 }
1741 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301742 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001743}
1744
Jeff Johnson295189b2012-06-20 16:38:30 -07001745#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1746static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1747 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001748#else
1749static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1750 struct cfg80211_beacon_data *params,
1751 const u8 *ssid, size_t ssid_len,
1752 enum nl80211_hidden_ssid hidden_ssid)
1753#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001754{
1755 tsap_Config_t *pConfig;
1756 beacon_data_t *pBeacon = NULL;
1757 struct ieee80211_mgmt *pMgmt_frame;
1758 v_U8_t *pIe=NULL;
1759 v_U16_t capab_info;
1760 eCsrAuthType RSNAuthType;
1761 eCsrEncryptionType RSNEncryptType;
1762 eCsrEncryptionType mcRSNEncryptType;
1763 int status = VOS_STATUS_SUCCESS;
1764 tpWLAN_SAPEventCB pSapEventCallback;
1765 hdd_hostapd_state_t *pHostapdState;
1766 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1767 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301768 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 struct qc_mac_acl_entry *acl_entry = NULL;
1770 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001771 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001772
1773 ENTER();
1774
1775 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1776
1777 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1778
1779 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1780
1781 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1782
1783 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1784
1785 //channel is already set in the set_channel Call back
1786 //pConfig->channel = pCommitConfig->channel;
1787
1788 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301789 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001790 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1791
1792 pConfig->dtim_period = pBeacon->dtim_period;
1793
Arif Hussain6d2a3322013-11-17 19:50:10 -08001794 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***",
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 pConfig->dtim_period);
1796
1797
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001798 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001799 {
1800 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 WLAN_EID_COUNTRY);
Kiet Lam083504c2013-11-25 14:17:45 +05301802 if(memcmp(pHddCtx->cfg_ini->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0)
1803 {
1804 tANI_BOOLEAN restartNeeded;
1805 pConfig->ieee80211d = 1;
1806 vos_mem_copy(pConfig->countryCode, pHddCtx->cfg_ini->apCntryCode, 3);
1807 sme_setRegInfo(hHal, pConfig->countryCode);
1808 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
1809 }
1810 else if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001811 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001812 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001813 pConfig->ieee80211d = 1;
1814 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1815 sme_setRegInfo(hHal, pConfig->countryCode);
1816 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001817 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001818 else
1819 {
1820 pConfig->ieee80211d = 0;
1821 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301822 /*
1823 * If auto channel is configured i.e. channel is 0,
1824 * so skip channel validation.
1825 */
1826 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1827 {
1828 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1829 {
1830 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001831 "%s: Invalid Channel [%d]", __func__, pConfig->channel);
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301832 return -EINVAL;
1833 }
1834 }
1835 else
1836 {
1837 if(1 != pHddCtx->is_dynamic_channel_range_set)
1838 {
1839 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1840 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1841 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1842 }
1843 pHddCtx->is_dynamic_channel_range_set = 0;
1844 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001845 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001846 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001847 {
1848 pConfig->ieee80211d = 0;
1849 }
1850 pConfig->authType = eSAP_AUTO_SWITCH;
1851
1852 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301853
1854 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001855 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1856
1857 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1858
1859 /*Set wps station to configured*/
1860 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1861
1862 if(pIe)
1863 {
1864 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1865 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08001866 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***");
Jeff Johnson295189b2012-06-20 16:38:30 -07001867 return -EINVAL;
1868 }
1869 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1870 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001871 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001872 /* Check 15 bit of WPS IE as it contain information for wps state
1873 * WPS state
1874 */
1875 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1876 {
1877 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1878 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1879 {
1880 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1881 }
1882 }
1883 }
1884 else
1885 {
1886 pConfig->wps_state = SAP_WPS_DISABLED;
1887 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301888 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001889
1890 pConfig->RSNWPAReqIELength = 0;
1891 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301892 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001893 WLAN_EID_RSN);
1894 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301895 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001896 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1897 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1898 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301899 /* The actual processing may eventually be more extensive than
1900 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001901 * by the app.
1902 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301903 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001904 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1905 &RSNEncryptType,
1906 &mcRSNEncryptType,
1907 &RSNAuthType,
1908 pConfig->pRSNWPAReqIE[1]+2,
1909 pConfig->pRSNWPAReqIE );
1910
1911 if( VOS_STATUS_SUCCESS == status )
1912 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301913 /* Now copy over all the security attributes you have
1914 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001915 * */
1916 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1917 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1918 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1919 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301920 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08001921 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001922 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1923 }
1924 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301925
Jeff Johnson295189b2012-06-20 16:38:30 -07001926 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1927 pBeacon->tail, pBeacon->tail_len);
1928
1929 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1930 {
1931 if (pConfig->pRSNWPAReqIE)
1932 {
1933 /*Mixed mode WPA/WPA2*/
1934 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1935 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1936 }
1937 else
1938 {
1939 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1940 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1941 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301942 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001943 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1944 &RSNEncryptType,
1945 &mcRSNEncryptType,
1946 &RSNAuthType,
1947 pConfig->pRSNWPAReqIE[1]+2,
1948 pConfig->pRSNWPAReqIE );
1949
1950 if( VOS_STATUS_SUCCESS == status )
1951 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301952 /* Now copy over all the security attributes you have
1953 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001954 * */
1955 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1956 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1957 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1958 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301959 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08001960 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001961 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1962 }
1963 }
1964 }
1965
Jeff Johnson4416a782013-03-25 14:17:50 -07001966 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1967 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1968 return -EINVAL;
1969 }
1970
Jeff Johnson295189b2012-06-20 16:38:30 -07001971 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1972
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001973#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001974 if (params->ssid != NULL)
1975 {
1976 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1977 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1978 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1979 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1980 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001981#else
1982 if (ssid != NULL)
1983 {
1984 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1985 pConfig->SSIDinfo.ssid.length = ssid_len;
1986 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1987 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1988 }
1989#endif
1990
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301991 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001992 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301993
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 /* default value */
1995 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1996 pConfig->num_accept_mac = 0;
1997 pConfig->num_deny_mac = 0;
1998
1999 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2000 pBeacon->tail, pBeacon->tail_len);
2001
2002 /* pIe for black list is following form:
2003 type : 1 byte
2004 length : 1 byte
2005 OUI : 4 bytes
2006 acl type : 1 byte
2007 no of mac addr in black list: 1 byte
2008 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302009 */
2010 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002011 {
2012 pConfig->SapMacaddr_acl = pIe[6];
2013 pConfig->num_deny_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002014 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002015 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302016 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2017 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002018 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2019 for (i = 0; i < pConfig->num_deny_mac; i++)
2020 {
2021 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2022 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302023 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002024 }
2025 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2026 pBeacon->tail, pBeacon->tail_len);
2027
2028 /* pIe for white list is following form:
2029 type : 1 byte
2030 length : 1 byte
2031 OUI : 4 bytes
2032 acl type : 1 byte
2033 no of mac addr in white list: 1 byte
2034 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302035 */
2036 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002037 {
2038 pConfig->SapMacaddr_acl = pIe[6];
2039 pConfig->num_accept_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002040 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002041 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302042 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2043 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002044 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2045 for (i = 0; i < pConfig->num_accept_mac; i++)
2046 {
2047 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2048 acl_entry++;
2049 }
2050 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302051
Jeff Johnson295189b2012-06-20 16:38:30 -07002052 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2053
Jeff Johnsone7245742012-09-05 17:12:55 -07002054#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002055 /* Overwrite the hostapd setting for HW mode only for 11ac.
Kiet Lam0f320422013-11-21 19:29:17 +05302056 * This is valid only if mode is set to 11n in hostapd, either AUTO or
2057 * 11ac in .ini and 11ac is supported by both host and firmware.
2058 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode)
2059 */
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002060 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2061 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302062 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002063 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
Kiet Lam0f320422013-11-21 19:29:17 +05302064 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) &&
2065 (sme_IsFeatureSupportedByDriver(DOT11AC)) && (sme_IsFeatureSupportedByFW(DOT11AC)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002066 {
2067 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002068
2069 /* Disable VHT support in 2.4 GHz band */
2070 if (pConfig->channel <= 14 &&
2071 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2072 {
2073 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2074 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002075 }
2076#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302077
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002078 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2079 {
2080 sme_SelectCBMode(hHal,
2081 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2082 pConfig->channel);
2083 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002084 // ht_capab is not what the name conveys,this is used for protection bitmap
2085 pConfig->ht_capab =
2086 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2087
2088 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2089 {
2090 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2091 return -EINVAL;
2092 }
2093
2094 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2097 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302098 pConfig->obssProtEnabled =
2099 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002100
Arif Hussain6d2a3322013-11-17 19:50:10 -08002101 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR),
Jeff Johnson295189b2012-06-20 16:38:30 -07002102 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002103 hddLog(LOGW,FL("ssid =%s, beaconint=%d, channel=%d"),
2104 pConfig->SSIDinfo.ssid.ssId, (int)pConfig->beacon_int,
2105 (int)pConfig->channel);
2106 hddLog(LOGW,FL("hw_mode=%x, privacy=%d, authType=%d"),
2107 pConfig->SapHw_mode, pConfig->privacy,
2108 pConfig->authType);
2109 hddLog(LOGW,FL("RSN/WPALen=%d, Uapsd = %d"),
2110 (int)pConfig->RSNWPAReqIELength, pConfig->UapsdEnable);
2111 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d"),
2112 pConfig->protEnabled, pConfig->obssProtEnabled);
Jeff Johnson295189b2012-06-20 16:38:30 -07002113
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302114 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002115 {
2116 //Bss already started. just return.
2117 //TODO Probably it should update some beacon params.
2118 hddLog( LOGE, "Bss Already started...Ignore the request");
2119 EXIT();
2120 return 0;
2121 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302122
Jeff Johnson295189b2012-06-20 16:38:30 -07002123 pConfig->persona = pHostapdAdapter->device_mode;
2124
2125 pSapEventCallback = hdd_hostapd_SAPEventCB;
2126 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2127 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2128 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002129 hddLog(LOGE,FL("SAP Start Bss fail"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002130 return -EINVAL;
2131 }
2132
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302133 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002134 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2135
2136 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302137
Jeff Johnson295189b2012-06-20 16:38:30 -07002138 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302139 {
2140 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002141 ("ERROR: HDD vos wait for single_event failed!!"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002142 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002143 VOS_ASSERT(0);
2144 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302145
Jeff Johnson295189b2012-06-20 16:38:30 -07002146 //Succesfully started Bss update the state bit.
2147 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2148
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002149#ifdef WLAN_FEATURE_P2P_DEBUG
2150 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2151 {
2152 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2153 {
2154 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2155 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002156 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002157 }
2158 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2159 {
2160 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2161 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002162 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002163 }
2164 }
2165#endif
2166
Jeff Johnson295189b2012-06-20 16:38:30 -07002167 pHostapdState->bCommit = TRUE;
2168 EXIT();
2169
2170 return 0;
2171}
2172
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002173#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302174static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2175 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002176 struct beacon_parameters *params)
2177{
2178 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302179 hdd_context_t *pHddCtx;
2180 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002181
2182 ENTER();
2183
Arif Hussain6d2a3322013-11-17 19:50:10 -08002184 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d",pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002185
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302186 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2187 status = wlan_hdd_validate_context(pHddCtx);
2188
2189 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002190 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302191 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2192 "%s: HDD context is not valid", __func__);
2193 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002194 }
2195
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302196 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002197 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002198 )
2199 {
2200 beacon_data_t *old,*new;
2201
2202 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302203
Jeff Johnson295189b2012-06-20 16:38:30 -07002204 if (old)
2205 return -EALREADY;
2206
2207 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2208
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302209 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002210 {
2211 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002212 "%s:Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002213 return -EINVAL;
2214 }
2215
2216 pAdapter->sessionCtx.ap.beacon = new;
2217
2218 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2219 }
2220
2221 EXIT();
2222 return status;
2223}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302224
2225static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 struct net_device *dev,
2227 struct beacon_parameters *params)
2228{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302229 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302230 hdd_context_t *pHddCtx;
2231 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002232
2233 ENTER();
2234
Arif Hussain6d2a3322013-11-17 19:50:10 -08002235 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002236 __func__,pAdapter->device_mode);
2237
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302238 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2239 status = wlan_hdd_validate_context(pHddCtx);
2240
2241 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002242 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302243 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2244 "%s: HDD context is not valid", __func__);
2245 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002246 }
2247
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302248 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002249 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302250 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002251 {
2252 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302253
Jeff Johnson295189b2012-06-20 16:38:30 -07002254 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302255
Jeff Johnson295189b2012-06-20 16:38:30 -07002256 if (!old)
2257 return -ENOENT;
2258
2259 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2260
2261 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302262 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002263 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002264 return -EINVAL;
2265 }
2266
2267 pAdapter->sessionCtx.ap.beacon = new;
2268
2269 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2270 }
2271
2272 EXIT();
2273 return status;
2274}
2275
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002276#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2277
2278#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002279static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2280 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002281#else
2282static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2283 struct net_device *dev)
2284#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002285{
2286 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002287 hdd_context_t *pHddCtx = NULL;
2288 hdd_scaninfo_t *pScanInfo = NULL;
2289 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302290 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002291
2292 ENTER();
2293
2294 if (NULL == pAdapter)
2295 {
2296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002297 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002298 return -ENODEV;
2299 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002300
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302301 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2302 status = wlan_hdd_validate_context(pHddCtx);
2303
2304 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002305 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302306 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2307 "%s: HDD context is not valid", __func__);
2308 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002309 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002310
2311 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2312 if (NULL == staAdapter)
2313 {
2314 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2315 if (NULL == staAdapter)
2316 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002317 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2318 "%s: HDD adapter context for STA/P2P-CLI is Null",
2319 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002320 }
2321 }
2322
2323 pScanInfo = &pHddCtx->scan_info;
2324
Arif Hussain6d2a3322013-11-17 19:50:10 -08002325 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 __func__,pAdapter->device_mode);
2327
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002328 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002329 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002330 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302331 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002332 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002333 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002334 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2335 if (!status)
2336 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002337 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson902c9832012-12-10 14:28:09 -08002338 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002339 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002340 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002341 }
2342 }
2343
Jeff Johnson295189b2012-06-20 16:38:30 -07002344 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002345 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002346 )
2347 {
2348 beacon_data_t *old;
2349
2350 old = pAdapter->sessionCtx.ap.beacon;
2351
2352 if (!old)
2353 return -ENOENT;
2354
Jeff Johnson295189b2012-06-20 16:38:30 -07002355 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002356
2357 mutex_lock(&pHddCtx->sap_lock);
2358 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2359 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002360 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002361 {
2362 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2363
2364 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2365
2366 if (!VOS_IS_STATUS_SUCCESS(status))
2367 {
2368 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002369 ("ERROR: HDD vos wait for single_event failed!!"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002370 VOS_ASSERT(0);
2371 }
2372 }
2373 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2374 }
2375 mutex_unlock(&pHddCtx->sap_lock);
2376
2377 if(status != VOS_STATUS_SUCCESS)
2378 {
2379 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002380 "%s:Error!!! Stopping the BSS",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002381 return -EINVAL;
2382 }
2383
Jeff Johnson4416a782013-03-25 14:17:50 -07002384 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002385 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2386 ==eHAL_STATUS_FAILURE)
2387 {
2388 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002389 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002390 }
2391
Jeff Johnson4416a782013-03-25 14:17:50 -07002392 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002393 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2394 eANI_BOOLEAN_FALSE) )
2395 {
2396 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002397 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002398 }
2399
2400 // Reset WNI_CFG_PROBE_RSP Flags
2401 wlan_hdd_reset_prob_rspies(pAdapter);
2402
2403 pAdapter->sessionCtx.ap.beacon = NULL;
2404 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002405#ifdef WLAN_FEATURE_P2P_DEBUG
2406 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2407 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2408 {
2409 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2410 "GO got removed");
2411 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2412 }
2413#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002414 }
2415 EXIT();
2416 return status;
2417}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002418
2419#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2420
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302421static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2422 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002423 struct cfg80211_ap_settings *params)
2424{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302425 hdd_adapter_t *pAdapter;
2426 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302427 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002428
2429 ENTER();
2430
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302431 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002432 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302433 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302434 "%s: Device is Null", __func__);
2435 return -ENODEV;
2436 }
2437
2438 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2439 if (NULL == pAdapter)
2440 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302441 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302442 "%s: HDD adapter is Null", __func__);
2443 return -ENODEV;
2444 }
2445
2446 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2447 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302448 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302449 "%s: HDD adapter magic is invalid", __func__);
2450 return -ENODEV;
2451 }
2452
2453 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302454 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302455
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302456 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302457 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302458 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2459 "%s: HDD context is not valid", __func__);
2460 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302461 }
2462
2463 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2464 __func__, pAdapter->device_mode);
2465
2466 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002467 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002468 )
2469 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302470 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002471
2472 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302473
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002474 if (old)
2475 return -EALREADY;
2476
2477 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2478
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302479 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002480 {
2481 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302482 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002483 return -EINVAL;
2484 }
2485 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002486#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002487 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2488#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2489 params->channel, params->channel_type);
2490#else
2491 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2492#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002493#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002494 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2495 params->ssid_len, params->hidden_ssid);
2496 }
2497
2498 EXIT();
2499 return status;
2500}
2501
2502
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302503static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002504 struct net_device *dev,
2505 struct cfg80211_beacon_data *params)
2506{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302507 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302508 hdd_context_t *pHddCtx;
2509 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002510
2511 ENTER();
2512
Arif Hussain6d2a3322013-11-17 19:50:10 -08002513 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002514 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302515
2516 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2517 status = wlan_hdd_validate_context(pHddCtx);
2518
2519 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002520 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302521 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2522 "%s: HDD context is not valid", __func__);
2523 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002524 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002525
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302526 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002527 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302528 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002529 {
2530 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302531
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002532 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302533
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002534 if (!old)
2535 return -ENOENT;
2536
2537 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2538
2539 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302540 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002541 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002542 return -EINVAL;
2543 }
2544
2545 pAdapter->sessionCtx.ap.beacon = new;
2546
2547 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2548 }
2549
2550 EXIT();
2551 return status;
2552}
2553
2554#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2555
Jeff Johnson295189b2012-06-20 16:38:30 -07002556
2557static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2558 struct net_device *dev,
2559 struct bss_parameters *params)
2560{
2561 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2562
2563 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302564
Arif Hussain6d2a3322013-11-17 19:50:10 -08002565 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002566 __func__,pAdapter->device_mode);
2567
2568 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002569 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302570 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002571 {
2572 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2573 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302574 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 {
2576 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302577 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002578 }
2579
2580 EXIT();
2581 return 0;
2582}
2583
Kiet Lam10841362013-11-01 11:36:50 +05302584/* FUNCTION: wlan_hdd_change_country_code_cd
2585* to wait for contry code completion
2586*/
2587void* wlan_hdd_change_country_code_cb(void *pAdapter)
2588{
2589 hdd_adapter_t *call_back_pAdapter = pAdapter;
2590 complete(&call_back_pAdapter->change_country_code);
2591 return NULL;
2592}
2593
Jeff Johnson295189b2012-06-20 16:38:30 -07002594/*
2595 * FUNCTION: wlan_hdd_cfg80211_change_iface
2596 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2597 */
2598int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2599 struct net_device *ndev,
2600 enum nl80211_iftype type,
2601 u32 *flags,
2602 struct vif_params *params
2603 )
2604{
2605 struct wireless_dev *wdev;
2606 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2607 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002608 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002609 tCsrRoamProfile *pRoamProfile = NULL;
2610 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302611 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002612 eMib_dot11DesiredBssType connectedBssType;
2613 VOS_STATUS status;
2614
2615 ENTER();
2616
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302617 status = wlan_hdd_validate_context(pHddCtx);
2618
2619 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002620 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302621 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2622 "%s: HDD context is not valid", __func__);
2623 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002624 }
2625
2626 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2627 __func__, pAdapter->device_mode);
2628
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302629 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002630 wdev = ndev->ieee80211_ptr;
2631
2632#ifdef WLAN_BTAMP_FEATURE
2633 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2634 (NL80211_IFTYPE_ADHOC == type)||
2635 (NL80211_IFTYPE_AP == type)||
2636 (NL80211_IFTYPE_P2P_GO == type))
2637 {
2638 pHddCtx->isAmpAllowed = VOS_FALSE;
2639 // stop AMP traffic
2640 status = WLANBAP_StopAmp();
2641 if(VOS_STATUS_SUCCESS != status )
2642 {
2643 pHddCtx->isAmpAllowed = VOS_TRUE;
2644 hddLog(VOS_TRACE_LEVEL_FATAL,
2645 "%s: Failed to stop AMP", __func__);
2646 return -EINVAL;
2647 }
2648 }
2649#endif //WLAN_BTAMP_FEATURE
2650 /* Reset the current device mode bit mask*/
2651 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2652
2653 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002654 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002655 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002656 )
2657 {
2658 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2659 pRoamProfile = &pWextState->roamProfile;
2660 LastBSSType = pRoamProfile->BSSType;
2661
2662 switch (type)
2663 {
2664 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002665 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002666 hddLog(VOS_TRACE_LEVEL_INFO,
2667 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2668 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002669#ifdef WLAN_FEATURE_11AC
2670 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2671 {
2672 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2673 }
2674#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302675 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002676 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002677 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002678 //Check for sub-string p2p to confirm its a p2p interface
2679 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302680 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002681 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2682 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2683 }
2684 else
2685 {
2686 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002687 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002688 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302689#ifdef FEATURE_WLAN_TDLS
2690 /* The open adapter for the p2p shall skip initializations in
2691 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2692 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2693 * tdls_init when the change_iface sets the device mode to
2694 * WLAN_HDD_P2P_CLIENT.
2695 */
2696
2697 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2698 {
2699 if (0 != wlan_hdd_tdls_init (pAdapter))
2700 {
2701 return -EINVAL;
2702 }
2703 }
2704#endif
2705
Jeff Johnson295189b2012-06-20 16:38:30 -07002706 break;
2707 case NL80211_IFTYPE_ADHOC:
2708 hddLog(VOS_TRACE_LEVEL_INFO,
2709 "%s: setting interface Type to ADHOC", __func__);
2710 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2711 pRoamProfile->phyMode =
2712 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002713 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002714 wdev->iftype = type;
2715 break;
2716
2717 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002718 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002719 {
2720 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2721 "%s: setting interface Type to %s", __func__,
2722 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2723
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002724 //Cancel any remain on channel for GO mode
2725 if (NL80211_IFTYPE_P2P_GO == type)
2726 {
2727 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2728 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002729 if (NL80211_IFTYPE_AP == type)
2730 {
2731 /* As Loading WLAN Driver one interface being created for p2p device
2732 * address. This will take one HW STA and the max number of clients
2733 * that can connect to softAP will be reduced by one. so while changing
2734 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2735 * interface as it is not required in SoftAP mode.
2736 */
2737
2738 // Get P2P Adapter
2739 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2740
2741 if (pP2pAdapter)
2742 {
2743 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2744 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2745 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2746 }
2747 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302748#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002749
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302750 /* A Mutex Lock is introduced while changing the mode to
2751 * protect the concurrent access for the Adapters by TDLS
2752 * module.
2753 */
2754 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2755 {
2756 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2757 "%s: unable to lock list", __func__);
2758 return -EINVAL;
2759 }
2760#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002761 //De-init the adapter.
2762 hdd_stop_adapter( pHddCtx, pAdapter );
2763 hdd_deinit_adapter( pHddCtx, pAdapter );
2764 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002765 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2766 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302767#ifdef FEATURE_WLAN_TDLS
2768 mutex_unlock(&pHddCtx->tdls_lock);
2769#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002770
2771 //Disable BMPS and IMPS if enabled
2772 //before starting Go
2773 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2774 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302775 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002776 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2777 {
2778 //Fail to Exit BMPS
2779 VOS_ASSERT(0);
2780 }
2781 }
2782
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002783 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2784 (pConfig->apRandomBssidEnabled))
2785 {
2786 /* To meet Android requirements create a randomized
2787 MAC address of the form 02:1A:11:Fx:xx:xx */
2788 get_random_bytes(&ndev->dev_addr[3], 3);
2789 ndev->dev_addr[0] = 0x02;
2790 ndev->dev_addr[1] = 0x1A;
2791 ndev->dev_addr[2] = 0x11;
2792 ndev->dev_addr[3] |= 0xF0;
2793 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2794 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08002795 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
2796 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002797 }
2798
Jeff Johnson295189b2012-06-20 16:38:30 -07002799 hdd_set_ap_ops( pAdapter->dev );
2800
Kiet Lam10841362013-11-01 11:36:50 +05302801 /* This is for only SAP mode where users can
2802 * control country through ini.
2803 * P2P GO follows station country code
2804 * acquired during the STA scanning. */
2805 if((NL80211_IFTYPE_AP == type) &&
2806 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2807 {
2808 int status = 0;
2809 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2810 "%s: setting country code from INI ", __func__);
2811 init_completion(&pAdapter->change_country_code);
2812 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2813 (void *)(tSmeChangeCountryCallback)
2814 wlan_hdd_change_country_code_cb,
2815 pConfig->apCntryCode, pAdapter,
2816 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05302817 eSIR_FALSE,
2818 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05302819 if (eHAL_STATUS_SUCCESS == status)
2820 {
2821 /* Wait for completion */
2822 status = wait_for_completion_interruptible_timeout(
2823 &pAdapter->change_country_code,
2824 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2825 if (status <= 0)
2826 {
2827 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2828 "%s: SME Timed out while setting country code ",
2829 __func__);
2830 }
2831 }
2832 else
2833 {
2834 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002835 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05302836 return -EINVAL;
2837 }
2838 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002839 status = hdd_init_ap_mode(pAdapter);
2840 if(status != VOS_STATUS_SUCCESS)
2841 {
2842 hddLog(VOS_TRACE_LEVEL_FATAL,
2843 "%s: Error initializing the ap mode", __func__);
2844 return -EINVAL;
2845 }
2846 hdd_set_conparam(1);
2847
Jeff Johnson295189b2012-06-20 16:38:30 -07002848 /*interface type changed update in wiphy structure*/
2849 if(wdev)
2850 {
2851 wdev->iftype = type;
2852 pHddCtx->change_iface = type;
2853 }
2854 else
2855 {
2856 hddLog(VOS_TRACE_LEVEL_ERROR,
2857 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2858 return -EINVAL;
2859 }
2860 goto done;
2861 }
2862
2863 default:
2864 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2865 __func__);
2866 return -EOPNOTSUPP;
2867 }
2868 }
2869 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002870 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002871 )
2872 {
2873 switch(type)
2874 {
2875 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002876 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002877 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302878#ifdef FEATURE_WLAN_TDLS
2879
2880 /* A Mutex Lock is introduced while changing the mode to
2881 * protect the concurrent access for the Adapters by TDLS
2882 * module.
2883 */
2884 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2885 {
2886 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2887 "%s: unable to lock list", __func__);
2888 return -EINVAL;
2889 }
2890#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002891 hdd_stop_adapter( pHddCtx, pAdapter );
2892 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002893 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002894 //Check for sub-string p2p to confirm its a p2p interface
2895 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002896 {
2897 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2898 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2899 }
2900 else
2901 {
2902 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002903 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002904 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002905 hdd_set_conparam(0);
2906 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002907 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2908 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302909#ifdef FEATURE_WLAN_TDLS
2910 mutex_unlock(&pHddCtx->tdls_lock);
2911#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05302912 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002913 if( VOS_STATUS_SUCCESS != status )
2914 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002915 /* In case of JB, for P2P-GO, only change interface will be called,
2916 * This is the right place to enable back bmps_imps()
2917 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302918 if (pHddCtx->hdd_wlan_suspended)
2919 {
2920 hdd_set_pwrparams(pHddCtx);
2921 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002922 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002923 goto done;
2924 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002925 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002926 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002927 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2928 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002929 goto done;
2930 default:
2931 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2932 __func__);
2933 return -EOPNOTSUPP;
2934
2935 }
2936
2937 }
2938 else
2939 {
2940 return -EOPNOTSUPP;
2941 }
2942
2943
2944 if(pRoamProfile)
2945 {
2946 if ( LastBSSType != pRoamProfile->BSSType )
2947 {
2948 /*interface type changed update in wiphy structure*/
2949 wdev->iftype = type;
2950
2951 /*the BSS mode changed, We need to issue disconnect
2952 if connected or in IBSS disconnect state*/
2953 if ( hdd_connGetConnectedBssType(
2954 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2955 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2956 {
2957 /*need to issue a disconnect to CSR.*/
2958 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2959 if( eHAL_STATUS_SUCCESS ==
2960 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2961 pAdapter->sessionId,
2962 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2963 {
2964 wait_for_completion_interruptible_timeout(
2965 &pAdapter->disconnect_comp_var,
2966 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2967 }
2968 }
2969 }
2970 }
2971
2972done:
2973 /*set bitmask based on updated value*/
2974 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002975
2976 /* Only STA mode support TM now
2977 * all other mode, TM feature should be disabled */
2978 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2979 (~VOS_STA & pHddCtx->concurrency_mode) )
2980 {
2981 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2982 }
2983
Jeff Johnson295189b2012-06-20 16:38:30 -07002984#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302985 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002986 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2987 {
2988 //we are ok to do AMP
2989 pHddCtx->isAmpAllowed = VOS_TRUE;
2990 }
2991#endif //WLAN_BTAMP_FEATURE
2992 EXIT();
2993 return 0;
2994}
2995
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002996#ifdef FEATURE_WLAN_TDLS
2997static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2998 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2999{
3000 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3001 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3002 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003003 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003004
3005 ENTER();
3006
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303007 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003008 {
3009 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3010 "Invalid arguments");
3011 return -EINVAL;
3012 }
Hoonki Lee27511902013-03-14 18:19:06 -07003013
3014 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3015 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3016 {
3017 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3018 "%s: TDLS mode is disabled OR not enabled in FW."
3019 MAC_ADDRESS_STR " Request declined.",
3020 __func__, MAC_ADDR_ARRAY(mac));
3021 return -ENOTSUPP;
3022 }
3023
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003024 if (pHddCtx->isLogpInProgress)
3025 {
3026 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3027 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003028 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003029 return -EBUSY;
3030 }
3031
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303032 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003033
3034 if ( NULL == pTdlsPeer ) {
3035 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3036 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3037 __func__, MAC_ADDR_ARRAY(mac), update);
3038 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003039 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003040
3041 /* in add station, we accept existing valid staId if there is */
3042 if ((0 == update) &&
3043 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3044 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003045 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003046 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003047 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003048 " link_status %d. staId %d. add station ignored.",
3049 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3050 return 0;
3051 }
3052 /* in change station, we accept only when staId is valid */
3053 if ((1 == update) &&
3054 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3055 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3056 {
3057 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3058 "%s: " MAC_ADDRESS_STR
3059 " link status %d. staId %d. change station %s.",
3060 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3061 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3062 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003063 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003064
3065 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303066 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003067 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003068 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3069 "%s: " MAC_ADDRESS_STR
3070 " TDLS setup is ongoing. Request declined.",
3071 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003072 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003073 }
3074
3075 /* first to check if we reached to maximum supported TDLS peer.
3076 TODO: for now, return -EPERM looks working fine,
3077 but need to check if any other errno fit into this category.*/
3078 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3079 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003080 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3081 "%s: " MAC_ADDRESS_STR
3082 " TDLS Max peer already connected. Request declined.",
3083 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003084 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003085 }
3086 else
3087 {
3088 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303089 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003090 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003091 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003092 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3093 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3094 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003095 return -EPERM;
3096 }
3097 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003098 if (0 == update)
3099 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003100
Jeff Johnsond75fe012013-04-06 10:53:06 -07003101 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303102 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003103 {
3104 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3105 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003106 if(StaParams->htcap_present)
3107 {
3108 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3109 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3110 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3111 "ht_capa->extended_capabilities: %0x",
3112 StaParams->HTCap.extendedHtCapInfo);
3113 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003114 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3115 "params->capability: %0x",StaParams->capability);
3116 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003117 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003118 if(StaParams->vhtcap_present)
3119 {
3120 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3121 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3122 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3123 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3124 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003125 {
3126 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003127 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003128 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3129 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3130 "[%d]: %x ", i, StaParams->supported_rates[i]);
3131 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003132 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303133 else if ((1 == update) && (NULL == StaParams))
3134 {
3135 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3136 "%s : update is true, but staParams is NULL. Error!", __func__);
3137 return -EPERM;
3138 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003139
3140 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3141
3142 if (!update)
3143 {
3144 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3145 pAdapter->sessionId, mac);
3146 }
3147 else
3148 {
3149 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3150 pAdapter->sessionId, mac, StaParams);
3151 }
3152
3153 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3154 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3155
3156 if (!status)
3157 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003158 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003159 "%s: timeout waiting for tdls add station indication",
3160 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003161 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003162 }
3163 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3164 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003165 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003166 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003167 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003168 }
3169
3170 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003171
3172error:
3173 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3174 return -EPERM;
3175
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003176}
3177#endif
3178
Jeff Johnson295189b2012-06-20 16:38:30 -07003179static int wlan_hdd_change_station(struct wiphy *wiphy,
3180 struct net_device *dev,
3181 u8 *mac,
3182 struct station_parameters *params)
3183{
3184 VOS_STATUS status = VOS_STATUS_SUCCESS;
3185 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303186 hdd_context_t *pHddCtx;
3187 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003188 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003189#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003190 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003191 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003192#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003193 ENTER();
3194
Gopichand Nakkala29149562013-05-10 21:43:41 +05303195 if ((NULL == pAdapter))
3196 {
3197 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3198 "invalid adapter ");
3199 return -EINVAL;
3200 }
3201
3202 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3203 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3204
3205 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3206 {
3207 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3208 "invalid HDD state or HDD station context");
3209 return -EINVAL;
3210 }
3211
3212 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003213 {
3214 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3215 "%s:LOGP in Progress. Ignore!!!", __func__);
3216 return -EAGAIN;
3217 }
3218
Jeff Johnson295189b2012-06-20 16:38:30 -07003219 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3220
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003221 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3222 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003223 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003224 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003225 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303226 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003227 WLANTL_STA_AUTHENTICATED);
3228
Gopichand Nakkala29149562013-05-10 21:43:41 +05303229 if (status != VOS_STATUS_SUCCESS)
3230 {
3231 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3232 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3233 return -EINVAL;
3234 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003235 }
3236 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003237 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3238 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303239#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003240 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3241 StaParams.capability = params->capability;
3242 StaParams.uapsd_queues = params->uapsd_queues;
3243 StaParams.max_sp = params->max_sp;
3244
3245 if (0 != params->ext_capab_len)
3246 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3247 sizeof(StaParams.extn_capability));
3248
3249 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003250 {
3251 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003252 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003253 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003254
3255 StaParams.supported_rates_len = params->supported_rates_len;
3256
3257 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3258 * The supported_rates array , for all the structures propogating till Add Sta
3259 * to the firmware has to be modified , if the supplicant (ieee80211) is
3260 * modified to send more rates.
3261 */
3262
3263 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3264 */
3265 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3266 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3267
3268 if (0 != StaParams.supported_rates_len) {
3269 int i = 0;
3270 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3271 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003272 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003273 "Supported Rates with Length %d", StaParams.supported_rates_len);
3274 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003275 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003276 "[%d]: %0x", i, StaParams.supported_rates[i]);
3277 }
3278
3279 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003280 {
3281 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003282 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003283 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003284
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003285 if (0 != params->ext_capab_len ) {
3286 /*Define A Macro : TODO Sunil*/
3287 if ((1<<4) & StaParams.extn_capability[3]) {
3288 isBufSta = 1;
3289 }
3290 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303291 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3292 params->max_sp, isBufSta);
3293 if (VOS_STATUS_SUCCESS != status) {
3294 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3295 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3296 return -EINVAL;
3297 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003298 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3299
3300 if (VOS_STATUS_SUCCESS != status) {
3301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3302 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3303 return -EINVAL;
3304 }
3305 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003306#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303307 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003308 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003309 return status;
3310}
3311
3312/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003313 * FUNCTION: wlan_hdd_cfg80211_add_key
3314 * This function is used to initialize the key information
3315 */
3316#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003317static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003318 struct net_device *ndev,
3319 u8 key_index, bool pairwise,
3320 const u8 *mac_addr,
3321 struct key_params *params
3322 )
3323#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003324static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003325 struct net_device *ndev,
3326 u8 key_index, const u8 *mac_addr,
3327 struct key_params *params
3328 )
3329#endif
3330{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003331 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003332 tCsrRoamSetKey setKey;
3333 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303334 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003335 v_U32_t roamId= 0xFF;
3336 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003337 hdd_hostapd_state_t *pHostapdState;
3338 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003339 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303340 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003341
3342 ENTER();
3343
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303344 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3345 status = wlan_hdd_validate_context(pHddCtx);
3346
3347 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003348 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303349 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3350 "%s: HDD context is not valid", __func__);
3351 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003352 }
3353
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003354 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3355 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003356
3357 if (CSR_MAX_NUM_KEY <= key_index)
3358 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003359 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003360 key_index);
3361
3362 return -EINVAL;
3363 }
3364
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003365 if (CSR_MAX_KEY_LEN < params->key_len)
3366 {
3367 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3368 params->key_len);
3369
3370 return -EINVAL;
3371 }
3372
3373 hddLog(VOS_TRACE_LEVEL_INFO,
3374 "%s: called with key index = %d & key length %d",
3375 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003376
3377 /*extract key idx, key len and key*/
3378 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3379 setKey.keyId = key_index;
3380 setKey.keyLength = params->key_len;
3381 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3382
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003383 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003384 {
3385 case WLAN_CIPHER_SUITE_WEP40:
3386 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3387 break;
3388
3389 case WLAN_CIPHER_SUITE_WEP104:
3390 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3391 break;
3392
3393 case WLAN_CIPHER_SUITE_TKIP:
3394 {
3395 u8 *pKey = &setKey.Key[0];
3396 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3397
3398 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3399
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003400 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003401
3402 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003403 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003404 |--------------|----------|----------|
3405 <---16bytes---><--8bytes--><--8bytes-->
3406
3407 */
3408 /*Sme expects the 32 bytes key to be in the below order
3409
3410 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003411 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 |--------------|----------|----------|
3413 <---16bytes---><--8bytes--><--8bytes-->
3414 */
3415 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003416 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003417
3418 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003419 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003420
3421 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003422 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003423
3424
3425 break;
3426 }
3427
3428 case WLAN_CIPHER_SUITE_CCMP:
3429 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3430 break;
3431
3432#ifdef FEATURE_WLAN_WAPI
3433 case WLAN_CIPHER_SUITE_SMS4:
3434 {
3435 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3436 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3437 params->key, params->key_len);
3438 return 0;
3439 }
3440#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003441
Jeff Johnson295189b2012-06-20 16:38:30 -07003442#ifdef FEATURE_WLAN_CCX
3443 case WLAN_CIPHER_SUITE_KRK:
3444 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3445 break;
3446#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003447
3448#ifdef WLAN_FEATURE_11W
3449 case WLAN_CIPHER_SUITE_AES_CMAC:
3450 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003451 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003452#endif
3453
Jeff Johnson295189b2012-06-20 16:38:30 -07003454 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003455 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003456 __func__, params->cipher);
3457 return -EOPNOTSUPP;
3458 }
3459
3460 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3461 __func__, setKey.encType);
3462
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003463 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003464#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3465 (!pairwise)
3466#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003467 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003468#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003469 )
3470 {
3471 /* set group key*/
3472 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3473 "%s- %d: setting Broadcast key",
3474 __func__, __LINE__);
3475 setKey.keyDirection = eSIR_RX_ONLY;
3476 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3477 }
3478 else
3479 {
3480 /* set pairwise key*/
3481 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3482 "%s- %d: setting pairwise key",
3483 __func__, __LINE__);
3484 setKey.keyDirection = eSIR_TX_RX;
3485 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3486 }
3487 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3488 {
3489 setKey.keyDirection = eSIR_TX_RX;
3490 /*Set the group key*/
3491 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3492 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003493
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003494 if ( 0 != status )
3495 {
3496 hddLog(VOS_TRACE_LEVEL_ERROR,
3497 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3498 return -EINVAL;
3499 }
3500 /*Save the keys here and call sme_RoamSetKey for setting
3501 the PTK after peer joins the IBSS network*/
3502 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3503 &setKey, sizeof(tCsrRoamSetKey));
3504 return status;
3505 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303506 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3507 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3508 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003509 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003510 if( pHostapdState->bssState == BSS_START )
3511 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3513
3514 if ( status != eHAL_STATUS_SUCCESS )
3515 {
3516 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3517 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3518 __LINE__, status );
3519 }
3520 }
3521
3522 /* Saving WEP keys */
3523 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3524 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3525 {
3526 //Save the wep key in ap context. Issue setkey after the BSS is started.
3527 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3528 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3529 }
3530 else
3531 {
3532 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003533 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003534 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3535 }
3536 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003537 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3538 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003539 {
3540 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3541 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3542
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303543#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3544 if (!pairwise)
3545#else
3546 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3547#endif
3548 {
3549 /* set group key*/
3550 if (pHddStaCtx->roam_info.deferKeyComplete)
3551 {
3552 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3553 "%s- %d: Perform Set key Complete",
3554 __func__, __LINE__);
3555 hdd_PerformRoamSetKeyComplete(pAdapter);
3556 }
3557 }
3558
Jeff Johnson295189b2012-06-20 16:38:30 -07003559 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3560
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003561 pWextState->roamProfile.Keys.defaultIndex = key_index;
3562
3563
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003564 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003565 params->key, params->key_len);
3566
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303567
Jeff Johnson295189b2012-06-20 16:38:30 -07003568 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3569
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303570 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003571 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303572 __func__, setKey.peerMac[0], setKey.peerMac[1],
3573 setKey.peerMac[2], setKey.peerMac[3],
3574 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003575 setKey.keyDirection);
3576
3577 vos_status = wlan_hdd_check_ula_done(pAdapter);
3578
3579 if ( vos_status != VOS_STATUS_SUCCESS )
3580 {
3581 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3582 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3583 __LINE__, vos_status );
3584
3585 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3586
3587 return -EINVAL;
3588
3589 }
3590
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003591#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303592 /* The supplicant may attempt to set the PTK once pre-authentication
3593 is done. Save the key in the UMAC and include it in the ADD BSS
3594 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003595 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303596 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003597 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303598 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3599 "%s: Update PreAuth Key success", __func__);
3600 return 0;
3601 }
3602 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3603 {
3604 hddLog(VOS_TRACE_LEVEL_ERROR,
3605 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303606 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003607 }
3608#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003609
3610 /* issue set key request to SME*/
3611 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3612 pAdapter->sessionId, &setKey, &roamId );
3613
3614 if ( 0 != status )
3615 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303616 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003617 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3618 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3619 return -EINVAL;
3620 }
3621
3622
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303623 /* in case of IBSS as there was no information available about WEP keys during
3624 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003625 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303626 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3627 !( ( IW_AUTH_KEY_MGMT_802_1X
3628 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003629 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3630 )
3631 &&
3632 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3633 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3634 )
3635 )
3636 {
3637 setKey.keyDirection = eSIR_RX_ONLY;
3638 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3639
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303640 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003641 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303642 __func__, setKey.peerMac[0], setKey.peerMac[1],
3643 setKey.peerMac[2], setKey.peerMac[3],
3644 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003645 setKey.keyDirection);
3646
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303647 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 pAdapter->sessionId, &setKey, &roamId );
3649
3650 if ( 0 != status )
3651 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303652 hddLog(VOS_TRACE_LEVEL_ERROR,
3653 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003654 __func__, status);
3655 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3656 return -EINVAL;
3657 }
3658 }
3659 }
3660
3661 return 0;
3662}
3663
3664/*
3665 * FUNCTION: wlan_hdd_cfg80211_get_key
3666 * This function is used to get the key information
3667 */
3668#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303669static int wlan_hdd_cfg80211_get_key(
3670 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003671 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303672 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003673 const u8 *mac_addr, void *cookie,
3674 void (*callback)(void *cookie, struct key_params*)
3675 )
3676#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303677static int wlan_hdd_cfg80211_get_key(
3678 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003679 struct net_device *ndev,
3680 u8 key_index, const u8 *mac_addr, void *cookie,
3681 void (*callback)(void *cookie, struct key_params*)
3682 )
3683#endif
3684{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303685 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003686 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3687 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3688 struct key_params params;
3689
3690 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303691
Arif Hussain6d2a3322013-11-17 19:50:10 -08003692 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003693 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303694
Jeff Johnson295189b2012-06-20 16:38:30 -07003695 memset(&params, 0, sizeof(params));
3696
3697 if (CSR_MAX_NUM_KEY <= key_index)
3698 {
3699 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303700 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003701
3702 switch(pRoamProfile->EncryptionType.encryptionType[0])
3703 {
3704 case eCSR_ENCRYPT_TYPE_NONE:
3705 params.cipher = IW_AUTH_CIPHER_NONE;
3706 break;
3707
3708 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3709 case eCSR_ENCRYPT_TYPE_WEP40:
3710 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3711 break;
3712
3713 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3714 case eCSR_ENCRYPT_TYPE_WEP104:
3715 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3716 break;
3717
3718 case eCSR_ENCRYPT_TYPE_TKIP:
3719 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3720 break;
3721
3722 case eCSR_ENCRYPT_TYPE_AES:
3723 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3724 break;
3725
3726 default:
3727 params.cipher = IW_AUTH_CIPHER_NONE;
3728 break;
3729 }
3730
3731 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3732 params.seq_len = 0;
3733 params.seq = NULL;
3734 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3735 callback(cookie, &params);
3736 return 0;
3737}
3738
3739/*
3740 * FUNCTION: wlan_hdd_cfg80211_del_key
3741 * This function is used to delete the key information
3742 */
3743#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303744static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303746 u8 key_index,
3747 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003748 const u8 *mac_addr
3749 )
3750#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303751static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 struct net_device *ndev,
3753 u8 key_index,
3754 const u8 *mac_addr
3755 )
3756#endif
3757{
3758 int status = 0;
3759
3760 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303761 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 //it is observed that this is invalidating peer
3763 //key index whenever re-key is done. This is affecting data link.
3764 //It should be ok to ignore del_key.
3765#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303766 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3767 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003768 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3769 tCsrRoamSetKey setKey;
3770 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303771
Jeff Johnson295189b2012-06-20 16:38:30 -07003772 ENTER();
3773
3774 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3775 __func__,pAdapter->device_mode);
3776
3777 if (CSR_MAX_NUM_KEY <= key_index)
3778 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303779 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003780 key_index);
3781
3782 return -EINVAL;
3783 }
3784
3785 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3786 setKey.keyId = key_index;
3787
3788 if (mac_addr)
3789 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3790 else
3791 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3792
3793 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3794
3795 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003796 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303797 )
3798 {
3799
3800 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003801 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3802 if( pHostapdState->bssState == BSS_START)
3803 {
3804 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303805
Jeff Johnson295189b2012-06-20 16:38:30 -07003806 if ( status != eHAL_STATUS_SUCCESS )
3807 {
3808 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3809 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3810 __LINE__, status );
3811 }
3812 }
3813 }
3814 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303815 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003816 )
3817 {
3818 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3819
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303820 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3821
3822 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003823 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303824 __func__, setKey.peerMac[0], setKey.peerMac[1],
3825 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003826 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303827 if(pAdapter->sessionCtx.station.conn_info.connState ==
3828 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303830 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003831 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303832
Jeff Johnson295189b2012-06-20 16:38:30 -07003833 if ( 0 != status )
3834 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303835 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003836 "%s: sme_RoamSetKey failure, returned %d",
3837 __func__, status);
3838 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3839 return -EINVAL;
3840 }
3841 }
3842 }
3843#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003844 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003845 return status;
3846}
3847
3848/*
3849 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3850 * This function is used to set the default tx key index
3851 */
3852#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3853static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3854 struct net_device *ndev,
3855 u8 key_index,
3856 bool unicast, bool multicast)
3857#else
3858static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3859 struct net_device *ndev,
3860 u8 key_index)
3861#endif
3862{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303863 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303864 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303865 hdd_wext_state_t *pWextState;
3866 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303867 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003868
3869 ENTER();
3870
Gopichand Nakkala29149562013-05-10 21:43:41 +05303871 if ((NULL == pAdapter))
3872 {
3873 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3874 "invalid adapter");
3875 return -EINVAL;
3876 }
3877
3878 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3879 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3880
3881 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3882 {
3883 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3884 "invalid Wext state or HDD context");
3885 return -EINVAL;
3886 }
3887
Arif Hussain6d2a3322013-11-17 19:50:10 -08003888 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003889 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303890
Jeff Johnson295189b2012-06-20 16:38:30 -07003891 if (CSR_MAX_NUM_KEY <= key_index)
3892 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303893 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003894 key_index);
3895
3896 return -EINVAL;
3897 }
3898
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303899 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3900 status = wlan_hdd_validate_context(pHddCtx);
3901
3902 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003903 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303904 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3905 "%s: HDD context is not valid", __func__);
3906 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003907 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303908
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303911 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003912 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303913 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08003914 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303915 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08003916 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07003917 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303918 {
3919 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003920 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303921
Jeff Johnson295189b2012-06-20 16:38:30 -07003922 tCsrRoamSetKey setKey;
3923 v_U32_t roamId= 0xFF;
3924 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303925
3926 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003927 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303928
Jeff Johnson295189b2012-06-20 16:38:30 -07003929 Keys->defaultIndex = (u8)key_index;
3930 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3931 setKey.keyId = key_index;
3932 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303933
3934 vos_mem_copy(&setKey.Key[0],
3935 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003936 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303937
Gopichand Nakkala29149562013-05-10 21:43:41 +05303938 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303939
3940 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003941 &pHddStaCtx->conn_info.bssId[0],
3942 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303943
Gopichand Nakkala29149562013-05-10 21:43:41 +05303944 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3945 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3946 eCSR_ENCRYPT_TYPE_WEP104)
3947 {
3948 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3949 even though ap is configured for WEP-40 encryption. In this canse the key length
3950 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3951 type(104) and switching encryption type to 40*/
3952 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3953 eCSR_ENCRYPT_TYPE_WEP40;
3954 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3955 eCSR_ENCRYPT_TYPE_WEP40;
3956 }
3957
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303958 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003959 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303960
Jeff Johnson295189b2012-06-20 16:38:30 -07003961 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303962 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003963 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303964
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 if ( 0 != status )
3966 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303967 hddLog(VOS_TRACE_LEVEL_ERROR,
3968 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003969 status);
3970 return -EINVAL;
3971 }
3972 }
3973 }
3974
3975 /* In SoftAp mode setting key direction for default mode */
3976 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3977 {
3978 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3979 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3980 (eCSR_ENCRYPT_TYPE_AES !=
3981 pWextState->roamProfile.EncryptionType.encryptionType[0])
3982 )
3983 {
3984 /* Saving key direction for default key index to TX default */
3985 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3986 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3987 }
3988 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303989
Jeff Johnson295189b2012-06-20 16:38:30 -07003990 return status;
3991}
3992
Jeff Johnson295189b2012-06-20 16:38:30 -07003993/*
3994 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3995 * This function is used to inform the BSS details to nl80211 interface.
3996 */
3997static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3998 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3999{
4000 struct net_device *dev = pAdapter->dev;
4001 struct wireless_dev *wdev = dev->ieee80211_ptr;
4002 struct wiphy *wiphy = wdev->wiphy;
4003 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4004 int chan_no;
4005 int ie_length;
4006 const char *ie;
4007 unsigned int freq;
4008 struct ieee80211_channel *chan;
4009 int rssi = 0;
4010 struct cfg80211_bss *bss = NULL;
4011
4012 ENTER();
4013
4014 if( NULL == pBssDesc )
4015 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004016 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004017 return bss;
4018 }
4019
4020 chan_no = pBssDesc->channelId;
4021 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4022 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4023
4024 if( NULL == ie )
4025 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004026 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004027 return bss;
4028 }
4029
4030#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4031 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4032 {
4033 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4034 }
4035 else
4036 {
4037 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4038 }
4039#else
4040 freq = ieee80211_channel_to_frequency(chan_no);
4041#endif
4042
4043 chan = __ieee80211_get_channel(wiphy, freq);
4044
4045 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4046 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4047 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4048 if (bss == NULL)
4049 {
4050 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4051
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304052 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4053 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004054 pBssDesc->capabilityInfo,
4055 pBssDesc->beaconInterval, ie, ie_length,
4056 rssi, GFP_KERNEL ));
4057}
4058 else
4059 {
4060 return bss;
4061 }
4062}
4063
4064
4065
4066/*
4067 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4068 * This function is used to inform the BSS details to nl80211 interface.
4069 */
4070struct cfg80211_bss*
4071wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4072 tSirBssDescription *bss_desc
4073 )
4074{
4075 /*
4076 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4077 already exists in bss data base of cfg80211 for that particular BSS ID.
4078 Using cfg80211_inform_bss_frame to update the bss entry instead of
4079 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4080 now there is no possibility to get the mgmt(probe response) frame from PE,
4081 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4082 cfg80211_inform_bss_frame.
4083 */
4084 struct net_device *dev = pAdapter->dev;
4085 struct wireless_dev *wdev = dev->ieee80211_ptr;
4086 struct wiphy *wiphy = wdev->wiphy;
4087 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004088#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4089 qcom_ie_age *qie_age = NULL;
4090 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4091#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004092 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004093#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004094 const char *ie =
4095 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4096 unsigned int freq;
4097 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304098 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004099 struct cfg80211_bss *bss_status = NULL;
4100 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4101 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004102 hdd_context_t *pHddCtx;
4103 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004104#ifdef WLAN_OPEN_SOURCE
4105 struct timespec ts;
4106#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004107
4108 ENTER();
4109
Wilson Yangf80a0542013-10-07 13:02:37 -07004110 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4111 status = wlan_hdd_validate_context(pHddCtx);
4112
4113 /*bss_update is not allowed during wlan driver loading or unloading*/
4114 if (pHddCtx->isLoadUnloadInProgress)
4115 {
4116 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4117 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4118 return NULL;
4119 }
4120
4121
4122 if (0 != status)
4123 {
4124 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4125 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004126 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004127 }
4128
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304129 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004130 if (!mgmt)
4131 {
4132 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4133 "%s: memory allocation failed ", __func__);
4134 return NULL;
4135 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004136
Jeff Johnson295189b2012-06-20 16:38:30 -07004137 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004138
4139#ifdef WLAN_OPEN_SOURCE
4140 /* Android does not want the timestamp from the frame.
4141 Instead it wants a monotonic increasing value */
4142 get_monotonic_boottime(&ts);
4143 mgmt->u.probe_resp.timestamp =
4144 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4145#else
4146 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004147 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4148 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004149
4150#endif
4151
Jeff Johnson295189b2012-06-20 16:38:30 -07004152 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4153 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004154
4155#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4156 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4157 /* Assuming this is the last IE, copy at the end */
4158 ie_length -=sizeof(qcom_ie_age);
4159 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4160 qie_age->element_id = QCOM_VENDOR_IE_ID;
4161 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4162 qie_age->oui_1 = QCOM_OUI1;
4163 qie_age->oui_2 = QCOM_OUI2;
4164 qie_age->oui_3 = QCOM_OUI3;
4165 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4166 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4167#endif
4168
Jeff Johnson295189b2012-06-20 16:38:30 -07004169 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304170 if (bss_desc->fProbeRsp)
4171 {
4172 mgmt->frame_control |=
4173 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4174 }
4175 else
4176 {
4177 mgmt->frame_control |=
4178 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4179 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004180
4181#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304182 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004183 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4184 {
4185 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4186 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304187 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004188 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4189
4190 {
4191 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4192 }
4193 else
4194 {
4195 kfree(mgmt);
4196 return NULL;
4197 }
4198#else
4199 freq = ieee80211_channel_to_frequency(chan_no);
4200#endif
4201 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004202 /*when the band is changed on the fly using the GUI, three things are done
4203 * 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)
4204 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4205 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4206 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4207 * and discards the channels correponding to previous band and calls back with zero bss results.
4208 * 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
4209 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4210 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4211 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4212 * So drop the bss and continue to next bss.
4213 */
4214 if(chan == NULL)
4215 {
4216 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004217 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004218 return NULL;
4219 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004220 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304221 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004222 * */
4223 if (( eConnectionState_Associated ==
4224 pAdapter->sessionCtx.station.conn_info.connState ) &&
4225 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4226 pAdapter->sessionCtx.station.conn_info.bssId,
4227 WNI_CFG_BSSID_LEN)))
4228 {
4229 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4230 rssi = (pAdapter->rssi * 100);
4231 }
4232 else
4233 {
4234 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4235 }
4236
4237 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4238 frame_len, rssi, GFP_KERNEL);
4239 kfree(mgmt);
4240 return bss_status;
4241}
4242
4243/*
4244 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4245 * This function is used to update the BSS data base of CFG8011
4246 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304247struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004248 tCsrRoamInfo *pRoamInfo
4249 )
4250{
4251 tCsrRoamConnectedProfile roamProfile;
4252 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4253 struct cfg80211_bss *bss = NULL;
4254
4255 ENTER();
4256
4257 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4258 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4259
4260 if (NULL != roamProfile.pBssDesc)
4261 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304262 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004263 &roamProfile);
4264
4265 if (NULL == bss)
4266 {
4267 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4268 __func__);
4269 }
4270
4271 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4272 }
4273 else
4274 {
4275 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4276 __func__);
4277 }
4278 return bss;
4279}
4280
4281/*
4282 * FUNCTION: wlan_hdd_cfg80211_update_bss
4283 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304284static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4285 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004286 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304287{
Jeff Johnson295189b2012-06-20 16:38:30 -07004288 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4289 tCsrScanResultInfo *pScanResult;
4290 eHalStatus status = 0;
4291 tScanResultHandle pResult;
4292 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004293 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004294
4295 ENTER();
4296
Wilson Yangf80a0542013-10-07 13:02:37 -07004297 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4298
4299 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004300 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4302 "%s:LOGP in Progress. Ignore!!!",__func__);
4303 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004304 }
4305
Wilson Yangf80a0542013-10-07 13:02:37 -07004306
4307 /*bss_update is not allowed during wlan driver loading or unloading*/
4308 if (pHddCtx->isLoadUnloadInProgress)
4309 {
4310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4311 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4312 return VOS_STATUS_E_PERM;
4313 }
4314
4315
Jeff Johnson295189b2012-06-20 16:38:30 -07004316 /*
4317 * start getting scan results and populate cgf80211 BSS database
4318 */
4319 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4320
4321 /* no scan results */
4322 if (NULL == pResult)
4323 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004324 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004325 return status;
4326 }
4327
4328 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4329
4330 while (pScanResult)
4331 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304332 /*
4333 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4334 * entry already exists in bss data base of cfg80211 for that
4335 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4336 * bss entry instead of cfg80211_inform_bss, But this call expects
4337 * mgmt packet as input. As of now there is no possibility to get
4338 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 * ieee80211_mgmt(probe response) and passing to c
4340 * fg80211_inform_bss_frame.
4341 * */
4342
4343 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4344 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304345
Jeff Johnson295189b2012-06-20 16:38:30 -07004346
4347 if (NULL == bss_status)
4348 {
4349 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004350 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004351 }
4352 else
4353 {
Yue Maf49ba872013-08-19 12:04:25 -07004354 cfg80211_put_bss(
4355#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4356 wiphy,
4357#endif
4358 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004359 }
4360
4361 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4362 }
4363
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304364 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004365
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304366 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004367}
4368
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004369void
4370hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4371{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304372 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004373 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004374} /****** end hddPrintMacAddr() ******/
4375
4376void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004377hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004378{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304379 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004380 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004381 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4382 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4383 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004384} /****** end hddPrintPmkId() ******/
4385
4386//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4387//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4388
4389//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4390//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4391
4392#define dump_bssid(bssid) \
4393 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004394 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4395 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004396 }
4397
4398#define dump_pmkid(pMac, pmkid) \
4399 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004400 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4401 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004402 }
4403
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004404#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004405/*
4406 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4407 * This function is used to notify the supplicant of a new PMKSA candidate.
4408 */
4409int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304410 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004411 int index, bool preauth )
4412{
Jeff Johnsone7245742012-09-05 17:12:55 -07004413#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004414 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004415 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004416
4417 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004418 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004419
4420 if( NULL == pRoamInfo )
4421 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004422 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004423 return -EINVAL;
4424 }
4425
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004426 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4427 {
4428 dump_bssid(pRoamInfo->bssid);
4429 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004430 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004431 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004432#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304433 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004434}
4435#endif //FEATURE_WLAN_LFR
4436
Yue Maef608272013-04-08 23:09:17 -07004437#ifdef FEATURE_WLAN_LFR_METRICS
4438/*
4439 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4440 * 802.11r/LFR metrics reporting function to report preauth initiation
4441 *
4442 */
4443#define MAX_LFR_METRICS_EVENT_LENGTH 100
4444VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4445 tCsrRoamInfo *pRoamInfo)
4446{
4447 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4448 union iwreq_data wrqu;
4449
4450 ENTER();
4451
4452 if (NULL == pAdapter)
4453 {
4454 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4455 return VOS_STATUS_E_FAILURE;
4456 }
4457
4458 /* create the event */
4459 memset(&wrqu, 0, sizeof(wrqu));
4460 memset(metrics_notification, 0, sizeof(metrics_notification));
4461
4462 wrqu.data.pointer = metrics_notification;
4463 wrqu.data.length = scnprintf(metrics_notification,
4464 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4465 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4466
4467 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4468
4469 EXIT();
4470
4471 return VOS_STATUS_SUCCESS;
4472}
4473
4474/*
4475 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4476 * 802.11r/LFR metrics reporting function to report preauth completion
4477 * or failure
4478 */
4479VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4480 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4481{
4482 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4483 union iwreq_data wrqu;
4484
4485 ENTER();
4486
4487 if (NULL == pAdapter)
4488 {
4489 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4490 return VOS_STATUS_E_FAILURE;
4491 }
4492
4493 /* create the event */
4494 memset(&wrqu, 0, sizeof(wrqu));
4495 memset(metrics_notification, 0, sizeof(metrics_notification));
4496
4497 scnprintf(metrics_notification, sizeof(metrics_notification),
4498 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4499 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4500
4501 if (1 == preauth_status)
4502 strncat(metrics_notification, " TRUE", 5);
4503 else
4504 strncat(metrics_notification, " FALSE", 6);
4505
4506 wrqu.data.pointer = metrics_notification;
4507 wrqu.data.length = strlen(metrics_notification);
4508
4509 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4510
4511 EXIT();
4512
4513 return VOS_STATUS_SUCCESS;
4514}
4515
4516/*
4517 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4518 * 802.11r/LFR metrics reporting function to report handover initiation
4519 *
4520 */
4521VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4522 tCsrRoamInfo *pRoamInfo)
4523{
4524 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4525 union iwreq_data wrqu;
4526
4527 ENTER();
4528
4529 if (NULL == pAdapter)
4530 {
4531 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4532 return VOS_STATUS_E_FAILURE;
4533 }
4534
4535 /* create the event */
4536 memset(&wrqu, 0, sizeof(wrqu));
4537 memset(metrics_notification, 0, sizeof(metrics_notification));
4538
4539 wrqu.data.pointer = metrics_notification;
4540 wrqu.data.length = scnprintf(metrics_notification,
4541 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4542 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4543
4544 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4545
4546 EXIT();
4547
4548 return VOS_STATUS_SUCCESS;
4549}
4550#endif
4551
Jeff Johnson295189b2012-06-20 16:38:30 -07004552/*
4553 * FUNCTION: hdd_cfg80211_scan_done_callback
4554 * scanning callback function, called after finishing scan
4555 *
4556 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304557static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004558 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4559{
4560 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304561 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004563 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4564 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004565 struct cfg80211_scan_request *req = NULL;
4566 int ret = 0;
4567
4568 ENTER();
4569
4570 hddLog(VOS_TRACE_LEVEL_INFO,
4571 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004572 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 __func__, halHandle, pContext, (int) scanId, (int) status);
4574
Kiet Lamac06e2c2013-10-23 16:25:07 +05304575 pScanInfo->mScanPendingCounter = 0;
4576
Jeff Johnson295189b2012-06-20 16:38:30 -07004577 //Block on scan req completion variable. Can't wait forever though.
4578 ret = wait_for_completion_interruptible_timeout(
4579 &pScanInfo->scan_req_completion_event,
4580 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4581 if (!ret)
4582 {
4583 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004584 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004585 }
4586
Yue Maef608272013-04-08 23:09:17 -07004587 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004588 {
4589 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004590 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004591 }
4592
4593 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304594 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004595 {
4596 hddLog(VOS_TRACE_LEVEL_INFO,
4597 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004598 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004599 (int) scanId);
4600 }
4601
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304602 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004603 pAdapter);
4604
4605 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304606 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004607
4608
4609 /* If any client wait scan result through WEXT
4610 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004611 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004612 {
4613 /* The other scan request waiting for current scan finish
4614 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004615 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004616 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004617 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004618 }
4619 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004620 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004621 {
4622 struct net_device *dev = pAdapter->dev;
4623 union iwreq_data wrqu;
4624 int we_event;
4625 char *msg;
4626
4627 memset(&wrqu, '\0', sizeof(wrqu));
4628 we_event = SIOCGIWSCAN;
4629 msg = NULL;
4630 wireless_send_event(dev, we_event, &wrqu, msg);
4631 }
4632 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004633 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004634
4635 /* Get the Scan Req */
4636 req = pAdapter->request;
4637
4638 if (!req)
4639 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004640 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004641 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004642 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004643 }
4644
4645 /*
4646 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304647 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004648 req->n_ssids = 0;
4649 req->n_channels = 0;
4650 req->ie = 0;
4651
Jeff Johnson295189b2012-06-20 16:38:30 -07004652 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004653 /* Scan is no longer pending */
4654 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004655
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004656 /*
4657 * cfg80211_scan_done informing NL80211 about completion
4658 * of scanning
4659 */
4660 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004661 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004662
Jeff Johnsone7245742012-09-05 17:12:55 -07004663allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004664 /* release the wake lock at the end of the scan*/
4665 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004666
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004667 /* Acquire wakelock to handle the case where APP's tries to suspend
4668 * immediatly after the driver gets connect request(i.e after scan)
4669 * from supplicant, this result in app's is suspending and not able
4670 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004671 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004672
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004673#ifdef FEATURE_WLAN_TDLS
4674 wlan_hdd_tdls_scan_done_callback(pAdapter);
4675#endif
4676
Jeff Johnson295189b2012-06-20 16:38:30 -07004677 EXIT();
4678 return 0;
4679}
4680
4681/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004682 * FUNCTION: hdd_isScanAllowed
4683 * Go through each adapter and check if scan allowed
4684 *
4685 */
4686v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4687{
4688 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4689 hdd_station_ctx_t *pHddStaCtx = NULL;
4690 hdd_adapter_t *pAdapter = NULL;
4691 VOS_STATUS status = 0;
4692 v_U8_t staId = 0;
4693 v_U8_t *staMac = NULL;
4694
c_hpothu9b781ba2013-12-30 20:57:45 +05304695 if (TRUE == pHddCtx->btCoexModeSet)
4696 {
4697 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4698 FL("BTCoex Mode operation in progress, Do not allow scan"));
4699 return VOS_FALSE;
4700 }
4701
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004702 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4703
4704 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4705 {
4706 pAdapter = pAdapterNode->pAdapter;
4707
4708 if( pAdapter )
4709 {
4710 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304711 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004712 __func__, pAdapter->device_mode);
4713 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4714 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4715 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4716 {
4717 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4718 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4719 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4720 {
4721 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4722 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004723 "%s: client " MAC_ADDRESS_STR
4724 " is in the middle of WPS/EAPOL exchange.", __func__,
4725 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004726 return VOS_FALSE;
4727 }
4728 }
4729 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4730 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4731 {
4732 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4733 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304734 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004735 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4736 {
4737 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4738
4739 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004740 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
4741 "middle of WPS/EAPOL exchange.", __func__,
4742 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004743 return VOS_FALSE;
4744 }
4745 }
4746 }
4747 }
4748 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4749 pAdapterNode = pNext;
4750 }
4751 hddLog(VOS_TRACE_LEVEL_INFO,
4752 "%s: Scan allowed", __func__);
4753 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304754}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004755
4756/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004757 * FUNCTION: wlan_hdd_cfg80211_scan
4758 * this scan respond to scan trigger and update cfg80211 scan database
4759 * later, scan dump command can be used to recieve scan results
4760 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004761int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4762#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4763 struct net_device *dev,
4764#endif
4765 struct cfg80211_scan_request *request)
4766{
4767#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4768 struct net_device *dev = request->wdev->netdev;
4769#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304770 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004771 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4772 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304773 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004774 tCsrScanRequest scanRequest;
4775 tANI_U8 *channelList = NULL, i;
4776 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304777 int status;
4778 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004779 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004780
4781 ENTER();
4782
Arif Hussain6d2a3322013-11-17 19:50:10 -08004783 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004784 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004785
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304786 status = wlan_hdd_validate_context(pHddCtx);
4787
4788 if (0 != status)
4789 {
4790 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4791 "%s: HDD context is not valid", __func__);
4792 return status;
4793 }
4794
4795 cfg_param = pHddCtx->cfg_ini;
4796 pScanInfo = &pHddCtx->scan_info;
4797
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004798 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004799 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004800 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004801 {
4802 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004803 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4804 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004805 return -EBUSY;
4806 }
4807
Jeff Johnson295189b2012-06-20 16:38:30 -07004808#ifdef WLAN_BTAMP_FEATURE
4809 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004810 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004811 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004812 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004813 "%s: No scanning when AMP is on", __func__);
4814 return -EOPNOTSUPP;
4815 }
4816#endif
4817 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004818 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004819 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004820 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004821 "%s: Not scanning on device_mode = %d",
4822 __func__, pAdapter->device_mode);
4823 return -EOPNOTSUPP;
4824 }
4825
4826 if (TRUE == pScanInfo->mScanPending)
4827 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05304828 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
4829 {
4830 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
4831 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004832 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004833 }
4834
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304835 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004836 //Channel and action frame is pending
4837 //Otherwise Cancel Remain On Channel and allow Scan
4838 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004839 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004840 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05304841 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004842 return -EBUSY;
4843 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004844#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004845 /* if tdls disagree scan right now, return immediately.
4846 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4847 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4848 */
4849 status = wlan_hdd_tdls_scan_callback (pAdapter,
4850 wiphy,
4851#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4852 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004853#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004854 request);
4855 if(status <= 0)
4856 {
4857 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4858 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004859 }
4860#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004861
Jeff Johnson295189b2012-06-20 16:38:30 -07004862 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4863 {
4864 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004865 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004866 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304867 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004868 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4869 {
4870 hddLog(VOS_TRACE_LEVEL_WARN,
4871 "%s: MAX TM Level Scan not allowed", __func__);
4872 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304873 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004874 }
4875 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4876
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004877 /* Check if scan is allowed at this point of time.
4878 */
4879 if (!hdd_isScanAllowed(pHddCtx))
4880 {
4881 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4882 return -EBUSY;
4883 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304884
Jeff Johnson295189b2012-06-20 16:38:30 -07004885 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4886
4887 if (NULL != request)
4888 {
4889 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304890 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004891
4892 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4893 * Becasue of this, driver is assuming that this is not wildcard scan and so
4894 * is not aging out the scan results.
4895 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004896 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004897 {
4898 request->n_ssids = 0;
4899 }
4900
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004901 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004902 {
4903 tCsrSSIDInfo *SsidInfo;
4904 int j;
4905 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4906 /* Allocate num_ssid tCsrSSIDInfo structure */
4907 SsidInfo = scanRequest.SSIDs.SSIDList =
4908 ( tCsrSSIDInfo *)vos_mem_malloc(
4909 request->n_ssids*sizeof(tCsrSSIDInfo));
4910
4911 if(NULL == scanRequest.SSIDs.SSIDList)
4912 {
4913 hddLog(VOS_TRACE_LEVEL_ERROR,
4914 "memory alloc failed SSIDInfo buffer");
4915 return -ENOMEM;
4916 }
4917
4918 /* copy all the ssid's and their length */
4919 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4920 {
4921 /* get the ssid length */
4922 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4923 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4924 SsidInfo->SSID.length);
4925 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4926 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4927 j, SsidInfo->SSID.ssId);
4928 }
4929 /* set the scan type to active */
4930 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4931 }
4932 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4933 {
4934 /* set the scan type to active */
4935 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4936 }
4937 else
4938 {
4939 /*Set the scan type to default type, in this case it is ACTIVE*/
4940 scanRequest.scanType = pScanInfo->scan_mode;
4941 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304942 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004943 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4944 }
4945 else
4946 {
4947 /* set the scan type to active */
4948 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4949 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4950
4951 /* set min and max channel time to zero */
4952 scanRequest.minChnTime = 0;
4953 scanRequest.maxChnTime = 0;
4954 }
4955
4956 /* set BSSType to default type */
4957 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4958
4959 /*TODO: scan the requested channels only*/
4960
4961 /*Right now scanning all the channels */
4962 if( request )
4963 {
4964 if( request->n_channels )
4965 {
4966 channelList = vos_mem_malloc( request->n_channels );
4967 if( NULL == channelList )
4968 {
4969 status = -ENOMEM;
4970 goto free_mem;
4971 }
4972
4973 for( i = 0 ; i < request->n_channels ; i++ )
4974 channelList[i] = request->channels[i]->hw_value;
4975 }
4976
4977 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4978 scanRequest.ChannelInfo.ChannelList = channelList;
4979
4980 /* set requestType to full scan */
4981 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304982
4983 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004984 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304985 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004986 */
4987
4988 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304989 * and in that case driver shoudnt flush scan results. If
4990 * driver flushes the scan results here and unfortunately if
4991 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004992 * fails which is not desired
4993 */
4994
4995 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4996 {
4997 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4998 pAdapter->sessionId );
4999 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005000
5001 if( request->ie_len )
5002 {
5003 /* save this for future association (join requires this) */
Agarwal Ashish4f616132013-12-30 23:32:50 +05305004 /*TODO: Array needs to be converted to dynamic allocation,
5005 * as multiple ie.s can be sent in cfg80211_scan_request structure
5006 * CR 597966
5007 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005008 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5009 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5010 pScanInfo->scanAddIE.length = request->ie_len;
5011
Agarwal Ashish4f616132013-12-30 23:32:50 +05305012 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07005013 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
Agarwal Ashish4f616132013-12-30 23:32:50 +05305014 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005015 {
Agarwal Ashish4f616132013-12-30 23:32:50 +05305016 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
5017 {
5018 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5019 memcpy( pwextBuf->roamProfile.addIEScan,
5020 request->ie, request->ie_len);
5021 }
5022 else
5023 {
5024 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
5025 "%d", request->ie_len);
5026 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005027
Agarwal Ashish4f616132013-12-30 23:32:50 +05305028 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005029 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5030 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5031
Jeff Johnson295189b2012-06-20 16:38:30 -07005032 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5033 request->ie_len);
5034 if (pP2pIe != NULL)
5035 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005036#ifdef WLAN_FEATURE_P2P_DEBUG
5037 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5038 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5039 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5040 {
5041 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5042 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5043 "Go nego completed to Connection is started");
5044 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5045 "for 8way Handshake");
5046 }
5047 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5048 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5049 {
5050 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5051 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5052 "Disconnected state to Connection is started");
5053 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5054 "for 4way Handshake");
5055 }
5056#endif
5057
Jeff Johnsone7245742012-09-05 17:12:55 -07005058 /* no_cck will be set during p2p find to disable 11b rates */
5059 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005060 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005061 hddLog(VOS_TRACE_LEVEL_INFO,
5062 "%s: This is a P2P Search", __func__);
5063 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005064
Jeff Johnsone7245742012-09-05 17:12:55 -07005065 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5066 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005067 /* set requestType to P2P Discovery */
5068 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005069 }
5070
5071 /*
5072 Skip Dfs Channel in case of P2P Search
5073 if it is set in ini file
5074 */
5075 if(cfg_param->skipDfsChnlInP2pSearch)
5076 {
5077 scanRequest.skipDfsChnlInP2pSearch = 1;
5078 }
5079 else
5080 {
5081 scanRequest.skipDfsChnlInP2pSearch = 0;
5082 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005083
Jeff Johnson295189b2012-06-20 16:38:30 -07005084 }
5085 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005086 }
5087 }
5088
5089 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5090
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005091 /* acquire the wakelock to avoid the apps suspend during the scan. To
5092 * address the following issues.
5093 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5094 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5095 * for long time, this result in apps running at full power for long time.
5096 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5097 * be stuck in full power because of resume BMPS
5098 */
5099 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005100
5101 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005102 pAdapter->sessionId, &scanRequest, &scanId,
5103 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005104
Jeff Johnson295189b2012-06-20 16:38:30 -07005105 if (eHAL_STATUS_SUCCESS != status)
5106 {
5107 hddLog(VOS_TRACE_LEVEL_ERROR,
5108 "%s: sme_ScanRequest returned error %d", __func__, status);
5109 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005110 if(eHAL_STATUS_RESOURCES == status)
5111 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07005112 hddLog(VOS_TRACE_LEVEL_INFO, "%s: HO is in progress.So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005113 status = -EBUSY;
5114 } else {
5115 status = -EIO;
5116 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005117 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005118 goto free_mem;
5119 }
5120
5121 pScanInfo->mScanPending = TRUE;
5122 pAdapter->request = request;
5123 pScanInfo->scanId = scanId;
5124
5125 complete(&pScanInfo->scan_req_completion_event);
5126
5127free_mem:
5128 if( scanRequest.SSIDs.SSIDList )
5129 {
5130 vos_mem_free(scanRequest.SSIDs.SSIDList);
5131 }
5132
5133 if( channelList )
5134 vos_mem_free( channelList );
5135
5136 EXIT();
5137
5138 return status;
5139}
5140
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005141
5142void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5143{
5144 v_U8_t iniDot11Mode =
5145 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5146 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5147
5148 switch ( iniDot11Mode )
5149 {
5150 case eHDD_DOT11_MODE_AUTO:
5151 case eHDD_DOT11_MODE_11ac:
5152 case eHDD_DOT11_MODE_11ac_ONLY:
5153#ifdef WLAN_FEATURE_11AC
5154 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5155#else
5156 hddDot11Mode = eHDD_DOT11_MODE_11n;
5157#endif
5158 break;
5159 case eHDD_DOT11_MODE_11n:
5160 case eHDD_DOT11_MODE_11n_ONLY:
5161 hddDot11Mode = eHDD_DOT11_MODE_11n;
5162 break;
5163 default:
5164 hddDot11Mode = iniDot11Mode;
5165 break;
5166 }
5167 /* This call decides required channel bonding mode */
5168 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5169 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5170 operationChannel);
5171}
5172
Jeff Johnson295189b2012-06-20 16:38:30 -07005173/*
5174 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305175 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005176 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305177int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005178 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005179{
5180 int status = 0;
5181 hdd_wext_state_t *pWextState;
5182 v_U32_t roamId;
5183 tCsrRoamProfile *pRoamProfile;
5184 eMib_dot11DesiredBssType connectedBssType;
5185 eCsrAuthType RSNAuthType;
5186
5187 ENTER();
5188
5189 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305190
Jeff Johnson295189b2012-06-20 16:38:30 -07005191 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5192 {
5193 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5194 return -EINVAL;
5195 }
5196
5197 pRoamProfile = &pWextState->roamProfile;
5198
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305199 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005200 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005201 int ret = 0;
5202 hdd_station_ctx_t *pHddStaCtx;
5203 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5204 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
5205
5206 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
5207 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
5208 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07005209 {
5210 /* Issue disconnect to CSR */
5211 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305212 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005213 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5214 pAdapter->sessionId,
5215 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
5216 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005217 ret = wait_for_completion_interruptible_timeout(
5218 &pAdapter->disconnect_comp_var,
5219 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5220 if (0 == ret)
5221 {
5222 VOS_ASSERT(0);
5223 }
5224 }
5225 }
5226 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
5227 {
5228 ret = wait_for_completion_interruptible_timeout(
5229 &pAdapter->disconnect_comp_var,
5230 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5231 if (0 == ret)
5232 {
5233 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 }
5235 }
5236
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305237 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005238 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5239 {
5240 /*QoS not enabled in cfg file*/
5241 pRoamProfile->uapsd_mask = 0;
5242 }
5243 else
5244 {
5245 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305246 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005247 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5248 }
5249
5250 pRoamProfile->SSIDs.numOfSSIDs = 1;
5251 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5252 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305253 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005254 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5255 ssid, ssid_len);
5256
5257 if (bssid)
5258 {
5259 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5260 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5261 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305262 /* Save BSSID in seperate variable as well, as RoamProfile
5263 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005264 case of join failure we should send valid BSSID to supplicant
5265 */
5266 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5267 WNI_CFG_BSSID_LEN);
5268 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005269 else
5270 {
5271 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5272 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005273
5274 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5275 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305276 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 /*set gen ie*/
5278 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5279 /*set auth*/
5280 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5281 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005282#ifdef FEATURE_WLAN_WAPI
5283 if (pAdapter->wapi_info.nWapiMode)
5284 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005285 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005286 switch (pAdapter->wapi_info.wapiAuthMode)
5287 {
5288 case WAPI_AUTH_MODE_PSK:
5289 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005290 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005291 pAdapter->wapi_info.wapiAuthMode);
5292 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5293 break;
5294 }
5295 case WAPI_AUTH_MODE_CERT:
5296 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005297 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 pAdapter->wapi_info.wapiAuthMode);
5299 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5300 break;
5301 }
5302 } // End of switch
5303 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5304 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5305 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005306 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 pRoamProfile->AuthType.numEntries = 1;
5308 pRoamProfile->EncryptionType.numEntries = 1;
5309 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5310 pRoamProfile->mcEncryptionType.numEntries = 1;
5311 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5312 }
5313 }
5314#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305315#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305316 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305317 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5318 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5319 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305320 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5321 sizeof (tSirGtkOffloadParams));
5322 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305323 }
5324#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005325 pRoamProfile->csrPersona = pAdapter->device_mode;
5326
Jeff Johnson32d95a32012-09-10 13:15:23 -07005327 if( operatingChannel )
5328 {
5329 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5330 pRoamProfile->ChannelInfo.numOfChannels = 1;
5331 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005332 else
5333 {
5334 pRoamProfile->ChannelInfo.ChannelList = NULL;
5335 pRoamProfile->ChannelInfo.numOfChannels = 0;
5336 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005337 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5338 {
5339 hdd_select_cbmode(pAdapter,operatingChannel);
5340 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005341 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5342 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305343 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005344 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005345 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5346 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305347 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5348 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005349 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5350 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305351
5352 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005353 pAdapter->sessionId, pRoamProfile, &roamId);
5354
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305355 if ((eHAL_STATUS_SUCCESS != status) &&
5356 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5357 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305358
5359 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005360 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5361 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5362 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305363 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005364 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305365 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005366
5367 pRoamProfile->ChannelInfo.ChannelList = NULL;
5368 pRoamProfile->ChannelInfo.numOfChannels = 0;
5369
Jeff Johnson295189b2012-06-20 16:38:30 -07005370 }
5371 else
5372 {
5373 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5374 return -EINVAL;
5375 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005376 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005377 return status;
5378}
5379
5380/*
5381 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5382 * This function is used to set the authentication type (OPEN/SHARED).
5383 *
5384 */
5385static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5386 enum nl80211_auth_type auth_type)
5387{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305388 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005389 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5390
5391 ENTER();
5392
5393 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305394 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005395 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005396 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305397 hddLog(VOS_TRACE_LEVEL_INFO,
5398 "%s: set authentication type to AUTOSWITCH", __func__);
5399 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5400 break;
5401
5402 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005403#ifdef WLAN_FEATURE_VOWIFI_11R
5404 case NL80211_AUTHTYPE_FT:
5405#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305406 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005407 "%s: set authentication type to OPEN", __func__);
5408 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5409 break;
5410
5411 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305412 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005413 "%s: set authentication type to SHARED", __func__);
5414 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5415 break;
5416#ifdef FEATURE_WLAN_CCX
5417 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305418 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005419 "%s: set authentication type to CCKM WPA", __func__);
5420 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5421 break;
5422#endif
5423
5424
5425 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305426 hddLog(VOS_TRACE_LEVEL_ERROR,
5427 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005428 auth_type);
5429 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5430 return -EINVAL;
5431 }
5432
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305433 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 pHddStaCtx->conn_info.authType;
5435 return 0;
5436}
5437
5438/*
5439 * FUNCTION: wlan_hdd_set_akm_suite
5440 * This function is used to set the key mgmt type(PSK/8021x).
5441 *
5442 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305443static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 u32 key_mgmt
5445 )
5446{
5447 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5448 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305449
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 /*set key mgmt type*/
5451 switch(key_mgmt)
5452 {
5453 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305454#ifdef WLAN_FEATURE_VOWIFI_11R
5455 case WLAN_AKM_SUITE_FT_PSK:
5456#endif
5457 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005458 __func__);
5459 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5460 break;
5461
5462 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305463#ifdef WLAN_FEATURE_VOWIFI_11R
5464 case WLAN_AKM_SUITE_FT_8021X:
5465#endif
5466 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005467 __func__);
5468 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5469 break;
5470#ifdef FEATURE_WLAN_CCX
5471#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5472#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5473 case WLAN_AKM_SUITE_CCKM:
5474 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5475 __func__);
5476 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5477 break;
5478#endif
5479
5480 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305481 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005482 __func__, key_mgmt);
5483 return -EINVAL;
5484
5485 }
5486 return 0;
5487}
5488
5489/*
5490 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305491 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005492 * (NONE/WEP40/WEP104/TKIP/CCMP).
5493 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305494static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5495 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005496 bool ucast
5497 )
5498{
5499 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305500 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005501 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5502
5503 ENTER();
5504
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305505 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305507 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005508 __func__, cipher);
5509 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5510 }
5511 else
5512 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305513
Jeff Johnson295189b2012-06-20 16:38:30 -07005514 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305515 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005516 {
5517 case IW_AUTH_CIPHER_NONE:
5518 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5519 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305520
Jeff Johnson295189b2012-06-20 16:38:30 -07005521 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305522 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005523 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305524
Jeff Johnson295189b2012-06-20 16:38:30 -07005525 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305526 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005527 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305528
Jeff Johnson295189b2012-06-20 16:38:30 -07005529 case WLAN_CIPHER_SUITE_TKIP:
5530 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5531 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305532
Jeff Johnson295189b2012-06-20 16:38:30 -07005533 case WLAN_CIPHER_SUITE_CCMP:
5534 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5535 break;
5536#ifdef FEATURE_WLAN_WAPI
5537 case WLAN_CIPHER_SUITE_SMS4:
5538 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5539 break;
5540#endif
5541
5542#ifdef FEATURE_WLAN_CCX
5543 case WLAN_CIPHER_SUITE_KRK:
5544 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5545 break;
5546#endif
5547 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305548 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005549 __func__, cipher);
5550 return -EOPNOTSUPP;
5551 }
5552 }
5553
5554 if (ucast)
5555 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305556 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005557 __func__, encryptionType);
5558 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5559 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305560 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005561 encryptionType;
5562 }
5563 else
5564 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305565 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 __func__, encryptionType);
5567 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5568 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5569 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5570 }
5571
5572 return 0;
5573}
5574
5575
5576/*
5577 * FUNCTION: wlan_hdd_cfg80211_set_ie
5578 * This function is used to parse WPA/RSN IE's.
5579 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305580int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5581 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 size_t ie_len
5583 )
5584{
5585 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5586 u8 *genie = ie;
5587 v_U16_t remLen = ie_len;
5588#ifdef FEATURE_WLAN_WAPI
5589 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5590 u16 *tmp;
5591 v_U16_t akmsuiteCount;
5592 int *akmlist;
5593#endif
5594 ENTER();
5595
5596 /* clear previous assocAddIE */
5597 pWextState->assocAddIE.length = 0;
5598 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5599
5600 while (remLen >= 2)
5601 {
5602 v_U16_t eLen = 0;
5603 v_U8_t elementId;
5604 elementId = *genie++;
5605 eLen = *genie++;
5606 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305607
Arif Hussain6d2a3322013-11-17 19:50:10 -08005608 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005609 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305610
5611 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005612 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305613 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005614 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 -07005615 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305616 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005617 "%s: Invalid WPA IE", __func__);
5618 return -EINVAL;
5619 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305620 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005621 {
5622 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305623 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005624 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305625
Jeff Johnson295189b2012-06-20 16:38:30 -07005626 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5627 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005628 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5629 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 VOS_ASSERT(0);
5631 return -ENOMEM;
5632 }
5633 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5634 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5635 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305636
Jeff Johnson295189b2012-06-20 16:38:30 -07005637 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5638 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5639 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5640 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305641 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5642 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005643 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5644 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5645 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5646 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5647 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5648 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305649 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05305650 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005651 {
5652 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305653 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305655
Jeff Johnson295189b2012-06-20 16:38:30 -07005656 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5657 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005658 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5659 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005660 VOS_ASSERT(0);
5661 return -ENOMEM;
5662 }
5663 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5664 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5665 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305666
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5668 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5669 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005670#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305671 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5672 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005673 /*Consider WFD IE, only for P2P Client */
5674 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5675 {
5676 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305677 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005678 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305679
Jeff Johnson295189b2012-06-20 16:38:30 -07005680 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5681 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005682 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5683 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005684 VOS_ASSERT(0);
5685 return -ENOMEM;
5686 }
5687 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5688 // WPS IE + P2P IE + WFD IE
5689 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5690 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305691
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5693 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5694 }
5695#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005696 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305697 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005698 HS20_OUI_TYPE_SIZE)) )
5699 {
5700 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305701 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005702 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005703
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005704 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5705 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005706 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5707 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005708 VOS_ASSERT(0);
5709 return -ENOMEM;
5710 }
5711 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5712 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005713
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005714 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5715 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5716 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005717
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005718 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5719
5720 /* populating as ADDIE in beacon frames */
5721 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5722 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5723 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5724 {
5725 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5726 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5727 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5728 {
5729 hddLog(LOGE,
5730 "Coldn't pass "
5731 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5732 }
5733 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5734 else
5735 hddLog(LOGE,
5736 "Could not pass on "
5737 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5738
5739 /* IBSS mode doesn't contain params->proberesp_ies still
5740 beaconIE's need to be populated in probe response frames */
5741 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5742 {
5743 u16 rem_probe_resp_ie_len = eLen + 2;
5744 u8 probe_rsp_ie_len[3] = {0};
5745 u8 counter = 0;
5746
5747 /* Check Probe Resp Length if it is greater then 255 then
5748 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5749 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5750 not able Store More then 255 bytes into One Variable */
5751
5752 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5753 {
5754 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5755 {
5756 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5757 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5758 }
5759 else
5760 {
5761 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5762 rem_probe_resp_ie_len = 0;
5763 }
5764 }
5765
5766 rem_probe_resp_ie_len = 0;
5767
5768 if (probe_rsp_ie_len[0] > 0)
5769 {
5770 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5771 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5772 (tANI_U8*)(genie - 2),
5773 probe_rsp_ie_len[0], NULL,
5774 eANI_BOOLEAN_FALSE)
5775 == eHAL_STATUS_FAILURE)
5776 {
5777 hddLog(LOGE,
5778 "Could not pass"
5779 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5780 }
5781 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5782 }
5783
5784 if (probe_rsp_ie_len[1] > 0)
5785 {
5786 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5787 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5788 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5789 probe_rsp_ie_len[1], NULL,
5790 eANI_BOOLEAN_FALSE)
5791 == eHAL_STATUS_FAILURE)
5792 {
5793 hddLog(LOGE,
5794 "Could not pass"
5795 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5796 }
5797 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5798 }
5799
5800 if (probe_rsp_ie_len[2] > 0)
5801 {
5802 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5803 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5804 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5805 probe_rsp_ie_len[2], NULL,
5806 eANI_BOOLEAN_FALSE)
5807 == eHAL_STATUS_FAILURE)
5808 {
5809 hddLog(LOGE,
5810 "Could not pass"
5811 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5812 }
5813 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5814 }
5815
5816 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5817 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5818 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5819 {
5820 hddLog(LOGE,
5821 "Could not pass"
5822 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5823 }
5824 }
5825 else
5826 {
5827 // Reset WNI_CFG_PROBE_RSP Flags
5828 wlan_hdd_reset_prob_rspies(pAdapter);
5829
5830 hddLog(VOS_TRACE_LEVEL_INFO,
5831 "%s: No Probe Response IE received in set beacon",
5832 __func__);
5833 }
5834 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005835 break;
5836 case DOT11F_EID_RSN:
5837 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5838 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5839 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5840 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5841 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5842 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005843 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5844 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305845 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005846 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305847 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005848 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305849
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005850 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5851 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005852 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5853 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005854 VOS_ASSERT(0);
5855 return -ENOMEM;
5856 }
5857 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5858 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305859
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005860 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5861 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5862 break;
5863 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005864#ifdef FEATURE_WLAN_WAPI
5865 case WLAN_EID_WAPI:
5866 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07005867 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07005868 pAdapter->wapi_info.nWapiMode);
5869 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305870 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005871 akmsuiteCount = WPA_GET_LE16(tmp);
5872 tmp = tmp + 1;
5873 akmlist = (int *)(tmp);
5874 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5875 {
5876 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5877 }
5878 else
5879 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08005880 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07005881 VOS_ASSERT(0);
5882 return -EINVAL;
5883 }
5884
5885 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5886 {
5887 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005888 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005889 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305890 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005891 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305892 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005893 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005894 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005895 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5896 }
5897 break;
5898#endif
5899 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305900 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005901 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005902 /* when Unknown IE is received we should break and continue
5903 * to the next IE in the buffer instead we were returning
5904 * so changing this to break */
5905 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005906 }
5907 genie += eLen;
5908 remLen -= eLen;
5909 }
5910 EXIT();
5911 return 0;
5912}
5913
5914/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305915 * FUNCTION: hdd_isWPAIEPresent
5916 * Parse the received IE to find the WPA IE
5917 *
5918 */
5919static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5920{
5921 v_U8_t eLen = 0;
5922 v_U16_t remLen = ie_len;
5923 v_U8_t elementId = 0;
5924
5925 while (remLen >= 2)
5926 {
5927 elementId = *ie++;
5928 eLen = *ie++;
5929 remLen -= 2;
5930 if (eLen > remLen)
5931 {
5932 hddLog(VOS_TRACE_LEVEL_ERROR,
5933 "%s: IE length is wrong %d", __func__, eLen);
5934 return FALSE;
5935 }
5936 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5937 {
5938 /* OUI - 0x00 0X50 0XF2
5939 WPA Information Element - 0x01
5940 WPA version - 0x01*/
5941 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5942 return TRUE;
5943 }
5944 ie += eLen;
5945 remLen -= eLen;
5946 }
5947 return FALSE;
5948}
5949
5950/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005951 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305952 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005953 * parameters during connect operation.
5954 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305955int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005956 struct cfg80211_connect_params *req
5957 )
5958{
5959 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305960 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005961 ENTER();
5962
5963 /*set wpa version*/
5964 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5965
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305966 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005967 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305968 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 {
5970 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5971 }
5972 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5973 {
5974 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5975 }
5976 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305977
5978 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005979 pWextState->wpaVersion);
5980
5981 /*set authentication type*/
5982 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5983
5984 if (0 > status)
5985 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305986 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005987 "%s: failed to set authentication type ", __func__);
5988 return status;
5989 }
5990
5991 /*set key mgmt type*/
5992 if (req->crypto.n_akm_suites)
5993 {
5994 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5995 if (0 > status)
5996 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305997 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005998 __func__);
5999 return status;
6000 }
6001 }
6002
6003 /*set pairwise cipher type*/
6004 if (req->crypto.n_ciphers_pairwise)
6005 {
6006 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6007 req->crypto.ciphers_pairwise[0], true);
6008 if (0 > status)
6009 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306010 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 "%s: failed to set unicast cipher type", __func__);
6012 return status;
6013 }
6014 }
6015 else
6016 {
6017 /*Reset previous cipher suite to none*/
6018 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6019 if (0 > status)
6020 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306021 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006022 "%s: failed to set unicast cipher type", __func__);
6023 return status;
6024 }
6025 }
6026
6027 /*set group cipher type*/
6028 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6029 false);
6030
6031 if (0 > status)
6032 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306033 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006034 __func__);
6035 return status;
6036 }
6037
Chet Lanctot186b5732013-03-18 10:26:30 -07006038#ifdef WLAN_FEATURE_11W
6039 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6040#endif
6041
Jeff Johnson295189b2012-06-20 16:38:30 -07006042 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6043 if (req->ie_len)
6044 {
6045 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6046 if ( 0 > status)
6047 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306048 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006049 __func__);
6050 return status;
6051 }
6052 }
6053
6054 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306055 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006056 {
6057 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6058 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6059 )
6060 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306061 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006062 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6063 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306064 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006065 __func__);
6066 return -EOPNOTSUPP;
6067 }
6068 else
6069 {
6070 u8 key_len = req->key_len;
6071 u8 key_idx = req->key_idx;
6072
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306073 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006074 && (CSR_MAX_NUM_KEY > key_idx)
6075 )
6076 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306077 hddLog(VOS_TRACE_LEVEL_INFO,
6078 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006079 __func__, key_idx, key_len);
6080 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306081 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306083 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006084 (u8)key_len;
6085 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6086 }
6087 }
6088 }
6089 }
6090
6091 return status;
6092}
6093
6094/*
6095 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306096 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006097 * parameters during connect operation.
6098 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306099static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006100 struct net_device *ndev,
6101 struct cfg80211_connect_params *req
6102 )
6103{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306104 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306105 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006106 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
6107 hdd_context_t *pHddCtx = NULL;
6108
6109 ENTER();
6110
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306111 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006112 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006113
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306114 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6115 status = wlan_hdd_validate_context(pHddCtx);
6116
6117 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006118 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306119 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6120 "%s: HDD context is not valid", __func__);
6121 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 }
6123
6124#ifdef WLAN_BTAMP_FEATURE
6125 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306126 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006127 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306128 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006129 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006130 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006131 }
6132#endif
6133 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306134 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006135
6136 if ( 0 > status)
6137 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306138 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006139 __func__);
6140 return status;
6141 }
6142
6143 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08006144 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07006145 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6146 (vos_concurrent_sessions_running()))
6147 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306148 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07006149 }
6150
Mohit Khanna765234a2012-09-11 15:08:35 -07006151 if ( req->channel )
6152 {
6153 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6154 req->ssid_len, req->bssid,
6155 req->channel->hw_value);
6156 }
6157 else
6158 {
6159 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306160 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006161 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006162
6163 if (0 > status)
6164 {
6165 //ReEnable BMPS if disabled
6166 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6167 (NULL != pHddCtx))
6168 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306169 if (pHddCtx->hdd_wlan_suspended)
6170 {
6171 hdd_set_pwrparams(pHddCtx);
6172 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006173 //ReEnable Bmps and Imps back
6174 hdd_enable_bmps_imps(pHddCtx);
6175 }
6176
6177 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6178 return status;
6179 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306180 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006181 EXIT();
6182 return status;
6183}
6184
6185
6186/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306187 * FUNCTION: wlan_hdd_disconnect
6188 * This function is used to issue a disconnect request to SME
6189 */
6190int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6191{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306192 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306193 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306194 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6195
6196 status = wlan_hdd_validate_context(pHddCtx);
6197
6198 if (0 != status)
6199 {
6200 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6201 "%s: HDD context is not valid", __func__);
6202 return status;
6203 }
6204
6205 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306206 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306207 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306208
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306209 /*issue disconnect*/
6210 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6211 pAdapter->sessionId, reason);
6212
6213 if ( 0 != status )
6214 {
6215 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006216 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306217 __func__, (int)status );
6218 return -EINVAL;
6219 }
6220 wait_for_completion_interruptible_timeout(
6221 &pAdapter->disconnect_comp_var,
6222 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6223 /*stop tx queues*/
6224 netif_tx_disable(pAdapter->dev);
6225 netif_carrier_off(pAdapter->dev);
6226 return status;
6227}
6228
6229
6230/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006231 * FUNCTION: wlan_hdd_cfg80211_disconnect
6232 * This function is used to issue a disconnect request to SME
6233 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306234static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 struct net_device *dev,
6236 u16 reason
6237 )
6238{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306239 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6240 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006241 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306242 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006244 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306245#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006246 tANI_U8 staIdx;
6247#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306248
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306250
Arif Hussain6d2a3322013-11-17 19:50:10 -08006251 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006252 __func__,pAdapter->device_mode);
6253
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306254 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6255 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006256
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306257 status = wlan_hdd_validate_context(pHddCtx);
6258
6259 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006260 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306261 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6262 "%s: HDD context is not valid", __func__);
6263 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006264 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306265
Jeff Johnson295189b2012-06-20 16:38:30 -07006266 if (NULL != pRoamProfile)
6267 {
6268 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306269 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6270 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006271 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306272 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306274 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006275 switch(reason)
6276 {
6277 case WLAN_REASON_MIC_FAILURE:
6278 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6279 break;
6280
6281 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6282 case WLAN_REASON_DISASSOC_AP_BUSY:
6283 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6284 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6285 break;
6286
6287 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6288 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6289 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6290 break;
6291
6292 case WLAN_REASON_DEAUTH_LEAVING:
6293 default:
6294 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6295 break;
6296 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306297 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6298 pScanInfo = &pHddCtx->scan_info;
6299 if (pScanInfo->mScanPending)
6300 {
6301 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6302 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306303 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306304 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006305
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006306#ifdef FEATURE_WLAN_TDLS
6307 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006308 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006309 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006310 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6311 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006312 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006313 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006314 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006315 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006316 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006317 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006318 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006319 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006320 pAdapter->sessionId,
6321 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006322 }
6323 }
6324#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306325 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6326 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006327 {
6328 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006329 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006330 __func__, (int)status );
6331 return -EINVAL;
6332 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006333 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306334 else
6335 {
6336 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6337 "called while in %d state", __func__,
6338 pHddStaCtx->conn_info.connState);
6339 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006340 }
6341 else
6342 {
6343 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6344 }
6345
6346 return status;
6347}
6348
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306349
Jeff Johnson295189b2012-06-20 16:38:30 -07006350/*
6351 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306352 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006353 * settings in IBSS mode.
6354 */
6355static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306356 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006357 struct cfg80211_ibss_params *params
6358 )
6359{
6360 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306361 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006362 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6363 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306364
Jeff Johnson295189b2012-06-20 16:38:30 -07006365 ENTER();
6366
6367 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006368 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006369
6370 if (params->ie_len && ( NULL != params->ie) )
6371 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006372 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6373 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006374 {
6375 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6376 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6377 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006378 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006379 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006380 tDot11fIEWPA dot11WPAIE;
6381 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006382 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006383
Wilson Yang00256342013-10-10 23:13:38 -07006384 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006385 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6386 params->ie_len, DOT11F_EID_WPA);
6387 if ( NULL != ie )
6388 {
6389 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6390 // Unpack the WPA IE
6391 //Skip past the EID byte and length byte - and four byte WiFi OUI
6392 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6393 &ie[2+4],
6394 ie[1] - 4,
6395 &dot11WPAIE);
6396 /*Extract the multicast cipher, the encType for unicast
6397 cipher for wpa-none is none*/
6398 encryptionType =
6399 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6400 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006401 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006402
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6404
6405 if (0 > status)
6406 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306407 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006408 __func__);
6409 return status;
6410 }
6411 }
6412
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306413 pWextState->roamProfile.AuthType.authType[0] =
6414 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006415 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6416
6417 if (params->privacy)
6418 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306419 /* Security enabled IBSS, At this time there is no information available
6420 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006421 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306422 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006423 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306424 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006425 *enable privacy bit in beacons */
6426
6427 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6428 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006429 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6430 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006431 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6432 pWextState->roamProfile.EncryptionType.numEntries = 1;
6433 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006434 return status;
6435}
6436
6437/*
6438 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306439 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006440 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306441static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006442 struct net_device *dev,
6443 struct cfg80211_ibss_params *params
6444 )
6445{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306446 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006447 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6448 tCsrRoamProfile *pRoamProfile;
6449 int status;
krunal sonie9002db2013-11-25 14:24:17 -08006450 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006451 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306452 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006453
6454 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306455
6456 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006457 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006458
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306459 status = wlan_hdd_validate_context(pHddCtx);
6460
6461 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306463 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6464 "%s: HDD context is not valid", __func__);
6465 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006466 }
6467
6468 if (NULL == pWextState)
6469 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006470 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006471 __func__);
6472 return -EIO;
6473 }
6474
6475 pRoamProfile = &pWextState->roamProfile;
6476
6477 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6478 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306479 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006480 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006481 return -EINVAL;
6482 }
6483
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006484 /* BSSID is provided by upper layers hence no need to AUTO generate */
6485 if (NULL != params->bssid) {
6486 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6487 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
6488 hddLog (VOS_TRACE_LEVEL_ERROR,
6489 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6490 return -EIO;
6491 }
6492 }
krunal sonie9002db2013-11-25 14:24:17 -08006493 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
6494 {
6495 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6496 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
6497 {
6498 hddLog (VOS_TRACE_LEVEL_ERROR,
6499 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6500 return -EIO;
6501 }
6502 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
6503 if (!params->bssid)
6504 {
6505 hddLog (VOS_TRACE_LEVEL_ERROR,
6506 "%s:Failed memory allocation", __func__);
6507 return -EIO;
6508 }
6509 vos_mem_copy((v_U8_t *)params->bssid,
6510 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
6511 VOS_MAC_ADDR_SIZE);
6512 alloc_bssid = VOS_TRUE;
6513 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006514
Jeff Johnson295189b2012-06-20 16:38:30 -07006515 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006516 if (NULL !=
6517#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6518 params->chandef.chan)
6519#else
6520 params->channel)
6521#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 {
6523 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006524 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6525 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6526 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6527 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006528
6529 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306530 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006531 ieee80211_frequency_to_channel(
6532#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6533 params->chandef.chan->center_freq);
6534#else
6535 params->channel->center_freq);
6536#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006537
6538 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6539 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006540 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006541 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6542 __func__);
6543 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006544 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006545
6546 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006547 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006548 if (channelNum == validChan[indx])
6549 {
6550 break;
6551 }
6552 }
6553 if (indx >= numChans)
6554 {
6555 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006556 __func__, channelNum);
6557 return -EINVAL;
6558 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006559 /* Set the Operational Channel */
6560 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6561 channelNum);
6562 pRoamProfile->ChannelInfo.numOfChannels = 1;
6563 pHddStaCtx->conn_info.operationChannel = channelNum;
6564 pRoamProfile->ChannelInfo.ChannelList =
6565 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006566 }
6567
6568 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306569 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006570 if (status < 0)
6571 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306572 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006573 __func__);
6574 return status;
6575 }
6576
6577 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306578 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006579 params->ssid_len, params->bssid,
6580 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006581
6582 if (0 > status)
6583 {
6584 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6585 return status;
6586 }
6587
krunal sonie9002db2013-11-25 14:24:17 -08006588 if (NULL != params->bssid &&
6589 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
6590 alloc_bssid == VOS_TRUE)
6591 {
6592 vos_mem_free(params->bssid);
6593 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 return 0;
6595}
6596
6597/*
6598 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306599 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006600 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306601static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006602 struct net_device *dev
6603 )
6604{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306605 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006606 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6607 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306608 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6609 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006610
6611 ENTER();
6612
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306613 status = wlan_hdd_validate_context(pHddCtx);
6614
6615 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006616 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306617 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6618 "%s: HDD context is not valid", __func__);
6619 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006620 }
6621
Arif Hussain6d2a3322013-11-17 19:50:10 -08006622 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006623 if (NULL == pWextState)
6624 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006625 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 __func__);
6627 return -EIO;
6628 }
6629
6630 pRoamProfile = &pWextState->roamProfile;
6631
6632 /* Issue disconnect only if interface type is set to IBSS */
6633 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6634 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306635 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006636 __func__);
6637 return -EINVAL;
6638 }
6639
6640 /* Issue Disconnect request */
6641 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6642 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6643 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6644
6645 return 0;
6646}
6647
6648/*
6649 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6650 * This function is used to set the phy parameters
6651 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6652 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306653static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006654 u32 changed)
6655{
6656 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6657 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306658 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006659
6660 ENTER();
6661
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306662 status = wlan_hdd_validate_context(pHddCtx);
6663
6664 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006665 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306666 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6667 "%s: HDD context is not valid", __func__);
6668 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006669 }
6670
Jeff Johnson295189b2012-06-20 16:38:30 -07006671 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6672 {
6673 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6674 WNI_CFG_RTS_THRESHOLD_STAMAX :
6675 wiphy->rts_threshold;
6676
6677 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306678 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006679 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306680 hddLog(VOS_TRACE_LEVEL_ERROR,
6681 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006682 __func__, rts_threshold);
6683 return -EINVAL;
6684 }
6685
6686 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6687 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306688 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006689 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306690 hddLog(VOS_TRACE_LEVEL_ERROR,
6691 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006692 __func__, rts_threshold);
6693 return -EIO;
6694 }
6695
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306696 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006697 rts_threshold);
6698 }
6699
6700 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6701 {
6702 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6703 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6704 wiphy->frag_threshold;
6705
6706 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306707 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006708 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306709 hddLog(VOS_TRACE_LEVEL_ERROR,
6710 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006711 frag_threshold);
6712 return -EINVAL;
6713 }
6714
6715 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6716 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306717 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006718 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306719 hddLog(VOS_TRACE_LEVEL_ERROR,
6720 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006721 __func__, frag_threshold);
6722 return -EIO;
6723 }
6724
6725 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6726 frag_threshold);
6727 }
6728
6729 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6730 || (changed & WIPHY_PARAM_RETRY_LONG))
6731 {
6732 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6733 wiphy->retry_short :
6734 wiphy->retry_long;
6735
6736 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6737 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6738 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306739 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006740 __func__, retry_value);
6741 return -EINVAL;
6742 }
6743
6744 if (changed & WIPHY_PARAM_RETRY_SHORT)
6745 {
6746 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6747 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306748 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006749 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306750 hddLog(VOS_TRACE_LEVEL_ERROR,
6751 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006752 __func__, retry_value);
6753 return -EIO;
6754 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306755 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006756 __func__, retry_value);
6757 }
6758 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6759 {
6760 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6761 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306762 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006763 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306764 hddLog(VOS_TRACE_LEVEL_ERROR,
6765 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006766 __func__, retry_value);
6767 return -EIO;
6768 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306769 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 __func__, retry_value);
6771 }
6772 }
6773
6774 return 0;
6775}
6776
6777/*
6778 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6779 * This function is used to set the txpower
6780 */
6781static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006782#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6783 struct wireless_dev *wdev,
6784#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006785#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306786 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006787#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306788 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006789#endif
6790 int dbm)
6791{
6792 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306793 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006794 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6795 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306796 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006797
6798 ENTER();
6799
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306800 status = wlan_hdd_validate_context(pHddCtx);
6801
6802 if (0 != status)
6803 {
6804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6805 "%s: HDD context is not valid", __func__);
6806 return status;
6807 }
6808
6809 hHal = pHddCtx->hHal;
6810
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306811 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6812 dbm, ccmCfgSetCallback,
6813 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006814 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306815 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6817 return -EIO;
6818 }
6819
6820 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6821 dbm);
6822
6823 switch(type)
6824 {
6825 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6826 /* Fall through */
6827 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6828 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6829 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306830 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6831 __func__);
6832 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006833 }
6834 break;
6835 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306836 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006837 __func__);
6838 return -EOPNOTSUPP;
6839 break;
6840 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306841 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6842 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006843 return -EIO;
6844 }
6845
6846 return 0;
6847}
6848
6849/*
6850 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6851 * This function is used to read the txpower
6852 */
Yue Maf49ba872013-08-19 12:04:25 -07006853static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6854#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6855 struct wireless_dev *wdev,
6856#endif
6857 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006858{
6859
6860 hdd_adapter_t *pAdapter;
6861 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306862 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006863
Jeff Johnsone7245742012-09-05 17:12:55 -07006864 ENTER();
6865
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306866 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006867
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306868 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006869 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306870 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6871 "%s: HDD context is not valid", __func__);
6872 *dbm = 0;
6873 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006874 }
6875
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6877 if (NULL == pAdapter)
6878 {
6879 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6880 return -ENOENT;
6881 }
6882
6883 wlan_hdd_get_classAstats(pAdapter);
6884 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6885
Jeff Johnsone7245742012-09-05 17:12:55 -07006886 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006887 return 0;
6888}
6889
6890static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6891 u8* mac, struct station_info *sinfo)
6892{
6893 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6894 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6895 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6896 tANI_U8 rate_flags;
6897
6898 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6899 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006900
6901 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6902 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6903 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6904 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6905 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6906 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6907 tANI_U16 maxRate = 0;
6908 tANI_U16 myRate;
6909 tANI_U16 currentRate = 0;
6910 tANI_U8 maxSpeedMCS = 0;
6911 tANI_U8 maxMCSIdx = 0;
6912 tANI_U8 rateFlag = 1;
6913 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006914 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306915 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006916
Leo Chang6f8870f2013-03-26 18:11:36 -07006917#ifdef WLAN_FEATURE_11AC
6918 tANI_U32 vht_mcs_map;
6919 eDataRate11ACMaxMcs vhtMaxMcs;
6920#endif /* WLAN_FEATURE_11AC */
6921
Jeff Johnsone7245742012-09-05 17:12:55 -07006922 ENTER();
6923
Jeff Johnson295189b2012-06-20 16:38:30 -07006924 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6925 (0 == ssidlen))
6926 {
6927 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6928 " Invalid ssidlen, %d", __func__, ssidlen);
6929 /*To keep GUI happy*/
6930 return 0;
6931 }
6932
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306933 status = wlan_hdd_validate_context(pHddCtx);
6934
6935 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006936 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306937 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6938 "%s: HDD context is not valid", __func__);
6939 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006940 }
6941
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006942 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006943 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6944
Kiet Lam3b17fc82013-09-27 05:24:08 +05306945 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6946 sinfo->filled |= STATION_INFO_SIGNAL;
6947
Jeff Johnson295189b2012-06-20 16:38:30 -07006948 //convert to the UI units of 100kbps
6949 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6950
6951#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006952 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 -07006953 sinfo->signal,
6954 pCfg->reportMaxLinkSpeed,
6955 myRate,
6956 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006957 (int) pCfg->linkSpeedRssiMid,
6958 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006959 (int) rate_flags,
6960 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006961#endif //LINKSPEED_DEBUG_ENABLED
6962
6963 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6964 {
6965 // we do not want to necessarily report the current speed
6966 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6967 {
6968 // report the max possible speed
6969 rssidx = 0;
6970 }
6971 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6972 {
6973 // report the max possible speed with RSSI scaling
6974 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6975 {
6976 // report the max possible speed
6977 rssidx = 0;
6978 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006979 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 {
6981 // report middle speed
6982 rssidx = 1;
6983 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006984 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6985 {
6986 // report middle speed
6987 rssidx = 2;
6988 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 else
6990 {
6991 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006992 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006993 }
6994 }
6995 else
6996 {
6997 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6998 hddLog(VOS_TRACE_LEVEL_ERROR,
6999 "%s: Invalid value for reportMaxLinkSpeed: %u",
7000 __func__, pCfg->reportMaxLinkSpeed);
7001 rssidx = 0;
7002 }
7003
7004 maxRate = 0;
7005
7006 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307007 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7008 OperationalRates, &ORLeng))
7009 {
7010 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7011 /*To keep GUI happy*/
7012 return 0;
7013 }
7014
Jeff Johnson295189b2012-06-20 16:38:30 -07007015 for (i = 0; i < ORLeng; i++)
7016 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007017 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 {
7019 /* Validate Rate Set */
7020 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7021 {
7022 currentRate = supported_data_rate[j].supported_rate[rssidx];
7023 break;
7024 }
7025 }
7026 /* Update MAX rate */
7027 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7028 }
7029
7030 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307031 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7032 ExtendedRates, &ERLeng))
7033 {
7034 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7035 /*To keep GUI happy*/
7036 return 0;
7037 }
7038
Jeff Johnson295189b2012-06-20 16:38:30 -07007039 for (i = 0; i < ERLeng; i++)
7040 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007041 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007042 {
7043 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7044 {
7045 currentRate = supported_data_rate[j].supported_rate[rssidx];
7046 break;
7047 }
7048 }
7049 /* Update MAX rate */
7050 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7051 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307052 /* Get MCS Rate Set --
7053 only if we are connected at MCS rates (or)
7054 if we are always reporting max speed (or)
7055 if we have good rssi */
7056 if (((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY)) ||
7057 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007058 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307059 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7060 MCSRates, &MCSLeng))
7061 {
7062 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7063 /*To keep GUI happy*/
7064 return 0;
7065 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007066 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007067#ifdef WLAN_FEATURE_11AC
7068 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307069 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007070 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007071 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307072 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007073 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007074 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007075 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007076 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007077 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007078 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007079 maxMCSIdx = 7;
7080 }
7081 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7082 {
7083 maxMCSIdx = 8;
7084 }
7085 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7086 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307087 //VHT20 is supporting 0~8
7088 if (rate_flags & eHAL_TX_RATE_VHT20)
7089 maxMCSIdx = 8;
7090 else
7091 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007092 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307093
7094 if (rate_flags & eHAL_TX_RATE_VHT80)
7095 {
7096 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7097 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7098 }
7099 else if (rate_flags & eHAL_TX_RATE_VHT40)
7100 {
7101 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7102 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7103 }
7104 else if (rate_flags & eHAL_TX_RATE_VHT20)
7105 {
7106 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7107 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7108 }
7109
Leo Chang6f8870f2013-03-26 18:11:36 -07007110 maxSpeedMCS = 1;
7111 if (currentRate > maxRate)
7112 {
7113 maxRate = currentRate;
7114 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307115
Leo Chang6f8870f2013-03-26 18:11:36 -07007116 }
7117 else
7118#endif /* WLAN_FEATURE_11AC */
7119 {
7120 if (rate_flags & eHAL_TX_RATE_HT40)
7121 {
7122 rateFlag |= 1;
7123 }
7124 if (rate_flags & eHAL_TX_RATE_SGI)
7125 {
7126 rateFlag |= 2;
7127 }
7128
7129 for (i = 0; i < MCSLeng; i++)
7130 {
7131 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7132 for (j = 0; j < temp; j++)
7133 {
7134 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7135 {
7136 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7137 break;
7138 }
7139 }
7140 if ((j < temp) && (currentRate > maxRate))
7141 {
7142 maxRate = currentRate;
7143 maxSpeedMCS = 1;
7144 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7145 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007146 }
7147 }
7148 }
7149
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307150 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7151 {
7152 maxRate = myRate;
7153 maxSpeedMCS = 1;
7154 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7155 }
7156
Jeff Johnson295189b2012-06-20 16:38:30 -07007157 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007158 if (((maxRate < myRate) && (0 == rssidx)) ||
7159 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 {
7161 maxRate = myRate;
7162 if (rate_flags & eHAL_TX_RATE_LEGACY)
7163 {
7164 maxSpeedMCS = 0;
7165 }
7166 else
7167 {
7168 maxSpeedMCS = 1;
7169 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7170 }
7171 }
7172
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307173 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007174 {
7175 sinfo->txrate.legacy = maxRate;
7176#ifdef LINKSPEED_DEBUG_ENABLED
7177 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7178#endif //LINKSPEED_DEBUG_ENABLED
7179 }
7180 else
7181 {
7182 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007183#ifdef WLAN_FEATURE_11AC
7184 sinfo->txrate.nss = 1;
7185 if (rate_flags & eHAL_TX_RATE_VHT80)
7186 {
7187 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307188 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007189 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307190 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007191 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307192 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7193 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7194 }
7195 else if (rate_flags & eHAL_TX_RATE_VHT20)
7196 {
7197 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7198 }
7199#endif /* WLAN_FEATURE_11AC */
7200 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7201 {
7202 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7203 if (rate_flags & eHAL_TX_RATE_HT40)
7204 {
7205 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7206 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007207 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007208 if (rate_flags & eHAL_TX_RATE_SGI)
7209 {
7210 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7211 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307212
Jeff Johnson295189b2012-06-20 16:38:30 -07007213#ifdef LINKSPEED_DEBUG_ENABLED
7214 pr_info("Reporting MCS rate %d flags %x\n",
7215 sinfo->txrate.mcs,
7216 sinfo->txrate.flags );
7217#endif //LINKSPEED_DEBUG_ENABLED
7218 }
7219 }
7220 else
7221 {
7222 // report current rate instead of max rate
7223
7224 if (rate_flags & eHAL_TX_RATE_LEGACY)
7225 {
7226 //provide to the UI in units of 100kbps
7227 sinfo->txrate.legacy = myRate;
7228#ifdef LINKSPEED_DEBUG_ENABLED
7229 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7230#endif //LINKSPEED_DEBUG_ENABLED
7231 }
7232 else
7233 {
7234 //must be MCS
7235 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007236#ifdef WLAN_FEATURE_11AC
7237 sinfo->txrate.nss = 1;
7238 if (rate_flags & eHAL_TX_RATE_VHT80)
7239 {
7240 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7241 }
7242 else
7243#endif /* WLAN_FEATURE_11AC */
7244 {
7245 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7246 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007247 if (rate_flags & eHAL_TX_RATE_SGI)
7248 {
7249 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7250 }
7251 if (rate_flags & eHAL_TX_RATE_HT40)
7252 {
7253 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7254 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007255#ifdef WLAN_FEATURE_11AC
7256 else if (rate_flags & eHAL_TX_RATE_VHT80)
7257 {
7258 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7259 }
7260#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007261#ifdef LINKSPEED_DEBUG_ENABLED
7262 pr_info("Reporting actual MCS rate %d flags %x\n",
7263 sinfo->txrate.mcs,
7264 sinfo->txrate.flags );
7265#endif //LINKSPEED_DEBUG_ENABLED
7266 }
7267 }
7268 sinfo->filled |= STATION_INFO_TX_BITRATE;
7269
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007270 sinfo->tx_packets =
7271 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7272 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7273 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7274 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7275
7276 sinfo->tx_retries =
7277 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7278 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7279 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7280 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7281
7282 sinfo->tx_failed =
7283 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7284 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7285 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7286 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7287
7288 sinfo->filled |=
7289 STATION_INFO_TX_PACKETS |
7290 STATION_INFO_TX_RETRIES |
7291 STATION_INFO_TX_FAILED;
7292
7293 EXIT();
7294 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007295}
7296
7297static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007298 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007299{
7300 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307301 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007302 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307303 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007304
Jeff Johnsone7245742012-09-05 17:12:55 -07007305 ENTER();
7306
Jeff Johnson295189b2012-06-20 16:38:30 -07007307 if (NULL == pAdapter)
7308 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007309 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007310 return -ENODEV;
7311 }
7312
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307313 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307314 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307315
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307316 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307317 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307318 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7319 "%s: HDD context is not valid", __func__);
7320 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307321 }
7322
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307323 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7324 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7325 (pHddCtx->cfg_ini->fhostArpOffload) &&
7326 (eConnectionState_Associated ==
7327 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7328 {
Amar Singhald53568e2013-09-26 11:03:45 -07007329
7330 hddLog(VOS_TRACE_LEVEL_INFO,
7331 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307332 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307333 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7334 {
7335 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007336 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307337 __func__, vos_status);
7338 }
7339 }
7340
Jeff Johnson295189b2012-06-20 16:38:30 -07007341 /**The get power cmd from the supplicant gets updated by the nl only
7342 *on successful execution of the function call
7343 *we are oppositely mapped w.r.t mode in the driver
7344 **/
7345 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7346
Jeff Johnsone7245742012-09-05 17:12:55 -07007347 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007348 if (VOS_STATUS_E_FAILURE == vos_status)
7349 {
7350 return -EINVAL;
7351 }
7352 return 0;
7353}
7354
7355
7356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7357static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7358 struct net_device *netdev,
7359 u8 key_index)
7360{
Jeff Johnsone7245742012-09-05 17:12:55 -07007361 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007362 return 0;
7363}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307364#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007365
7366#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7367static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7368 struct net_device *dev,
7369 struct ieee80211_txq_params *params)
7370{
Jeff Johnsone7245742012-09-05 17:12:55 -07007371 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007372 return 0;
7373}
7374#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7375static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7376 struct ieee80211_txq_params *params)
7377{
Jeff Johnsone7245742012-09-05 17:12:55 -07007378 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007379 return 0;
7380}
7381#endif //LINUX_VERSION_CODE
7382
7383static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7384 struct net_device *dev, u8 *mac)
7385{
7386 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307387 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007388 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307389 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007390 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007391
Jeff Johnsone7245742012-09-05 17:12:55 -07007392 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307393 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007394 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307395 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007396 return -EINVAL;
7397 }
7398
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307399 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7400 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007401
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307402 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007403 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307404 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7405 "%s: HDD context is not valid", __func__);
7406 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007407 }
7408
Jeff Johnson295189b2012-06-20 16:38:30 -07007409 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007410 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007411 )
7412 {
7413 if( NULL == mac )
7414 {
7415 v_U16_t i;
7416 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7417 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007418 if ((pAdapter->aStaInfo[i].isUsed) &&
7419 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007420 {
7421 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7422 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007423 "%s: Delete STA with MAC::"
7424 MAC_ADDRESS_STR,
7425 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007426 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7427 if (VOS_IS_STATUS_SUCCESS(vos_status))
7428 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007429 }
7430 }
7431 }
7432 else
7433 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007434
7435 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7436 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7437 {
7438 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007439 "%s: Skip this DEL STA as this is not used::"
7440 MAC_ADDRESS_STR,
7441 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007442 return -ENOENT;
7443 }
7444
7445 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7446 {
7447 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007448 "%s: Skip this DEL STA as deauth is in progress::"
7449 MAC_ADDRESS_STR,
7450 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007451 return -ENOENT;
7452 }
7453
7454 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7455
Jeff Johnson295189b2012-06-20 16:38:30 -07007456 hddLog(VOS_TRACE_LEVEL_INFO,
7457 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007458 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007459 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007460 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007461
7462 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7463 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7464 {
7465 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7466 hddLog(VOS_TRACE_LEVEL_INFO,
7467 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007468 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007469 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007470 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007471 return -ENOENT;
7472 }
7473
Jeff Johnson295189b2012-06-20 16:38:30 -07007474 }
7475 }
7476
7477 EXIT();
7478
7479 return 0;
7480}
7481
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007482static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7483 struct net_device *dev, u8 *mac, struct station_parameters *params)
7484{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007485 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007486#ifdef FEATURE_WLAN_TDLS
7487 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007488 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007489 mask = params->sta_flags_mask;
7490
7491 set = params->sta_flags_set;
7492
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007493#ifdef WLAN_FEATURE_TDLS_DEBUG
7494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7495 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7496 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7497#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007498
7499 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7500 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007501 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007502 }
7503 }
7504#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007505 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007506}
7507
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007508
7509#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007510#define MAX_PMKSAIDS_IN_CACHE 8
7511
7512static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7513static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7514
7515
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007516static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007517 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007518{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307519 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007520 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7521 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307522 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307523 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007524 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307525 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307526
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007527 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
7528 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07007529
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307530 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307531 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007532 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307533 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007534 return -EINVAL;
7535 }
7536
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307537 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7538 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007539
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307540 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007541 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307542 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7543 "%s: HDD context is not valid", __func__);
7544 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007545 }
7546
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307547 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007548 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7549
Wilson Yang6507c4e2013-10-01 20:11:19 -07007550 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007551 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307552 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007553 pmksa->bssid, WNI_CFG_BSSID_LEN))
7554 {
7555 /* BSSID matched previous entry. Overwrite it. */
7556 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307557 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007558 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307559 vos_mem_copy(PMKIDCache[j].PMKID,
7560 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007561 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307562 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007563 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007564 dump_bssid(pmksa->bssid);
7565 dump_pmkid(halHandle, pmksa->pmkid);
7566 break;
7567 }
7568 }
7569
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007570 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007571 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007572
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007573 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307574 {
7575 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007576 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307577 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007578 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307579 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007580 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307581 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007582 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007583 dump_bssid(pmksa->bssid);
7584 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307585 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007586 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007587 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007588 }
7589
7590
7591 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307592 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007593 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307594 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007595 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007596 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307597 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7598 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007599 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007600 return 0;
7601}
7602
7603
Wilson Yang6507c4e2013-10-01 20:11:19 -07007604
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007605static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007606 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007607{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007608 tANI_U32 j=0;
7609 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7610 tHalHandle halHandle;
7611 int status;
7612 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007613 hdd_context_t *pHddCtx;
7614 int result = 0;
7615
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007616 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
7617 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007618
7619 /* Validate pAdapter */
7620 if (NULL == pAdapter)
7621 {
7622 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7623 return -EINVAL;
7624 }
7625
7626 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7627 status = wlan_hdd_validate_context(pHddCtx);
7628
7629 if (0 != status)
7630 {
7631 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7632 "%s: HDD context is not valid", __func__);
7633 return status;
7634 }
7635
7636 /*Retrieve halHandle*/
7637 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7638
7639 /*in case index is 0,no entry to delete*/
7640 if (0 == PMKIDCacheIndex)
7641 {
7642 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7643 __func__);
7644 return -EINVAL;
7645 }
7646
7647 /*find the matching PMKSA entry from j=0 to (index-1),
7648 * and delete the matched one
7649 */
7650 for (j = 0; j<PMKIDCacheIndex; j++)
7651 {
7652 if (vos_mem_compare(PMKIDCache[j].BSSID,
7653 pmksa->bssid,
7654 WNI_CFG_BSSID_LEN))
7655 {
7656 /* BSSID matched entry */
7657 BSSIDMatched = 1;
7658
7659 if (j<PMKIDCacheIndex-1)
7660 {
7661 /*replace the matching entry with the last entry in HDD local cache*/
7662 vos_mem_copy(PMKIDCache[j].BSSID,
7663 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7664 WNI_CFG_BSSID_LEN);
7665 vos_mem_copy(PMKIDCache[j].PMKID,
7666 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7667 CSR_RSN_PMKID_SIZE);
7668 }
7669
7670 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07007671 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7672 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7673
7674 /*reduce the PMKID array index*/
7675 PMKIDCacheIndex--;
7676
7677 /*delete the last PMKID cache in CSR*/
Kiet Lam8d21d5b2013-10-31 17:18:29 +05307678 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007679 if (0 != result)
7680 {
7681 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7682 __func__,PMKIDCacheIndex);
7683 }
7684
7685 dump_bssid(pmksa->bssid);
7686 dump_pmkid(halHandle,pmksa->pmkid);
7687
7688 break;
7689 }
7690 }
7691
7692 /* we compare all entries,but cannot find matching entry */
7693 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7694 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007695 hddLog(VOS_TRACE_LEVEL_FATAL,
7696 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
7697 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007698 dump_bssid(pmksa->bssid);
7699 dump_pmkid(halHandle, pmksa->pmkid);
7700 return -EINVAL;
7701 }
7702 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007703}
7704
Wilson Yang6507c4e2013-10-01 20:11:19 -07007705
7706
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007707static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7708{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007709 tANI_U32 j=0;
7710 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7711 tHalHandle halHandle;
7712 hdd_context_t *pHddCtx;
7713 tANI_U8 *pBSSId;
7714 int status;
7715 int result;
7716
7717 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7718
7719 /* Validate pAdapter */
7720 if (NULL == pAdapter)
7721 {
7722 hddLog(VOS_TRACE_LEVEL_ERROR,
7723 "%s: Invalid Adapter" ,__func__);
7724 return -EINVAL;
7725 }
7726
7727 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7728 status = wlan_hdd_validate_context(pHddCtx);
7729
7730 if (0 != status)
7731 {
7732 hddLog(VOS_TRACE_LEVEL_ERROR,
7733 "%s: HDD context is not valid", __func__);
7734 return status;
7735 }
7736
7737 /*Retrieve halHandle*/
7738 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7739
7740 /*in case index is 0,no entry to delete*/
7741 if (0 == PMKIDCacheIndex)
7742 {
7743 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7744 __func__);
7745 return -EINVAL;
7746 }
7747
7748 /*delete all the PMKSA one by one */
7749 for (j = 0; j<PMKIDCacheIndex; j++)
7750 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07007751 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007752
7753 /*delete the PMKID in CSR*/
7754 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7755
7756 if (0!= result)
7757 {
7758 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
7759 __func__,j);
7760 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05307761 /*clear the entry in HDD cache 0--index-1 */
7762 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
7763 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007764 }
7765
7766 PMKIDCacheIndex = 0;
7767 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007768}
7769#endif
7770
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007771#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307772static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007773 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7774{
7775 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7776 hdd_station_ctx_t *pHddStaCtx;
7777
7778 if (NULL == pAdapter)
7779 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007780 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007781 return -ENODEV;
7782 }
7783
7784 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7785
7786 // Added for debug on reception of Re-assoc Req.
7787 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7788 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007789 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007790 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08007791 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007792 }
7793
7794#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08007795 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007796 ftie->ie_len);
7797#endif
7798
7799 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307800 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7801 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007802 ftie->ie_len);
7803 return 0;
7804}
7805#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007806
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307807#ifdef FEATURE_WLAN_SCAN_PNO
7808
7809void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7810 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7811{
7812 int ret;
7813 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7814 hdd_context_t *pHddCtx;
7815
7816 if (NULL == pAdapter)
7817 {
7818 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7819 "%s: HDD adapter is Null", __func__);
7820 return ;
7821 }
7822
7823 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7824 if (NULL == pHddCtx)
7825 {
7826 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7827 "%s: HDD context is Null!!!", __func__);
7828 return ;
7829 }
7830
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307831 spin_lock(&pHddCtx->schedScan_lock);
7832 if (TRUE == pHddCtx->isWiphySuspended)
7833 {
7834 pHddCtx->isSchedScanUpdatePending = TRUE;
7835 spin_unlock(&pHddCtx->schedScan_lock);
7836 hddLog(VOS_TRACE_LEVEL_INFO,
7837 "%s: Update cfg80211 scan database after it resume", __func__);
7838 return ;
7839 }
7840 spin_unlock(&pHddCtx->schedScan_lock);
7841
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307842 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7843
7844 if (0 > ret)
7845 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7846
7847 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307848 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7849 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307850}
7851
7852/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307853 * FUNCTION: wlan_hdd_is_pno_allowed
7854 * To check is there any P2P GO/SAP or P2P Client/STA
7855 * session is active
7856 */
7857static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
7858{
7859 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
7860 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307861 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307862 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7863 int status = 0;
7864 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
7865
7866 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
7867 {
7868 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307869 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307870
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307871 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
7872 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
7873 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
7874 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
7875 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
7876 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307877 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307878 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307879 }
7880 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
7881 pAdapterNode = pNext;
7882 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307883 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307884}
7885
7886/*
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307887 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7888 * NL interface to enable PNO
7889 */
7890static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7891 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7892{
7893 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7894 tpSirPNOScanReq pPnoRequest = NULL;
7895 hdd_context_t *pHddCtx;
7896 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307897 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307898 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7899 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7900 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7901 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307902 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307903
7904 if (NULL == pAdapter)
7905 {
7906 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7907 "%s: HDD adapter is Null", __func__);
7908 return -ENODEV;
7909 }
7910
7911 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307912 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307913
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307914 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307915 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307916 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7917 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307918 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307919 }
7920
7921 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7922 if (NULL == hHal)
7923 {
7924 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7925 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307926 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307927 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307928
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307929 /* The current firmware design for PNO does not consider concurrent
7930 * active sessions.Hence , determine the concurrent active sessions
7931 * and return a failure to the framework on a request for schedule
7932 * scan.
7933 */
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307934 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307935 {
7936 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05307937 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05307938 return -EBUSY;
7939 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307940
7941 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7942 if (NULL == pPnoRequest)
7943 {
7944 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7945 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307946 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307947 }
7948
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05307949 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307950 pPnoRequest->enable = 1; /*Enable PNO */
7951 pPnoRequest->ucNetworksCount = request->n_match_sets;
7952
7953 if (( !pPnoRequest->ucNetworksCount ) ||
7954 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7955 {
7956 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7957 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307958 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307959 goto error;
7960 }
7961
7962 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7963 {
7964 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7965 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307966 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307967 goto error;
7968 }
7969
7970 /* Framework provides one set of channels(all)
7971 * common for all saved profile */
7972 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7973 channels_allowed, &num_channels_allowed))
7974 {
7975 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7976 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307977 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307978 goto error;
7979 }
7980 /* Checking each channel against allowed channel list */
7981 num_ch = 0;
7982 for (i = 0; i < request->n_channels; i++)
7983 {
7984 for (indx = 0; indx < num_channels_allowed; indx++)
7985 {
7986 if (request->channels[i]->hw_value == channels_allowed[indx])
7987 {
7988 valid_ch[num_ch++] = request->channels[i]->hw_value;
7989 break ;
7990 }
7991 }
7992 }
7993
7994 /* Filling per profile params */
7995 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7996 {
7997 pPnoRequest->aNetworks[i].ssId.length =
7998 request->match_sets[i].ssid.ssid_len;
7999
8000 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8001 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8002 {
8003 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8004 "SSID Len %d is not correct for network %d",
8005 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308006 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308007 goto error;
8008 }
8009
8010 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8011 request->match_sets[i].ssid.ssid,
8012 request->match_sets[i].ssid.ssid_len);
8013 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8014 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8015 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8016
8017 /*Copying list of valid channel into request */
8018 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8019 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8020
8021 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8022 }
8023
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308024 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008025 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308026 if ((0 < request->ie_len) && (NULL != request->ie))
8027 {
8028 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8029 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8030 pPnoRequest->us24GProbeTemplateLen);
8031
8032 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8033 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8034 pPnoRequest->us5GProbeTemplateLen);
8035 }
8036
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308037 /* Driver gets only one time interval which is hardcoded in
8038 * supplicant for 10000ms. Taking power consumption into account 6 timers
8039 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8040 * 80,160,320 secs. And number of scan cycle for each timer
8041 * is configurable through INI param gPNOScanTimerRepeatValue.
8042 * If it is set to 0 only one timer will be used and PNO scan cycle
8043 * will be repeated after each interval specified by supplicant
8044 * till PNO is disabled.
8045 */
8046 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8047 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8048 else
8049 pPnoRequest->scanTimers.ucScanTimersCount =
8050 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8051
8052 tempInterval = (request->interval)/1000;
8053 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8054 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8055 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8056 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8057 {
8058 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8059 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8060 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8061 tempInterval *= 2;
8062 }
8063 //Repeat last timer until pno disabled.
8064 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8065
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308066 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308067
8068 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8069 pPnoRequest, pAdapter->sessionId,
8070 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8071 if (eHAL_STATUS_SUCCESS != status)
8072 {
8073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8074 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308075 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308076 goto error;
8077 }
8078
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308079 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8080 "PNO scanRequest offloaded");
8081
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308082error:
8083 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308084 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308085}
8086
8087/*
8088 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8089 * NL interface to disable PNO
8090 */
8091static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8092 struct net_device *dev)
8093{
8094 eHalStatus status = eHAL_STATUS_FAILURE;
8095 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8096 hdd_context_t *pHddCtx;
8097 tHalHandle hHal;
8098 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308099 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308100
8101 ENTER();
8102
8103 if (NULL == pAdapter)
8104 {
8105 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8106 "%s: HDD adapter is Null", __func__);
8107 return -ENODEV;
8108 }
8109
8110 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308111
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308112 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308113 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308114 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308115 "%s: HDD context is Null", __func__);
8116 return -ENODEV;
8117 }
8118
8119 /* The return 0 is intentional when isLogpInProgress and
8120 * isLoadUnloadInProgress. We did observe a crash due to a return of
8121 * failure in sched_scan_stop , especially for a case where the unload
8122 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8123 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8124 * success. If it returns a failure , then its next invocation due to the
8125 * clean up of the second interface will have the dev pointer corresponding
8126 * to the first one leading to a crash.
8127 */
8128 if (pHddCtx->isLogpInProgress)
8129 {
8130 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8131 "%s: LOGP in Progress. Ignore!!!", __func__);
8132 return ret;
8133 }
8134
8135 if (pHddCtx->isLoadUnloadInProgress)
8136 {
8137 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8138 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8139 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308140 }
8141
8142 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8143 if (NULL == hHal)
8144 {
8145 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8146 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308147 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308148 }
8149
8150 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8151 if (NULL == pPnoRequest)
8152 {
8153 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8154 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308155 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308156 }
8157
8158 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8159 pPnoRequest->enable = 0; /* Disable PNO */
8160 pPnoRequest->ucNetworksCount = 0;
8161
8162 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8163 pAdapter->sessionId,
8164 NULL, pAdapter);
8165 if (eHAL_STATUS_SUCCESS != status)
8166 {
8167 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8168 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308169 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308170 }
8171
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8173 "%s: PNO scan disabled", __func__);
8174
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308175 vos_mem_free(pPnoRequest);
8176
8177 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308178 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308179}
8180
8181#endif /*FEATURE_WLAN_SCAN_PNO*/
8182
8183
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008184#ifdef FEATURE_WLAN_TDLS
8185static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8186 u8 *peer, u8 action_code, u8 dialog_token,
8187 u16 status_code, const u8 *buf, size_t len)
8188{
8189
8190 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8191 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008192 u8 peerMac[6];
8193 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008194 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008195 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008196 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008197
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008198 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008199 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308200 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008201 "Invalid arguments");
8202 return -EINVAL;
8203 }
8204
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008205 if (pHddCtx->isLogpInProgress)
8206 {
8207 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8208 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008209 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008210 return -EBUSY;
8211 }
8212
Hoonki Lee27511902013-03-14 18:19:06 -07008213 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008214 {
Hoonki Lee27511902013-03-14 18:19:06 -07008215 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8216 "%s: TDLS mode is disabled OR not enabled in FW."
8217 MAC_ADDRESS_STR " action %d declined.",
8218 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008219 return -ENOTSUPP;
8220 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008221
Hoonki Lee27511902013-03-14 18:19:06 -07008222 /* other than teardown frame, other mgmt frames are not sent if disabled */
8223 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8224 {
8225 /* if tdls_mode is disabled to respond to peer's request */
8226 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8227 {
8228 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8229 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008230 " TDLS mode is disabled. action %d declined.",
8231 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008232
8233 return -ENOTSUPP;
8234 }
8235 }
8236
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008237 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8238 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308239 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008240 {
8241 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008242 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008243 " TDLS setup is ongoing. action %d declined.",
8244 __func__, MAC_ADDR_ARRAY(peer), action_code);
8245 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008246 }
8247 }
8248
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008249 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8250 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008251 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008252 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008253 {
8254 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8255 we return error code at 'add_station()'. Hence we have this
8256 check again in addtion to add_station().
8257 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008258 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008259 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008260 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8261 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008262 " TDLS Max peer already connected. action %d declined.",
8263 __func__, MAC_ADDR_ARRAY(peer), action_code);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308264 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008265 }
8266 else
8267 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008268 /* maximum reached. tweak to send error code to peer and return
8269 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008270 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008271 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8272 "%s: " MAC_ADDRESS_STR
8273 " TDLS Max peer already connected send response status %d",
8274 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008275 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008276 /* fall through to send setup resp with failure status
8277 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008278 }
8279 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008280 else
8281 {
8282 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308283 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008284 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008285 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008286 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008287 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8288 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008289 return -EPERM;
8290 }
8291 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008292 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008293 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008294
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008295#ifdef WLAN_FEATURE_TDLS_DEBUG
8296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008297 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8298 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8299 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008300#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008301
Hoonki Leea34dd892013-02-05 22:56:02 -08008302 /*Except teardown responder will not be used so just make 0*/
8303 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008304 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008305 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008306
8307 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308308 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008309
8310 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8311 responder = pTdlsPeer->is_responder;
8312 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008313 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008314 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8315 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8316 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8317 dialog_token, status_code, len);
8318 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008319 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008320 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008321
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308322 /* For explicit trigger of DIS_REQ come out of BMPS for
8323 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008324 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308325 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8326 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008327 {
8328 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8329 {
8330 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308331 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008332 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8333 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308334 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8335 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008336 }
8337
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008338 /* make sure doesn't call send_mgmt() while it is pending */
8339 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8340 {
8341 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008342 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008343 __func__, MAC_ADDR_ARRAY(peer), action_code);
8344 return -EBUSY;
8345 }
8346
8347 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008348 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8349
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008350 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008351 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008352
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008353 if (VOS_STATUS_SUCCESS != status)
8354 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008355 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8356 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008357 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008358 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308359 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008360 }
8361
Hoonki Leed37cbb32013-04-20 00:31:14 -07008362 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8363 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8364
8365 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008366 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008367 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008368 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008369 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008370 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008371 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308372 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008373 }
8374
Gopichand Nakkala05922802013-03-14 12:23:19 -07008375 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008376 {
8377 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008378 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008379 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008380
Hoonki Leea34dd892013-02-05 22:56:02 -08008381 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8382 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008383 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008384 }
8385 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8386 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008387 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008388 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008389
8390 return 0;
8391}
8392
8393static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8394 u8 *peer, enum nl80211_tdls_operation oper)
8395{
8396 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8397 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308398 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008399 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008400
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308401 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008402 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008403 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008404 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008405 return -EINVAL;
8406 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008407
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308408 status = wlan_hdd_validate_context(pHddCtx);
8409
8410 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008411 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308412 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8413 "%s: HDD context is not valid", __func__);
8414 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008415 }
8416
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008417
8418 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008419 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008420 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008422 "TDLS Disabled in INI OR not enabled in FW. "
8423 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008424 return -ENOTSUPP;
8425 }
8426
8427 switch (oper) {
8428 case NL80211_TDLS_ENABLE_LINK:
8429 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008430 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308431 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008432
Sunil Dutt41de4e22013-11-14 18:09:02 +05308433 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8434
8435 if ( NULL == pTdlsPeer ) {
8436 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8437 " (oper %d) not exsting. ignored",
8438 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8439 return -EINVAL;
8440 }
8441
8442 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8443 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8444 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8445 "NL80211_TDLS_ENABLE_LINK");
8446
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008447 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8448 {
8449 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8450 MAC_ADDRESS_STR " failed",
8451 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8452 return -EINVAL;
8453 }
8454
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008455 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008456 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308457 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308458 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308459
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308460 if (0 != wlan_hdd_tdls_get_link_establish_params(
8461 pAdapter, peer,&tdlsLinkEstablishParams)) {
8462 return -EINVAL;
8463 }
8464 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308465
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308466 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8467 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8468 /* Send TDLS peer UAPSD capabilities to the firmware and
8469 * register with the TL on after the response for this operation
8470 * is received .
8471 */
8472 ret = wait_for_completion_interruptible_timeout(
8473 &pAdapter->tdls_link_establish_req_comp,
8474 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8475 if (ret <= 0)
8476 {
8477 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8478 "%s: Link Establish Request Faled Status %ld",
8479 __func__, ret);
8480 return -EINVAL;
8481 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308482 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008483 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308484 /* Mark TDLS client Authenticated .*/
8485 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8486 pTdlsPeer->staId,
8487 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008488 if (VOS_STATUS_SUCCESS == status)
8489 {
Hoonki Lee14621352013-04-16 17:51:19 -07008490 if (pTdlsPeer->is_responder == 0)
8491 {
8492 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8493
8494 wlan_hdd_tdls_timer_restart(pAdapter,
8495 &pTdlsPeer->initiatorWaitTimeoutTimer,
8496 WAIT_TIME_TDLS_INITIATOR);
8497 /* suspend initiator TX until it receives direct packet from the
8498 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8499 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8500 &staId, NULL);
8501 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008502 wlan_hdd_tdls_increment_peer_count(pAdapter);
8503 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008504 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308505
8506 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308507 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8508 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308509 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308510 int ac;
8511 uint8 ucAc[4] = { WLANTL_AC_VO,
8512 WLANTL_AC_VI,
8513 WLANTL_AC_BK,
8514 WLANTL_AC_BE };
8515 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8516 for(ac=0; ac < 4; ac++)
8517 {
8518 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8519 pTdlsPeer->staId, ucAc[ac],
8520 tlTid[ac], tlTid[ac], 0, 0,
8521 WLANTL_BI_DIR );
8522 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308523 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008524 }
8525
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008526 }
8527 break;
8528 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008529 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05308530 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8531
8532 if ( NULL == pTdlsPeer ) {
8533 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8534 " (oper %d) not exsting. ignored",
8535 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8536 return -EINVAL;
8537 }
8538
8539 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8540 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8541 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8542 "NL80211_TDLS_DISABLE_LINK");
8543
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008544 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008545 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008546 long status;
8547
8548 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8549
Lee Hoonkic1262f22013-01-24 21:59:00 -08008550 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8551 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008552
8553 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8554 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8555 if (status <= 0)
8556 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008557 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008558 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8559 "%s: Del station failed status %ld",
8560 __func__, status);
8561 return -EPERM;
8562 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008563 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008564 }
8565 else
8566 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008567 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8568 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008569 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008570 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008571 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008572 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308573 {
8574 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8575 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
8576 __func__, MAC_ADDR_ARRAY(peer));
8577
8578 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8579 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8580
8581 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8582 " %s TDLS External control and Implicit Trigger not enabled ",
8583 __func__);
8584 return -ENOTSUPP;
8585 }
8586
Sunil Dutt41de4e22013-11-14 18:09:02 +05308587
8588 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8589
8590 if ( NULL == pTdlsPeer ) {
8591 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
8592 " peer not exsting",
8593 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308594 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308595 }
8596 else {
8597 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
8598 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
8599 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308600
8601 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
8602 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308603 break;
8604 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008605 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308606 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308607 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308608 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8609 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
8610 __func__, MAC_ADDR_ARRAY(peer));
8611
8612 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8613 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8614
8615 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8616 " %s TDLS External control and Implicit Trigger not enabled ",
8617 __func__);
8618 return -ENOTSUPP;
8619 }
8620
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308621 /* To cater the requirement of establishing the TDLS link
8622 * irrespective of the data traffic , get an entry of TDLS peer.
8623 */
8624 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
8625 if (pTdlsPeer == NULL) {
8626 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8627 "%s: peer " MAC_ADDRESS_STR " not existing",
8628 __func__, MAC_ADDR_ARRAY(peer));
8629 return -EINVAL;
8630 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308631
8632 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
8633
8634 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8635 " %s TDLS Add Force Peer Failed",
8636 __func__);
8637 return -EINVAL;
8638 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308639 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308640 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008641 case NL80211_TDLS_DISCOVERY_REQ:
8642 /* We don't support in-driver setup/teardown/discovery */
8643 return -ENOTSUPP;
8644 default:
8645 return -ENOTSUPP;
8646 }
8647 return 0;
8648}
Chilam NG571c65a2013-01-19 12:27:36 +05308649
8650int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8651 struct net_device *dev, u8 *peer)
8652{
Arif Hussaina7c8e412013-11-20 11:06:42 -08008653 hddLog(VOS_TRACE_LEVEL_INFO,
8654 "tdls send discover req: "MAC_ADDRESS_STR,
8655 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05308656
8657 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8658 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8659}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008660#endif
8661
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308662#ifdef WLAN_FEATURE_GTK_OFFLOAD
8663/*
8664 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8665 * Callback rountine called upon receiving response for
8666 * get offload info
8667 */
8668void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8669 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8670{
8671
8672 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308673 tANI_U8 tempReplayCounter[8];
8674 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308675
8676 ENTER();
8677
8678 if (NULL == pAdapter)
8679 {
8680 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8681 "%s: HDD adapter is Null", __func__);
8682 return ;
8683 }
8684
8685 if (NULL == pGtkOffloadGetInfoRsp)
8686 {
8687 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8688 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8689 return ;
8690 }
8691
8692 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8693 {
8694 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8695 "%s: wlan Failed to get replay counter value",
8696 __func__);
8697 return ;
8698 }
8699
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308700 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8701 /* Update replay counter */
8702 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8703 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8704
8705 {
8706 /* changing from little to big endian since supplicant
8707 * works on big endian format
8708 */
8709 int i;
8710 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8711
8712 for (i = 0; i < 8; i++)
8713 {
8714 tempReplayCounter[7-i] = (tANI_U8)p[i];
8715 }
8716 }
8717
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308718 /* Update replay counter to NL */
8719 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308720 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308721}
8722
8723/*
8724 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8725 * This function is used to offload GTK rekeying job to the firmware.
8726 */
8727int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8728 struct cfg80211_gtk_rekey_data *data)
8729{
8730 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8731 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8732 hdd_station_ctx_t *pHddStaCtx;
8733 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308734 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308735 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308736 eHalStatus status = eHAL_STATUS_FAILURE;
8737
8738 ENTER();
8739
8740 if (NULL == pAdapter)
8741 {
8742 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8743 "%s: HDD adapter is Null", __func__);
8744 return -ENODEV;
8745 }
8746
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308747 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308748
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308749 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308750 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308751 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8752 "%s: HDD context is not valid", __func__);
8753 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308754 }
8755
8756 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8757 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8758 if (NULL == hHal)
8759 {
8760 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8761 "%s: HAL context is Null!!!", __func__);
8762 return -EAGAIN;
8763 }
8764
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308765 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8766 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8767 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8768 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308769 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308770 {
8771 /* changing from big to little endian since driver
8772 * works on little endian format
8773 */
8774 tANI_U8 *p =
8775 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8776 int i;
8777
8778 for (i = 0; i < 8; i++)
8779 {
8780 p[7-i] = data->replay_ctr[i];
8781 }
8782 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308783
8784 if (TRUE == pHddCtx->hdd_wlan_suspended)
8785 {
8786 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308787 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8788 sizeof (tSirGtkOffloadParams));
8789 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308790 pAdapter->sessionId);
8791
8792 if (eHAL_STATUS_SUCCESS != status)
8793 {
8794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8795 "%s: sme_SetGTKOffload failed, returned %d",
8796 __func__, status);
8797 return status;
8798 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308799 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8800 "%s: sme_SetGTKOffload successfull", __func__);
8801 }
8802 else
8803 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308804 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8805 "%s: wlan not suspended GTKOffload request is stored",
8806 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308807 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308808
8809 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308810}
8811#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8812
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308813/*
8814 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8815 * This function is used to set access control policy
8816 */
8817static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8818 struct net_device *dev, const struct cfg80211_acl_data *params)
8819{
8820 int i;
8821 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8822 hdd_hostapd_state_t *pHostapdState;
8823 tsap_Config_t *pConfig;
8824 v_CONTEXT_t pVosContext = NULL;
8825 hdd_context_t *pHddCtx;
8826 int status;
8827
8828 ENTER();
8829
8830 if (NULL == pAdapter)
8831 {
8832 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8833 "%s: HDD adapter is Null", __func__);
8834 return -ENODEV;
8835 }
8836
8837 if (NULL == params)
8838 {
8839 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8840 "%s: params is Null", __func__);
8841 return -EINVAL;
8842 }
8843
8844 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8845 status = wlan_hdd_validate_context(pHddCtx);
8846
8847 if (0 != status)
8848 {
8849 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8850 "%s: HDD context is not valid", __func__);
8851 return status;
8852 }
8853
8854 pVosContext = pHddCtx->pvosContext;
8855 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8856
8857 if (NULL == pHostapdState)
8858 {
8859 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8860 "%s: pHostapdState is Null", __func__);
8861 return -EINVAL;
8862 }
8863
8864 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8865 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8866
8867 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8868 {
8869 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8870
8871 /* default value */
8872 pConfig->num_accept_mac = 0;
8873 pConfig->num_deny_mac = 0;
8874
8875 /**
8876 * access control policy
8877 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8878 * listed in hostapd.deny file.
8879 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8880 * listed in hostapd.accept file.
8881 */
8882 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8883 {
8884 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8885 }
8886 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8887 {
8888 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8889 }
8890 else
8891 {
8892 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8893 "%s:Acl Policy : %d is not supported",
8894 __func__, params->acl_policy);
8895 return -ENOTSUPP;
8896 }
8897
8898 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8899 {
8900 pConfig->num_accept_mac = params->n_acl_entries;
8901 for (i = 0; i < params->n_acl_entries; i++)
8902 {
8903 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8904 "** Add ACL MAC entry %i in WhiletList :"
8905 MAC_ADDRESS_STR, i,
8906 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8907
8908 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8909 sizeof(qcmacaddr));
8910 }
8911 }
8912 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8913 {
8914 pConfig->num_deny_mac = params->n_acl_entries;
8915 for (i = 0; i < params->n_acl_entries; i++)
8916 {
8917 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8918 "** Add ACL MAC entry %i in BlackList :"
8919 MAC_ADDRESS_STR, i,
8920 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8921
8922 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8923 sizeof(qcmacaddr));
8924 }
8925 }
8926
8927 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8928 {
8929 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8930 "%s: SAP Set Mac Acl fail", __func__);
8931 return -EINVAL;
8932 }
8933 }
8934 else
8935 {
8936 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8937 "%s: Invalid device_mode = %d",
8938 __func__, pAdapter->device_mode);
8939 return -EINVAL;
8940 }
8941
8942 return 0;
8943}
8944
Leo Chang9056f462013-08-01 19:21:11 -07008945#ifdef WLAN_NL80211_TESTMODE
8946#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07008947void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07008948(
8949 void *pAdapter,
8950 void *indCont
8951)
8952{
Leo Changd9df8aa2013-09-26 13:32:26 -07008953 tSirLPHBInd *lphbInd;
8954 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07008955
8956 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008957 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07008958
8959 if (NULL == indCont)
8960 {
8961 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008962 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07008963 return;
8964 }
8965
Leo Changd9df8aa2013-09-26 13:32:26 -07008966 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07008967 skb = cfg80211_testmode_alloc_event_skb(
8968 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07008969 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07008970 GFP_ATOMIC);
8971 if (!skb)
8972 {
8973 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8974 "LPHB timeout, NL buffer alloc fail");
8975 return;
8976 }
8977
Leo Changac3ba772013-10-07 09:47:04 -07008978 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07008979 {
8980 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8981 "WLAN_HDD_TM_ATTR_CMD put fail");
8982 goto nla_put_failure;
8983 }
Leo Changac3ba772013-10-07 09:47:04 -07008984 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07008985 {
8986 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8987 "WLAN_HDD_TM_ATTR_TYPE put fail");
8988 goto nla_put_failure;
8989 }
Leo Changac3ba772013-10-07 09:47:04 -07008990 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07008991 sizeof(tSirLPHBInd), lphbInd))
8992 {
8993 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8994 "WLAN_HDD_TM_ATTR_DATA put fail");
8995 goto nla_put_failure;
8996 }
Leo Chang9056f462013-08-01 19:21:11 -07008997 cfg80211_testmode_event(skb, GFP_ATOMIC);
8998 return;
8999
9000nla_put_failure:
9001 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9002 "NLA Put fail");
9003 kfree_skb(skb);
9004
9005 return;
9006}
9007#endif /* FEATURE_WLAN_LPHB */
9008
9009static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9010{
9011 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9012 int err = 0;
9013#ifdef FEATURE_WLAN_LPHB
9014 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009015 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009016#endif /* FEATURE_WLAN_LPHB */
9017
9018 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9019 if (err)
9020 {
9021 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9022 "%s Testmode INV ATTR", __func__);
9023 return err;
9024 }
9025
9026 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9027 {
9028 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9029 "%s Testmode INV CMD", __func__);
9030 return -EINVAL;
9031 }
9032
9033 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9034 {
9035#ifdef FEATURE_WLAN_LPHB
9036 /* Low Power Heartbeat configuration request */
9037 case WLAN_HDD_TM_CMD_WLAN_HB:
9038 {
9039 int buf_len;
9040 void *buf;
9041 tSirLPHBReq *hb_params = NULL;
9042
9043 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9044 {
9045 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9046 "%s Testmode INV DATA", __func__);
9047 return -EINVAL;
9048 }
9049
9050 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9051 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
9052 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9053 if (NULL == hb_params)
9054 {
9055 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9056 "%s Request Buffer Alloc Fail", __func__);
9057 return -EINVAL;
9058 }
9059
9060 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009061 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9062 hb_params,
9063 wlan_hdd_cfg80211_lphb_ind_handler);
9064 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009065 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009066 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9067 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009068 vos_mem_free(hb_params);
9069 }
Leo Chang9056f462013-08-01 19:21:11 -07009070 return 0;
9071 }
9072#endif /* FEATURE_WLAN_LPHB */
9073 default:
9074 return -EOPNOTSUPP;
9075 }
9076
9077 return err;
9078}
9079#endif /* CONFIG_NL80211_TESTMODE */
9080
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309081static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9082 struct net_device *dev,
9083 int idx, struct survey_info *survey)
9084{
9085 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9086 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309087 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309088 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309089 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309090 v_S7_t snr,rssi;
9091 int status, i, j, filled = 0;
9092
9093 ENTER();
9094
9095
9096 if (NULL == pAdapter)
9097 {
9098 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9099 "%s: HDD adapter is Null", __func__);
9100 return -ENODEV;
9101 }
9102
9103 if (NULL == wiphy)
9104 {
9105 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9106 "%s: wiphy is Null", __func__);
9107 return -ENODEV;
9108 }
9109
9110 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9111 status = wlan_hdd_validate_context(pHddCtx);
9112
9113 if (0 != status)
9114 {
9115 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9116 "%s: HDD context is not valid", __func__);
9117 return status;
9118 }
9119
Mihir Sheted9072e02013-08-21 17:02:29 +05309120 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9121
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309122 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309123 0 != pAdapter->survey_idx ||
9124 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309125 {
9126 /* The survey dump ops when implemented completely is expected to
9127 * return a survey of all channels and the ops is called by the
9128 * kernel with incremental values of the argument 'idx' till it
9129 * returns -ENONET. But we can only support the survey for the
9130 * operating channel for now. survey_idx is used to track
9131 * that the ops is called only once and then return -ENONET for
9132 * the next iteration
9133 */
9134 pAdapter->survey_idx = 0;
9135 return -ENONET;
9136 }
9137
9138 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9139
9140 wlan_hdd_get_snr(pAdapter, &snr);
9141 wlan_hdd_get_rssi(pAdapter, &rssi);
9142
9143 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9144 hdd_wlan_get_freq(channel, &freq);
9145
9146
9147 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9148 {
9149 if (NULL == wiphy->bands[i])
9150 {
9151 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9152 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9153 continue;
9154 }
9155
9156 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9157 {
9158 struct ieee80211_supported_band *band = wiphy->bands[i];
9159
9160 if (band->channels[j].center_freq == (v_U16_t)freq)
9161 {
9162 survey->channel = &band->channels[j];
9163 /* The Rx BDs contain SNR values in dB for the received frames
9164 * while the supplicant expects noise. So we calculate and
9165 * return the value of noise (dBm)
9166 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9167 */
9168 survey->noise = rssi - snr;
9169 survey->filled = SURVEY_INFO_NOISE_DBM;
9170 filled = 1;
9171 }
9172 }
9173 }
9174
9175 if (filled)
9176 pAdapter->survey_idx = 1;
9177 else
9178 {
9179 pAdapter->survey_idx = 0;
9180 return -ENONET;
9181 }
9182
9183 return 0;
9184}
9185
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309186/*
9187 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9188 * this is called when cfg80211 driver resume
9189 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9190 */
9191int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9192{
9193 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9194 hdd_adapter_t *pAdapter;
9195 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9196 VOS_STATUS status = VOS_STATUS_SUCCESS;
9197
9198 ENTER();
9199
9200 if ( NULL == pHddCtx )
9201 {
9202 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9203 "%s: HddCtx validation failed", __func__);
9204 return 0;
9205 }
9206
9207 if (pHddCtx->isLogpInProgress)
9208 {
9209 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9210 "%s: LOGP in Progress. Ignore!!!", __func__);
9211 return 0;
9212 }
9213
9214 if (pHddCtx->isLoadUnloadInProgress)
9215 {
9216 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9217 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9218 return 0;
9219 }
9220
9221 spin_lock(&pHddCtx->schedScan_lock);
9222 pHddCtx->isWiphySuspended = FALSE;
9223 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9224 {
9225 spin_unlock(&pHddCtx->schedScan_lock);
9226 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9227 "%s: Return resume is not due to PNO indication", __func__);
9228 return 0;
9229 }
9230 // Reset flag to avoid updatating cfg80211 data old results again
9231 pHddCtx->isSchedScanUpdatePending = FALSE;
9232 spin_unlock(&pHddCtx->schedScan_lock);
9233
9234 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9235
9236 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9237 {
9238 pAdapter = pAdapterNode->pAdapter;
9239 if ( (NULL != pAdapter) &&
9240 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9241 {
9242 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
9243 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9244 "%s: NO SCAN result", __func__);
9245 else
9246 cfg80211_sched_scan_results(pHddCtx->wiphy);
9247
9248 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9249 "%s : cfg80211 scan result database updated", __func__);
9250
9251 return 0;
9252
9253 }
9254 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9255 pAdapterNode = pNext;
9256 }
9257
9258 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9259 "%s: Failed to find Adapter", __func__);
9260 return 0;
9261}
9262
9263/*
9264 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9265 * this is called when cfg80211 driver suspends
9266 */
9267int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9268 struct cfg80211_wowlan *wow)
9269{
9270 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9271
9272 ENTER();
9273 if (NULL == pHddCtx)
9274 {
9275 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9276 "%s: HddCtx validation failed", __func__);
9277 return 0;
9278 }
9279
9280 pHddCtx->isWiphySuspended = TRUE;
9281
9282 EXIT();
9283
9284 return 0;
9285}
9286
Jeff Johnson295189b2012-06-20 16:38:30 -07009287/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309288static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009289{
9290 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9291 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9292 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9293 .change_station = wlan_hdd_change_station,
9294#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9295 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9296 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9297 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009298#else
9299 .start_ap = wlan_hdd_cfg80211_start_ap,
9300 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9301 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009302#endif
9303 .change_bss = wlan_hdd_cfg80211_change_bss,
9304 .add_key = wlan_hdd_cfg80211_add_key,
9305 .get_key = wlan_hdd_cfg80211_get_key,
9306 .del_key = wlan_hdd_cfg80211_del_key,
9307 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009308#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009309 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009310#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009311 .scan = wlan_hdd_cfg80211_scan,
9312 .connect = wlan_hdd_cfg80211_connect,
9313 .disconnect = wlan_hdd_cfg80211_disconnect,
9314 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9315 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9316 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9317 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9318 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009319 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9320 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9321 .mgmt_tx = wlan_hdd_action,
9322#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9323 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9324 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9325 .set_txq_params = wlan_hdd_set_txq_params,
9326#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009327 .get_station = wlan_hdd_cfg80211_get_station,
9328 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9329 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009330 .add_station = wlan_hdd_cfg80211_add_station,
9331#ifdef FEATURE_WLAN_LFR
9332 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9333 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9334 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9335#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009336#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9337 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9338#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009339#ifdef FEATURE_WLAN_TDLS
9340 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9341 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9342#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309343#ifdef WLAN_FEATURE_GTK_OFFLOAD
9344 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9345#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309346#ifdef FEATURE_WLAN_SCAN_PNO
9347 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9348 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9349#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309350 .resume = wlan_hdd_cfg80211_resume_wlan,
9351 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309352 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009353#ifdef WLAN_NL80211_TESTMODE
9354 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9355#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309356 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009357};
9358