blob: 0666ba17b382b598547137dd1afc971dafbbaa37 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Wilson Yangef657d32014-01-15 19:19:23 -08002 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20*/
Jeff Johnson295189b2012-06-20 16:38:30 -070021
22/**========================================================================
23
24 \file wlan_hdd_cfg80211.c
25
26 \brief WLAN Host Device Driver implementation
27
Gopichand Nakkala747461f2013-04-24 19:24:45 +053028 Copyright 2008 (c) Qualcomm Technologies, Inc. All Rights Reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070029
Gopichand Nakkala747461f2013-04-24 19:24:45 +053030 Qualcomm Technologies Confidential and Proprietary.
Jeff Johnson295189b2012-06-20 16:38:30 -070031
32 ========================================================================*/
33
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070034/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070036 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070039 This section contains comments describing changes made to the module.
40 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070044
45
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070046 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070047 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070048 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
50 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070051 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070052 ==========================================================================*/
53
Jeff Johnson295189b2012-06-20 16:38:30 -070054
55#include <linux/version.h>
56#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
59#include <linux/wireless.h>
60#include <wlan_hdd_includes.h>
61#include <net/arp.h>
62#include <net/cfg80211.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_wowl.h>
65#include <aniGlobal.h>
66#include "ccmApi.h"
67#include "sirParams.h"
68#include "dot11f.h"
69#include "wlan_hdd_assoc.h"
70#include "wlan_hdd_wext.h"
71#include "sme_Api.h"
72#include "wlan_hdd_p2p.h"
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_hostapd.h"
75#include "sapInternal.h"
76#include "wlan_hdd_softap_tx_rx.h"
77#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053078#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053079#include "wlan_hdd_power.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070080#ifdef WLAN_BTAMP_FEATURE
81#include "bap_hdd_misc.h"
82#endif
83#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080084#ifdef FEATURE_WLAN_TDLS
85#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053086#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053087#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080088#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053089#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070090#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070091
92#define g_mode_rates_size (12)
93#define a_mode_rates_size (8)
94#define FREQ_BASE_80211G (2407)
95#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070096#define MAX_SCAN_SSID 9
Kiet Lamac06e2c2013-10-23 16:25:07 +053097#define MAX_PENDING_LOG 5
Jeff Johnson295189b2012-06-20 16:38:30 -070098#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
99 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
100
101#define HDD2GHZCHAN(freq, chan, flag) { \
102 .band = IEEE80211_BAND_2GHZ, \
103 .center_freq = (freq), \
104 .hw_value = (chan),\
105 .flags = (flag), \
106 .max_antenna_gain = 0 ,\
107 .max_power = 30, \
108}
109
110#define HDD5GHZCHAN(freq, chan, flag) { \
111 .band = IEEE80211_BAND_5GHZ, \
112 .center_freq = (freq), \
113 .hw_value = (chan),\
114 .flags = (flag), \
115 .max_antenna_gain = 0 ,\
116 .max_power = 30, \
117}
118
119#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
120{\
121 .bitrate = rate, \
122 .hw_value = rate_id, \
123 .flags = flag, \
124}
125
Lee Hoonkic1262f22013-01-24 21:59:00 -0800126#ifndef WLAN_FEATURE_TDLS_DEBUG
127#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
128#else
129#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
130#endif
131
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530132#ifdef WLAN_FEATURE_VOWIFI_11R
133#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
134#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
135#endif
136
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530137static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700138{
139 WLAN_CIPHER_SUITE_WEP40,
140 WLAN_CIPHER_SUITE_WEP104,
141 WLAN_CIPHER_SUITE_TKIP,
142#ifdef FEATURE_WLAN_CCX
143#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
144 WLAN_CIPHER_SUITE_KRK,
145 WLAN_CIPHER_SUITE_CCMP,
146#else
147 WLAN_CIPHER_SUITE_CCMP,
148#endif
149#ifdef FEATURE_WLAN_WAPI
150 WLAN_CIPHER_SUITE_SMS4,
151#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700152#ifdef WLAN_FEATURE_11W
153 WLAN_CIPHER_SUITE_AES_CMAC,
154#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700155};
156
157static inline int is_broadcast_ether_addr(const u8 *addr)
158{
159 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
160 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
161}
162
163static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530164{
Jeff Johnson295189b2012-06-20 16:38:30 -0700165 HDD2GHZCHAN(2412, 1, 0) ,
166 HDD2GHZCHAN(2417, 2, 0) ,
167 HDD2GHZCHAN(2422, 3, 0) ,
168 HDD2GHZCHAN(2427, 4, 0) ,
169 HDD2GHZCHAN(2432, 5, 0) ,
170 HDD2GHZCHAN(2437, 6, 0) ,
171 HDD2GHZCHAN(2442, 7, 0) ,
172 HDD2GHZCHAN(2447, 8, 0) ,
173 HDD2GHZCHAN(2452, 9, 0) ,
174 HDD2GHZCHAN(2457, 10, 0) ,
175 HDD2GHZCHAN(2462, 11, 0) ,
176 HDD2GHZCHAN(2467, 12, 0) ,
177 HDD2GHZCHAN(2472, 13, 0) ,
178 HDD2GHZCHAN(2484, 14, 0) ,
179};
180
Jeff Johnson295189b2012-06-20 16:38:30 -0700181static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
182{
183 HDD2GHZCHAN(2412, 1, 0) ,
184 HDD2GHZCHAN(2437, 6, 0) ,
185 HDD2GHZCHAN(2462, 11, 0) ,
186};
Jeff Johnson295189b2012-06-20 16:38:30 -0700187
188static struct ieee80211_channel hdd_channels_5_GHZ[] =
189{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700190 HDD5GHZCHAN(4920, 240, 0) ,
191 HDD5GHZCHAN(4940, 244, 0) ,
192 HDD5GHZCHAN(4960, 248, 0) ,
193 HDD5GHZCHAN(4980, 252, 0) ,
194 HDD5GHZCHAN(5040, 208, 0) ,
195 HDD5GHZCHAN(5060, 212, 0) ,
196 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700197 HDD5GHZCHAN(5180, 36, 0) ,
198 HDD5GHZCHAN(5200, 40, 0) ,
199 HDD5GHZCHAN(5220, 44, 0) ,
200 HDD5GHZCHAN(5240, 48, 0) ,
201 HDD5GHZCHAN(5260, 52, 0) ,
202 HDD5GHZCHAN(5280, 56, 0) ,
203 HDD5GHZCHAN(5300, 60, 0) ,
204 HDD5GHZCHAN(5320, 64, 0) ,
205 HDD5GHZCHAN(5500,100, 0) ,
206 HDD5GHZCHAN(5520,104, 0) ,
207 HDD5GHZCHAN(5540,108, 0) ,
208 HDD5GHZCHAN(5560,112, 0) ,
209 HDD5GHZCHAN(5580,116, 0) ,
210 HDD5GHZCHAN(5600,120, 0) ,
211 HDD5GHZCHAN(5620,124, 0) ,
212 HDD5GHZCHAN(5640,128, 0) ,
213 HDD5GHZCHAN(5660,132, 0) ,
214 HDD5GHZCHAN(5680,136, 0) ,
215 HDD5GHZCHAN(5700,140, 0) ,
Leo Chang80de3c22013-11-26 10:52:12 -0800216#ifdef FEATURE_WLAN_CH144
217 HDD5GHZCHAN(5720,144, 0) ,
218#endif /* FEATURE_WLAN_CH144 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700219 HDD5GHZCHAN(5745,149, 0) ,
220 HDD5GHZCHAN(5765,153, 0) ,
221 HDD5GHZCHAN(5785,157, 0) ,
222 HDD5GHZCHAN(5805,161, 0) ,
223 HDD5GHZCHAN(5825,165, 0) ,
224};
225
226static struct ieee80211_rate g_mode_rates[] =
227{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530228 HDD_G_MODE_RATETAB(10, 0x1, 0),
229 HDD_G_MODE_RATETAB(20, 0x2, 0),
230 HDD_G_MODE_RATETAB(55, 0x4, 0),
231 HDD_G_MODE_RATETAB(110, 0x8, 0),
232 HDD_G_MODE_RATETAB(60, 0x10, 0),
233 HDD_G_MODE_RATETAB(90, 0x20, 0),
234 HDD_G_MODE_RATETAB(120, 0x40, 0),
235 HDD_G_MODE_RATETAB(180, 0x80, 0),
236 HDD_G_MODE_RATETAB(240, 0x100, 0),
237 HDD_G_MODE_RATETAB(360, 0x200, 0),
238 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530240};
Jeff Johnson295189b2012-06-20 16:38:30 -0700241
242static struct ieee80211_rate a_mode_rates[] =
243{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530244 HDD_G_MODE_RATETAB(60, 0x10, 0),
245 HDD_G_MODE_RATETAB(90, 0x20, 0),
246 HDD_G_MODE_RATETAB(120, 0x40, 0),
247 HDD_G_MODE_RATETAB(180, 0x80, 0),
248 HDD_G_MODE_RATETAB(240, 0x100, 0),
249 HDD_G_MODE_RATETAB(360, 0x200, 0),
250 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700251 HDD_G_MODE_RATETAB(540, 0x800, 0),
252};
253
254static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
255{
256 .channels = hdd_channels_2_4_GHZ,
257 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
258 .band = IEEE80211_BAND_2GHZ,
259 .bitrates = g_mode_rates,
260 .n_bitrates = g_mode_rates_size,
261 .ht_cap.ht_supported = 1,
262 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
263 | IEEE80211_HT_CAP_GRN_FLD
264 | IEEE80211_HT_CAP_DSSSCCK40
265 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
266 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
267 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
268 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
269 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
270 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
271};
272
Jeff Johnson295189b2012-06-20 16:38:30 -0700273static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
274{
275 .channels = hdd_social_channels_2_4_GHZ,
276 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
277 .band = IEEE80211_BAND_2GHZ,
278 .bitrates = g_mode_rates,
279 .n_bitrates = g_mode_rates_size,
280 .ht_cap.ht_supported = 1,
281 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
282 | IEEE80211_HT_CAP_GRN_FLD
283 | IEEE80211_HT_CAP_DSSSCCK40
284 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
285 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
286 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
287 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
288 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
289 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
290};
Jeff Johnson295189b2012-06-20 16:38:30 -0700291
292static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
293{
294 .channels = hdd_channels_5_GHZ,
295 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
296 .band = IEEE80211_BAND_5GHZ,
297 .bitrates = a_mode_rates,
298 .n_bitrates = a_mode_rates_size,
299 .ht_cap.ht_supported = 1,
300 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
301 | IEEE80211_HT_CAP_GRN_FLD
302 | IEEE80211_HT_CAP_DSSSCCK40
303 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
304 | IEEE80211_HT_CAP_SGI_40
305 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
306 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
307 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
308 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
309 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
310 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
311};
312
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530313/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 TX/RX direction for each kind of interface */
315static const struct ieee80211_txrx_stypes
316wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
317 [NL80211_IFTYPE_STATION] = {
318 .tx = 0xffff,
319 .rx = BIT(SIR_MAC_MGMT_ACTION) |
320 BIT(SIR_MAC_MGMT_PROBE_REQ),
321 },
322 [NL80211_IFTYPE_AP] = {
323 .tx = 0xffff,
324 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
325 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
326 BIT(SIR_MAC_MGMT_PROBE_REQ) |
327 BIT(SIR_MAC_MGMT_DISASSOC) |
328 BIT(SIR_MAC_MGMT_AUTH) |
329 BIT(SIR_MAC_MGMT_DEAUTH) |
330 BIT(SIR_MAC_MGMT_ACTION),
331 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700332 [NL80211_IFTYPE_ADHOC] = {
333 .tx = 0xffff,
334 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
335 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
336 BIT(SIR_MAC_MGMT_PROBE_REQ) |
337 BIT(SIR_MAC_MGMT_DISASSOC) |
338 BIT(SIR_MAC_MGMT_AUTH) |
339 BIT(SIR_MAC_MGMT_DEAUTH) |
340 BIT(SIR_MAC_MGMT_ACTION),
341 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700342 [NL80211_IFTYPE_P2P_CLIENT] = {
343 .tx = 0xffff,
344 .rx = BIT(SIR_MAC_MGMT_ACTION) |
345 BIT(SIR_MAC_MGMT_PROBE_REQ),
346 },
347 [NL80211_IFTYPE_P2P_GO] = {
348 /* This is also same as for SoftAP */
349 .tx = 0xffff,
350 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
351 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
352 BIT(SIR_MAC_MGMT_PROBE_REQ) |
353 BIT(SIR_MAC_MGMT_DISASSOC) |
354 BIT(SIR_MAC_MGMT_AUTH) |
355 BIT(SIR_MAC_MGMT_DEAUTH) |
356 BIT(SIR_MAC_MGMT_ACTION),
357 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700358};
359
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800360#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800361static const struct ieee80211_iface_limit
362wlan_hdd_iface_limit[] = {
363 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800364 /* max = 3 ; Our driver create two interfaces during driver init
365 * wlan0 and p2p0 interfaces. p2p0 is considered as station
366 * interface until a group is formed. In JB architecture, once the
367 * group is formed, interface type of p2p0 is changed to P2P GO or
368 * Client.
369 * When supplicant remove the group, it first issue a set interface
370 * cmd to change the mode back to Station. In JB this works fine as
371 * we advertize two station type interface during driver init.
372 * Some vendors create separate interface for P2P GO/Client,
373 * after group formation(Third one). But while group remove
374 * supplicant first tries to change the mode(3rd interface) to STATION
375 * But as we advertized only two sta type interfaces nl80211 was
376 * returning error for the third one which was leading to failure in
377 * delete interface. Ideally while removing the group, supplicant
378 * should not try to change the 3rd interface mode to Station type.
379 * Till we get a fix in wpa_supplicant, we advertize max STA
380 * interface type to 3
381 */
382 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800383 .types = BIT(NL80211_IFTYPE_STATION),
384 },
385 {
386 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700387 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800388 },
389 {
390 .max = 1,
391 .types = BIT(NL80211_IFTYPE_P2P_GO) |
392 BIT(NL80211_IFTYPE_P2P_CLIENT),
393 },
394};
395
396/* By default, only single channel concurrency is allowed */
397static struct ieee80211_iface_combination
398wlan_hdd_iface_combination = {
399 .limits = wlan_hdd_iface_limit,
400 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800401 /*
402 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
403 * and p2p0 interfaces during driver init
404 * Some vendors create separate interface for P2P operations.
405 * wlan0: STA interface
406 * p2p0: P2P Device interface, action frames goes
407 * through this interface.
408 * p2p-xx: P2P interface, After GO negotiation this interface is
409 * created for p2p operations(GO/CLIENT interface).
410 */
411 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800412 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
413 .beacon_int_infra_match = false,
414};
415#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800416
Jeff Johnson295189b2012-06-20 16:38:30 -0700417static struct cfg80211_ops wlan_hdd_cfg80211_ops;
418
419/* Data rate 100KBPS based on IE Index */
420struct index_data_rate_type
421{
422 v_U8_t beacon_rate_index;
423 v_U16_t supported_rate[4];
424};
425
426/* 11B, 11G Rate table include Basic rate and Extended rate
427 The IDX field is the rate index
428 The HI field is the rate when RSSI is strong or being ignored
429 (in this case we report actual rate)
430 The MID field is the rate when RSSI is moderate
431 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
432 The LO field is the rate when RSSI is low
433 (in this case we don't report rates, actual current rate used)
434 */
435static const struct
436{
437 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700438 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700439} supported_data_rate[] =
440{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700441/* IDX HI HM LM LO (RSSI-based index */
442 {2, { 10, 10, 10, 0}},
443 {4, { 20, 20, 10, 0}},
444 {11, { 55, 20, 10, 0}},
445 {12, { 60, 55, 20, 0}},
446 {18, { 90, 55, 20, 0}},
447 {22, {110, 55, 20, 0}},
448 {24, {120, 90, 60, 0}},
449 {36, {180, 120, 60, 0}},
450 {44, {220, 180, 60, 0}},
451 {48, {240, 180, 90, 0}},
452 {66, {330, 180, 90, 0}},
453 {72, {360, 240, 90, 0}},
454 {96, {480, 240, 120, 0}},
455 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700456};
457
458/* MCS Based rate table */
459static struct index_data_rate_type supported_mcs_rate[] =
460{
461/* MCS L20 L40 S20 S40 */
462 {0, {65, 135, 72, 150}},
463 {1, {130, 270, 144, 300}},
464 {2, {195, 405, 217, 450}},
465 {3, {260, 540, 289, 600}},
466 {4, {390, 810, 433, 900}},
467 {5, {520, 1080, 578, 1200}},
468 {6, {585, 1215, 650, 1350}},
469 {7, {650, 1350, 722, 1500}}
470};
471
Leo Chang6f8870f2013-03-26 18:11:36 -0700472#ifdef WLAN_FEATURE_11AC
473
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530474#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700475
476struct index_vht_data_rate_type
477{
478 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530479 v_U16_t supported_VHT80_rate[2];
480 v_U16_t supported_VHT40_rate[2];
481 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700482};
483
484typedef enum
485{
486 DATA_RATE_11AC_MAX_MCS_7,
487 DATA_RATE_11AC_MAX_MCS_8,
488 DATA_RATE_11AC_MAX_MCS_9,
489 DATA_RATE_11AC_MAX_MCS_NA
490} eDataRate11ACMaxMcs;
491
492/* MCS Based VHT rate table */
493static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
494{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530495/* MCS L80 S80 L40 S40 L20 S40*/
496 {0, {293, 325}, {135, 150}, {65, 72}},
497 {1, {585, 650}, {270, 300}, {130, 144}},
498 {2, {878, 975}, {405, 450}, {195, 217}},
499 {3, {1170, 1300}, {540, 600}, {260, 289}},
500 {4, {1755, 1950}, {810, 900}, {390, 433}},
501 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
502 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
503 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
504 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
505 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700506};
507#endif /* WLAN_FEATURE_11AC */
508
Jeff Johnson295189b2012-06-20 16:38:30 -0700509extern struct net_device_ops net_ops_struct;
510
Leo Chang9056f462013-08-01 19:21:11 -0700511#ifdef WLAN_NL80211_TESTMODE
512enum wlan_hdd_tm_attr
513{
514 WLAN_HDD_TM_ATTR_INVALID = 0,
515 WLAN_HDD_TM_ATTR_CMD = 1,
516 WLAN_HDD_TM_ATTR_DATA = 2,
517 WLAN_HDD_TM_ATTR_TYPE = 3,
518 /* keep last */
519 WLAN_HDD_TM_ATTR_AFTER_LAST,
520 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
521};
522
523enum wlan_hdd_tm_cmd
524{
525 WLAN_HDD_TM_CMD_WLAN_HB = 1,
526};
527
528#define WLAN_HDD_TM_DATA_MAX_LEN 5000
529
530static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
531{
532 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
533 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
534 .len = WLAN_HDD_TM_DATA_MAX_LEN },
535};
536#endif /* WLAN_NL80211_TESTMODE */
537
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800538#ifdef FEATURE_WLAN_CH_AVOID
539/*
540 * FUNCTION: wlan_hdd_send_avoid_freq_event
541 * This is called when wlan driver needs to send vendor specific
542 * avoid frequency range event to userspace
543 */
544int wlan_hdd_send_avoid_freq_event(hdd_context_t *pHddCtx,
545 tHddAvoidFreqList *pAvoidFreqList)
546{
547 struct sk_buff *vendor_event;
548
549 ENTER();
550
551 if (!pHddCtx)
552 {
553 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
554 "%s: HDD context is null", __func__);
555 return -1;
556 }
557
558 if (!pAvoidFreqList)
559 {
560 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
561 "%s: pAvoidFreqList is null", __func__);
562 return -1;
563 }
564
565 vendor_event = cfg80211_vendor_event_alloc(pHddCtx->wiphy,
566 sizeof(tHddAvoidFreqList),
567 QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX,
568 GFP_KERNEL);
569 if (!vendor_event)
570 {
571 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
572 "%s: cfg80211_vendor_event_alloc failed", __func__);
573 return -1;
574 }
575
576 memcpy(skb_put(vendor_event, sizeof(tHddAvoidFreqList)),
577 (void *)pAvoidFreqList, sizeof(tHddAvoidFreqList));
578
579 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
580
581 EXIT();
582 return 0;
583}
584#endif /* FEATURE_WLAN_CH_AVOID */
585
586/* vendor specific events */
587static const struct nl80211_vendor_cmd_info wlan_hdd_cfg80211_vendor_events[] =
588{
589#ifdef FEATURE_WLAN_CH_AVOID
590 {
591 .vendor_id = QCOM_NL80211_VENDOR_ID,
592 .subcmd = QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY
593 },
594#endif /* FEATURE_WLAN_CH_AVOID */
595};
596
Jeff Johnson295189b2012-06-20 16:38:30 -0700597/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530598 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530599 * This function is called by hdd_wlan_startup()
600 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530601 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700602 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530603struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700604{
605 struct wiphy *wiphy;
606 ENTER();
607
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530608 /*
609 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700610 */
611 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
612
613 if (!wiphy)
614 {
615 /* Print error and jump into err label and free the memory */
616 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
617 return NULL;
618 }
619
620 return wiphy;
621}
622
623/*
624 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530625 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 * private ioctl to change the band value
627 */
628int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
629{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530630 int i, j;
631 eNVChannelEnabledType channelEnabledState;
632
Jeff Johnsone7245742012-09-05 17:12:55 -0700633 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530634 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700635 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530636
637 if (NULL == wiphy->bands[i])
638 {
639 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
640 __func__, i);
641 continue;
642 }
643
644 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
645 {
646 struct ieee80211_supported_band *band = wiphy->bands[i];
647
648 channelEnabledState = vos_nv_getChannelEnabledState(
649 band->channels[j].hw_value);
650
651 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
652 {
653 // Enable Social channels for P2P
654 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
655 NV_CHANNEL_ENABLE == channelEnabledState)
656 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
657 else
658 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
659 continue;
660 }
661 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
662 {
663 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
664 continue;
665 }
666
667 if (NV_CHANNEL_DISABLE == channelEnabledState ||
668 NV_CHANNEL_INVALID == channelEnabledState)
669 {
670 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
671 }
672 else if (NV_CHANNEL_DFS == channelEnabledState)
673 {
674 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
675 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
676 }
677 else
678 {
679 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
680 |IEEE80211_CHAN_RADAR);
681 }
682 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700683 }
684 return 0;
685}
686/*
687 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530688 * This function is called by hdd_wlan_startup()
689 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700690 * This function is used to initialize and register wiphy structure.
691 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530692int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700693 struct wiphy *wiphy,
694 hdd_config_t *pCfg
695 )
696{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530697 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700698 ENTER();
699
Jeff Johnson295189b2012-06-20 16:38:30 -0700700 /* Now bind the underlying wlan device with wiphy */
701 set_wiphy_dev(wiphy, dev);
702
703 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700704
Kiet Lam6c583332013-10-14 05:37:09 +0530705#ifndef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -0700706 /* the flag for the other case would be initialzed in
707 vos_init_wiphy_from_nv_bin */
Amar Singhal0a402232013-10-11 20:57:16 -0700708 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
Kiet Lam6c583332013-10-14 05:37:09 +0530709#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700710
Amar Singhalfddc28c2013-09-05 13:03:40 -0700711 /* This will disable updating of NL channels from passive to
712 * active if a beacon is received on passive channel. */
713 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700714
Amar Singhalfddc28c2013-09-05 13:03:40 -0700715
Amar Singhala49cbc52013-10-08 18:37:44 -0700716
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700717#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700718 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
719 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
720 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700721 | WIPHY_FLAG_OFFCHAN_TX;
Kiet Lam6c583332013-10-14 05:37:09 +0530722 wiphy->country_ie_pref = NL80211_COUNTRY_IE_IGNORE_CORE;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700723#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700724
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700725#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
726 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800727#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700728 || pCfg->isFastRoamIniFeatureEnabled
729#endif
730#ifdef FEATURE_WLAN_CCX
731 || pCfg->isCcxIniFeatureEnabled
732#endif
733 )
734 {
735 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
736 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800737#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800738#ifdef FEATURE_WLAN_TDLS
739 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
740 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
741#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530742#ifdef FEATURE_WLAN_SCAN_PNO
Hardik Kantilal Patel3dfd8792013-11-13 20:34:57 +0530743 if (pCfg->configPNOScanSupport)
744 {
745 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
746 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
747 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
748 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
749 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530750#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800751
Amar Singhalfddc28c2013-09-05 13:03:40 -0700752#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700753 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
754 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700755 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700756 driver need to determine what to do with both
757 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700758
759 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700760#else
761 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700762#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700763
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530764 wiphy->max_scan_ssids = MAX_SCAN_SSID;
765
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530766 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700767
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530768 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
769
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530771 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 | BIT(NL80211_IFTYPE_P2P_CLIENT)
774 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700775 | BIT(NL80211_IFTYPE_AP);
776
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800777#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800778 if( pCfg->enableMCC )
779 {
780 /* Currently, supports up to two channels */
781 wlan_hdd_iface_combination.num_different_channels = 2;
782
783 if( !pCfg->allowMCCGODiffBI )
784 wlan_hdd_iface_combination.beacon_int_infra_match = true;
785
786 }
787 wiphy->iface_combinations = &wlan_hdd_iface_combination;
788 wiphy->n_iface_combinations = 1;
789#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800790
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 /* Before registering we need to update the ht capabilitied based
792 * on ini values*/
793 if( !pCfg->ShortGI20MhzEnable )
794 {
795 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
796 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
797 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
798 }
799
800 if( !pCfg->ShortGI40MhzEnable )
801 {
802 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
803 }
804
805 if( !pCfg->nChannelBondingMode5GHz )
806 {
807 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
808 }
809
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530810 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
811 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
812
813 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
814 {
815
816 if (NULL == wiphy->bands[i])
817 {
818 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
819 __func__, i);
820 continue;
821 }
822
823 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
824 {
825 struct ieee80211_supported_band *band = wiphy->bands[i];
826
827 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
828 {
829 // Enable social channels for P2P
830 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
831 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
832 else
833 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
834 continue;
835 }
836 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
837 {
838 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
839 continue;
840 }
841 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700842 }
843 /*Initialise the supported cipher suite details*/
844 wiphy->cipher_suites = hdd_cipher_suites;
845 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
846
847 /*signal strength in mBm (100*dBm) */
848 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
849
850#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700851 wiphy->max_remain_on_channel_duration = 1000;
852#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700853
Rajesh Chauhan98a31f82014-01-06 20:15:25 -0800854 wiphy->n_vendor_commands = 0;
855 wiphy->vendor_events = wlan_hdd_cfg80211_vendor_events;
856 wiphy->n_vendor_events = ARRAY_SIZE(wlan_hdd_cfg80211_vendor_events);
857
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530858 EXIT();
859 return 0;
860}
861
862/* In this function we are registering wiphy. */
863int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
864{
865 ENTER();
866 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700867 if (0 > wiphy_register(wiphy))
868 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530869 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
871 return -EIO;
872 }
873
874 EXIT();
875 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530876}
Jeff Johnson295189b2012-06-20 16:38:30 -0700877
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530878/* In this function we are updating channel list when,
879 regulatory domain is FCC and country code is US.
880 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
881 As per FCC smart phone is not a indoor device.
882 GO should not opeate on indoor channels */
883void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
884{
885 int j;
886 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
887 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
888 //Default counrtycode from NV at the time of wiphy initialization.
889 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
890 &defaultCountryCode[0]))
891 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -0700892 hddLog(LOGE, FL("Failed to get default country code from NV"));
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530893 }
894 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
895 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530896 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
897 {
898 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
899 return;
900 }
901 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
902 {
903 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
904 // Mark UNII -1 band channel as passive
905 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
906 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
907 }
908 }
909}
910
Jeff Johnson295189b2012-06-20 16:38:30 -0700911/* In this function we will do all post VOS start initialization.
912 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530913 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700914*/
915void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
916{
Jeff Johnson295189b2012-06-20 16:38:30 -0700917 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
918 /* Register for all P2P action, public action etc frames */
919 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
920
Jeff Johnsone7245742012-09-05 17:12:55 -0700921 ENTER();
922
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 /* Right now we are registering these frame when driver is getting
924 initialized. Once we will move to 2.6.37 kernel, in which we have
925 frame register ops, we will move this code as a part of that */
926 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530927 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700928 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
929
930 /* GAS Initial Response */
931 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
932 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530933
Jeff Johnson295189b2012-06-20 16:38:30 -0700934 /* GAS Comeback Request */
935 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
936 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
937
938 /* GAS Comeback Response */
939 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
940 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
941
942 /* P2P Public Action */
943 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530944 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 P2P_PUBLIC_ACTION_FRAME_SIZE );
946
947 /* P2P Action */
948 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
949 (v_U8_t*)P2P_ACTION_FRAME,
950 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700951
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530952 /* WNM BSS Transition Request frame */
953 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
954 (v_U8_t*)WNM_BSS_ACTION_FRAME,
955 WNM_BSS_ACTION_FRAME_SIZE );
956
Chet Lanctot186b5732013-03-18 10:26:30 -0700957#ifdef WLAN_FEATURE_11W
958 /* SA Query Response Action Frame */
959 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
960 (v_U8_t*)SA_QUERY_FRAME_RSP,
961 SA_QUERY_FRAME_RSP_SIZE );
962#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700963}
964
965void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
966{
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
968 /* Register for all P2P action, public action etc frames */
969 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
970
Jeff Johnsone7245742012-09-05 17:12:55 -0700971 ENTER();
972
Jeff Johnson295189b2012-06-20 16:38:30 -0700973 /* Right now we are registering these frame when driver is getting
974 initialized. Once we will move to 2.6.37 kernel, in which we have
975 frame register ops, we will move this code as a part of that */
976 /* GAS Initial Request */
977
978 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
979 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
980
981 /* GAS Initial Response */
982 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
983 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530984
Jeff Johnson295189b2012-06-20 16:38:30 -0700985 /* GAS Comeback Request */
986 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
987 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
988
989 /* GAS Comeback Response */
990 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
991 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
992
993 /* P2P Public Action */
994 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530995 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700996 P2P_PUBLIC_ACTION_FRAME_SIZE );
997
998 /* P2P Action */
999 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1000 (v_U8_t*)P2P_ACTION_FRAME,
1001 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -07001002
1003#ifdef WLAN_FEATURE_11W
1004 /* SA Query Response Action Frame */
1005 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
1006 (v_U8_t*)SA_QUERY_FRAME_RSP,
1007 SA_QUERY_FRAME_RSP_SIZE );
1008#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -07001009}
1010
1011#ifdef FEATURE_WLAN_WAPI
1012void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
1013 const u8 *mac_addr, u8 *key , int key_Len)
1014{
1015 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1016 tCsrRoamSetKey setKey;
1017 v_BOOL_t isConnected = TRUE;
1018 int status = 0;
1019 v_U32_t roamId= 0xFF;
1020 tANI_U8 *pKeyPtr = NULL;
1021 int n = 0;
1022
Arif Hussain6d2a3322013-11-17 19:50:10 -08001023 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07001024 __func__,pAdapter->device_mode);
1025
Gopichand Nakkalae7480202013-02-11 15:24:22 +05301026 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07001027 setKey.keyId = key_index; // Store Key ID
1028 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
1029 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
1030 setKey.paeRole = 0 ; // the PAE role
1031 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
1032 {
1033 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
1034 }
1035 else
1036 {
1037 isConnected = hdd_connIsConnected(pHddStaCtx);
1038 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
1039 }
1040 setKey.keyLength = key_Len;
1041 pKeyPtr = setKey.Key;
1042 memcpy( pKeyPtr, key, key_Len);
1043
Arif Hussain6d2a3322013-11-17 19:50:10 -08001044 hddLog(VOS_TRACE_LEVEL_INFO,"%s: WAPI KEY LENGTH:0x%04x",
Jeff Johnson295189b2012-06-20 16:38:30 -07001045 __func__, key_Len);
1046 for (n = 0 ; n < key_Len; n++)
1047 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
1048 __func__,n,setKey.Key[n]);
1049
1050 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
1051 if ( isConnected )
1052 {
1053 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
1054 pAdapter->sessionId, &setKey, &roamId );
1055 }
1056 if ( status != 0 )
1057 {
1058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1059 "[%4d] sme_RoamSetKey returned ERROR status= %d",
1060 __LINE__, status );
1061 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
1062 }
1063}
1064#endif /* FEATURE_WLAN_WAPI*/
1065
1066#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301067int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07001068 beacon_data_t **ppBeacon,
1069 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001070#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301071int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001072 beacon_data_t **ppBeacon,
1073 struct cfg80211_beacon_data *params,
1074 int dtim_period)
1075#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301076{
Jeff Johnson295189b2012-06-20 16:38:30 -07001077 int size;
1078 beacon_data_t *beacon = NULL;
1079 beacon_data_t *old = NULL;
1080 int head_len,tail_len;
1081
Jeff Johnsone7245742012-09-05 17:12:55 -07001082 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001083 if (params->head && !params->head_len)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301084 {
1085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1086 FL("head_len is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301088 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001089
1090 old = pAdapter->sessionCtx.ap.beacon;
1091
1092 if (!params->head && !old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301093 {
1094 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1095 FL("session(%d) old and new heads points to NULL"),
1096 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07001097 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301098 }
1099
1100 if (params->tail && !params->tail_len)
1101 {
1102 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1103 FL("tail_len is zero but tail is not NULL"));
1104 return -EINVAL;
1105 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001106
Jeff Johnson295189b2012-06-20 16:38:30 -07001107#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1108 /* Kernel 3.0 is not updating dtim_period for set beacon */
1109 if (!params->dtim_period)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301110 {
1111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1112 FL("dtim period is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001113 return -EINVAL;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301114 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001115#endif
1116
1117 if(params->head)
1118 head_len = params->head_len;
1119 else
1120 head_len = old->head_len;
1121
1122 if(params->tail || !old)
1123 tail_len = params->tail_len;
1124 else
1125 tail_len = old->tail_len;
1126
1127 size = sizeof(beacon_data_t) + head_len + tail_len;
1128
1129 beacon = kzalloc(size, GFP_KERNEL);
1130
1131 if( beacon == NULL )
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301132 {
1133 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1134 FL("Mem allocation for beacon failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 return -ENOMEM;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301136 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001137
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001138#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001139 if(params->dtim_period || !old )
1140 beacon->dtim_period = params->dtim_period;
1141 else
1142 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001143#else
1144 if(dtim_period || !old )
1145 beacon->dtim_period = dtim_period;
1146 else
1147 beacon->dtim_period = old->dtim_period;
1148#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301149
Jeff Johnson295189b2012-06-20 16:38:30 -07001150 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1151 beacon->tail = beacon->head + head_len;
1152 beacon->head_len = head_len;
1153 beacon->tail_len = tail_len;
1154
1155 if(params->head) {
1156 memcpy (beacon->head,params->head,beacon->head_len);
1157 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301158 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001159 if(old)
1160 memcpy (beacon->head,old->head,beacon->head_len);
1161 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301162
Jeff Johnson295189b2012-06-20 16:38:30 -07001163 if(params->tail) {
1164 memcpy (beacon->tail,params->tail,beacon->tail_len);
1165 }
1166 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301167 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001168 memcpy (beacon->tail,old->tail,beacon->tail_len);
1169 }
1170
1171 *ppBeacon = beacon;
1172
1173 kfree(old);
1174
1175 return 0;
1176
1177}
Jeff Johnson295189b2012-06-20 16:38:30 -07001178
1179v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1180{
1181 int left = length;
1182 v_U8_t *ptr = pIes;
1183 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301184
Jeff Johnson295189b2012-06-20 16:38:30 -07001185 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301186 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001187 elem_id = ptr[0];
1188 elem_len = ptr[1];
1189 left -= 2;
1190 if(elem_len > left)
1191 {
1192 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001193 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 eid,elem_len,left);
1195 return NULL;
1196 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301197 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001198 {
1199 return ptr;
1200 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301201
Jeff Johnson295189b2012-06-20 16:38:30 -07001202 left -= elem_len;
1203 ptr += (elem_len + 2);
1204 }
1205 return NULL;
1206}
1207
Jeff Johnson295189b2012-06-20 16:38:30 -07001208/* Check if rate is 11g rate or not */
1209static int wlan_hdd_rate_is_11g(u8 rate)
1210{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001211 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001212 u8 i;
1213 for (i = 0; i < 8; i++)
1214 {
1215 if(rate == gRateArray[i])
1216 return TRUE;
1217 }
1218 return FALSE;
1219}
1220
1221/* Check for 11g rate and set proper 11g only mode */
1222static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1223 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1224{
1225 u8 i, num_rates = pIe[0];
1226
1227 pIe += 1;
1228 for ( i = 0; i < num_rates; i++)
1229 {
1230 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1231 {
1232 /* If rate set have 11g rate than change the mode to 11G */
1233 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1234 if (pIe[i] & BASIC_RATE_MASK)
1235 {
1236 /* If we have 11g rate as basic rate, it means mode
1237 is 11g only mode.
1238 */
1239 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1240 *pCheckRatesfor11g = FALSE;
1241 }
1242 }
1243 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1244 {
1245 *require_ht = TRUE;
1246 }
1247 }
1248 return;
1249}
1250
1251static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1252{
1253 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1254 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1255 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1256 u8 checkRatesfor11g = TRUE;
1257 u8 require_ht = FALSE;
1258 u8 *pIe=NULL;
1259
1260 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1261
1262 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1263 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1264 if (pIe != NULL)
1265 {
1266 pIe += 1;
1267 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1268 &pConfig->SapHw_mode);
1269 }
1270
1271 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1272 WLAN_EID_EXT_SUPP_RATES);
1273 if (pIe != NULL)
1274 {
1275
1276 pIe += 1;
1277 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1278 &pConfig->SapHw_mode);
1279 }
1280
1281 if( pConfig->channel > 14 )
1282 {
1283 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1284 }
1285
1286 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1287 WLAN_EID_HT_CAPABILITY);
1288
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301289 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001290 {
1291 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1292 if(require_ht)
1293 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1294 }
1295}
1296
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301297static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1298 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1299{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001300 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301301 v_U8_t *pIe = NULL;
1302 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1303
1304 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1305 pBeacon->tail, pBeacon->tail_len);
1306
1307 if (pIe)
1308 {
1309 ielen = pIe[1] + 2;
1310 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1311 {
1312 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1313 }
1314 else
1315 {
1316 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1317 return -EINVAL;
1318 }
1319 *total_ielen += ielen;
1320 }
1321 return 0;
1322}
1323
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001324static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1325 v_U8_t *genie, v_U8_t *total_ielen)
1326{
1327 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1328 int left = pBeacon->tail_len;
1329 v_U8_t *ptr = pBeacon->tail;
1330 v_U8_t elem_id, elem_len;
1331 v_U16_t ielen = 0;
1332
1333 if ( NULL == ptr || 0 == left )
1334 return;
1335
1336 while (left >= 2)
1337 {
1338 elem_id = ptr[0];
1339 elem_len = ptr[1];
1340 left -= 2;
1341 if (elem_len > left)
1342 {
1343 hddLog( VOS_TRACE_LEVEL_ERROR,
1344 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1345 elem_id, elem_len, left);
1346 return;
1347 }
1348 if (IE_EID_VENDOR == elem_id)
1349 {
1350 /* skipping the VSIE's which we don't want to include or
1351 * it will be included by existing code
1352 */
1353 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1354#ifdef WLAN_FEATURE_WFD
1355 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1356#endif
1357 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1358 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1359 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1360 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1361 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1362 {
1363 ielen = ptr[1] + 2;
1364 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1365 {
1366 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1367 *total_ielen += ielen;
1368 }
1369 else
1370 {
1371 hddLog( VOS_TRACE_LEVEL_ERROR,
1372 "IE Length is too big "
1373 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1374 elem_id, elem_len, *total_ielen);
1375 }
1376 }
1377 }
1378
1379 left -= elem_len;
1380 ptr += (elem_len + 2);
1381 }
1382 return;
1383}
1384
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001385#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001386static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1387 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001388#else
1389static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1390 struct cfg80211_beacon_data *params)
1391#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001392{
1393 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301394 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001396 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001397
1398 genie = vos_mem_malloc(MAX_GENIE_LEN);
1399
1400 if(genie == NULL) {
1401
1402 return -ENOMEM;
1403 }
1404
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301405 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1406 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301408 hddLog(LOGE,
1409 FL("Adding WPS IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301410 ret = -EINVAL;
1411 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001412 }
1413
1414#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301415 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1416 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1417 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301418 hddLog(LOGE,
1419 FL("Adding WFD IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301420 ret = -EINVAL;
1421 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001422 }
1423#endif
1424
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301425 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1426 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001427 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05301428 hddLog(LOGE,
1429 FL("Adding P2P IE failed"));
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301430 ret = -EINVAL;
1431 goto done;
1432 }
1433
1434 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1435 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001436 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001438
1439 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1440 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1441 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1442 {
1443 hddLog(LOGE,
1444 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001445 ret = -EINVAL;
1446 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001447 }
1448
1449 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1450 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1451 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1452 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1453 ==eHAL_STATUS_FAILURE)
1454 {
1455 hddLog(LOGE,
1456 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001457 ret = -EINVAL;
1458 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001459 }
1460
1461 // Added for ProResp IE
1462 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1463 {
1464 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1465 u8 probe_rsp_ie_len[3] = {0};
1466 u8 counter = 0;
1467 /* Check Probe Resp Length if it is greater then 255 then Store
1468 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1469 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1470 Store More then 255 bytes into One Variable.
1471 */
1472 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1473 {
1474 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1475 {
1476 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1477 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1478 }
1479 else
1480 {
1481 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1482 rem_probe_resp_ie_len = 0;
1483 }
1484 }
1485
1486 rem_probe_resp_ie_len = 0;
1487
1488 if (probe_rsp_ie_len[0] > 0)
1489 {
1490 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1491 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1492 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1493 probe_rsp_ie_len[0], NULL,
1494 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1495 {
1496 hddLog(LOGE,
1497 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001498 ret = -EINVAL;
1499 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001500 }
1501 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1502 }
1503
1504 if (probe_rsp_ie_len[1] > 0)
1505 {
1506 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1507 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1508 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1509 probe_rsp_ie_len[1], NULL,
1510 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1511 {
1512 hddLog(LOGE,
1513 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001514 ret = -EINVAL;
1515 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001516 }
1517 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1518 }
1519
1520 if (probe_rsp_ie_len[2] > 0)
1521 {
1522 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1523 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1524 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1525 probe_rsp_ie_len[2], NULL,
1526 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1527 {
1528 hddLog(LOGE,
1529 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001530 ret = -EINVAL;
1531 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001532 }
1533 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1534 }
1535
1536 if (probe_rsp_ie_len[1] == 0 )
1537 {
1538 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1539 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1540 eANI_BOOLEAN_FALSE) )
1541 {
1542 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001543 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001544 }
1545 }
1546
1547 if (probe_rsp_ie_len[2] == 0 )
1548 {
1549 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1550 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1551 eANI_BOOLEAN_FALSE) )
1552 {
1553 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001554 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 }
1556 }
1557
1558 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1559 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1560 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1561 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1562 == eHAL_STATUS_FAILURE)
1563 {
1564 hddLog(LOGE,
1565 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001566 ret = -EINVAL;
1567 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001568 }
1569 }
1570 else
1571 {
1572 // Reset WNI_CFG_PROBE_RSP Flags
1573 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1574
1575 hddLog(VOS_TRACE_LEVEL_INFO,
1576 "%s: No Probe Response IE received in set beacon",
1577 __func__);
1578 }
1579
1580 // Added for AssocResp IE
1581 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1582 {
1583 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1584 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1585 params->assocresp_ies_len, NULL,
1586 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1587 {
1588 hddLog(LOGE,
1589 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001590 ret = -EINVAL;
1591 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001592 }
1593
1594 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1595 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1596 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1597 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1598 == eHAL_STATUS_FAILURE)
1599 {
1600 hddLog(LOGE,
1601 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001602 ret = -EINVAL;
1603 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001604 }
1605 }
1606 else
1607 {
1608 hddLog(VOS_TRACE_LEVEL_INFO,
1609 "%s: No Assoc Response IE received in set beacon",
1610 __func__);
1611
1612 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1613 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1614 eANI_BOOLEAN_FALSE) )
1615 {
1616 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001617 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 }
1619 }
1620
Jeff Johnsone7245742012-09-05 17:12:55 -07001621done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001622 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301623 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001624}
Jeff Johnson295189b2012-06-20 16:38:30 -07001625
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301626/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 * FUNCTION: wlan_hdd_validate_operation_channel
1628 * called by wlan_hdd_cfg80211_start_bss() and
1629 * wlan_hdd_cfg80211_set_channel()
1630 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301631 * channel list.
1632 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001633VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001634{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301635
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 v_U32_t num_ch = 0;
1637 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1638 u32 indx = 0;
1639 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301640 v_U8_t fValidChannel = FALSE, count = 0;
1641 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301642
Jeff Johnson295189b2012-06-20 16:38:30 -07001643 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1644
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301645 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001646 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301647 /* Validate the channel */
1648 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001649 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301650 if ( channel == rfChannels[count].channelNum )
1651 {
1652 fValidChannel = TRUE;
1653 break;
1654 }
1655 }
1656 if (fValidChannel != TRUE)
1657 {
1658 hddLog(VOS_TRACE_LEVEL_ERROR,
1659 "%s: Invalid Channel [%d]", __func__, channel);
1660 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 }
1662 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301663 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001664 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301665 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1666 valid_ch, &num_ch))
1667 {
1668 hddLog(VOS_TRACE_LEVEL_ERROR,
1669 "%s: failed to get valid channel list", __func__);
1670 return VOS_STATUS_E_FAILURE;
1671 }
1672 for (indx = 0; indx < num_ch; indx++)
1673 {
1674 if (channel == valid_ch[indx])
1675 {
1676 break;
1677 }
1678 }
1679
1680 if (indx >= num_ch)
1681 {
1682 hddLog(VOS_TRACE_LEVEL_ERROR,
1683 "%s: Invalid Channel [%d]", __func__, channel);
1684 return VOS_STATUS_E_FAILURE;
1685 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001686 }
1687 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301688
Jeff Johnson295189b2012-06-20 16:38:30 -07001689}
1690
Viral Modi3a32cc52013-02-08 11:14:52 -08001691/**
1692 * FUNCTION: wlan_hdd_cfg80211_set_channel
1693 * This function is used to set the channel number
1694 */
1695static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1696 struct ieee80211_channel *chan,
1697 enum nl80211_channel_type channel_type
1698 )
1699{
1700 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001701 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001702 hdd_adapter_t *pAdapter = NULL;
1703 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301704 hdd_context_t *pHddCtx;
1705 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001706
1707 ENTER();
1708
1709 if( NULL == dev )
1710 {
1711 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001712 "%s: Called with dev = NULL.", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001713 return -ENODEV;
1714 }
1715 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1716
1717 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001718 "%s: device_mode = %d freq = %d", __func__,
Viral Modi3a32cc52013-02-08 11:14:52 -08001719 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301720
1721 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1722 status = wlan_hdd_validate_context(pHddCtx);
1723
1724 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001725 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301726 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1727 "%s: HDD context is not valid", __func__);
1728 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001729 }
1730
1731 /*
1732 * Do freq to chan conversion
1733 * TODO: for 11a
1734 */
1735
1736 channel = ieee80211_frequency_to_channel(freq);
1737
1738 /* Check freq range */
1739 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1740 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1741 {
1742 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001743 "%s: Channel [%d] is outside valid range from %d to %d",
Viral Modi3a32cc52013-02-08 11:14:52 -08001744 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1745 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1746 return -EINVAL;
1747 }
1748
1749 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1750
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301751 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1752 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001753 {
1754 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1755 {
1756 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001757 "%s: Invalid Channel [%d]", __func__, channel);
Viral Modi3a32cc52013-02-08 11:14:52 -08001758 return -EINVAL;
1759 }
1760 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1761 "%s: set channel to [%d] for device mode =%d",
1762 __func__, channel,pAdapter->device_mode);
1763 }
1764 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001765 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001766 )
1767 {
1768 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1769 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1770 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1771
1772 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1773 {
1774 /* Link is up then return cant set channel*/
1775 hddLog( VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001776 "%s: IBSS Associated, can't set the channel", __func__);
Viral Modi3a32cc52013-02-08 11:14:52 -08001777 return -EINVAL;
1778 }
1779
1780 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1781 pHddStaCtx->conn_info.operationChannel = channel;
1782 pRoamProfile->ChannelInfo.ChannelList =
1783 &pHddStaCtx->conn_info.operationChannel;
1784 }
1785 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001786 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001787 )
1788 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301789 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1790 {
1791 if(VOS_STATUS_SUCCESS !=
1792 wlan_hdd_validate_operation_channel(pAdapter,channel))
1793 {
1794 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001795 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301796 return -EINVAL;
1797 }
1798 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1799 }
1800 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001801 {
1802 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1803
1804 /* If auto channel selection is configured as enable/ 1 then ignore
1805 channel set by supplicant
1806 */
1807 if ( cfg_param->apAutoChannelSelection )
1808 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301809 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1810 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001811 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1812 "%s: set channel to auto channel (0) for device mode =%d",
1813 __func__, pAdapter->device_mode);
1814 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301815 else
1816 {
1817 if(VOS_STATUS_SUCCESS !=
1818 wlan_hdd_validate_operation_channel(pAdapter,channel))
1819 {
1820 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001821 "%s: Invalid Channel [%d]", __func__, channel);
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301822 return -EINVAL;
1823 }
1824 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1825 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001826 }
1827 }
1828 else
1829 {
1830 hddLog(VOS_TRACE_LEVEL_FATAL,
1831 "%s: Invalid device mode failed to set valid channel", __func__);
1832 return -EINVAL;
1833 }
1834 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301835 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001836}
1837
Jeff Johnson295189b2012-06-20 16:38:30 -07001838#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1839static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1840 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001841#else
1842static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1843 struct cfg80211_beacon_data *params,
1844 const u8 *ssid, size_t ssid_len,
1845 enum nl80211_hidden_ssid hidden_ssid)
1846#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001847{
1848 tsap_Config_t *pConfig;
1849 beacon_data_t *pBeacon = NULL;
1850 struct ieee80211_mgmt *pMgmt_frame;
1851 v_U8_t *pIe=NULL;
1852 v_U16_t capab_info;
1853 eCsrAuthType RSNAuthType;
1854 eCsrEncryptionType RSNEncryptType;
1855 eCsrEncryptionType mcRSNEncryptType;
1856 int status = VOS_STATUS_SUCCESS;
1857 tpWLAN_SAPEventCB pSapEventCallback;
1858 hdd_hostapd_state_t *pHostapdState;
1859 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1860 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301861 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001862 struct qc_mac_acl_entry *acl_entry = NULL;
1863 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001864 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001865
1866 ENTER();
1867
1868 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1869
1870 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1871
1872 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1873
1874 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1875
1876 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1877
1878 //channel is already set in the set_channel Call back
1879 //pConfig->channel = pCommitConfig->channel;
1880
1881 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301882 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001883 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1884
1885 pConfig->dtim_period = pBeacon->dtim_period;
1886
Arif Hussain6d2a3322013-11-17 19:50:10 -08001887 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***",
Jeff Johnson295189b2012-06-20 16:38:30 -07001888 pConfig->dtim_period);
1889
1890
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001891 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001892 {
1893 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001894 WLAN_EID_COUNTRY);
Kiet Lam083504c2013-11-25 14:17:45 +05301895 if(memcmp(pHddCtx->cfg_ini->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0)
1896 {
1897 tANI_BOOLEAN restartNeeded;
1898 pConfig->ieee80211d = 1;
1899 vos_mem_copy(pConfig->countryCode, pHddCtx->cfg_ini->apCntryCode, 3);
1900 sme_setRegInfo(hHal, pConfig->countryCode);
1901 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
1902 }
1903 else if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001904 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001905 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001906 pConfig->ieee80211d = 1;
1907 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1908 sme_setRegInfo(hHal, pConfig->countryCode);
1909 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001911 else
1912 {
1913 pConfig->ieee80211d = 0;
1914 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301915 /*
1916 * If auto channel is configured i.e. channel is 0,
1917 * so skip channel validation.
1918 */
1919 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1920 {
1921 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1922 {
1923 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08001924 "%s: Invalid Channel [%d]", __func__, pConfig->channel);
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301925 return -EINVAL;
1926 }
1927 }
1928 else
1929 {
1930 if(1 != pHddCtx->is_dynamic_channel_range_set)
1931 {
1932 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1933 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1934 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1935 }
1936 pHddCtx->is_dynamic_channel_range_set = 0;
1937 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001938 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001939 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001940 {
1941 pConfig->ieee80211d = 0;
1942 }
1943 pConfig->authType = eSAP_AUTO_SWITCH;
1944
1945 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301946
1947 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1949
1950 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1951
1952 /*Set wps station to configured*/
1953 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1954
1955 if(pIe)
1956 {
1957 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1958 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08001959 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***");
Jeff Johnson295189b2012-06-20 16:38:30 -07001960 return -EINVAL;
1961 }
1962 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1963 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001964 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001965 /* Check 15 bit of WPS IE as it contain information for wps state
1966 * WPS state
1967 */
1968 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1969 {
1970 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1971 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1972 {
1973 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1974 }
1975 }
1976 }
1977 else
1978 {
1979 pConfig->wps_state = SAP_WPS_DISABLED;
1980 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301981 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001982
1983 pConfig->RSNWPAReqIELength = 0;
1984 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301985 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001986 WLAN_EID_RSN);
1987 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301988 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001989 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1990 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1991 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301992 /* The actual processing may eventually be more extensive than
1993 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 * by the app.
1995 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301996 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001997 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1998 &RSNEncryptType,
1999 &mcRSNEncryptType,
2000 &RSNAuthType,
2001 pConfig->pRSNWPAReqIE[1]+2,
2002 pConfig->pRSNWPAReqIE );
2003
2004 if( VOS_STATUS_SUCCESS == status )
2005 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302006 /* Now copy over all the security attributes you have
2007 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 * */
2009 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2010 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2011 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2012 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302013 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002014 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002015 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2016 }
2017 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302018
Jeff Johnson295189b2012-06-20 16:38:30 -07002019 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2020 pBeacon->tail, pBeacon->tail_len);
2021
2022 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
2023 {
2024 if (pConfig->pRSNWPAReqIE)
2025 {
2026 /*Mixed mode WPA/WPA2*/
2027 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
2028 pConfig->RSNWPAReqIELength += pIe[1] + 2;
2029 }
2030 else
2031 {
2032 pConfig->RSNWPAReqIELength = pIe[1] + 2;
2033 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
2034 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302035 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07002036 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
2037 &RSNEncryptType,
2038 &mcRSNEncryptType,
2039 &RSNAuthType,
2040 pConfig->pRSNWPAReqIE[1]+2,
2041 pConfig->pRSNWPAReqIE );
2042
2043 if( VOS_STATUS_SUCCESS == status )
2044 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302045 /* Now copy over all the security attributes you have
2046 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07002047 * */
2048 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
2049 pConfig->mcRSNEncryptType = mcRSNEncryptType;
2050 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
2051 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05302052 hddLog( LOG1, FL("CSR AuthType = %d, "
Arif Hussain6d2a3322013-11-17 19:50:10 -08002053 "EncryptionType = %d mcEncryptionType = %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002054 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
2055 }
2056 }
2057 }
2058
Jeff Johnson4416a782013-03-25 14:17:50 -07002059 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
2060 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
2061 return -EINVAL;
2062 }
2063
Jeff Johnson295189b2012-06-20 16:38:30 -07002064 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
2065
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002066#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002067 if (params->ssid != NULL)
2068 {
2069 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
2070 pConfig->SSIDinfo.ssid.length = params->ssid_len;
2071 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2072 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2073 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002074#else
2075 if (ssid != NULL)
2076 {
2077 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
2078 pConfig->SSIDinfo.ssid.length = ssid_len;
2079 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2080 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
2081 }
2082#endif
2083
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302084 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302086
Jeff Johnson295189b2012-06-20 16:38:30 -07002087 /* default value */
2088 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
2089 pConfig->num_accept_mac = 0;
2090 pConfig->num_deny_mac = 0;
2091
2092 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2093 pBeacon->tail, pBeacon->tail_len);
2094
2095 /* pIe for black list is following form:
2096 type : 1 byte
2097 length : 1 byte
2098 OUI : 4 bytes
2099 acl type : 1 byte
2100 no of mac addr in black list: 1 byte
2101 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302102 */
2103 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002104 {
2105 pConfig->SapMacaddr_acl = pIe[6];
2106 pConfig->num_deny_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002107 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002108 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302109 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2110 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002111 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2112 for (i = 0; i < pConfig->num_deny_mac; i++)
2113 {
2114 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2115 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302116 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002117 }
2118 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2119 pBeacon->tail, pBeacon->tail_len);
2120
2121 /* pIe for white list is following form:
2122 type : 1 byte
2123 length : 1 byte
2124 OUI : 4 bytes
2125 acl type : 1 byte
2126 no of mac addr in white list: 1 byte
2127 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302128 */
2129 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002130 {
2131 pConfig->SapMacaddr_acl = pIe[6];
2132 pConfig->num_accept_mac = pIe[7];
Arif Hussain6d2a3322013-11-17 19:50:10 -08002133 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002134 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302135 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2136 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002137 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2138 for (i = 0; i < pConfig->num_accept_mac; i++)
2139 {
2140 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2141 acl_entry++;
2142 }
2143 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302144
Jeff Johnson295189b2012-06-20 16:38:30 -07002145 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2146
Jeff Johnsone7245742012-09-05 17:12:55 -07002147#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002148 /* Overwrite the hostapd setting for HW mode only for 11ac.
Kiet Lam0f320422013-11-21 19:29:17 +05302149 * This is valid only if mode is set to 11n in hostapd, either AUTO or
2150 * 11ac in .ini and 11ac is supported by both host and firmware.
2151 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode)
2152 */
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002153 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2154 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302155 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002156 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
Kiet Lam0f320422013-11-21 19:29:17 +05302157 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) &&
2158 (sme_IsFeatureSupportedByDriver(DOT11AC)) && (sme_IsFeatureSupportedByFW(DOT11AC)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002159 {
2160 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002161
2162 /* Disable VHT support in 2.4 GHz band */
2163 if (pConfig->channel <= 14 &&
2164 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2165 {
2166 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2167 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002168 }
2169#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302170
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002171 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2172 {
2173 sme_SelectCBMode(hHal,
2174 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2175 pConfig->channel);
2176 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002177 // ht_capab is not what the name conveys,this is used for protection bitmap
2178 pConfig->ht_capab =
2179 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2180
2181 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2182 {
2183 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2184 return -EINVAL;
2185 }
2186
2187 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302188 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002189 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2190 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302191 pConfig->obssProtEnabled =
2192 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002193
Arif Hussain6d2a3322013-11-17 19:50:10 -08002194 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR),
Jeff Johnson295189b2012-06-20 16:38:30 -07002195 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Arif Hussain6d2a3322013-11-17 19:50:10 -08002196 hddLog(LOGW,FL("ssid =%s, beaconint=%d, channel=%d"),
2197 pConfig->SSIDinfo.ssid.ssId, (int)pConfig->beacon_int,
2198 (int)pConfig->channel);
2199 hddLog(LOGW,FL("hw_mode=%x, privacy=%d, authType=%d"),
2200 pConfig->SapHw_mode, pConfig->privacy,
2201 pConfig->authType);
2202 hddLog(LOGW,FL("RSN/WPALen=%d, Uapsd = %d"),
2203 (int)pConfig->RSNWPAReqIELength, pConfig->UapsdEnable);
2204 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d"),
2205 pConfig->protEnabled, pConfig->obssProtEnabled);
Jeff Johnson295189b2012-06-20 16:38:30 -07002206
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302207 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002208 {
2209 //Bss already started. just return.
2210 //TODO Probably it should update some beacon params.
2211 hddLog( LOGE, "Bss Already started...Ignore the request");
2212 EXIT();
2213 return 0;
2214 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302215
Jeff Johnson295189b2012-06-20 16:38:30 -07002216 pConfig->persona = pHostapdAdapter->device_mode;
2217
2218 pSapEventCallback = hdd_hostapd_SAPEventCB;
2219 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2220 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2221 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08002222 hddLog(LOGE,FL("SAP Start Bss fail"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002223 return -EINVAL;
2224 }
2225
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302226 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002227 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2228
2229 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302230
Jeff Johnson295189b2012-06-20 16:38:30 -07002231 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302232 {
2233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002234 ("ERROR: HDD vos wait for single_event failed!!"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002235 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002236 VOS_ASSERT(0);
2237 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302238
Jeff Johnson295189b2012-06-20 16:38:30 -07002239 //Succesfully started Bss update the state bit.
2240 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2241
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002242#ifdef WLAN_FEATURE_P2P_DEBUG
2243 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2244 {
2245 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2246 {
2247 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2248 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002249 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002250 }
2251 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2252 {
2253 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2254 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002255 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002256 }
2257 }
2258#endif
2259
Jeff Johnson295189b2012-06-20 16:38:30 -07002260 pHostapdState->bCommit = TRUE;
2261 EXIT();
2262
2263 return 0;
2264}
2265
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002266#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302267static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2268 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002269 struct beacon_parameters *params)
2270{
2271 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302272 hdd_context_t *pHddCtx;
2273 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002274
2275 ENTER();
2276
Arif Hussain6d2a3322013-11-17 19:50:10 -08002277 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d",pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002278
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302279 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2280 status = wlan_hdd_validate_context(pHddCtx);
2281
2282 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002283 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302284 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2285 "%s: HDD context is not valid", __func__);
2286 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002287 }
2288
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302289 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002290 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002291 )
2292 {
2293 beacon_data_t *old,*new;
2294
2295 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302296
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302298 {
2299 hddLog(VOS_TRACE_LEVEL_WARN,
2300 FL("already beacon info added to session(%d)"),
2301 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002302 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302303 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002304
2305 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2306
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302307 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002308 {
2309 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002310 "%s:Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002311 return -EINVAL;
2312 }
2313
2314 pAdapter->sessionCtx.ap.beacon = new;
2315
2316 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2317 }
2318
2319 EXIT();
2320 return status;
2321}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302322
2323static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002324 struct net_device *dev,
2325 struct beacon_parameters *params)
2326{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302327 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302328 hdd_context_t *pHddCtx;
2329 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002330
2331 ENTER();
2332
Arif Hussain6d2a3322013-11-17 19:50:10 -08002333 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002334 __func__,pAdapter->device_mode);
2335
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302336 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2337 status = wlan_hdd_validate_context(pHddCtx);
2338
2339 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002340 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302341 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2342 "%s: HDD context is not valid", __func__);
2343 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002344 }
2345
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302346 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002347 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302348 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002349 {
2350 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302351
Jeff Johnson295189b2012-06-20 16:38:30 -07002352 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302353
Jeff Johnson295189b2012-06-20 16:38:30 -07002354 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302355 {
2356 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2357 FL("session(%d) old and new heads points to NULL"),
2358 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002359 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302360 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002361
2362 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2363
2364 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302365 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002366 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002367 return -EINVAL;
2368 }
2369
2370 pAdapter->sessionCtx.ap.beacon = new;
2371
2372 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2373 }
2374
2375 EXIT();
2376 return status;
2377}
2378
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002379#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2380
2381#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002382static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2383 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002384#else
2385static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2386 struct net_device *dev)
2387#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002388{
2389 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002390 hdd_context_t *pHddCtx = NULL;
2391 hdd_scaninfo_t *pScanInfo = NULL;
2392 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302393 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002394
2395 ENTER();
2396
2397 if (NULL == pAdapter)
2398 {
2399 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002400 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002401 return -ENODEV;
2402 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002403
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302404 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2405 status = wlan_hdd_validate_context(pHddCtx);
2406
2407 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002408 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302409 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2410 "%s: HDD context is not valid", __func__);
2411 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002412 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002413
2414 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2415 if (NULL == staAdapter)
2416 {
2417 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2418 if (NULL == staAdapter)
2419 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002420 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2421 "%s: HDD adapter context for STA/P2P-CLI is Null",
2422 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002423 }
2424 }
2425
2426 pScanInfo = &pHddCtx->scan_info;
2427
Arif Hussain6d2a3322013-11-17 19:50:10 -08002428 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002429 __func__,pAdapter->device_mode);
2430
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002431 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002432 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302433 long ret;
2434
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002435 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302436 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302437 ret = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002438 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002439 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302440 if (ret <= 0)
Jeff Johnsone7245742012-09-05 17:12:55 -07002441 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002442 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302443 FL("Timeout occurred while waiting for abortscan %ld"),
2444 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002445
2446 if (pHddCtx->isLogpInProgress)
2447 {
2448 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2449 "%s: LOGP in Progress. Ignore!!!", __func__);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302450
2451 VOS_ASSERT(pScanInfo->mScanPending);
Yue Ma4f55ef32014-01-23 16:45:33 -08002452 return -EAGAIN;
2453 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002454 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002455 }
2456 }
2457
Arun Kumar Khandavallia3bd8002014-01-17 16:21:19 +05302458 hdd_hostapd_stop(dev);
2459
Jeff Johnson295189b2012-06-20 16:38:30 -07002460 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002461 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002462 )
2463 {
2464 beacon_data_t *old;
2465
2466 old = pAdapter->sessionCtx.ap.beacon;
2467
2468 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302469 {
2470 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2471 FL("session(%d) beacon data points to NULL"),
2472 pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002473 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302474 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002475
Jeff Johnson295189b2012-06-20 16:38:30 -07002476 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002477
2478 mutex_lock(&pHddCtx->sap_lock);
2479 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2480 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002481 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002482 {
2483 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2484
2485 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2486
2487 if (!VOS_IS_STATUS_SUCCESS(status))
2488 {
2489 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002490 ("ERROR: HDD vos wait for single_event failed!!"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002491 VOS_ASSERT(0);
2492 }
2493 }
2494 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2495 }
2496 mutex_unlock(&pHddCtx->sap_lock);
2497
2498 if(status != VOS_STATUS_SUCCESS)
2499 {
2500 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002501 "%s:Error!!! Stopping the BSS",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002502 return -EINVAL;
2503 }
2504
Jeff Johnson4416a782013-03-25 14:17:50 -07002505 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002506 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2507 ==eHAL_STATUS_FAILURE)
2508 {
2509 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002510 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002511 }
2512
Jeff Johnson4416a782013-03-25 14:17:50 -07002513 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002514 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2515 eANI_BOOLEAN_FALSE) )
2516 {
2517 hddLog(LOGE,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002518 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnson295189b2012-06-20 16:38:30 -07002519 }
2520
2521 // Reset WNI_CFG_PROBE_RSP Flags
2522 wlan_hdd_reset_prob_rspies(pAdapter);
2523
2524 pAdapter->sessionCtx.ap.beacon = NULL;
2525 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002526#ifdef WLAN_FEATURE_P2P_DEBUG
2527 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2528 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2529 {
2530 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2531 "GO got removed");
2532 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2533 }
2534#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002535 }
2536 EXIT();
2537 return status;
2538}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002539
2540#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2541
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302542static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2543 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002544 struct cfg80211_ap_settings *params)
2545{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302546 hdd_adapter_t *pAdapter;
2547 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302548 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002549
2550 ENTER();
2551
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302552 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002553 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302554 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302555 "%s: Device is Null", __func__);
2556 return -ENODEV;
2557 }
2558
2559 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2560 if (NULL == pAdapter)
2561 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302562 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302563 "%s: HDD adapter is Null", __func__);
2564 return -ENODEV;
2565 }
2566
2567 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2568 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302569 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302570 "%s: HDD adapter magic is invalid", __func__);
2571 return -ENODEV;
2572 }
2573
2574 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302575 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302576
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302577 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302578 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302579 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2580 "%s: HDD context is not valid", __func__);
2581 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302582 }
2583
2584 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2585 __func__, pAdapter->device_mode);
2586
2587 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002588 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002589 )
2590 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302591 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002592
2593 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302594
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002595 if (old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302596 {
2597 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2598 FL("already beacon info added to session(%d)"),
2599 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002600 return -EALREADY;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302601 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002602
2603 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2604
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302605 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002606 {
2607 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302608 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002609 return -EINVAL;
2610 }
2611 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002612#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002613 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2614#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2615 params->channel, params->channel_type);
2616#else
2617 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2618#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002619#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002620 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2621 params->ssid_len, params->hidden_ssid);
2622 }
2623
2624 EXIT();
2625 return status;
2626}
2627
2628
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302629static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002630 struct net_device *dev,
2631 struct cfg80211_beacon_data *params)
2632{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302633 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302634 hdd_context_t *pHddCtx;
2635 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002636
2637 ENTER();
2638
Arif Hussain6d2a3322013-11-17 19:50:10 -08002639 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002640 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302641
2642 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2643 status = wlan_hdd_validate_context(pHddCtx);
2644
2645 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002646 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302647 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2648 "%s: HDD context is not valid", __func__);
2649 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002650 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002651
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302652 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002653 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302654 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002655 {
2656 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302657
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002658 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302659
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002660 if (!old)
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302661 {
2662 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2663 FL("session(%d) beacon data points to NULL"),
2664 pAdapter->sessionId);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002665 return -ENOENT;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302666 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002667
2668 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2669
2670 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302671 hddLog(VOS_TRACE_LEVEL_FATAL,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002672 "%s: Error!!! Allocating the new beacon",__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002673 return -EINVAL;
2674 }
2675
2676 pAdapter->sessionCtx.ap.beacon = new;
2677
2678 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2679 }
2680
2681 EXIT();
2682 return status;
2683}
2684
2685#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2686
Jeff Johnson295189b2012-06-20 16:38:30 -07002687
2688static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2689 struct net_device *dev,
2690 struct bss_parameters *params)
2691{
2692 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2693
2694 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302695
Arif Hussain6d2a3322013-11-17 19:50:10 -08002696 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002697 __func__,pAdapter->device_mode);
2698
2699 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002700 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302701 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002702 {
2703 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2704 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302705 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002706 {
2707 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302708 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002709 }
2710
2711 EXIT();
2712 return 0;
2713}
2714
Kiet Lam10841362013-11-01 11:36:50 +05302715/* FUNCTION: wlan_hdd_change_country_code_cd
2716* to wait for contry code completion
2717*/
2718void* wlan_hdd_change_country_code_cb(void *pAdapter)
2719{
2720 hdd_adapter_t *call_back_pAdapter = pAdapter;
2721 complete(&call_back_pAdapter->change_country_code);
2722 return NULL;
2723}
2724
Jeff Johnson295189b2012-06-20 16:38:30 -07002725/*
2726 * FUNCTION: wlan_hdd_cfg80211_change_iface
2727 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2728 */
2729int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2730 struct net_device *ndev,
2731 enum nl80211_iftype type,
2732 u32 *flags,
2733 struct vif_params *params
2734 )
2735{
2736 struct wireless_dev *wdev;
2737 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2738 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002739 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002740 tCsrRoamProfile *pRoamProfile = NULL;
2741 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302742 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 eMib_dot11DesiredBssType connectedBssType;
2744 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302745 long ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07002746
2747 ENTER();
2748
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302749 status = wlan_hdd_validate_context(pHddCtx);
2750
2751 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002752 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302753 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2754 "%s: HDD context is not valid", __func__);
2755 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002756 }
2757
2758 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2759 __func__, pAdapter->device_mode);
2760
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302761 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002762 wdev = ndev->ieee80211_ptr;
2763
2764#ifdef WLAN_BTAMP_FEATURE
2765 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2766 (NL80211_IFTYPE_ADHOC == type)||
2767 (NL80211_IFTYPE_AP == type)||
2768 (NL80211_IFTYPE_P2P_GO == type))
2769 {
2770 pHddCtx->isAmpAllowed = VOS_FALSE;
2771 // stop AMP traffic
2772 status = WLANBAP_StopAmp();
2773 if(VOS_STATUS_SUCCESS != status )
2774 {
2775 pHddCtx->isAmpAllowed = VOS_TRUE;
2776 hddLog(VOS_TRACE_LEVEL_FATAL,
2777 "%s: Failed to stop AMP", __func__);
2778 return -EINVAL;
2779 }
2780 }
2781#endif //WLAN_BTAMP_FEATURE
2782 /* Reset the current device mode bit mask*/
2783 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2784
2785 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002787 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002788 )
2789 {
2790 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2791 pRoamProfile = &pWextState->roamProfile;
2792 LastBSSType = pRoamProfile->BSSType;
2793
2794 switch (type)
2795 {
2796 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002797 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002798 hddLog(VOS_TRACE_LEVEL_INFO,
2799 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2800 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002801#ifdef WLAN_FEATURE_11AC
2802 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2803 {
2804 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2805 }
2806#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302807 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002808 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002809 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002810 //Check for sub-string p2p to confirm its a p2p interface
2811 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302812 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002813 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2814 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2815 }
2816 else
2817 {
2818 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002819 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002820 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302821#ifdef FEATURE_WLAN_TDLS
2822 /* The open adapter for the p2p shall skip initializations in
2823 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2824 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2825 * tdls_init when the change_iface sets the device mode to
2826 * WLAN_HDD_P2P_CLIENT.
2827 */
2828
2829 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2830 {
2831 if (0 != wlan_hdd_tdls_init (pAdapter))
2832 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302833 hddLog(VOS_TRACE_LEVEL_ERROR,
2834 "%s: tdls initialization failed", __func__);
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302835 return -EINVAL;
2836 }
2837 }
2838#endif
2839
Jeff Johnson295189b2012-06-20 16:38:30 -07002840 break;
2841 case NL80211_IFTYPE_ADHOC:
2842 hddLog(VOS_TRACE_LEVEL_INFO,
2843 "%s: setting interface Type to ADHOC", __func__);
2844 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2845 pRoamProfile->phyMode =
2846 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002847 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002848 wdev->iftype = type;
2849 break;
2850
2851 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002852 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002853 {
2854 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2855 "%s: setting interface Type to %s", __func__,
2856 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2857
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002858 //Cancel any remain on channel for GO mode
2859 if (NL80211_IFTYPE_P2P_GO == type)
2860 {
2861 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2862 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002863 if (NL80211_IFTYPE_AP == type)
2864 {
2865 /* As Loading WLAN Driver one interface being created for p2p device
2866 * address. This will take one HW STA and the max number of clients
2867 * that can connect to softAP will be reduced by one. so while changing
2868 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2869 * interface as it is not required in SoftAP mode.
2870 */
2871
2872 // Get P2P Adapter
2873 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2874
2875 if (pP2pAdapter)
2876 {
2877 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2878 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2879 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2880 }
2881 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302882#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002883
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302884 /* A Mutex Lock is introduced while changing the mode to
2885 * protect the concurrent access for the Adapters by TDLS
2886 * module.
2887 */
2888 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2889 {
2890 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2891 "%s: unable to lock list", __func__);
2892 return -EINVAL;
2893 }
2894#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002895 //De-init the adapter.
2896 hdd_stop_adapter( pHddCtx, pAdapter );
2897 hdd_deinit_adapter( pHddCtx, pAdapter );
2898 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002899 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2900 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302901#ifdef FEATURE_WLAN_TDLS
2902 mutex_unlock(&pHddCtx->tdls_lock);
2903#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002904
2905 //Disable BMPS and IMPS if enabled
2906 //before starting Go
2907 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2908 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302909 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002910 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2911 {
2912 //Fail to Exit BMPS
2913 VOS_ASSERT(0);
2914 }
2915 }
2916
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002917 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2918 (pConfig->apRandomBssidEnabled))
2919 {
2920 /* To meet Android requirements create a randomized
2921 MAC address of the form 02:1A:11:Fx:xx:xx */
2922 get_random_bytes(&ndev->dev_addr[3], 3);
2923 ndev->dev_addr[0] = 0x02;
2924 ndev->dev_addr[1] = 0x1A;
2925 ndev->dev_addr[2] = 0x11;
2926 ndev->dev_addr[3] |= 0xF0;
2927 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2928 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08002929 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
2930 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002931 }
2932
Jeff Johnson295189b2012-06-20 16:38:30 -07002933 hdd_set_ap_ops( pAdapter->dev );
2934
Kiet Lam10841362013-11-01 11:36:50 +05302935 /* This is for only SAP mode where users can
2936 * control country through ini.
2937 * P2P GO follows station country code
2938 * acquired during the STA scanning. */
2939 if((NL80211_IFTYPE_AP == type) &&
2940 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2941 {
2942 int status = 0;
2943 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2944 "%s: setting country code from INI ", __func__);
2945 init_completion(&pAdapter->change_country_code);
2946 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2947 (void *)(tSmeChangeCountryCallback)
2948 wlan_hdd_change_country_code_cb,
2949 pConfig->apCntryCode, pAdapter,
2950 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05302951 eSIR_FALSE,
2952 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05302953 if (eHAL_STATUS_SUCCESS == status)
2954 {
2955 /* Wait for completion */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302956 ret = wait_for_completion_interruptible_timeout(
Kiet Lam10841362013-11-01 11:36:50 +05302957 &pAdapter->change_country_code,
2958 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302959 if (ret <= 0)
Kiet Lam10841362013-11-01 11:36:50 +05302960 {
2961 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302962 FL("SME Timed out while setting country code %ld"),
2963 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002964
2965 if (pHddCtx->isLogpInProgress)
2966 {
2967 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2968 "%s: LOGP in Progress. Ignore!!!", __func__);
2969 return -EAGAIN;
2970 }
Kiet Lam10841362013-11-01 11:36:50 +05302971 }
2972 }
2973 else
2974 {
2975 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002976 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05302977 return -EINVAL;
2978 }
2979 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002980 status = hdd_init_ap_mode(pAdapter);
2981 if(status != VOS_STATUS_SUCCESS)
2982 {
2983 hddLog(VOS_TRACE_LEVEL_FATAL,
2984 "%s: Error initializing the ap mode", __func__);
2985 return -EINVAL;
2986 }
2987 hdd_set_conparam(1);
2988
Jeff Johnson295189b2012-06-20 16:38:30 -07002989 /*interface type changed update in wiphy structure*/
2990 if(wdev)
2991 {
2992 wdev->iftype = type;
2993 pHddCtx->change_iface = type;
2994 }
2995 else
2996 {
2997 hddLog(VOS_TRACE_LEVEL_ERROR,
2998 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2999 return -EINVAL;
3000 }
3001 goto done;
3002 }
3003
3004 default:
3005 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3006 __func__);
3007 return -EOPNOTSUPP;
3008 }
3009 }
3010 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003011 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003012 )
3013 {
3014 switch(type)
3015 {
3016 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07003017 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07003018 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303019#ifdef FEATURE_WLAN_TDLS
3020
3021 /* A Mutex Lock is introduced while changing the mode to
3022 * protect the concurrent access for the Adapters by TDLS
3023 * module.
3024 */
3025 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
3026 {
3027 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3028 "%s: unable to lock list", __func__);
3029 return -EINVAL;
3030 }
3031#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07003032 hdd_stop_adapter( pHddCtx, pAdapter );
3033 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003034 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08003035 //Check for sub-string p2p to confirm its a p2p interface
3036 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003037 {
3038 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
3039 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
3040 }
3041 else
3042 {
3043 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07003044 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003045 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003046 hdd_set_conparam(0);
3047 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003048 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
3049 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303050#ifdef FEATURE_WLAN_TDLS
3051 mutex_unlock(&pHddCtx->tdls_lock);
3052#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05303053 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003054 if( VOS_STATUS_SUCCESS != status )
3055 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07003056 /* In case of JB, for P2P-GO, only change interface will be called,
3057 * This is the right place to enable back bmps_imps()
3058 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05303059 if (pHddCtx->hdd_wlan_suspended)
3060 {
3061 hdd_set_pwrparams(pHddCtx);
3062 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003063 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003064 goto done;
3065 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07003066 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07003067 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003068 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3069 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003070 goto done;
3071 default:
3072 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3073 __func__);
3074 return -EOPNOTSUPP;
3075
3076 }
3077
3078 }
3079 else
3080 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303081 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: unsupported device mode(%d)",
3082 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003083 return -EOPNOTSUPP;
3084 }
3085
3086
3087 if(pRoamProfile)
3088 {
3089 if ( LastBSSType != pRoamProfile->BSSType )
3090 {
3091 /*interface type changed update in wiphy structure*/
3092 wdev->iftype = type;
3093
3094 /*the BSS mode changed, We need to issue disconnect
3095 if connected or in IBSS disconnect state*/
3096 if ( hdd_connGetConnectedBssType(
3097 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
3098 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
3099 {
3100 /*need to issue a disconnect to CSR.*/
3101 INIT_COMPLETION(pAdapter->disconnect_comp_var);
3102 if( eHAL_STATUS_SUCCESS ==
3103 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
3104 pAdapter->sessionId,
3105 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
3106 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303107 ret = wait_for_completion_interruptible_timeout(
3108 &pAdapter->disconnect_comp_var,
3109 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
3110 if (ret <= 0)
3111 {
3112 hddLog(VOS_TRACE_LEVEL_ERROR,
3113 FL("wait on disconnect_comp_var failed %ld"), ret);
3114 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003115 }
3116 }
3117 }
3118 }
3119
3120done:
3121 /*set bitmask based on updated value*/
3122 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07003123
3124 /* Only STA mode support TM now
3125 * all other mode, TM feature should be disabled */
3126 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
3127 (~VOS_STA & pHddCtx->concurrency_mode) )
3128 {
3129 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
3130 }
3131
Jeff Johnson295189b2012-06-20 16:38:30 -07003132#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303133 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
3135 {
3136 //we are ok to do AMP
3137 pHddCtx->isAmpAllowed = VOS_TRUE;
3138 }
3139#endif //WLAN_BTAMP_FEATURE
3140 EXIT();
3141 return 0;
3142}
3143
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003144#ifdef FEATURE_WLAN_TDLS
3145static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
3146 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
3147{
3148 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3149 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3150 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003151 hddTdlsPeer_t *pTdlsPeer;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303152 long ret;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003153
3154 ENTER();
3155
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303156 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003157 {
3158 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3159 "Invalid arguments");
3160 return -EINVAL;
3161 }
Hoonki Lee27511902013-03-14 18:19:06 -07003162
3163 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3164 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3165 {
3166 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3167 "%s: TDLS mode is disabled OR not enabled in FW."
3168 MAC_ADDRESS_STR " Request declined.",
3169 __func__, MAC_ADDR_ARRAY(mac));
3170 return -ENOTSUPP;
3171 }
3172
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003173 if (pHddCtx->isLogpInProgress)
3174 {
3175 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3176 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003177 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003178 return -EBUSY;
3179 }
3180
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303181 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003182
3183 if ( NULL == pTdlsPeer ) {
3184 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3185 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3186 __func__, MAC_ADDR_ARRAY(mac), update);
3187 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003188 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003189
3190 /* in add station, we accept existing valid staId if there is */
3191 if ((0 == update) &&
3192 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3193 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003194 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003195 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003196 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003197 " link_status %d. staId %d. add station ignored.",
3198 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3199 return 0;
3200 }
3201 /* in change station, we accept only when staId is valid */
3202 if ((1 == update) &&
3203 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3204 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3205 {
3206 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3207 "%s: " MAC_ADDRESS_STR
3208 " link status %d. staId %d. change station %s.",
3209 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3210 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3211 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003212 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003213
3214 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303215 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003216 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003217 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3218 "%s: " MAC_ADDRESS_STR
3219 " TDLS setup is ongoing. Request declined.",
3220 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003221 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003222 }
3223
3224 /* first to check if we reached to maximum supported TDLS peer.
3225 TODO: for now, return -EPERM looks working fine,
3226 but need to check if any other errno fit into this category.*/
3227 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3228 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003229 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3230 "%s: " MAC_ADDRESS_STR
3231 " TDLS Max peer already connected. Request declined.",
3232 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003233 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003234 }
3235 else
3236 {
3237 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303238 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003239 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003240 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003241 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3242 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3243 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003244 return -EPERM;
3245 }
3246 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003247 if (0 == update)
3248 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003249
Jeff Johnsond75fe012013-04-06 10:53:06 -07003250 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303251 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003252 {
3253 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3254 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003255 if(StaParams->htcap_present)
3256 {
3257 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3258 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3259 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3260 "ht_capa->extended_capabilities: %0x",
3261 StaParams->HTCap.extendedHtCapInfo);
3262 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003263 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3264 "params->capability: %0x",StaParams->capability);
3265 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003266 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003267 if(StaParams->vhtcap_present)
3268 {
3269 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3270 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3271 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3272 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3273 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003274 {
3275 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003276 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003277 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3278 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3279 "[%d]: %x ", i, StaParams->supported_rates[i]);
3280 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003281 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303282 else if ((1 == update) && (NULL == StaParams))
3283 {
3284 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3285 "%s : update is true, but staParams is NULL. Error!", __func__);
3286 return -EPERM;
3287 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003288
3289 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3290
3291 if (!update)
3292 {
3293 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3294 pAdapter->sessionId, mac);
3295 }
3296 else
3297 {
3298 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3299 pAdapter->sessionId, mac, StaParams);
3300 }
3301
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303302 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003303 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3304
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303305 if (ret <= 0)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003306 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003307 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303308 "%s: timeout waiting for tdls add station indication %ld",
3309 __func__, ret);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003310 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003311 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303312
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003313 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3314 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003315 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003316 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003317 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003318 }
3319
3320 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003321
3322error:
3323 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3324 return -EPERM;
3325
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003326}
3327#endif
3328
Jeff Johnson295189b2012-06-20 16:38:30 -07003329static int wlan_hdd_change_station(struct wiphy *wiphy,
3330 struct net_device *dev,
3331 u8 *mac,
3332 struct station_parameters *params)
3333{
3334 VOS_STATUS status = VOS_STATUS_SUCCESS;
3335 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303336 hdd_context_t *pHddCtx;
3337 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003338 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003339#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003340 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003341 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003342#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003343 ENTER();
3344
Gopichand Nakkala29149562013-05-10 21:43:41 +05303345 if ((NULL == pAdapter))
3346 {
3347 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3348 "invalid adapter ");
3349 return -EINVAL;
3350 }
3351
3352 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3353 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3354
3355 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3356 {
3357 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3358 "invalid HDD state or HDD station context");
3359 return -EINVAL;
3360 }
3361
3362 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003363 {
3364 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3365 "%s:LOGP in Progress. Ignore!!!", __func__);
3366 return -EAGAIN;
3367 }
3368
Jeff Johnson295189b2012-06-20 16:38:30 -07003369 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3370
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003371 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3372 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003373 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003374 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003375 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303376 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003377 WLANTL_STA_AUTHENTICATED);
3378
Gopichand Nakkala29149562013-05-10 21:43:41 +05303379 if (status != VOS_STATUS_SUCCESS)
3380 {
3381 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3382 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3383 return -EINVAL;
3384 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003385 }
3386 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003387 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3388 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303389#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003390 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3391 StaParams.capability = params->capability;
3392 StaParams.uapsd_queues = params->uapsd_queues;
3393 StaParams.max_sp = params->max_sp;
3394
3395 if (0 != params->ext_capab_len)
3396 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3397 sizeof(StaParams.extn_capability));
3398
3399 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003400 {
3401 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003402 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003403 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003404
3405 StaParams.supported_rates_len = params->supported_rates_len;
3406
3407 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3408 * The supported_rates array , for all the structures propogating till Add Sta
3409 * to the firmware has to be modified , if the supplicant (ieee80211) is
3410 * modified to send more rates.
3411 */
3412
3413 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3414 */
3415 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3416 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3417
3418 if (0 != StaParams.supported_rates_len) {
3419 int i = 0;
3420 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3421 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003423 "Supported Rates with Length %d", StaParams.supported_rates_len);
3424 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003425 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003426 "[%d]: %0x", i, StaParams.supported_rates[i]);
3427 }
3428
3429 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003430 {
3431 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003432 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003433 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003434
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003435 if (0 != params->ext_capab_len ) {
3436 /*Define A Macro : TODO Sunil*/
3437 if ((1<<4) & StaParams.extn_capability[3]) {
3438 isBufSta = 1;
3439 }
3440 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303441 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3442 params->max_sp, isBufSta);
3443 if (VOS_STATUS_SUCCESS != status) {
3444 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3445 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3446 return -EINVAL;
3447 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003448 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3449
3450 if (VOS_STATUS_SUCCESS != status) {
3451 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3452 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3453 return -EINVAL;
3454 }
3455 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003456#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303457 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003458 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 return status;
3460}
3461
3462/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003463 * FUNCTION: wlan_hdd_cfg80211_add_key
3464 * This function is used to initialize the key information
3465 */
3466#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003467static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003468 struct net_device *ndev,
3469 u8 key_index, bool pairwise,
3470 const u8 *mac_addr,
3471 struct key_params *params
3472 )
3473#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003474static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 struct net_device *ndev,
3476 u8 key_index, const u8 *mac_addr,
3477 struct key_params *params
3478 )
3479#endif
3480{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003481 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003482 tCsrRoamSetKey setKey;
3483 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303484 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003485 v_U32_t roamId= 0xFF;
3486 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003487 hdd_hostapd_state_t *pHostapdState;
3488 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003489 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303490 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003491
3492 ENTER();
3493
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303494 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3495 status = wlan_hdd_validate_context(pHddCtx);
3496
3497 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003498 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303499 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3500 "%s: HDD context is not valid", __func__);
3501 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003502 }
3503
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003504 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3505 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003506
3507 if (CSR_MAX_NUM_KEY <= key_index)
3508 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003509 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003510 key_index);
3511
3512 return -EINVAL;
3513 }
3514
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003515 if (CSR_MAX_KEY_LEN < params->key_len)
3516 {
3517 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3518 params->key_len);
3519
3520 return -EINVAL;
3521 }
3522
3523 hddLog(VOS_TRACE_LEVEL_INFO,
3524 "%s: called with key index = %d & key length %d",
3525 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003526
3527 /*extract key idx, key len and key*/
3528 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3529 setKey.keyId = key_index;
3530 setKey.keyLength = params->key_len;
3531 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3532
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003533 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003534 {
3535 case WLAN_CIPHER_SUITE_WEP40:
3536 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3537 break;
3538
3539 case WLAN_CIPHER_SUITE_WEP104:
3540 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3541 break;
3542
3543 case WLAN_CIPHER_SUITE_TKIP:
3544 {
3545 u8 *pKey = &setKey.Key[0];
3546 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3547
3548 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3549
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003550 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003551
3552 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003553 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 |--------------|----------|----------|
3555 <---16bytes---><--8bytes--><--8bytes-->
3556
3557 */
3558 /*Sme expects the 32 bytes key to be in the below order
3559
3560 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003561 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003562 |--------------|----------|----------|
3563 <---16bytes---><--8bytes--><--8bytes-->
3564 */
3565 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003566 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003567
3568 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003569 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003570
3571 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003572 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003573
3574
3575 break;
3576 }
3577
3578 case WLAN_CIPHER_SUITE_CCMP:
3579 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3580 break;
3581
3582#ifdef FEATURE_WLAN_WAPI
3583 case WLAN_CIPHER_SUITE_SMS4:
3584 {
3585 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3586 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3587 params->key, params->key_len);
3588 return 0;
3589 }
3590#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003591
Jeff Johnson295189b2012-06-20 16:38:30 -07003592#ifdef FEATURE_WLAN_CCX
3593 case WLAN_CIPHER_SUITE_KRK:
3594 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3595 break;
3596#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003597
3598#ifdef WLAN_FEATURE_11W
3599 case WLAN_CIPHER_SUITE_AES_CMAC:
3600 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003601 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003602#endif
3603
Jeff Johnson295189b2012-06-20 16:38:30 -07003604 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003605 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003606 __func__, params->cipher);
3607 return -EOPNOTSUPP;
3608 }
3609
3610 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3611 __func__, setKey.encType);
3612
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003613 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003614#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3615 (!pairwise)
3616#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003617 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003618#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003619 )
3620 {
3621 /* set group key*/
3622 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3623 "%s- %d: setting Broadcast key",
3624 __func__, __LINE__);
3625 setKey.keyDirection = eSIR_RX_ONLY;
3626 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3627 }
3628 else
3629 {
3630 /* set pairwise key*/
3631 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3632 "%s- %d: setting pairwise key",
3633 __func__, __LINE__);
3634 setKey.keyDirection = eSIR_TX_RX;
3635 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3636 }
3637 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3638 {
3639 setKey.keyDirection = eSIR_TX_RX;
3640 /*Set the group key*/
3641 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3642 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003643
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003644 if ( 0 != status )
3645 {
3646 hddLog(VOS_TRACE_LEVEL_ERROR,
3647 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3648 return -EINVAL;
3649 }
3650 /*Save the keys here and call sme_RoamSetKey for setting
3651 the PTK after peer joins the IBSS network*/
3652 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3653 &setKey, sizeof(tCsrRoamSetKey));
3654 return status;
3655 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303656 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3657 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3658 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003659 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003660 if( pHostapdState->bssState == BSS_START )
3661 {
c_hpothu7c55da62014-01-23 18:34:02 +05303662 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3663 vos_status = wlan_hdd_check_ula_done(pAdapter);
3664
3665 if ( vos_status != VOS_STATUS_SUCCESS )
3666 {
3667 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3668 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3669 __LINE__, vos_status );
3670
3671 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3672
3673 return -EINVAL;
3674 }
3675
Jeff Johnson295189b2012-06-20 16:38:30 -07003676 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3677
3678 if ( status != eHAL_STATUS_SUCCESS )
3679 {
3680 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3681 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3682 __LINE__, status );
3683 }
3684 }
3685
3686 /* Saving WEP keys */
3687 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3688 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3689 {
3690 //Save the wep key in ap context. Issue setkey after the BSS is started.
3691 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3692 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3693 }
3694 else
3695 {
3696 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003697 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003698 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3699 }
3700 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003701 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3702 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003703 {
3704 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3705 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3706
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303707#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3708 if (!pairwise)
3709#else
3710 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3711#endif
3712 {
3713 /* set group key*/
3714 if (pHddStaCtx->roam_info.deferKeyComplete)
3715 {
3716 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3717 "%s- %d: Perform Set key Complete",
3718 __func__, __LINE__);
3719 hdd_PerformRoamSetKeyComplete(pAdapter);
3720 }
3721 }
3722
Jeff Johnson295189b2012-06-20 16:38:30 -07003723 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3724
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003725 pWextState->roamProfile.Keys.defaultIndex = key_index;
3726
3727
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003728 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003729 params->key, params->key_len);
3730
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303731
Jeff Johnson295189b2012-06-20 16:38:30 -07003732 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3733
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303734 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003735 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303736 __func__, setKey.peerMac[0], setKey.peerMac[1],
3737 setKey.peerMac[2], setKey.peerMac[3],
3738 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003739 setKey.keyDirection);
3740
3741 vos_status = wlan_hdd_check_ula_done(pAdapter);
3742
3743 if ( vos_status != VOS_STATUS_SUCCESS )
3744 {
3745 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3746 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3747 __LINE__, vos_status );
3748
3749 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3750
3751 return -EINVAL;
3752
3753 }
3754
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003755#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303756 /* The supplicant may attempt to set the PTK once pre-authentication
3757 is done. Save the key in the UMAC and include it in the ADD BSS
3758 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003759 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303760 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003761 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303762 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3763 "%s: Update PreAuth Key success", __func__);
3764 return 0;
3765 }
3766 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3767 {
3768 hddLog(VOS_TRACE_LEVEL_ERROR,
3769 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303770 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003771 }
3772#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003773
3774 /* issue set key request to SME*/
3775 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3776 pAdapter->sessionId, &setKey, &roamId );
3777
3778 if ( 0 != status )
3779 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303780 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003781 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3782 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3783 return -EINVAL;
3784 }
3785
3786
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303787 /* in case of IBSS as there was no information available about WEP keys during
3788 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003789 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303790 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3791 !( ( IW_AUTH_KEY_MGMT_802_1X
3792 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003793 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3794 )
3795 &&
3796 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3797 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3798 )
3799 )
3800 {
3801 setKey.keyDirection = eSIR_RX_ONLY;
3802 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3803
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303804 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003805 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303806 __func__, setKey.peerMac[0], setKey.peerMac[1],
3807 setKey.peerMac[2], setKey.peerMac[3],
3808 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003809 setKey.keyDirection);
3810
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303811 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 pAdapter->sessionId, &setKey, &roamId );
3813
3814 if ( 0 != status )
3815 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303816 hddLog(VOS_TRACE_LEVEL_ERROR,
3817 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003818 __func__, status);
3819 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3820 return -EINVAL;
3821 }
3822 }
3823 }
3824
3825 return 0;
3826}
3827
3828/*
3829 * FUNCTION: wlan_hdd_cfg80211_get_key
3830 * This function is used to get the key information
3831 */
3832#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303833static int wlan_hdd_cfg80211_get_key(
3834 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003835 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303836 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003837 const u8 *mac_addr, void *cookie,
3838 void (*callback)(void *cookie, struct key_params*)
3839 )
3840#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303841static int wlan_hdd_cfg80211_get_key(
3842 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003843 struct net_device *ndev,
3844 u8 key_index, const u8 *mac_addr, void *cookie,
3845 void (*callback)(void *cookie, struct key_params*)
3846 )
3847#endif
3848{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303849 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003850 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3851 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3852 struct key_params params;
3853
3854 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303855
Arif Hussain6d2a3322013-11-17 19:50:10 -08003856 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003857 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303858
Jeff Johnson295189b2012-06-20 16:38:30 -07003859 memset(&params, 0, sizeof(params));
3860
3861 if (CSR_MAX_NUM_KEY <= key_index)
3862 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303863 hddLog(VOS_TRACE_LEVEL_ERROR, FL("invalid key index %d"), key_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07003864 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303865 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003866
3867 switch(pRoamProfile->EncryptionType.encryptionType[0])
3868 {
3869 case eCSR_ENCRYPT_TYPE_NONE:
3870 params.cipher = IW_AUTH_CIPHER_NONE;
3871 break;
3872
3873 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3874 case eCSR_ENCRYPT_TYPE_WEP40:
3875 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3876 break;
3877
3878 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3879 case eCSR_ENCRYPT_TYPE_WEP104:
3880 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3881 break;
3882
3883 case eCSR_ENCRYPT_TYPE_TKIP:
3884 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3885 break;
3886
3887 case eCSR_ENCRYPT_TYPE_AES:
3888 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3889 break;
3890
3891 default:
3892 params.cipher = IW_AUTH_CIPHER_NONE;
3893 break;
3894 }
3895
3896 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3897 params.seq_len = 0;
3898 params.seq = NULL;
3899 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3900 callback(cookie, &params);
3901 return 0;
3902}
3903
3904/*
3905 * FUNCTION: wlan_hdd_cfg80211_del_key
3906 * This function is used to delete the key information
3907 */
3908#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303909static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303911 u8 key_index,
3912 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003913 const u8 *mac_addr
3914 )
3915#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303916static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003917 struct net_device *ndev,
3918 u8 key_index,
3919 const u8 *mac_addr
3920 )
3921#endif
3922{
3923 int status = 0;
3924
3925 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303926 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003927 //it is observed that this is invalidating peer
3928 //key index whenever re-key is done. This is affecting data link.
3929 //It should be ok to ignore del_key.
3930#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303931 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3932 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003933 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3934 tCsrRoamSetKey setKey;
3935 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303936
Jeff Johnson295189b2012-06-20 16:38:30 -07003937 ENTER();
3938
3939 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3940 __func__,pAdapter->device_mode);
3941
3942 if (CSR_MAX_NUM_KEY <= key_index)
3943 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303944 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003945 key_index);
3946
3947 return -EINVAL;
3948 }
3949
3950 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3951 setKey.keyId = key_index;
3952
3953 if (mac_addr)
3954 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3955 else
3956 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3957
3958 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3959
3960 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003961 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303962 )
3963 {
3964
3965 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003966 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3967 if( pHostapdState->bssState == BSS_START)
3968 {
3969 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303970
Jeff Johnson295189b2012-06-20 16:38:30 -07003971 if ( status != eHAL_STATUS_SUCCESS )
3972 {
3973 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3974 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3975 __LINE__, status );
3976 }
3977 }
3978 }
3979 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303980 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003981 )
3982 {
3983 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3984
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303985 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3986
3987 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003988 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303989 __func__, setKey.peerMac[0], setKey.peerMac[1],
3990 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003991 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303992 if(pAdapter->sessionCtx.station.conn_info.connState ==
3993 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003994 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303995 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003996 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303997
Jeff Johnson295189b2012-06-20 16:38:30 -07003998 if ( 0 != status )
3999 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304000 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004001 "%s: sme_RoamSetKey failure, returned %d",
4002 __func__, status);
4003 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
4004 return -EINVAL;
4005 }
4006 }
4007 }
4008#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07004009 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004010 return status;
4011}
4012
4013/*
4014 * FUNCTION: wlan_hdd_cfg80211_set_default_key
4015 * This function is used to set the default tx key index
4016 */
4017#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
4018static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4019 struct net_device *ndev,
4020 u8 key_index,
4021 bool unicast, bool multicast)
4022#else
4023static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4024 struct net_device *ndev,
4025 u8 key_index)
4026#endif
4027{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304028 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304029 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05304030 hdd_wext_state_t *pWextState;
4031 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304032 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004033
4034 ENTER();
4035
Gopichand Nakkala29149562013-05-10 21:43:41 +05304036 if ((NULL == pAdapter))
4037 {
4038 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4039 "invalid adapter");
4040 return -EINVAL;
4041 }
4042
4043 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4044 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4045
4046 if ((NULL == pWextState) || (NULL == pHddStaCtx))
4047 {
4048 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4049 "invalid Wext state or HDD context");
4050 return -EINVAL;
4051 }
4052
Arif Hussain6d2a3322013-11-17 19:50:10 -08004053 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004054 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304055
Jeff Johnson295189b2012-06-20 16:38:30 -07004056 if (CSR_MAX_NUM_KEY <= key_index)
4057 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304058 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004059 key_index);
4060
4061 return -EINVAL;
4062 }
4063
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304064 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4065 status = wlan_hdd_validate_context(pHddCtx);
4066
4067 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004068 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304069 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4070 "%s: HDD context is not valid", __func__);
4071 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004072 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304073
Jeff Johnson295189b2012-06-20 16:38:30 -07004074 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07004075 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304076 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004077 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05304078 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08004079 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304080 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08004081 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304083 {
4084 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07004085 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304086
Jeff Johnson295189b2012-06-20 16:38:30 -07004087 tCsrRoamSetKey setKey;
4088 v_U32_t roamId= 0xFF;
4089 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304090
4091 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004092 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304093
Jeff Johnson295189b2012-06-20 16:38:30 -07004094 Keys->defaultIndex = (u8)key_index;
4095 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4096 setKey.keyId = key_index;
4097 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304098
4099 vos_mem_copy(&setKey.Key[0],
4100 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07004101 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304102
Gopichand Nakkala29149562013-05-10 21:43:41 +05304103 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304104
4105 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07004106 &pHddStaCtx->conn_info.bssId[0],
4107 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304108
Gopichand Nakkala29149562013-05-10 21:43:41 +05304109 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
4110 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4111 eCSR_ENCRYPT_TYPE_WEP104)
4112 {
4113 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
4114 even though ap is configured for WEP-40 encryption. In this canse the key length
4115 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
4116 type(104) and switching encryption type to 40*/
4117 pWextState->roamProfile.EncryptionType.encryptionType[0] =
4118 eCSR_ENCRYPT_TYPE_WEP40;
4119 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
4120 eCSR_ENCRYPT_TYPE_WEP40;
4121 }
4122
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304123 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07004124 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304125
Jeff Johnson295189b2012-06-20 16:38:30 -07004126 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304127 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004128 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304129
Jeff Johnson295189b2012-06-20 16:38:30 -07004130 if ( 0 != status )
4131 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304132 hddLog(VOS_TRACE_LEVEL_ERROR,
4133 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004134 status);
4135 return -EINVAL;
4136 }
4137 }
4138 }
4139
4140 /* In SoftAp mode setting key direction for default mode */
4141 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
4142 {
4143 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
4144 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
4145 (eCSR_ENCRYPT_TYPE_AES !=
4146 pWextState->roamProfile.EncryptionType.encryptionType[0])
4147 )
4148 {
4149 /* Saving key direction for default key index to TX default */
4150 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
4151 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
4152 }
4153 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304154
Jeff Johnson295189b2012-06-20 16:38:30 -07004155 return status;
4156}
4157
Jeff Johnson295189b2012-06-20 16:38:30 -07004158/*
4159 * FUNCTION: wlan_hdd_cfg80211_inform_bss
4160 * This function is used to inform the BSS details to nl80211 interface.
4161 */
4162static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
4163 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
4164{
4165 struct net_device *dev = pAdapter->dev;
4166 struct wireless_dev *wdev = dev->ieee80211_ptr;
4167 struct wiphy *wiphy = wdev->wiphy;
4168 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4169 int chan_no;
4170 int ie_length;
4171 const char *ie;
4172 unsigned int freq;
4173 struct ieee80211_channel *chan;
4174 int rssi = 0;
4175 struct cfg80211_bss *bss = NULL;
4176
4177 ENTER();
4178
4179 if( NULL == pBssDesc )
4180 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004181 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004182 return bss;
4183 }
4184
4185 chan_no = pBssDesc->channelId;
4186 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4187 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4188
4189 if( NULL == ie )
4190 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004191 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004192 return bss;
4193 }
4194
4195#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4196 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4197 {
4198 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4199 }
4200 else
4201 {
4202 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4203 }
4204#else
4205 freq = ieee80211_channel_to_frequency(chan_no);
4206#endif
4207
4208 chan = __ieee80211_get_channel(wiphy, freq);
4209
4210 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4211 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4212 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4213 if (bss == NULL)
4214 {
4215 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4216
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304217 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4218 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004219 pBssDesc->capabilityInfo,
4220 pBssDesc->beaconInterval, ie, ie_length,
4221 rssi, GFP_KERNEL ));
4222}
4223 else
4224 {
4225 return bss;
4226 }
4227}
4228
4229
4230
4231/*
4232 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4233 * This function is used to inform the BSS details to nl80211 interface.
4234 */
4235struct cfg80211_bss*
4236wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4237 tSirBssDescription *bss_desc
4238 )
4239{
4240 /*
4241 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4242 already exists in bss data base of cfg80211 for that particular BSS ID.
4243 Using cfg80211_inform_bss_frame to update the bss entry instead of
4244 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4245 now there is no possibility to get the mgmt(probe response) frame from PE,
4246 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4247 cfg80211_inform_bss_frame.
4248 */
4249 struct net_device *dev = pAdapter->dev;
4250 struct wireless_dev *wdev = dev->ieee80211_ptr;
4251 struct wiphy *wiphy = wdev->wiphy;
4252 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004253#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4254 qcom_ie_age *qie_age = NULL;
4255 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4256#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004257 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004258#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004259 const char *ie =
4260 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4261 unsigned int freq;
4262 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304263 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004264 struct cfg80211_bss *bss_status = NULL;
4265 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4266 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004267 hdd_context_t *pHddCtx;
4268 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004269#ifdef WLAN_OPEN_SOURCE
4270 struct timespec ts;
4271#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004272
4273 ENTER();
4274
Wilson Yangf80a0542013-10-07 13:02:37 -07004275 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4276 status = wlan_hdd_validate_context(pHddCtx);
4277
4278 /*bss_update is not allowed during wlan driver loading or unloading*/
4279 if (pHddCtx->isLoadUnloadInProgress)
4280 {
4281 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4282 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4283 return NULL;
4284 }
4285
4286
4287 if (0 != status)
4288 {
4289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4290 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004291 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004292 }
4293
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304294 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004295 if (!mgmt)
4296 {
4297 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4298 "%s: memory allocation failed ", __func__);
4299 return NULL;
4300 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004301
Jeff Johnson295189b2012-06-20 16:38:30 -07004302 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004303
4304#ifdef WLAN_OPEN_SOURCE
4305 /* Android does not want the timestamp from the frame.
4306 Instead it wants a monotonic increasing value */
4307 get_monotonic_boottime(&ts);
4308 mgmt->u.probe_resp.timestamp =
4309 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4310#else
4311 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4313 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004314
4315#endif
4316
Jeff Johnson295189b2012-06-20 16:38:30 -07004317 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4318 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004319
4320#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4321 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4322 /* Assuming this is the last IE, copy at the end */
4323 ie_length -=sizeof(qcom_ie_age);
4324 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4325 qie_age->element_id = QCOM_VENDOR_IE_ID;
4326 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4327 qie_age->oui_1 = QCOM_OUI1;
4328 qie_age->oui_2 = QCOM_OUI2;
4329 qie_age->oui_3 = QCOM_OUI3;
4330 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4331 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4332#endif
4333
Jeff Johnson295189b2012-06-20 16:38:30 -07004334 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304335 if (bss_desc->fProbeRsp)
4336 {
4337 mgmt->frame_control |=
4338 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4339 }
4340 else
4341 {
4342 mgmt->frame_control |=
4343 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4344 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004345
4346#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304347 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004348 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4349 {
4350 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4351 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304352 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004353 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4354
4355 {
4356 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4357 }
4358 else
4359 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304360 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4361 "%s: invalid chan_no %d", __func__, chan_no);
Jeff Johnson295189b2012-06-20 16:38:30 -07004362 kfree(mgmt);
4363 return NULL;
4364 }
4365#else
4366 freq = ieee80211_channel_to_frequency(chan_no);
4367#endif
4368 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004369 /*when the band is changed on the fly using the GUI, three things are done
4370 * 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)
4371 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4372 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4373 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4374 * and discards the channels correponding to previous band and calls back with zero bss results.
4375 * 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
4376 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4377 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4378 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4379 * So drop the bss and continue to next bss.
4380 */
4381 if(chan == NULL)
4382 {
4383 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004384 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004385 return NULL;
4386 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004387 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304388 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004389 * */
4390 if (( eConnectionState_Associated ==
4391 pAdapter->sessionCtx.station.conn_info.connState ) &&
4392 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4393 pAdapter->sessionCtx.station.conn_info.bssId,
4394 WNI_CFG_BSSID_LEN)))
4395 {
4396 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4397 rssi = (pAdapter->rssi * 100);
4398 }
4399 else
4400 {
4401 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4402 }
4403
4404 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4405 frame_len, rssi, GFP_KERNEL);
4406 kfree(mgmt);
4407 return bss_status;
4408}
4409
4410/*
4411 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4412 * This function is used to update the BSS data base of CFG8011
4413 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304414struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004415 tCsrRoamInfo *pRoamInfo
4416 )
4417{
4418 tCsrRoamConnectedProfile roamProfile;
4419 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4420 struct cfg80211_bss *bss = NULL;
4421
4422 ENTER();
4423
4424 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4425 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4426
4427 if (NULL != roamProfile.pBssDesc)
4428 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304429 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004430 &roamProfile);
4431
4432 if (NULL == bss)
4433 {
4434 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4435 __func__);
4436 }
4437
4438 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4439 }
4440 else
4441 {
4442 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4443 __func__);
4444 }
4445 return bss;
4446}
4447
4448/*
4449 * FUNCTION: wlan_hdd_cfg80211_update_bss
4450 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304451static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4452 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004453 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304454{
Jeff Johnson295189b2012-06-20 16:38:30 -07004455 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4456 tCsrScanResultInfo *pScanResult;
4457 eHalStatus status = 0;
4458 tScanResultHandle pResult;
4459 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004460 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004461
4462 ENTER();
4463
Wilson Yangf80a0542013-10-07 13:02:37 -07004464 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4465
4466 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004467 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004468 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4469 "%s:LOGP in Progress. Ignore!!!",__func__);
4470 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004471 }
4472
Wilson Yangf80a0542013-10-07 13:02:37 -07004473
4474 /*bss_update is not allowed during wlan driver loading or unloading*/
4475 if (pHddCtx->isLoadUnloadInProgress)
4476 {
4477 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4478 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4479 return VOS_STATUS_E_PERM;
4480 }
4481
4482
Jeff Johnson295189b2012-06-20 16:38:30 -07004483 /*
4484 * start getting scan results and populate cgf80211 BSS database
4485 */
4486 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4487
4488 /* no scan results */
4489 if (NULL == pResult)
4490 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004491 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004492 return status;
4493 }
4494
4495 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4496
4497 while (pScanResult)
4498 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304499 /*
4500 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4501 * entry already exists in bss data base of cfg80211 for that
4502 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4503 * bss entry instead of cfg80211_inform_bss, But this call expects
4504 * mgmt packet as input. As of now there is no possibility to get
4505 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004506 * ieee80211_mgmt(probe response) and passing to c
4507 * fg80211_inform_bss_frame.
4508 * */
4509
4510 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4511 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304512
Jeff Johnson295189b2012-06-20 16:38:30 -07004513
4514 if (NULL == bss_status)
4515 {
4516 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004517 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004518 }
4519 else
4520 {
Yue Maf49ba872013-08-19 12:04:25 -07004521 cfg80211_put_bss(
4522#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4523 wiphy,
4524#endif
4525 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004526 }
4527
4528 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4529 }
4530
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304531 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004532
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304533 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004534}
4535
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004536void
4537hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4538{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304539 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004540 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004541} /****** end hddPrintMacAddr() ******/
4542
4543void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004544hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004545{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304546 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004547 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004548 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4549 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4550 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004551} /****** end hddPrintPmkId() ******/
4552
4553//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4554//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4555
4556//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4557//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4558
4559#define dump_bssid(bssid) \
4560 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004561 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4562 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004563 }
4564
4565#define dump_pmkid(pMac, pmkid) \
4566 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004567 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4568 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004569 }
4570
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004571#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004572/*
4573 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4574 * This function is used to notify the supplicant of a new PMKSA candidate.
4575 */
4576int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304577 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004578 int index, bool preauth )
4579{
Jeff Johnsone7245742012-09-05 17:12:55 -07004580#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004581 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004582 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004583
4584 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004585 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004586
4587 if( NULL == pRoamInfo )
4588 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004589 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004590 return -EINVAL;
4591 }
4592
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004593 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4594 {
4595 dump_bssid(pRoamInfo->bssid);
4596 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004597 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004598 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004599#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304600 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004601}
4602#endif //FEATURE_WLAN_LFR
4603
Yue Maef608272013-04-08 23:09:17 -07004604#ifdef FEATURE_WLAN_LFR_METRICS
4605/*
4606 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4607 * 802.11r/LFR metrics reporting function to report preauth initiation
4608 *
4609 */
4610#define MAX_LFR_METRICS_EVENT_LENGTH 100
4611VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4612 tCsrRoamInfo *pRoamInfo)
4613{
4614 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4615 union iwreq_data wrqu;
4616
4617 ENTER();
4618
4619 if (NULL == pAdapter)
4620 {
4621 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4622 return VOS_STATUS_E_FAILURE;
4623 }
4624
4625 /* create the event */
4626 memset(&wrqu, 0, sizeof(wrqu));
4627 memset(metrics_notification, 0, sizeof(metrics_notification));
4628
4629 wrqu.data.pointer = metrics_notification;
4630 wrqu.data.length = scnprintf(metrics_notification,
4631 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4632 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4633
4634 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4635
4636 EXIT();
4637
4638 return VOS_STATUS_SUCCESS;
4639}
4640
4641/*
4642 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4643 * 802.11r/LFR metrics reporting function to report preauth completion
4644 * or failure
4645 */
4646VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4647 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4648{
4649 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4650 union iwreq_data wrqu;
4651
4652 ENTER();
4653
4654 if (NULL == pAdapter)
4655 {
4656 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4657 return VOS_STATUS_E_FAILURE;
4658 }
4659
4660 /* create the event */
4661 memset(&wrqu, 0, sizeof(wrqu));
4662 memset(metrics_notification, 0, sizeof(metrics_notification));
4663
4664 scnprintf(metrics_notification, sizeof(metrics_notification),
4665 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4666 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4667
4668 if (1 == preauth_status)
4669 strncat(metrics_notification, " TRUE", 5);
4670 else
4671 strncat(metrics_notification, " FALSE", 6);
4672
4673 wrqu.data.pointer = metrics_notification;
4674 wrqu.data.length = strlen(metrics_notification);
4675
4676 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4677
4678 EXIT();
4679
4680 return VOS_STATUS_SUCCESS;
4681}
4682
4683/*
4684 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4685 * 802.11r/LFR metrics reporting function to report handover initiation
4686 *
4687 */
4688VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4689 tCsrRoamInfo *pRoamInfo)
4690{
4691 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4692 union iwreq_data wrqu;
4693
4694 ENTER();
4695
4696 if (NULL == pAdapter)
4697 {
4698 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4699 return VOS_STATUS_E_FAILURE;
4700 }
4701
4702 /* create the event */
4703 memset(&wrqu, 0, sizeof(wrqu));
4704 memset(metrics_notification, 0, sizeof(metrics_notification));
4705
4706 wrqu.data.pointer = metrics_notification;
4707 wrqu.data.length = scnprintf(metrics_notification,
4708 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4709 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4710
4711 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4712
4713 EXIT();
4714
4715 return VOS_STATUS_SUCCESS;
4716}
4717#endif
4718
Jeff Johnson295189b2012-06-20 16:38:30 -07004719/*
4720 * FUNCTION: hdd_cfg80211_scan_done_callback
4721 * scanning callback function, called after finishing scan
4722 *
4723 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304724static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004725 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4726{
4727 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304728 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004729 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004730 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4731 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004732 struct cfg80211_scan_request *req = NULL;
4733 int ret = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304734 long waitRet = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004735
4736 ENTER();
4737
4738 hddLog(VOS_TRACE_LEVEL_INFO,
4739 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004740 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004741 __func__, halHandle, pContext, (int) scanId, (int) status);
4742
Kiet Lamac06e2c2013-10-23 16:25:07 +05304743 pScanInfo->mScanPendingCounter = 0;
4744
Jeff Johnson295189b2012-06-20 16:38:30 -07004745 //Block on scan req completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304746 waitRet = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07004747 &pScanInfo->scan_req_completion_event,
4748 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304749 if (waitRet <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07004750 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304751 hddLog(VOS_TRACE_LEVEL_ERROR,
4752 "%s wait on scan_req_completion_event failed %ld",__func__, waitRet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004754 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 }
4756
Yue Maef608272013-04-08 23:09:17 -07004757 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004758 {
4759 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004760 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004761 }
4762
4763 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304764 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004765 {
4766 hddLog(VOS_TRACE_LEVEL_INFO,
4767 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004768 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004769 (int) scanId);
4770 }
4771
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304772 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004773 pAdapter);
4774
4775 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304776 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004777
4778
4779 /* If any client wait scan result through WEXT
4780 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004781 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004782 {
4783 /* The other scan request waiting for current scan finish
4784 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004785 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004786 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004787 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004788 }
4789 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004790 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004791 {
4792 struct net_device *dev = pAdapter->dev;
4793 union iwreq_data wrqu;
4794 int we_event;
4795 char *msg;
4796
4797 memset(&wrqu, '\0', sizeof(wrqu));
4798 we_event = SIOCGIWSCAN;
4799 msg = NULL;
4800 wireless_send_event(dev, we_event, &wrqu, msg);
4801 }
4802 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004803 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004804
4805 /* Get the Scan Req */
4806 req = pAdapter->request;
4807
4808 if (!req)
4809 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004810 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004811 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004812 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004813 }
4814
4815 /*
4816 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304817 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004818 req->n_ssids = 0;
4819 req->n_channels = 0;
4820 req->ie = 0;
4821
Jeff Johnson295189b2012-06-20 16:38:30 -07004822 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004823 /* Scan is no longer pending */
4824 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004825
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004826 /*
4827 * cfg80211_scan_done informing NL80211 about completion
4828 * of scanning
4829 */
4830 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004831 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004832
Jeff Johnsone7245742012-09-05 17:12:55 -07004833allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004834 /* release the wake lock at the end of the scan*/
4835 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004836
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004837 /* Acquire wakelock to handle the case where APP's tries to suspend
4838 * immediatly after the driver gets connect request(i.e after scan)
4839 * from supplicant, this result in app's is suspending and not able
4840 * to process the connect request to AP */
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05304841 hdd_prevent_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004842
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004843#ifdef FEATURE_WLAN_TDLS
4844 wlan_hdd_tdls_scan_done_callback(pAdapter);
4845#endif
4846
Jeff Johnson295189b2012-06-20 16:38:30 -07004847 EXIT();
4848 return 0;
4849}
4850
4851/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004852 * FUNCTION: hdd_isScanAllowed
4853 * Go through each adapter and check if scan allowed
4854 *
4855 */
4856v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4857{
4858 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4859 hdd_station_ctx_t *pHddStaCtx = NULL;
4860 hdd_adapter_t *pAdapter = NULL;
4861 VOS_STATUS status = 0;
4862 v_U8_t staId = 0;
4863 v_U8_t *staMac = NULL;
4864
c_hpothu9b781ba2013-12-30 20:57:45 +05304865 if (TRUE == pHddCtx->btCoexModeSet)
4866 {
4867 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4868 FL("BTCoex Mode operation in progress, Do not allow scan"));
4869 return VOS_FALSE;
4870 }
4871
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004872 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4873
4874 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4875 {
4876 pAdapter = pAdapterNode->pAdapter;
4877
4878 if( pAdapter )
4879 {
4880 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304881 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004882 __func__, pAdapter->device_mode);
4883 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4884 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4885 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4886 {
4887 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4888 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4889 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4890 {
4891 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4892 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004893 "%s: client " MAC_ADDRESS_STR
4894 " is in the middle of WPS/EAPOL exchange.", __func__,
4895 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004896 return VOS_FALSE;
4897 }
4898 }
4899 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4900 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4901 {
4902 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4903 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304904 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004905 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4906 {
4907 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4908
4909 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004910 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
4911 "middle of WPS/EAPOL exchange.", __func__,
4912 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004913 return VOS_FALSE;
4914 }
4915 }
4916 }
4917 }
4918 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4919 pAdapterNode = pNext;
4920 }
4921 hddLog(VOS_TRACE_LEVEL_INFO,
4922 "%s: Scan allowed", __func__);
4923 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304924}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004925
4926/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004927 * FUNCTION: wlan_hdd_cfg80211_scan
4928 * this scan respond to scan trigger and update cfg80211 scan database
4929 * later, scan dump command can be used to recieve scan results
4930 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004931int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4932#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4933 struct net_device *dev,
4934#endif
4935 struct cfg80211_scan_request *request)
4936{
4937#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4938 struct net_device *dev = request->wdev->netdev;
4939#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304940 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004941 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4942 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304943 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004944 tCsrScanRequest scanRequest;
4945 tANI_U8 *channelList = NULL, i;
4946 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304947 int status;
4948 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004949 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004950
4951 ENTER();
4952
Arif Hussain6d2a3322013-11-17 19:50:10 -08004953 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004954 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004955
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304956 status = wlan_hdd_validate_context(pHddCtx);
4957
4958 if (0 != status)
4959 {
4960 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4961 "%s: HDD context is not valid", __func__);
4962 return status;
4963 }
4964
4965 cfg_param = pHddCtx->cfg_ini;
4966 pScanInfo = &pHddCtx->scan_info;
4967
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004968 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004969 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004970 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004971 {
4972 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004973 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4974 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004975 return -EBUSY;
4976 }
4977
Jeff Johnson295189b2012-06-20 16:38:30 -07004978#ifdef WLAN_BTAMP_FEATURE
4979 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004980 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004981 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004982 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004983 "%s: No scanning when AMP is on", __func__);
4984 return -EOPNOTSUPP;
4985 }
4986#endif
4987 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004988 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004989 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004990 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004991 "%s: Not scanning on device_mode = %d",
4992 __func__, pAdapter->device_mode);
4993 return -EOPNOTSUPP;
4994 }
4995
4996 if (TRUE == pScanInfo->mScanPending)
4997 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05304998 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
4999 {
5000 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
5001 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005002 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005003 }
5004
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305005 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07005006 //Channel and action frame is pending
5007 //Otherwise Cancel Remain On Channel and allow Scan
5008 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005009 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07005010 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305011 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005012 return -EBUSY;
5013 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005014#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005015 /* if tdls disagree scan right now, return immediately.
5016 tdls will schedule the scan when scan is allowed. (return SUCCESS)
5017 or will reject the scan if any TDLS is in progress. (return -EBUSY)
5018 */
5019 status = wlan_hdd_tdls_scan_callback (pAdapter,
5020 wiphy,
5021#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5022 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07005023#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005024 request);
5025 if(status <= 0)
5026 {
5027 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
5028 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005029 }
5030#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07005031
Jeff Johnson295189b2012-06-20 16:38:30 -07005032 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
5033 {
5034 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08005035 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005036 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305037 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005038 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
5039 {
5040 hddLog(VOS_TRACE_LEVEL_WARN,
5041 "%s: MAX TM Level Scan not allowed", __func__);
5042 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305043 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005044 }
5045 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
5046
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005047 /* Check if scan is allowed at this point of time.
5048 */
5049 if (!hdd_isScanAllowed(pHddCtx))
5050 {
5051 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
5052 return -EBUSY;
5053 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305054
Jeff Johnson295189b2012-06-20 16:38:30 -07005055 vos_mem_zero( &scanRequest, sizeof(scanRequest));
5056
5057 if (NULL != request)
5058 {
5059 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305060 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07005061
5062 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
5063 * Becasue of this, driver is assuming that this is not wildcard scan and so
5064 * is not aging out the scan results.
5065 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07005066 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07005067 {
5068 request->n_ssids = 0;
5069 }
5070
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07005071 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07005072 {
5073 tCsrSSIDInfo *SsidInfo;
5074 int j;
5075 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
5076 /* Allocate num_ssid tCsrSSIDInfo structure */
5077 SsidInfo = scanRequest.SSIDs.SSIDList =
5078 ( tCsrSSIDInfo *)vos_mem_malloc(
5079 request->n_ssids*sizeof(tCsrSSIDInfo));
5080
5081 if(NULL == scanRequest.SSIDs.SSIDList)
5082 {
5083 hddLog(VOS_TRACE_LEVEL_ERROR,
5084 "memory alloc failed SSIDInfo buffer");
5085 return -ENOMEM;
5086 }
5087
5088 /* copy all the ssid's and their length */
5089 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
5090 {
5091 /* get the ssid length */
5092 SsidInfo->SSID.length = request->ssids[j].ssid_len;
5093 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
5094 SsidInfo->SSID.length);
5095 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
5096 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
5097 j, SsidInfo->SSID.ssId);
5098 }
5099 /* set the scan type to active */
5100 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5101 }
5102 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
5103 {
5104 /* set the scan type to active */
5105 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5106 }
5107 else
5108 {
5109 /*Set the scan type to default type, in this case it is ACTIVE*/
5110 scanRequest.scanType = pScanInfo->scan_mode;
5111 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305112 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07005113 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
5114 }
5115 else
5116 {
5117 /* set the scan type to active */
5118 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5119 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
5120
5121 /* set min and max channel time to zero */
5122 scanRequest.minChnTime = 0;
5123 scanRequest.maxChnTime = 0;
5124 }
5125
5126 /* set BSSType to default type */
5127 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
5128
5129 /*TODO: scan the requested channels only*/
5130
5131 /*Right now scanning all the channels */
5132 if( request )
5133 {
5134 if( request->n_channels )
5135 {
5136 channelList = vos_mem_malloc( request->n_channels );
5137 if( NULL == channelList )
5138 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305139 hddLog(VOS_TRACE_LEVEL_ERROR,
5140 "channelList memory alloc failed channelList");
Jeff Johnson295189b2012-06-20 16:38:30 -07005141 status = -ENOMEM;
5142 goto free_mem;
5143 }
5144
5145 for( i = 0 ; i < request->n_channels ; i++ )
5146 channelList[i] = request->channels[i]->hw_value;
5147 }
5148
5149 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
5150 scanRequest.ChannelInfo.ChannelList = channelList;
5151
5152 /* set requestType to full scan */
5153 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305154
5155 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005156 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305157 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005158 */
5159
5160 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305161 * and in that case driver shoudnt flush scan results. If
5162 * driver flushes the scan results here and unfortunately if
5163 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005164 * fails which is not desired
5165 */
5166
5167 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
5168 {
5169 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
5170 pAdapter->sessionId );
5171 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005172
5173 if( request->ie_len )
5174 {
5175 /* save this for future association (join requires this) */
Agarwal Ashish4f616132013-12-30 23:32:50 +05305176 /*TODO: Array needs to be converted to dynamic allocation,
5177 * as multiple ie.s can be sent in cfg80211_scan_request structure
5178 * CR 597966
5179 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005180 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5181 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5182 pScanInfo->scanAddIE.length = request->ie_len;
5183
Agarwal Ashish4f616132013-12-30 23:32:50 +05305184 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07005185 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
Agarwal Ashish4f616132013-12-30 23:32:50 +05305186 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005187 {
Agarwal Ashish4f616132013-12-30 23:32:50 +05305188 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
5189 {
5190 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5191 memcpy( pwextBuf->roamProfile.addIEScan,
5192 request->ie, request->ie_len);
5193 }
5194 else
5195 {
5196 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
5197 "%d", request->ie_len);
5198 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005199
Agarwal Ashish4f616132013-12-30 23:32:50 +05305200 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005201 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5202 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5203
Jeff Johnson295189b2012-06-20 16:38:30 -07005204 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5205 request->ie_len);
5206 if (pP2pIe != NULL)
5207 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005208#ifdef WLAN_FEATURE_P2P_DEBUG
5209 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5210 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5211 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5212 {
5213 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5214 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5215 "Go nego completed to Connection is started");
5216 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5217 "for 8way Handshake");
5218 }
5219 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5220 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5221 {
5222 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5223 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5224 "Disconnected state to Connection is started");
5225 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5226 "for 4way Handshake");
5227 }
5228#endif
5229
Jeff Johnsone7245742012-09-05 17:12:55 -07005230 /* no_cck will be set during p2p find to disable 11b rates */
5231 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005232 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005233 hddLog(VOS_TRACE_LEVEL_INFO,
5234 "%s: This is a P2P Search", __func__);
5235 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005236
Jeff Johnsone7245742012-09-05 17:12:55 -07005237 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5238 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005239 /* set requestType to P2P Discovery */
5240 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005241 }
5242
5243 /*
5244 Skip Dfs Channel in case of P2P Search
5245 if it is set in ini file
5246 */
5247 if(cfg_param->skipDfsChnlInP2pSearch)
5248 {
5249 scanRequest.skipDfsChnlInP2pSearch = 1;
5250 }
5251 else
5252 {
5253 scanRequest.skipDfsChnlInP2pSearch = 0;
5254 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005255
Jeff Johnson295189b2012-06-20 16:38:30 -07005256 }
5257 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005258 }
5259 }
5260
5261 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5262
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005263 /* acquire the wakelock to avoid the apps suspend during the scan. To
5264 * address the following issues.
5265 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5266 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5267 * for long time, this result in apps running at full power for long time.
5268 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5269 * be stuck in full power because of resume BMPS
5270 */
5271 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005272
5273 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 pAdapter->sessionId, &scanRequest, &scanId,
5275 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005276
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 if (eHAL_STATUS_SUCCESS != status)
5278 {
5279 hddLog(VOS_TRACE_LEVEL_ERROR,
5280 "%s: sme_ScanRequest returned error %d", __func__, status);
5281 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005282 if(eHAL_STATUS_RESOURCES == status)
5283 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07005284 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 -07005285 status = -EBUSY;
5286 } else {
5287 status = -EIO;
5288 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005289 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005290 goto free_mem;
5291 }
5292
5293 pScanInfo->mScanPending = TRUE;
5294 pAdapter->request = request;
5295 pScanInfo->scanId = scanId;
5296
5297 complete(&pScanInfo->scan_req_completion_event);
5298
5299free_mem:
5300 if( scanRequest.SSIDs.SSIDList )
5301 {
5302 vos_mem_free(scanRequest.SSIDs.SSIDList);
5303 }
5304
5305 if( channelList )
5306 vos_mem_free( channelList );
5307
5308 EXIT();
5309
5310 return status;
5311}
5312
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005313
5314void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5315{
5316 v_U8_t iniDot11Mode =
5317 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5318 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5319
5320 switch ( iniDot11Mode )
5321 {
5322 case eHDD_DOT11_MODE_AUTO:
5323 case eHDD_DOT11_MODE_11ac:
5324 case eHDD_DOT11_MODE_11ac_ONLY:
5325#ifdef WLAN_FEATURE_11AC
5326 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5327#else
5328 hddDot11Mode = eHDD_DOT11_MODE_11n;
5329#endif
5330 break;
5331 case eHDD_DOT11_MODE_11n:
5332 case eHDD_DOT11_MODE_11n_ONLY:
5333 hddDot11Mode = eHDD_DOT11_MODE_11n;
5334 break;
5335 default:
5336 hddDot11Mode = iniDot11Mode;
5337 break;
5338 }
5339 /* This call decides required channel bonding mode */
5340 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5341 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5342 operationChannel);
5343}
5344
Jeff Johnson295189b2012-06-20 16:38:30 -07005345/*
5346 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305347 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005348 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305349int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005350 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005351{
5352 int status = 0;
5353 hdd_wext_state_t *pWextState;
5354 v_U32_t roamId;
5355 tCsrRoamProfile *pRoamProfile;
Jeff Johnson295189b2012-06-20 16:38:30 -07005356 eCsrAuthType RSNAuthType;
5357
5358 ENTER();
5359
5360 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305361
Jeff Johnson295189b2012-06-20 16:38:30 -07005362 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5363 {
5364 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5365 return -EINVAL;
5366 }
5367
5368 pRoamProfile = &pWextState->roamProfile;
5369
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305370 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005372 hdd_station_ctx_t *pHddStaCtx;
5373 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005374
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305375 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005376 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5377 {
5378 /*QoS not enabled in cfg file*/
5379 pRoamProfile->uapsd_mask = 0;
5380 }
5381 else
5382 {
5383 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305384 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005385 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5386 }
5387
5388 pRoamProfile->SSIDs.numOfSSIDs = 1;
5389 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5390 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305391 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005392 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5393 ssid, ssid_len);
5394
5395 if (bssid)
5396 {
5397 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5398 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5399 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305400 /* Save BSSID in seperate variable as well, as RoamProfile
5401 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005402 case of join failure we should send valid BSSID to supplicant
5403 */
5404 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5405 WNI_CFG_BSSID_LEN);
5406 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005407 else
5408 {
5409 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5410 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005411
5412 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5413 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305414 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 /*set gen ie*/
5416 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5417 /*set auth*/
5418 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5419 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005420#ifdef FEATURE_WLAN_WAPI
5421 if (pAdapter->wapi_info.nWapiMode)
5422 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005423 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005424 switch (pAdapter->wapi_info.wapiAuthMode)
5425 {
5426 case WAPI_AUTH_MODE_PSK:
5427 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005428 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005429 pAdapter->wapi_info.wapiAuthMode);
5430 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5431 break;
5432 }
5433 case WAPI_AUTH_MODE_CERT:
5434 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005435 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005436 pAdapter->wapi_info.wapiAuthMode);
5437 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5438 break;
5439 }
5440 } // End of switch
5441 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5442 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5443 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005444 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005445 pRoamProfile->AuthType.numEntries = 1;
5446 pRoamProfile->EncryptionType.numEntries = 1;
5447 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5448 pRoamProfile->mcEncryptionType.numEntries = 1;
5449 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5450 }
5451 }
5452#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305453#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305454 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305455 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5456 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5457 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305458 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5459 sizeof (tSirGtkOffloadParams));
5460 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305461 }
5462#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005463 pRoamProfile->csrPersona = pAdapter->device_mode;
5464
Jeff Johnson32d95a32012-09-10 13:15:23 -07005465 if( operatingChannel )
5466 {
5467 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5468 pRoamProfile->ChannelInfo.numOfChannels = 1;
5469 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005470 else
5471 {
5472 pRoamProfile->ChannelInfo.ChannelList = NULL;
5473 pRoamProfile->ChannelInfo.numOfChannels = 0;
5474 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005475 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5476 {
5477 hdd_select_cbmode(pAdapter,operatingChannel);
5478 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005479 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5480 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305481 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005482 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005483 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5484 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305485 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5486 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005487 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5488 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305489
5490 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005491 pAdapter->sessionId, pRoamProfile, &roamId);
5492
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305493 if ((eHAL_STATUS_SUCCESS != status) &&
5494 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5495 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305496
5497 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005498 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5499 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5500 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305501 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005502 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305503 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005504
5505 pRoamProfile->ChannelInfo.ChannelList = NULL;
5506 pRoamProfile->ChannelInfo.numOfChannels = 0;
5507
Jeff Johnson295189b2012-06-20 16:38:30 -07005508 }
5509 else
5510 {
5511 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5512 return -EINVAL;
5513 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005514 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005515 return status;
5516}
5517
5518/*
5519 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5520 * This function is used to set the authentication type (OPEN/SHARED).
5521 *
5522 */
5523static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5524 enum nl80211_auth_type auth_type)
5525{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305526 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005527 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5528
5529 ENTER();
5530
5531 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305532 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005533 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005534 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305535 hddLog(VOS_TRACE_LEVEL_INFO,
5536 "%s: set authentication type to AUTOSWITCH", __func__);
5537 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5538 break;
5539
5540 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005541#ifdef WLAN_FEATURE_VOWIFI_11R
5542 case NL80211_AUTHTYPE_FT:
5543#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305544 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005545 "%s: set authentication type to OPEN", __func__);
5546 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5547 break;
5548
5549 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305550 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 "%s: set authentication type to SHARED", __func__);
5552 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5553 break;
5554#ifdef FEATURE_WLAN_CCX
5555 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305556 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005557 "%s: set authentication type to CCKM WPA", __func__);
5558 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5559 break;
5560#endif
5561
5562
5563 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305564 hddLog(VOS_TRACE_LEVEL_ERROR,
5565 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 auth_type);
5567 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5568 return -EINVAL;
5569 }
5570
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305571 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005572 pHddStaCtx->conn_info.authType;
5573 return 0;
5574}
5575
5576/*
5577 * FUNCTION: wlan_hdd_set_akm_suite
5578 * This function is used to set the key mgmt type(PSK/8021x).
5579 *
5580 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305581static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 u32 key_mgmt
5583 )
5584{
5585 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5586 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305587
Jeff Johnson295189b2012-06-20 16:38:30 -07005588 /*set key mgmt type*/
5589 switch(key_mgmt)
5590 {
5591 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305592#ifdef WLAN_FEATURE_VOWIFI_11R
5593 case WLAN_AKM_SUITE_FT_PSK:
5594#endif
5595 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005596 __func__);
5597 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5598 break;
5599
5600 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305601#ifdef WLAN_FEATURE_VOWIFI_11R
5602 case WLAN_AKM_SUITE_FT_8021X:
5603#endif
5604 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005605 __func__);
5606 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5607 break;
5608#ifdef FEATURE_WLAN_CCX
5609#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5610#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5611 case WLAN_AKM_SUITE_CCKM:
5612 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5613 __func__);
5614 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5615 break;
5616#endif
5617
5618 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305619 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005620 __func__, key_mgmt);
5621 return -EINVAL;
5622
5623 }
5624 return 0;
5625}
5626
5627/*
5628 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305629 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 * (NONE/WEP40/WEP104/TKIP/CCMP).
5631 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305632static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5633 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005634 bool ucast
5635 )
5636{
5637 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305638 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005639 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5640
5641 ENTER();
5642
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305643 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305645 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005646 __func__, cipher);
5647 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5648 }
5649 else
5650 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305651
Jeff Johnson295189b2012-06-20 16:38:30 -07005652 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305653 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 {
5655 case IW_AUTH_CIPHER_NONE:
5656 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5657 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305658
Jeff Johnson295189b2012-06-20 16:38:30 -07005659 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305660 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005661 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305662
Jeff Johnson295189b2012-06-20 16:38:30 -07005663 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305664 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005665 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305666
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 case WLAN_CIPHER_SUITE_TKIP:
5668 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5669 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305670
Jeff Johnson295189b2012-06-20 16:38:30 -07005671 case WLAN_CIPHER_SUITE_CCMP:
5672 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5673 break;
5674#ifdef FEATURE_WLAN_WAPI
5675 case WLAN_CIPHER_SUITE_SMS4:
5676 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5677 break;
5678#endif
5679
5680#ifdef FEATURE_WLAN_CCX
5681 case WLAN_CIPHER_SUITE_KRK:
5682 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5683 break;
5684#endif
5685 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305686 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 __func__, cipher);
5688 return -EOPNOTSUPP;
5689 }
5690 }
5691
5692 if (ucast)
5693 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305694 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005695 __func__, encryptionType);
5696 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5697 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305698 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 encryptionType;
5700 }
5701 else
5702 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305703 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005704 __func__, encryptionType);
5705 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5706 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5707 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5708 }
5709
5710 return 0;
5711}
5712
5713
5714/*
5715 * FUNCTION: wlan_hdd_cfg80211_set_ie
5716 * This function is used to parse WPA/RSN IE's.
5717 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305718int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5719 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005720 size_t ie_len
5721 )
5722{
5723 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5724 u8 *genie = ie;
5725 v_U16_t remLen = ie_len;
5726#ifdef FEATURE_WLAN_WAPI
5727 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5728 u16 *tmp;
5729 v_U16_t akmsuiteCount;
5730 int *akmlist;
5731#endif
5732 ENTER();
5733
5734 /* clear previous assocAddIE */
5735 pWextState->assocAddIE.length = 0;
5736 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5737
5738 while (remLen >= 2)
5739 {
5740 v_U16_t eLen = 0;
5741 v_U8_t elementId;
5742 elementId = *genie++;
5743 eLen = *genie++;
5744 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305745
Arif Hussain6d2a3322013-11-17 19:50:10 -08005746 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005747 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305748
5749 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005750 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305751 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005752 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 -07005753 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305754 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005755 "%s: Invalid WPA IE", __func__);
5756 return -EINVAL;
5757 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305758 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005759 {
5760 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305761 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005762 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305763
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5765 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005766 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5767 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005768 VOS_ASSERT(0);
5769 return -ENOMEM;
5770 }
5771 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5772 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5773 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305774
Jeff Johnson295189b2012-06-20 16:38:30 -07005775 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5776 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5777 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5778 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305779 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5780 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005781 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5782 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5783 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5784 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5785 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5786 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305787 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05305788 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005789 {
5790 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305791 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005792 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305793
Jeff Johnson295189b2012-06-20 16:38:30 -07005794 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5795 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005796 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5797 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005798 VOS_ASSERT(0);
5799 return -ENOMEM;
5800 }
5801 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5802 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5803 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305804
Jeff Johnson295189b2012-06-20 16:38:30 -07005805 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5806 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5807 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005808#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305809 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5810 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005811 /*Consider WFD IE, only for P2P Client */
5812 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5813 {
5814 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305815 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005816 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305817
Jeff Johnson295189b2012-06-20 16:38:30 -07005818 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5819 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005820 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5821 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005822 VOS_ASSERT(0);
5823 return -ENOMEM;
5824 }
5825 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5826 // WPS IE + P2P IE + WFD IE
5827 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5828 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305829
Jeff Johnson295189b2012-06-20 16:38:30 -07005830 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5831 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5832 }
5833#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005834 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305835 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005836 HS20_OUI_TYPE_SIZE)) )
5837 {
5838 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305839 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005840 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005841
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005842 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5843 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005844 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5845 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005846 VOS_ASSERT(0);
5847 return -ENOMEM;
5848 }
5849 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5850 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005851
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005852 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5853 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5854 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005855
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005856 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5857
5858 /* populating as ADDIE in beacon frames */
5859 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5860 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5861 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5862 {
5863 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5864 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5865 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5866 {
5867 hddLog(LOGE,
5868 "Coldn't pass "
5869 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5870 }
5871 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5872 else
5873 hddLog(LOGE,
5874 "Could not pass on "
5875 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5876
5877 /* IBSS mode doesn't contain params->proberesp_ies still
5878 beaconIE's need to be populated in probe response frames */
5879 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5880 {
5881 u16 rem_probe_resp_ie_len = eLen + 2;
5882 u8 probe_rsp_ie_len[3] = {0};
5883 u8 counter = 0;
5884
5885 /* Check Probe Resp Length if it is greater then 255 then
5886 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5887 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5888 not able Store More then 255 bytes into One Variable */
5889
5890 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5891 {
5892 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5893 {
5894 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5895 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5896 }
5897 else
5898 {
5899 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5900 rem_probe_resp_ie_len = 0;
5901 }
5902 }
5903
5904 rem_probe_resp_ie_len = 0;
5905
5906 if (probe_rsp_ie_len[0] > 0)
5907 {
5908 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5909 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5910 (tANI_U8*)(genie - 2),
5911 probe_rsp_ie_len[0], NULL,
5912 eANI_BOOLEAN_FALSE)
5913 == eHAL_STATUS_FAILURE)
5914 {
5915 hddLog(LOGE,
5916 "Could not pass"
5917 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5918 }
5919 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5920 }
5921
5922 if (probe_rsp_ie_len[1] > 0)
5923 {
5924 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5925 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5926 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5927 probe_rsp_ie_len[1], NULL,
5928 eANI_BOOLEAN_FALSE)
5929 == eHAL_STATUS_FAILURE)
5930 {
5931 hddLog(LOGE,
5932 "Could not pass"
5933 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5934 }
5935 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5936 }
5937
5938 if (probe_rsp_ie_len[2] > 0)
5939 {
5940 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5941 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5942 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5943 probe_rsp_ie_len[2], NULL,
5944 eANI_BOOLEAN_FALSE)
5945 == eHAL_STATUS_FAILURE)
5946 {
5947 hddLog(LOGE,
5948 "Could not pass"
5949 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5950 }
5951 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5952 }
5953
5954 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5955 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5956 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5957 {
5958 hddLog(LOGE,
5959 "Could not pass"
5960 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5961 }
5962 }
5963 else
5964 {
5965 // Reset WNI_CFG_PROBE_RSP Flags
5966 wlan_hdd_reset_prob_rspies(pAdapter);
5967
5968 hddLog(VOS_TRACE_LEVEL_INFO,
5969 "%s: No Probe Response IE received in set beacon",
5970 __func__);
5971 }
5972 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 break;
5974 case DOT11F_EID_RSN:
5975 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5976 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5977 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5978 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5979 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5980 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005981 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5982 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305983 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005984 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305985 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005986 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305987
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005988 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5989 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005990 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5991 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005992 VOS_ASSERT(0);
5993 return -ENOMEM;
5994 }
5995 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5996 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305997
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005998 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5999 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6000 break;
6001 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006002#ifdef FEATURE_WLAN_WAPI
6003 case WLAN_EID_WAPI:
6004 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006005 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07006006 pAdapter->wapi_info.nWapiMode);
6007 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306008 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07006009 akmsuiteCount = WPA_GET_LE16(tmp);
6010 tmp = tmp + 1;
6011 akmlist = (int *)(tmp);
6012 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
6013 {
6014 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
6015 }
6016 else
6017 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006018 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07006019 VOS_ASSERT(0);
6020 return -EINVAL;
6021 }
6022
6023 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
6024 {
6025 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006026 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306028 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006029 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306030 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006031 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006032 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006033 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
6034 }
6035 break;
6036#endif
6037 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306038 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006039 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006040 /* when Unknown IE is received we should break and continue
6041 * to the next IE in the buffer instead we were returning
6042 * so changing this to break */
6043 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 }
6045 genie += eLen;
6046 remLen -= eLen;
6047 }
6048 EXIT();
6049 return 0;
6050}
6051
6052/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05306053 * FUNCTION: hdd_isWPAIEPresent
6054 * Parse the received IE to find the WPA IE
6055 *
6056 */
6057static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
6058{
6059 v_U8_t eLen = 0;
6060 v_U16_t remLen = ie_len;
6061 v_U8_t elementId = 0;
6062
6063 while (remLen >= 2)
6064 {
6065 elementId = *ie++;
6066 eLen = *ie++;
6067 remLen -= 2;
6068 if (eLen > remLen)
6069 {
6070 hddLog(VOS_TRACE_LEVEL_ERROR,
6071 "%s: IE length is wrong %d", __func__, eLen);
6072 return FALSE;
6073 }
6074 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
6075 {
6076 /* OUI - 0x00 0X50 0XF2
6077 WPA Information Element - 0x01
6078 WPA version - 0x01*/
6079 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
6080 return TRUE;
6081 }
6082 ie += eLen;
6083 remLen -= eLen;
6084 }
6085 return FALSE;
6086}
6087
6088/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006089 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306090 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006091 * parameters during connect operation.
6092 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306093int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 struct cfg80211_connect_params *req
6095 )
6096{
6097 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306098 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006099 ENTER();
6100
6101 /*set wpa version*/
6102 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6103
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306104 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006105 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05306106 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006107 {
6108 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6109 }
6110 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
6111 {
6112 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6113 }
6114 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306115
6116 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006117 pWextState->wpaVersion);
6118
6119 /*set authentication type*/
6120 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
6121
6122 if (0 > status)
6123 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306124 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006125 "%s: failed to set authentication type ", __func__);
6126 return status;
6127 }
6128
6129 /*set key mgmt type*/
6130 if (req->crypto.n_akm_suites)
6131 {
6132 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
6133 if (0 > status)
6134 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306135 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 __func__);
6137 return status;
6138 }
6139 }
6140
6141 /*set pairwise cipher type*/
6142 if (req->crypto.n_ciphers_pairwise)
6143 {
6144 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6145 req->crypto.ciphers_pairwise[0], true);
6146 if (0 > status)
6147 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306148 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006149 "%s: failed to set unicast cipher type", __func__);
6150 return status;
6151 }
6152 }
6153 else
6154 {
6155 /*Reset previous cipher suite to none*/
6156 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6157 if (0 > status)
6158 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306159 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006160 "%s: failed to set unicast cipher type", __func__);
6161 return status;
6162 }
6163 }
6164
6165 /*set group cipher type*/
6166 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6167 false);
6168
6169 if (0 > status)
6170 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306171 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006172 __func__);
6173 return status;
6174 }
6175
Chet Lanctot186b5732013-03-18 10:26:30 -07006176#ifdef WLAN_FEATURE_11W
6177 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6178#endif
6179
Jeff Johnson295189b2012-06-20 16:38:30 -07006180 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6181 if (req->ie_len)
6182 {
6183 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6184 if ( 0 > status)
6185 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306186 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006187 __func__);
6188 return status;
6189 }
6190 }
6191
6192 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306193 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006194 {
6195 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6196 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6197 )
6198 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306199 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6201 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306202 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006203 __func__);
6204 return -EOPNOTSUPP;
6205 }
6206 else
6207 {
6208 u8 key_len = req->key_len;
6209 u8 key_idx = req->key_idx;
6210
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306211 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006212 && (CSR_MAX_NUM_KEY > key_idx)
6213 )
6214 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306215 hddLog(VOS_TRACE_LEVEL_INFO,
6216 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006217 __func__, key_idx, key_len);
6218 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306219 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306221 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006222 (u8)key_len;
6223 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6224 }
6225 }
6226 }
6227 }
6228
6229 return status;
6230}
6231
6232/*
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306233 * FUNCTION: wlan_hdd_try_disconnect
6234 * This function is used to disconnect from previous
6235 * connection
6236 */
6237static int wlan_hdd_try_disconnect( hdd_adapter_t *pAdapter )
6238{
6239 long ret = 0;
6240 hdd_station_ctx_t *pHddStaCtx;
6241 eMib_dot11DesiredBssType connectedBssType;
6242
6243 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6244
6245 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
6246
6247 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
6248 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
6249 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
6250 {
6251 /* Issue disconnect to CSR */
6252 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6253 if( eHAL_STATUS_SUCCESS ==
6254 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6255 pAdapter->sessionId,
6256 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
6257 {
6258 ret = wait_for_completion_interruptible_timeout(
6259 &pAdapter->disconnect_comp_var,
6260 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6261 if (0 >= ret)
6262 {
6263 hddLog(LOGE, FL("Failed to receive disconnect event"));
6264 return -EALREADY;
6265 }
6266 }
6267 }
6268 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
6269 {
6270 ret = wait_for_completion_interruptible_timeout(
6271 &pAdapter->disconnect_comp_var,
6272 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6273 if (0 >= ret)
6274 {
6275 hddLog(LOGE, FL("Failed to receive disconnect event"));
6276 return -EALREADY;
6277 }
6278 }
6279
6280 return 0;
6281}
6282
6283/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006284 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306285 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006286 * parameters during connect operation.
6287 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306288static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006289 struct net_device *ndev,
6290 struct cfg80211_connect_params *req
6291 )
6292{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306293 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306294 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006295 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
6296 hdd_context_t *pHddCtx = NULL;
6297
6298 ENTER();
6299
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306300 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006301 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006302
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306303 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6304 status = wlan_hdd_validate_context(pHddCtx);
6305
6306 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6309 "%s: HDD context is not valid", __func__);
6310 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006311 }
6312
6313#ifdef WLAN_BTAMP_FEATURE
6314 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306315 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006316 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306317 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006318 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006319 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006320 }
6321#endif
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306322
6323 //If Device Mode is Station Concurrent Sessions Exit BMps
6324 //P2P Mode will be taken care in Open/close adapter
6325 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6326 (vos_concurrent_sessions_running()))
6327 {
6328 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
6329 }
6330
6331 /*Try disconnecting if already in connected state*/
6332 status = wlan_hdd_try_disconnect(pAdapter);
6333 if ( 0 > status)
6334 {
6335 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6336 " connection"));
6337 return -EALREADY;
6338 }
6339
Jeff Johnson295189b2012-06-20 16:38:30 -07006340 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306341 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006342
6343 if ( 0 > status)
6344 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306345 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006346 __func__);
6347 return status;
6348 }
6349
Mohit Khanna765234a2012-09-11 15:08:35 -07006350 if ( req->channel )
6351 {
6352 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6353 req->ssid_len, req->bssid,
6354 req->channel->hw_value);
6355 }
6356 else
6357 {
6358 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306359 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006360 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006361
6362 if (0 > status)
6363 {
6364 //ReEnable BMPS if disabled
6365 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6366 (NULL != pHddCtx))
6367 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306368 if (pHddCtx->hdd_wlan_suspended)
6369 {
6370 hdd_set_pwrparams(pHddCtx);
6371 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 //ReEnable Bmps and Imps back
6373 hdd_enable_bmps_imps(pHddCtx);
6374 }
6375
6376 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6377 return status;
6378 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306379 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 EXIT();
6381 return status;
6382}
6383
6384
6385/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306386 * FUNCTION: wlan_hdd_disconnect
6387 * This function is used to issue a disconnect request to SME
6388 */
6389int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6390{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306391 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306392 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306393 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306394 long ret;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306395
6396 status = wlan_hdd_validate_context(pHddCtx);
6397
6398 if (0 != status)
6399 {
6400 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6401 "%s: HDD context is not valid", __func__);
6402 return status;
6403 }
6404
6405 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306406 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306407 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306408
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306409 /*issue disconnect*/
6410 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6411 pAdapter->sessionId, reason);
6412
6413 if ( 0 != status )
6414 {
6415 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006416 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306417 __func__, (int)status );
6418 return -EINVAL;
6419 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306420 ret = wait_for_completion_interruptible_timeout(
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306421 &pAdapter->disconnect_comp_var,
6422 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306423 if (ret <= 0)
6424 {
6425 hddLog(VOS_TRACE_LEVEL_ERROR,
6426 FL("wait on disconnect_comp_var failed %ld"), ret);
6427 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306428 /*stop tx queues*/
6429 netif_tx_disable(pAdapter->dev);
6430 netif_carrier_off(pAdapter->dev);
6431 return status;
6432}
6433
6434
6435/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 * FUNCTION: wlan_hdd_cfg80211_disconnect
6437 * This function is used to issue a disconnect request to SME
6438 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306439static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006440 struct net_device *dev,
6441 u16 reason
6442 )
6443{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306444 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6445 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006446 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306447 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006448 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006449 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306450#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006451 tANI_U8 staIdx;
6452#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306453
Jeff Johnson295189b2012-06-20 16:38:30 -07006454 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306455
Arif Hussain6d2a3322013-11-17 19:50:10 -08006456 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006457 __func__,pAdapter->device_mode);
6458
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306459 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6460 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006461
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306462 status = wlan_hdd_validate_context(pHddCtx);
6463
6464 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006465 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306466 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6467 "%s: HDD context is not valid", __func__);
6468 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006469 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306470
Jeff Johnson295189b2012-06-20 16:38:30 -07006471 if (NULL != pRoamProfile)
6472 {
6473 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306474 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6475 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006476 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306477 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006478 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306479 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 switch(reason)
6481 {
6482 case WLAN_REASON_MIC_FAILURE:
6483 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6484 break;
6485
6486 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6487 case WLAN_REASON_DISASSOC_AP_BUSY:
6488 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6489 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6490 break;
6491
6492 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6493 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6494 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6495 break;
6496
6497 case WLAN_REASON_DEAUTH_LEAVING:
6498 default:
6499 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6500 break;
6501 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306502 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6503 pScanInfo = &pHddCtx->scan_info;
6504 if (pScanInfo->mScanPending)
6505 {
6506 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6507 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306508 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306509 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006510
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006511#ifdef FEATURE_WLAN_TDLS
6512 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006513 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006514 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006515 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6516 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006517 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006518 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006519 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006520 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006521 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006522 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006523 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006524 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006525 pAdapter->sessionId,
6526 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006527 }
6528 }
6529#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306530 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6531 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006532 {
6533 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006534 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006535 __func__, (int)status );
6536 return -EINVAL;
6537 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306539 else
6540 {
6541 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6542 "called while in %d state", __func__,
6543 pHddStaCtx->conn_info.connState);
6544 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006545 }
6546 else
6547 {
6548 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6549 }
6550
6551 return status;
6552}
6553
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306554
Jeff Johnson295189b2012-06-20 16:38:30 -07006555/*
6556 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306557 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006558 * settings in IBSS mode.
6559 */
6560static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306561 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006562 struct cfg80211_ibss_params *params
6563 )
6564{
6565 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306566 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006567 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6568 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306569
Jeff Johnson295189b2012-06-20 16:38:30 -07006570 ENTER();
6571
6572 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006573 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006574
6575 if (params->ie_len && ( NULL != params->ie) )
6576 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006577 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6578 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006579 {
6580 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6581 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6582 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006583 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006585 tDot11fIEWPA dot11WPAIE;
6586 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006587 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006588
Wilson Yang00256342013-10-10 23:13:38 -07006589 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006590 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6591 params->ie_len, DOT11F_EID_WPA);
6592 if ( NULL != ie )
6593 {
6594 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6595 // Unpack the WPA IE
6596 //Skip past the EID byte and length byte - and four byte WiFi OUI
6597 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6598 &ie[2+4],
6599 ie[1] - 4,
6600 &dot11WPAIE);
6601 /*Extract the multicast cipher, the encType for unicast
6602 cipher for wpa-none is none*/
6603 encryptionType =
6604 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6605 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006606 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006607
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6609
6610 if (0 > status)
6611 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306612 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006613 __func__);
6614 return status;
6615 }
6616 }
6617
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306618 pWextState->roamProfile.AuthType.authType[0] =
6619 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006620 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6621
6622 if (params->privacy)
6623 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306624 /* Security enabled IBSS, At this time there is no information available
6625 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306627 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006628 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306629 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 *enable privacy bit in beacons */
6631
6632 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6633 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006634 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6635 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006636 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6637 pWextState->roamProfile.EncryptionType.numEntries = 1;
6638 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006639 return status;
6640}
6641
6642/*
6643 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306644 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006645 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306646static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 struct net_device *dev,
6648 struct cfg80211_ibss_params *params
6649 )
6650{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306651 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006652 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6653 tCsrRoamProfile *pRoamProfile;
6654 int status;
krunal sonie9002db2013-11-25 14:24:17 -08006655 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006656 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306657 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006658
6659 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306660
6661 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006662 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006663
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306664 status = wlan_hdd_validate_context(pHddCtx);
6665
6666 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006667 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306668 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6669 "%s: HDD context is not valid", __func__);
6670 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006671 }
6672
6673 if (NULL == pWextState)
6674 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006675 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006676 __func__);
6677 return -EIO;
6678 }
6679
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306680 /*Try disconnecting if already in connected state*/
6681 status = wlan_hdd_try_disconnect(pAdapter);
6682 if ( 0 > status)
6683 {
6684 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6685 " IBSS connection"));
6686 return -EALREADY;
6687 }
6688
Jeff Johnson295189b2012-06-20 16:38:30 -07006689 pRoamProfile = &pWextState->roamProfile;
6690
6691 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6692 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306693 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006694 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 return -EINVAL;
6696 }
6697
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006698 /* BSSID is provided by upper layers hence no need to AUTO generate */
6699 if (NULL != params->bssid) {
6700 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6701 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
6702 hddLog (VOS_TRACE_LEVEL_ERROR,
6703 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6704 return -EIO;
6705 }
6706 }
krunal sonie9002db2013-11-25 14:24:17 -08006707 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
6708 {
6709 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6710 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
6711 {
6712 hddLog (VOS_TRACE_LEVEL_ERROR,
6713 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6714 return -EIO;
6715 }
6716 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
6717 if (!params->bssid)
6718 {
6719 hddLog (VOS_TRACE_LEVEL_ERROR,
6720 "%s:Failed memory allocation", __func__);
6721 return -EIO;
6722 }
6723 vos_mem_copy((v_U8_t *)params->bssid,
6724 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
6725 VOS_MAC_ADDR_SIZE);
6726 alloc_bssid = VOS_TRUE;
6727 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006728
Jeff Johnson295189b2012-06-20 16:38:30 -07006729 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006730 if (NULL !=
6731#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6732 params->chandef.chan)
6733#else
6734 params->channel)
6735#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006736 {
6737 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006738 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6739 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6740 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6741 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006742
6743 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306744 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006745 ieee80211_frequency_to_channel(
6746#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6747 params->chandef.chan->center_freq);
6748#else
6749 params->channel->center_freq);
6750#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006751
6752 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6753 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006754 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006755 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6756 __func__);
6757 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006758 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006759
6760 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006761 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006762 if (channelNum == validChan[indx])
6763 {
6764 break;
6765 }
6766 }
6767 if (indx >= numChans)
6768 {
6769 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 __func__, channelNum);
6771 return -EINVAL;
6772 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006773 /* Set the Operational Channel */
6774 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6775 channelNum);
6776 pRoamProfile->ChannelInfo.numOfChannels = 1;
6777 pHddStaCtx->conn_info.operationChannel = channelNum;
6778 pRoamProfile->ChannelInfo.ChannelList =
6779 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006780 }
6781
6782 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306783 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006784 if (status < 0)
6785 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306786 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 __func__);
6788 return status;
6789 }
6790
6791 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306792 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006793 params->ssid_len, params->bssid,
6794 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006795
6796 if (0 > status)
6797 {
6798 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6799 return status;
6800 }
6801
krunal sonie9002db2013-11-25 14:24:17 -08006802 if (NULL != params->bssid &&
6803 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
6804 alloc_bssid == VOS_TRUE)
6805 {
6806 vos_mem_free(params->bssid);
6807 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006808 return 0;
6809}
6810
6811/*
6812 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306813 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006814 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306815static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 struct net_device *dev
6817 )
6818{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306819 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006820 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6821 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306822 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6823 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006824
6825 ENTER();
6826
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306827 status = wlan_hdd_validate_context(pHddCtx);
6828
6829 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006830 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306831 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6832 "%s: HDD context is not valid", __func__);
6833 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006834 }
6835
Arif Hussain6d2a3322013-11-17 19:50:10 -08006836 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006837 if (NULL == pWextState)
6838 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006839 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006840 __func__);
6841 return -EIO;
6842 }
6843
6844 pRoamProfile = &pWextState->roamProfile;
6845
6846 /* Issue disconnect only if interface type is set to IBSS */
6847 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6848 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306849 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006850 __func__);
6851 return -EINVAL;
6852 }
6853
6854 /* Issue Disconnect request */
6855 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6856 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6857 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6858
6859 return 0;
6860}
6861
6862/*
6863 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6864 * This function is used to set the phy parameters
6865 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6866 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306867static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006868 u32 changed)
6869{
6870 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6871 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306872 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006873
6874 ENTER();
6875
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306876 status = wlan_hdd_validate_context(pHddCtx);
6877
6878 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006879 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306880 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6881 "%s: HDD context is not valid", __func__);
6882 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006883 }
6884
Jeff Johnson295189b2012-06-20 16:38:30 -07006885 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6886 {
6887 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6888 WNI_CFG_RTS_THRESHOLD_STAMAX :
6889 wiphy->rts_threshold;
6890
6891 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306892 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006893 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306894 hddLog(VOS_TRACE_LEVEL_ERROR,
6895 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006896 __func__, rts_threshold);
6897 return -EINVAL;
6898 }
6899
6900 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6901 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306902 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006903 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306904 hddLog(VOS_TRACE_LEVEL_ERROR,
6905 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006906 __func__, rts_threshold);
6907 return -EIO;
6908 }
6909
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306910 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006911 rts_threshold);
6912 }
6913
6914 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6915 {
6916 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6917 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6918 wiphy->frag_threshold;
6919
6920 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306921 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006922 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306923 hddLog(VOS_TRACE_LEVEL_ERROR,
6924 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006925 frag_threshold);
6926 return -EINVAL;
6927 }
6928
6929 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6930 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306931 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006932 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306933 hddLog(VOS_TRACE_LEVEL_ERROR,
6934 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006935 __func__, frag_threshold);
6936 return -EIO;
6937 }
6938
6939 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6940 frag_threshold);
6941 }
6942
6943 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6944 || (changed & WIPHY_PARAM_RETRY_LONG))
6945 {
6946 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6947 wiphy->retry_short :
6948 wiphy->retry_long;
6949
6950 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6951 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6952 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306953 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006954 __func__, retry_value);
6955 return -EINVAL;
6956 }
6957
6958 if (changed & WIPHY_PARAM_RETRY_SHORT)
6959 {
6960 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6961 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306962 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306964 hddLog(VOS_TRACE_LEVEL_ERROR,
6965 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006966 __func__, retry_value);
6967 return -EIO;
6968 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306969 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 __func__, retry_value);
6971 }
6972 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6973 {
6974 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6975 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306976 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306978 hddLog(VOS_TRACE_LEVEL_ERROR,
6979 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 __func__, retry_value);
6981 return -EIO;
6982 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306983 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 __func__, retry_value);
6985 }
6986 }
6987
6988 return 0;
6989}
6990
6991/*
6992 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6993 * This function is used to set the txpower
6994 */
6995static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006996#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6997 struct wireless_dev *wdev,
6998#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006999#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307000 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007001#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307002 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007003#endif
7004 int dbm)
7005{
7006 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307007 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
7009 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307010 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007011
7012 ENTER();
7013
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307014 status = wlan_hdd_validate_context(pHddCtx);
7015
7016 if (0 != status)
7017 {
7018 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7019 "%s: HDD context is not valid", __func__);
7020 return status;
7021 }
7022
7023 hHal = pHddCtx->hHal;
7024
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307025 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
7026 dbm, ccmCfgSetCallback,
7027 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007028 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307029 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007030 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
7031 return -EIO;
7032 }
7033
7034 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
7035 dbm);
7036
7037 switch(type)
7038 {
7039 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
7040 /* Fall through */
7041 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
7042 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
7043 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307044 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
7045 __func__);
7046 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07007047 }
7048 break;
7049 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307050 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07007051 __func__);
7052 return -EOPNOTSUPP;
7053 break;
7054 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307055 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
7056 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07007057 return -EIO;
7058 }
7059
7060 return 0;
7061}
7062
7063/*
7064 * FUNCTION: wlan_hdd_cfg80211_get_txpower
7065 * This function is used to read the txpower
7066 */
Yue Maf49ba872013-08-19 12:04:25 -07007067static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
7068#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7069 struct wireless_dev *wdev,
7070#endif
7071 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07007072{
7073
7074 hdd_adapter_t *pAdapter;
7075 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307076 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007077
Jeff Johnsone7245742012-09-05 17:12:55 -07007078 ENTER();
7079
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307080 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007081
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307082 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007083 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307084 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7085 "%s: HDD context is not valid", __func__);
7086 *dbm = 0;
7087 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007088 }
7089
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
7091 if (NULL == pAdapter)
7092 {
7093 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
7094 return -ENOENT;
7095 }
7096
7097 wlan_hdd_get_classAstats(pAdapter);
7098 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
7099
Jeff Johnsone7245742012-09-05 17:12:55 -07007100 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007101 return 0;
7102}
7103
7104static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
7105 u8* mac, struct station_info *sinfo)
7106{
7107 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
7108 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7109 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
7110 tANI_U8 rate_flags;
7111
7112 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
7113 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07007114
7115 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
7116 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
7117 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
7118 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
7119 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
7120 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
7121 tANI_U16 maxRate = 0;
7122 tANI_U16 myRate;
7123 tANI_U16 currentRate = 0;
7124 tANI_U8 maxSpeedMCS = 0;
7125 tANI_U8 maxMCSIdx = 0;
7126 tANI_U8 rateFlag = 1;
7127 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07007128 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307129 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007130
Leo Chang6f8870f2013-03-26 18:11:36 -07007131#ifdef WLAN_FEATURE_11AC
7132 tANI_U32 vht_mcs_map;
7133 eDataRate11ACMaxMcs vhtMaxMcs;
7134#endif /* WLAN_FEATURE_11AC */
7135
Jeff Johnsone7245742012-09-05 17:12:55 -07007136 ENTER();
7137
Jeff Johnson295189b2012-06-20 16:38:30 -07007138 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
7139 (0 == ssidlen))
7140 {
7141 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
7142 " Invalid ssidlen, %d", __func__, ssidlen);
7143 /*To keep GUI happy*/
7144 return 0;
7145 }
7146
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307147 status = wlan_hdd_validate_context(pHddCtx);
7148
7149 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007150 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307151 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7152 "%s: HDD context is not valid", __func__);
7153 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007154 }
7155
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007156 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007157 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
7158
Kiet Lam3b17fc82013-09-27 05:24:08 +05307159 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
7160 sinfo->filled |= STATION_INFO_SIGNAL;
7161
Jeff Johnson295189b2012-06-20 16:38:30 -07007162 //convert to the UI units of 100kbps
7163 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
7164
7165#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07007166 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 -07007167 sinfo->signal,
7168 pCfg->reportMaxLinkSpeed,
7169 myRate,
7170 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007171 (int) pCfg->linkSpeedRssiMid,
7172 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07007173 (int) rate_flags,
7174 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07007175#endif //LINKSPEED_DEBUG_ENABLED
7176
7177 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
7178 {
7179 // we do not want to necessarily report the current speed
7180 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
7181 {
7182 // report the max possible speed
7183 rssidx = 0;
7184 }
7185 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
7186 {
7187 // report the max possible speed with RSSI scaling
7188 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
7189 {
7190 // report the max possible speed
7191 rssidx = 0;
7192 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007193 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07007194 {
7195 // report middle speed
7196 rssidx = 1;
7197 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007198 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
7199 {
7200 // report middle speed
7201 rssidx = 2;
7202 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007203 else
7204 {
7205 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007206 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07007207 }
7208 }
7209 else
7210 {
7211 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
7212 hddLog(VOS_TRACE_LEVEL_ERROR,
7213 "%s: Invalid value for reportMaxLinkSpeed: %u",
7214 __func__, pCfg->reportMaxLinkSpeed);
7215 rssidx = 0;
7216 }
7217
7218 maxRate = 0;
7219
7220 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307221 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7222 OperationalRates, &ORLeng))
7223 {
7224 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7225 /*To keep GUI happy*/
7226 return 0;
7227 }
7228
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 for (i = 0; i < ORLeng; i++)
7230 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007231 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007232 {
7233 /* Validate Rate Set */
7234 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7235 {
7236 currentRate = supported_data_rate[j].supported_rate[rssidx];
7237 break;
7238 }
7239 }
7240 /* Update MAX rate */
7241 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7242 }
7243
7244 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307245 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7246 ExtendedRates, &ERLeng))
7247 {
7248 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7249 /*To keep GUI happy*/
7250 return 0;
7251 }
7252
Jeff Johnson295189b2012-06-20 16:38:30 -07007253 for (i = 0; i < ERLeng; i++)
7254 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007255 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007256 {
7257 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7258 {
7259 currentRate = supported_data_rate[j].supported_rate[rssidx];
7260 break;
7261 }
7262 }
7263 /* Update MAX rate */
7264 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7265 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307266 /* Get MCS Rate Set --
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307267 Only if we are always reporting max speed (or)
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307268 if we have good rssi */
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307269 if ((0 == rssidx) ||
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307270 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307272 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7273 MCSRates, &MCSLeng))
7274 {
7275 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7276 /*To keep GUI happy*/
7277 return 0;
7278 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007279 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007280#ifdef WLAN_FEATURE_11AC
7281 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307282 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007283 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007284 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307285 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007286 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007287 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007288 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007289 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007290 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007291 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007292 maxMCSIdx = 7;
7293 }
7294 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7295 {
7296 maxMCSIdx = 8;
7297 }
7298 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7299 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307300 //VHT20 is supporting 0~8
7301 if (rate_flags & eHAL_TX_RATE_VHT20)
7302 maxMCSIdx = 8;
7303 else
7304 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007305 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307306
7307 if (rate_flags & eHAL_TX_RATE_VHT80)
7308 {
7309 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7310 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7311 }
7312 else if (rate_flags & eHAL_TX_RATE_VHT40)
7313 {
7314 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7315 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7316 }
7317 else if (rate_flags & eHAL_TX_RATE_VHT20)
7318 {
7319 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7320 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7321 }
7322
Leo Chang6f8870f2013-03-26 18:11:36 -07007323 maxSpeedMCS = 1;
7324 if (currentRate > maxRate)
7325 {
7326 maxRate = currentRate;
7327 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307328
Leo Chang6f8870f2013-03-26 18:11:36 -07007329 }
7330 else
7331#endif /* WLAN_FEATURE_11AC */
7332 {
7333 if (rate_flags & eHAL_TX_RATE_HT40)
7334 {
7335 rateFlag |= 1;
7336 }
7337 if (rate_flags & eHAL_TX_RATE_SGI)
7338 {
7339 rateFlag |= 2;
7340 }
7341
7342 for (i = 0; i < MCSLeng; i++)
7343 {
7344 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7345 for (j = 0; j < temp; j++)
7346 {
7347 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7348 {
7349 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7350 break;
7351 }
7352 }
7353 if ((j < temp) && (currentRate > maxRate))
7354 {
7355 maxRate = currentRate;
7356 maxSpeedMCS = 1;
7357 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7358 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007359 }
7360 }
7361 }
7362
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307363 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7364 {
7365 maxRate = myRate;
7366 maxSpeedMCS = 1;
7367 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7368 }
7369
Jeff Johnson295189b2012-06-20 16:38:30 -07007370 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007371 if (((maxRate < myRate) && (0 == rssidx)) ||
7372 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007373 {
7374 maxRate = myRate;
7375 if (rate_flags & eHAL_TX_RATE_LEGACY)
7376 {
7377 maxSpeedMCS = 0;
7378 }
7379 else
7380 {
7381 maxSpeedMCS = 1;
7382 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7383 }
7384 }
7385
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307386 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007387 {
7388 sinfo->txrate.legacy = maxRate;
7389#ifdef LINKSPEED_DEBUG_ENABLED
7390 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7391#endif //LINKSPEED_DEBUG_ENABLED
7392 }
7393 else
7394 {
7395 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007396#ifdef WLAN_FEATURE_11AC
7397 sinfo->txrate.nss = 1;
7398 if (rate_flags & eHAL_TX_RATE_VHT80)
7399 {
7400 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307401 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007402 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307403 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007404 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307405 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7406 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7407 }
7408 else if (rate_flags & eHAL_TX_RATE_VHT20)
7409 {
7410 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7411 }
7412#endif /* WLAN_FEATURE_11AC */
7413 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7414 {
7415 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7416 if (rate_flags & eHAL_TX_RATE_HT40)
7417 {
7418 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7419 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007420 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007421 if (rate_flags & eHAL_TX_RATE_SGI)
7422 {
7423 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7424 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307425
Jeff Johnson295189b2012-06-20 16:38:30 -07007426#ifdef LINKSPEED_DEBUG_ENABLED
7427 pr_info("Reporting MCS rate %d flags %x\n",
7428 sinfo->txrate.mcs,
7429 sinfo->txrate.flags );
7430#endif //LINKSPEED_DEBUG_ENABLED
7431 }
7432 }
7433 else
7434 {
7435 // report current rate instead of max rate
7436
7437 if (rate_flags & eHAL_TX_RATE_LEGACY)
7438 {
7439 //provide to the UI in units of 100kbps
7440 sinfo->txrate.legacy = myRate;
7441#ifdef LINKSPEED_DEBUG_ENABLED
7442 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7443#endif //LINKSPEED_DEBUG_ENABLED
7444 }
7445 else
7446 {
7447 //must be MCS
7448 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007449#ifdef WLAN_FEATURE_11AC
7450 sinfo->txrate.nss = 1;
7451 if (rate_flags & eHAL_TX_RATE_VHT80)
7452 {
7453 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7454 }
7455 else
7456#endif /* WLAN_FEATURE_11AC */
7457 {
7458 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7459 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007460 if (rate_flags & eHAL_TX_RATE_SGI)
7461 {
7462 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7463 }
7464 if (rate_flags & eHAL_TX_RATE_HT40)
7465 {
7466 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7467 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007468#ifdef WLAN_FEATURE_11AC
7469 else if (rate_flags & eHAL_TX_RATE_VHT80)
7470 {
7471 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7472 }
7473#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007474#ifdef LINKSPEED_DEBUG_ENABLED
7475 pr_info("Reporting actual MCS rate %d flags %x\n",
7476 sinfo->txrate.mcs,
7477 sinfo->txrate.flags );
7478#endif //LINKSPEED_DEBUG_ENABLED
7479 }
7480 }
7481 sinfo->filled |= STATION_INFO_TX_BITRATE;
7482
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007483 sinfo->tx_packets =
7484 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7485 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7486 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7487 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7488
7489 sinfo->tx_retries =
7490 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7491 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7492 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7493 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7494
7495 sinfo->tx_failed =
7496 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7497 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7498 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7499 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7500
7501 sinfo->filled |=
7502 STATION_INFO_TX_PACKETS |
7503 STATION_INFO_TX_RETRIES |
7504 STATION_INFO_TX_FAILED;
7505
7506 EXIT();
7507 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007508}
7509
7510static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007511 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007512{
7513 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307514 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007515 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307516 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007517
Jeff Johnsone7245742012-09-05 17:12:55 -07007518 ENTER();
7519
Jeff Johnson295189b2012-06-20 16:38:30 -07007520 if (NULL == pAdapter)
7521 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007522 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007523 return -ENODEV;
7524 }
7525
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307526 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307527 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307528
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307529 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307530 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307531 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7532 "%s: HDD context is not valid", __func__);
7533 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307534 }
7535
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307536 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7537 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7538 (pHddCtx->cfg_ini->fhostArpOffload) &&
7539 (eConnectionState_Associated ==
7540 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7541 {
Amar Singhald53568e2013-09-26 11:03:45 -07007542
7543 hddLog(VOS_TRACE_LEVEL_INFO,
7544 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307545 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307546 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7547 {
7548 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007549 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307550 __func__, vos_status);
7551 }
7552 }
7553
Jeff Johnson295189b2012-06-20 16:38:30 -07007554 /**The get power cmd from the supplicant gets updated by the nl only
7555 *on successful execution of the function call
7556 *we are oppositely mapped w.r.t mode in the driver
7557 **/
7558 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7559
Jeff Johnsone7245742012-09-05 17:12:55 -07007560 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007561 if (VOS_STATUS_E_FAILURE == vos_status)
7562 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7564 "%s: failed to enter bmps mode", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007565 return -EINVAL;
7566 }
7567 return 0;
7568}
7569
7570
7571#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7572static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7573 struct net_device *netdev,
7574 u8 key_index)
7575{
Jeff Johnsone7245742012-09-05 17:12:55 -07007576 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 return 0;
7578}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307579#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007580
7581#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7582static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7583 struct net_device *dev,
7584 struct ieee80211_txq_params *params)
7585{
Jeff Johnsone7245742012-09-05 17:12:55 -07007586 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007587 return 0;
7588}
7589#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7590static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7591 struct ieee80211_txq_params *params)
7592{
Jeff Johnsone7245742012-09-05 17:12:55 -07007593 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007594 return 0;
7595}
7596#endif //LINUX_VERSION_CODE
7597
7598static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7599 struct net_device *dev, u8 *mac)
7600{
7601 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307602 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007603 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307604 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007605 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007606
Jeff Johnsone7245742012-09-05 17:12:55 -07007607 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307608 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007609 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307610 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007611 return -EINVAL;
7612 }
7613
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307614 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7615 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007616
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307617 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007618 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307619 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7620 "%s: HDD context is not valid", __func__);
7621 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007622 }
7623
Jeff Johnson295189b2012-06-20 16:38:30 -07007624 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007625 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007626 )
7627 {
7628 if( NULL == mac )
7629 {
7630 v_U16_t i;
7631 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7632 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007633 if ((pAdapter->aStaInfo[i].isUsed) &&
7634 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007635 {
7636 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7637 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007638 "%s: Delete STA with MAC::"
7639 MAC_ADDRESS_STR,
7640 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007641 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7642 if (VOS_IS_STATUS_SUCCESS(vos_status))
7643 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007644 }
7645 }
7646 }
7647 else
7648 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007649
7650 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7651 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7652 {
7653 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007654 "%s: Skip this DEL STA as this is not used::"
7655 MAC_ADDRESS_STR,
7656 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007657 return -ENOENT;
7658 }
7659
7660 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7661 {
7662 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007663 "%s: Skip this DEL STA as deauth is in progress::"
7664 MAC_ADDRESS_STR,
7665 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007666 return -ENOENT;
7667 }
7668
7669 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7670
Jeff Johnson295189b2012-06-20 16:38:30 -07007671 hddLog(VOS_TRACE_LEVEL_INFO,
7672 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007673 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007674 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007675 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007676
7677 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7678 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7679 {
7680 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7681 hddLog(VOS_TRACE_LEVEL_INFO,
7682 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007683 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007684 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007685 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007686 return -ENOENT;
7687 }
7688
Jeff Johnson295189b2012-06-20 16:38:30 -07007689 }
7690 }
7691
7692 EXIT();
7693
7694 return 0;
7695}
7696
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007697static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7698 struct net_device *dev, u8 *mac, struct station_parameters *params)
7699{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007700 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007701#ifdef FEATURE_WLAN_TDLS
7702 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007703 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007704 mask = params->sta_flags_mask;
7705
7706 set = params->sta_flags_set;
7707
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007708#ifdef WLAN_FEATURE_TDLS_DEBUG
7709 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7710 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7711 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7712#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007713
7714 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7715 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007716 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007717 }
7718 }
7719#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007720 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007721}
7722
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007723
7724#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007725#define MAX_PMKSAIDS_IN_CACHE 8
7726
7727static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7728static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7729
7730
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007731static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007732 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007733{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307734 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007735 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7736 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307737 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307738 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007739 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307740 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307741
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007742 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
7743 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07007744
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307745 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307746 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007747 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307748 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007749 return -EINVAL;
7750 }
7751
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307752 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7753 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007754
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307755 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007756 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307757 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7758 "%s: HDD context is not valid", __func__);
7759 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007760 }
7761
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307762 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007763 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7764
Wilson Yang6507c4e2013-10-01 20:11:19 -07007765 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007766 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307767 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007768 pmksa->bssid, WNI_CFG_BSSID_LEN))
7769 {
7770 /* BSSID matched previous entry. Overwrite it. */
7771 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307772 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007773 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307774 vos_mem_copy(PMKIDCache[j].PMKID,
7775 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007776 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307777 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007778 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007779 dump_bssid(pmksa->bssid);
7780 dump_pmkid(halHandle, pmksa->pmkid);
7781 break;
7782 }
7783 }
7784
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007785 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007786 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007787
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007788 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307789 {
7790 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007791 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307792 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007793 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307794 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007795 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307796 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007797 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007798 dump_bssid(pmksa->bssid);
7799 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307800 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007801 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007802 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007803 }
7804
7805
7806 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307807 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007808 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307809 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007810 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007811 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307812 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7813 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007814 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007815 return 0;
7816}
7817
7818
Wilson Yang6507c4e2013-10-01 20:11:19 -07007819
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007820static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007821 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007822{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007823 tANI_U32 j=0;
7824 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7825 tHalHandle halHandle;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007826 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007827 hdd_context_t *pHddCtx;
Wilson Yangef657d32014-01-15 19:19:23 -08007828 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007829
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007830 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
7831 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007832
7833 /* Validate pAdapter */
7834 if (NULL == pAdapter)
7835 {
7836 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7837 return -EINVAL;
7838 }
7839
7840 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7841 status = wlan_hdd_validate_context(pHddCtx);
7842
7843 if (0 != status)
7844 {
7845 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7846 "%s: HDD context is not valid", __func__);
7847 return status;
7848 }
7849
7850 /*Retrieve halHandle*/
7851 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7852
7853 /*in case index is 0,no entry to delete*/
7854 if (0 == PMKIDCacheIndex)
7855 {
7856 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7857 __func__);
7858 return -EINVAL;
7859 }
7860
7861 /*find the matching PMKSA entry from j=0 to (index-1),
7862 * and delete the matched one
7863 */
7864 for (j = 0; j<PMKIDCacheIndex; j++)
7865 {
7866 if (vos_mem_compare(PMKIDCache[j].BSSID,
7867 pmksa->bssid,
7868 WNI_CFG_BSSID_LEN))
7869 {
7870 /* BSSID matched entry */
7871 BSSIDMatched = 1;
7872
7873 if (j<PMKIDCacheIndex-1)
7874 {
7875 /*replace the matching entry with the last entry in HDD local cache*/
7876 vos_mem_copy(PMKIDCache[j].BSSID,
7877 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7878 WNI_CFG_BSSID_LEN);
7879 vos_mem_copy(PMKIDCache[j].PMKID,
7880 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7881 CSR_RSN_PMKID_SIZE);
7882 }
7883
7884 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07007885 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7886 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7887
7888 /*reduce the PMKID array index*/
7889 PMKIDCacheIndex--;
7890
7891 /*delete the last PMKID cache in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08007892 if (eHAL_STATUS_SUCCESS !=
7893 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid))
Wilson Yang6507c4e2013-10-01 20:11:19 -07007894 {
7895 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7896 __func__,PMKIDCacheIndex);
Wilson Yangef657d32014-01-15 19:19:23 -08007897 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007898 }
7899
7900 dump_bssid(pmksa->bssid);
7901 dump_pmkid(halHandle,pmksa->pmkid);
7902
7903 break;
7904 }
7905 }
7906
7907 /* we compare all entries,but cannot find matching entry */
7908 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7909 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007910 hddLog(VOS_TRACE_LEVEL_FATAL,
7911 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
7912 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007913 dump_bssid(pmksa->bssid);
7914 dump_pmkid(halHandle, pmksa->pmkid);
7915 return -EINVAL;
7916 }
Wilson Yangef657d32014-01-15 19:19:23 -08007917 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007918}
7919
Wilson Yang6507c4e2013-10-01 20:11:19 -07007920
7921
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007922static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7923{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007924 tANI_U32 j=0;
7925 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7926 tHalHandle halHandle;
7927 hdd_context_t *pHddCtx;
7928 tANI_U8 *pBSSId;
Wilson Yangef657d32014-01-15 19:19:23 -08007929 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007930
7931 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7932
7933 /* Validate pAdapter */
7934 if (NULL == pAdapter)
7935 {
7936 hddLog(VOS_TRACE_LEVEL_ERROR,
7937 "%s: Invalid Adapter" ,__func__);
7938 return -EINVAL;
7939 }
7940
7941 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7942 status = wlan_hdd_validate_context(pHddCtx);
7943
7944 if (0 != status)
7945 {
7946 hddLog(VOS_TRACE_LEVEL_ERROR,
7947 "%s: HDD context is not valid", __func__);
7948 return status;
7949 }
7950
7951 /*Retrieve halHandle*/
7952 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7953
7954 /*in case index is 0,no entry to delete*/
7955 if (0 == PMKIDCacheIndex)
7956 {
7957 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7958 __func__);
7959 return -EINVAL;
7960 }
7961
7962 /*delete all the PMKSA one by one */
7963 for (j = 0; j<PMKIDCacheIndex; j++)
7964 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07007965 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007966
7967 /*delete the PMKID in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08007968 if (eHAL_STATUS_SUCCESS !=
7969 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId))
Wilson Yang6507c4e2013-10-01 20:11:19 -07007970 {
7971 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
7972 __func__,j);
Wilson Yangef657d32014-01-15 19:19:23 -08007973 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007974 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05307975 /*clear the entry in HDD cache 0--index-1 */
7976 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
7977 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007978 }
7979
7980 PMKIDCacheIndex = 0;
Wilson Yangef657d32014-01-15 19:19:23 -08007981 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007982}
7983#endif
7984
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007985#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307986static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007987 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7988{
7989 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7990 hdd_station_ctx_t *pHddStaCtx;
7991
7992 if (NULL == pAdapter)
7993 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007994 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007995 return -ENODEV;
7996 }
7997
7998 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7999
8000 // Added for debug on reception of Re-assoc Req.
8001 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
8002 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008003 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008004 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08008005 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008006 }
8007
8008#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08008009 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008010 ftie->ie_len);
8011#endif
8012
8013 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05308014 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
8015 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008016 ftie->ie_len);
8017 return 0;
8018}
8019#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008020
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308021#ifdef FEATURE_WLAN_SCAN_PNO
8022
8023void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
8024 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8025{
8026 int ret;
8027 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
8028 hdd_context_t *pHddCtx;
8029
Nirav Shah80830bf2013-12-31 16:35:12 +05308030 ENTER();
8031
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308032 if (NULL == pAdapter)
8033 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308034 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308035 "%s: HDD adapter is Null", __func__);
8036 return ;
8037 }
8038
8039 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8040 if (NULL == pHddCtx)
8041 {
8042 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8043 "%s: HDD context is Null!!!", __func__);
8044 return ;
8045 }
8046
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308047 spin_lock(&pHddCtx->schedScan_lock);
8048 if (TRUE == pHddCtx->isWiphySuspended)
8049 {
8050 pHddCtx->isSchedScanUpdatePending = TRUE;
8051 spin_unlock(&pHddCtx->schedScan_lock);
8052 hddLog(VOS_TRACE_LEVEL_INFO,
8053 "%s: Update cfg80211 scan database after it resume", __func__);
8054 return ;
8055 }
8056 spin_unlock(&pHddCtx->schedScan_lock);
8057
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308058 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
8059
8060 if (0 > ret)
8061 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
8062
8063 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308064 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8065 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308066}
8067
8068/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308069 * FUNCTION: wlan_hdd_is_pno_allowed
8070 * To check is there any P2P GO/SAP or P2P Client/STA
8071 * session is active
8072 */
8073static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
8074{
8075 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8076 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308077 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308078 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8079 int status = 0;
8080 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
8081
8082 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
8083 {
8084 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308085 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308086
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308087 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
8088 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
8089 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
8090 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
8091 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
8092 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308093 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308094 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308095 }
8096 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8097 pAdapterNode = pNext;
8098 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308099 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308100}
8101
8102/*
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308103 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
8104 * NL interface to enable PNO
8105 */
8106static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
8107 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8108{
8109 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8110 tpSirPNOScanReq pPnoRequest = NULL;
8111 hdd_context_t *pHddCtx;
8112 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308113 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308114 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8115 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8116 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8117 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308118 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308119
8120 if (NULL == pAdapter)
8121 {
8122 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8123 "%s: HDD adapter is Null", __func__);
8124 return -ENODEV;
8125 }
8126
8127 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308128 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308129
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308130 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308131 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308132 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8133 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308134 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308135 }
8136
8137 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8138 if (NULL == hHal)
8139 {
8140 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8141 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308142 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308143 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308144
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308145 /* The current firmware design for PNO does not consider concurrent
8146 * active sessions.Hence , determine the concurrent active sessions
8147 * and return a failure to the framework on a request for schedule
8148 * scan.
8149 */
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308150 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308151 {
8152 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308153 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308154 return -EBUSY;
8155 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308156
8157 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8158 if (NULL == pPnoRequest)
8159 {
8160 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8161 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308162 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308163 }
8164
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05308165 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308166 pPnoRequest->enable = 1; /*Enable PNO */
8167 pPnoRequest->ucNetworksCount = request->n_match_sets;
8168
8169 if (( !pPnoRequest->ucNetworksCount ) ||
8170 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
8171 {
8172 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308173 "%s: Network input is not correct %d",
8174 __func__, pPnoRequest->ucNetworksCount);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308175 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308176 goto error;
8177 }
8178
8179 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
8180 {
8181 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308182 "%s: Incorrect number of channels %d",
8183 __func__, request->n_channels);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308184 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308185 goto error;
8186 }
8187
8188 /* Framework provides one set of channels(all)
8189 * common for all saved profile */
8190 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
8191 channels_allowed, &num_channels_allowed))
8192 {
8193 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8194 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308195 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308196 goto error;
8197 }
8198 /* Checking each channel against allowed channel list */
8199 num_ch = 0;
Nirav Shah80830bf2013-12-31 16:35:12 +05308200 if (request->n_channels)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308201 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308202 char chList [(request->n_channels*5)+1];
8203 int len;
8204 for (i = 0, len = 0; i < request->n_channels; i++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308205 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308206 for (indx = 0; indx < num_channels_allowed; indx++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308207 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308208 if (request->channels[i]->hw_value == channels_allowed[indx])
8209 {
8210 valid_ch[num_ch++] = request->channels[i]->hw_value;
8211 len += snprintf(chList+len, 5, "%d ",
8212 request->channels[i]->hw_value);
8213 break ;
8214 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308215 }
8216 }
Nirav Shah80830bf2013-12-31 16:35:12 +05308217 hddLog(VOS_TRACE_LEVEL_INFO,"Channel-List: %s ", chList);
8218 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308219
8220 /* Filling per profile params */
8221 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
8222 {
8223 pPnoRequest->aNetworks[i].ssId.length =
8224 request->match_sets[i].ssid.ssid_len;
8225
8226 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8227 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8228 {
8229 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308230 "%s: SSID Len %d is not correct for network %d",
8231 __func__, pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308232 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308233 goto error;
8234 }
8235
8236 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8237 request->match_sets[i].ssid.ssid,
8238 request->match_sets[i].ssid.ssid_len);
8239 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8240 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8241 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8242
8243 /*Copying list of valid channel into request */
8244 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8245 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8246
8247 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8248 }
8249
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308250 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008251 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308252 if ((0 < request->ie_len) && (NULL != request->ie))
8253 {
8254 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8255 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8256 pPnoRequest->us24GProbeTemplateLen);
8257
8258 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8259 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8260 pPnoRequest->us5GProbeTemplateLen);
8261 }
8262
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308263 /* Driver gets only one time interval which is hardcoded in
8264 * supplicant for 10000ms. Taking power consumption into account 6 timers
8265 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8266 * 80,160,320 secs. And number of scan cycle for each timer
8267 * is configurable through INI param gPNOScanTimerRepeatValue.
8268 * If it is set to 0 only one timer will be used and PNO scan cycle
8269 * will be repeated after each interval specified by supplicant
8270 * till PNO is disabled.
8271 */
8272 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8273 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8274 else
8275 pPnoRequest->scanTimers.ucScanTimersCount =
8276 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8277
8278 tempInterval = (request->interval)/1000;
8279 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8280 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8281 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8282 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8283 {
8284 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8285 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8286 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8287 tempInterval *= 2;
8288 }
8289 //Repeat last timer until pno disabled.
8290 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8291
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308292 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308293
Nirav Shah80830bf2013-12-31 16:35:12 +05308294 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8295 "SessionId %d, enable %d, modePNO %d, ucScanTimersCount %d",
8296 pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO,
8297 pPnoRequest->scanTimers.ucScanTimersCount);
8298
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308299 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8300 pPnoRequest, pAdapter->sessionId,
8301 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8302 if (eHAL_STATUS_SUCCESS != status)
8303 {
8304 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308305 "%s: Failed to enable PNO", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308306 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308307 goto error;
8308 }
8309
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8311 "PNO scanRequest offloaded");
8312
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308313error:
8314 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308315 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308316}
8317
8318/*
8319 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8320 * NL interface to disable PNO
8321 */
8322static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8323 struct net_device *dev)
8324{
8325 eHalStatus status = eHAL_STATUS_FAILURE;
8326 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8327 hdd_context_t *pHddCtx;
8328 tHalHandle hHal;
8329 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308330 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308331
8332 ENTER();
8333
8334 if (NULL == pAdapter)
8335 {
8336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8337 "%s: HDD adapter is Null", __func__);
8338 return -ENODEV;
8339 }
8340
8341 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308342
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308343 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308344 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308345 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308346 "%s: HDD context is Null", __func__);
8347 return -ENODEV;
8348 }
8349
8350 /* The return 0 is intentional when isLogpInProgress and
8351 * isLoadUnloadInProgress. We did observe a crash due to a return of
8352 * failure in sched_scan_stop , especially for a case where the unload
8353 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8354 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8355 * success. If it returns a failure , then its next invocation due to the
8356 * clean up of the second interface will have the dev pointer corresponding
8357 * to the first one leading to a crash.
8358 */
8359 if (pHddCtx->isLogpInProgress)
8360 {
8361 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8362 "%s: LOGP in Progress. Ignore!!!", __func__);
8363 return ret;
8364 }
8365
8366 if (pHddCtx->isLoadUnloadInProgress)
8367 {
8368 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8369 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8370 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308371 }
8372
8373 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8374 if (NULL == hHal)
8375 {
8376 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8377 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308378 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308379 }
8380
8381 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8382 if (NULL == pPnoRequest)
8383 {
8384 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8385 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308386 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308387 }
8388
8389 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8390 pPnoRequest->enable = 0; /* Disable PNO */
8391 pPnoRequest->ucNetworksCount = 0;
8392
8393 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8394 pAdapter->sessionId,
8395 NULL, pAdapter);
8396 if (eHAL_STATUS_SUCCESS != status)
8397 {
8398 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8399 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308400 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308401 }
8402
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308403 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8404 "%s: PNO scan disabled", __func__);
8405
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308406 vos_mem_free(pPnoRequest);
8407
8408 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308409 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308410}
8411
8412#endif /*FEATURE_WLAN_SCAN_PNO*/
8413
8414
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008415#ifdef FEATURE_WLAN_TDLS
8416static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8417 u8 *peer, u8 action_code, u8 dialog_token,
8418 u16 status_code, const u8 *buf, size_t len)
8419{
8420
8421 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8422 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008423 u8 peerMac[6];
8424 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008425 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008426 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008427 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008428
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008429 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008430 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308431 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008432 "Invalid arguments");
8433 return -EINVAL;
8434 }
8435
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008436 if (pHddCtx->isLogpInProgress)
8437 {
8438 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8439 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008440 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008441 return -EBUSY;
8442 }
8443
Hoonki Lee27511902013-03-14 18:19:06 -07008444 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008445 {
Hoonki Lee27511902013-03-14 18:19:06 -07008446 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8447 "%s: TDLS mode is disabled OR not enabled in FW."
8448 MAC_ADDRESS_STR " action %d declined.",
8449 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008450 return -ENOTSUPP;
8451 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008452
Hoonki Lee27511902013-03-14 18:19:06 -07008453 /* other than teardown frame, other mgmt frames are not sent if disabled */
8454 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8455 {
8456 /* if tdls_mode is disabled to respond to peer's request */
8457 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8458 {
8459 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8460 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008461 " TDLS mode is disabled. action %d declined.",
8462 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008463
8464 return -ENOTSUPP;
8465 }
8466 }
8467
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008468 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8469 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308470 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008471 {
8472 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008473 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008474 " TDLS setup is ongoing. action %d declined.",
8475 __func__, MAC_ADDR_ARRAY(peer), action_code);
8476 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008477 }
8478 }
8479
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008480 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8481 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008482 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008483 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008484 {
8485 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8486 we return error code at 'add_station()'. Hence we have this
8487 check again in addtion to add_station().
8488 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008489 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008490 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008491 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8492 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008493 " TDLS Max peer already connected. action %d declined.",
8494 __func__, MAC_ADDR_ARRAY(peer), action_code);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308495 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008496 }
8497 else
8498 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008499 /* maximum reached. tweak to send error code to peer and return
8500 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008501 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008502 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8503 "%s: " MAC_ADDRESS_STR
8504 " TDLS Max peer already connected send response status %d",
8505 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008506 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008507 /* fall through to send setup resp with failure status
8508 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008509 }
8510 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008511 else
8512 {
8513 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308514 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008515 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008516 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008517 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008518 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8519 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008520 return -EPERM;
8521 }
8522 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008523 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008524 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008525
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008526#ifdef WLAN_FEATURE_TDLS_DEBUG
8527 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008528 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8529 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8530 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008531#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008532
Hoonki Leea34dd892013-02-05 22:56:02 -08008533 /*Except teardown responder will not be used so just make 0*/
8534 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008535 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008536 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008537
8538 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308539 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008540
8541 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8542 responder = pTdlsPeer->is_responder;
8543 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008544 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008545 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8546 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8547 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8548 dialog_token, status_code, len);
8549 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008550 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008551 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008552
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308553 /* For explicit trigger of DIS_REQ come out of BMPS for
8554 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008555 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308556 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8557 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008558 {
8559 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8560 {
8561 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308562 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008563 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8564 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308565 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8566 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008567 }
8568
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008569 /* make sure doesn't call send_mgmt() while it is pending */
8570 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8571 {
8572 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008573 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008574 __func__, MAC_ADDR_ARRAY(peer), action_code);
8575 return -EBUSY;
8576 }
8577
8578 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008579 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8580
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008581 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008582 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008583
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008584 if (VOS_STATUS_SUCCESS != status)
8585 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008586 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8587 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008588 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008589 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308590 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008591 }
8592
Hoonki Leed37cbb32013-04-20 00:31:14 -07008593 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8594 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8595
8596 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008597 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008598 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008599 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008600 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008601 pAdapter->mgmtTxCompletionStatus = FALSE;
Yue Ma4f55ef32014-01-23 16:45:33 -08008602
8603 if (pHddCtx->isLogpInProgress)
8604 {
8605 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8606 "%s: LOGP in Progress. Ignore!!!", __func__);
8607 return -EAGAIN;
8608 }
8609
Hoonki Leed37cbb32013-04-20 00:31:14 -07008610 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308611 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008612 }
8613
Gopichand Nakkala05922802013-03-14 12:23:19 -07008614 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008615 {
8616 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008617 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008618 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008619
Hoonki Leea34dd892013-02-05 22:56:02 -08008620 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8621 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008622 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008623 }
8624 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8625 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008626 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008627 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008628
8629 return 0;
8630}
8631
8632static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8633 u8 *peer, enum nl80211_tdls_operation oper)
8634{
8635 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8636 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308637 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008638 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008639
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308640 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008641 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008642 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008643 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008644 return -EINVAL;
8645 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008646
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308647 status = wlan_hdd_validate_context(pHddCtx);
8648
8649 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008650 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308651 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8652 "%s: HDD context is not valid", __func__);
8653 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008654 }
8655
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008656
8657 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008658 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008659 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008660 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008661 "TDLS Disabled in INI OR not enabled in FW. "
8662 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008663 return -ENOTSUPP;
8664 }
8665
8666 switch (oper) {
8667 case NL80211_TDLS_ENABLE_LINK:
8668 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008669 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308670 long ret;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308671 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008672
Sunil Dutt41de4e22013-11-14 18:09:02 +05308673 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8674
8675 if ( NULL == pTdlsPeer ) {
8676 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8677 " (oper %d) not exsting. ignored",
8678 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8679 return -EINVAL;
8680 }
8681
8682 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8683 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8684 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8685 "NL80211_TDLS_ENABLE_LINK");
8686
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008687 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8688 {
8689 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8690 MAC_ADDRESS_STR " failed",
8691 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8692 return -EINVAL;
8693 }
8694
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008695 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008696 {
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308697 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308698
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308699 if (0 != wlan_hdd_tdls_get_link_establish_params(
8700 pAdapter, peer,&tdlsLinkEstablishParams)) {
8701 return -EINVAL;
8702 }
8703 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308704
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308705 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8706 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8707 /* Send TDLS peer UAPSD capabilities to the firmware and
8708 * register with the TL on after the response for this operation
8709 * is received .
8710 */
8711 ret = wait_for_completion_interruptible_timeout(
8712 &pAdapter->tdls_link_establish_req_comp,
8713 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8714 if (ret <= 0)
8715 {
8716 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8717 "%s: Link Establish Request Faled Status %ld",
8718 __func__, ret);
8719 return -EINVAL;
8720 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308721 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008722 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308723 /* Mark TDLS client Authenticated .*/
8724 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8725 pTdlsPeer->staId,
8726 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008727 if (VOS_STATUS_SUCCESS == status)
8728 {
Hoonki Lee14621352013-04-16 17:51:19 -07008729 if (pTdlsPeer->is_responder == 0)
8730 {
8731 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8732
8733 wlan_hdd_tdls_timer_restart(pAdapter,
8734 &pTdlsPeer->initiatorWaitTimeoutTimer,
8735 WAIT_TIME_TDLS_INITIATOR);
8736 /* suspend initiator TX until it receives direct packet from the
8737 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8738 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8739 &staId, NULL);
8740 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008741 wlan_hdd_tdls_increment_peer_count(pAdapter);
8742 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008743 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308744
8745 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308746 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8747 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308748 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308749 int ac;
8750 uint8 ucAc[4] = { WLANTL_AC_VO,
8751 WLANTL_AC_VI,
8752 WLANTL_AC_BK,
8753 WLANTL_AC_BE };
8754 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8755 for(ac=0; ac < 4; ac++)
8756 {
8757 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8758 pTdlsPeer->staId, ucAc[ac],
8759 tlTid[ac], tlTid[ac], 0, 0,
8760 WLANTL_BI_DIR );
8761 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308762 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008763 }
8764
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008765 }
8766 break;
8767 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008768 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05308769 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8770
8771 if ( NULL == pTdlsPeer ) {
8772 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8773 " (oper %d) not exsting. ignored",
8774 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8775 return -EINVAL;
8776 }
8777
8778 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8779 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8780 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8781 "NL80211_TDLS_DISABLE_LINK");
8782
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008783 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008784 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008785 long status;
8786
8787 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8788
Lee Hoonkic1262f22013-01-24 21:59:00 -08008789 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8790 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008791
8792 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8793 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8794 if (status <= 0)
8795 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008796 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008797 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8798 "%s: Del station failed status %ld",
8799 __func__, status);
8800 return -EPERM;
8801 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008802 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008803 }
8804 else
8805 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008806 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8807 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008808 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008809 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008810 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008811 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308812 {
8813 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8814 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
8815 __func__, MAC_ADDR_ARRAY(peer));
8816
8817 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8818 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8819
8820 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8821 " %s TDLS External control and Implicit Trigger not enabled ",
8822 __func__);
8823 return -ENOTSUPP;
8824 }
8825
Sunil Dutt41de4e22013-11-14 18:09:02 +05308826
8827 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8828
8829 if ( NULL == pTdlsPeer ) {
8830 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
8831 " peer not exsting",
8832 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308833 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308834 }
8835 else {
8836 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
8837 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
8838 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308839
8840 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
8841 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308842 break;
8843 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008844 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308845 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308846 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308847 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8848 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
8849 __func__, MAC_ADDR_ARRAY(peer));
8850
8851 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8852 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8853
8854 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8855 " %s TDLS External control and Implicit Trigger not enabled ",
8856 __func__);
8857 return -ENOTSUPP;
8858 }
8859
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308860 /* To cater the requirement of establishing the TDLS link
8861 * irrespective of the data traffic , get an entry of TDLS peer.
8862 */
8863 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
8864 if (pTdlsPeer == NULL) {
8865 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8866 "%s: peer " MAC_ADDRESS_STR " not existing",
8867 __func__, MAC_ADDR_ARRAY(peer));
8868 return -EINVAL;
8869 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308870
8871 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
8872
8873 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8874 " %s TDLS Add Force Peer Failed",
8875 __func__);
8876 return -EINVAL;
8877 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308878 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308879 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008880 case NL80211_TDLS_DISCOVERY_REQ:
8881 /* We don't support in-driver setup/teardown/discovery */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308882 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8883 "%s: We don't support in-driver setup/teardown/discovery "
8884 ,__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008885 return -ENOTSUPP;
8886 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308887 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8888 "%s: unsupported event",__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008889 return -ENOTSUPP;
8890 }
8891 return 0;
8892}
Chilam NG571c65a2013-01-19 12:27:36 +05308893
8894int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8895 struct net_device *dev, u8 *peer)
8896{
Arif Hussaina7c8e412013-11-20 11:06:42 -08008897 hddLog(VOS_TRACE_LEVEL_INFO,
8898 "tdls send discover req: "MAC_ADDRESS_STR,
8899 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05308900
8901 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8902 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8903}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008904#endif
8905
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308906#ifdef WLAN_FEATURE_GTK_OFFLOAD
8907/*
8908 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8909 * Callback rountine called upon receiving response for
8910 * get offload info
8911 */
8912void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8913 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8914{
8915
8916 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308917 tANI_U8 tempReplayCounter[8];
8918 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308919
8920 ENTER();
8921
8922 if (NULL == pAdapter)
8923 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308924 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308925 "%s: HDD adapter is Null", __func__);
8926 return ;
8927 }
8928
8929 if (NULL == pGtkOffloadGetInfoRsp)
8930 {
8931 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8932 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8933 return ;
8934 }
8935
8936 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8937 {
8938 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8939 "%s: wlan Failed to get replay counter value",
8940 __func__);
8941 return ;
8942 }
8943
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308944 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8945 /* Update replay counter */
8946 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8947 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8948
8949 {
8950 /* changing from little to big endian since supplicant
8951 * works on big endian format
8952 */
8953 int i;
8954 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8955
8956 for (i = 0; i < 8; i++)
8957 {
8958 tempReplayCounter[7-i] = (tANI_U8)p[i];
8959 }
8960 }
8961
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308962 /* Update replay counter to NL */
8963 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308964 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308965}
8966
8967/*
8968 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8969 * This function is used to offload GTK rekeying job to the firmware.
8970 */
8971int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8972 struct cfg80211_gtk_rekey_data *data)
8973{
8974 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8975 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8976 hdd_station_ctx_t *pHddStaCtx;
8977 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308978 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308979 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308980 eHalStatus status = eHAL_STATUS_FAILURE;
8981
8982 ENTER();
8983
8984 if (NULL == pAdapter)
8985 {
8986 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8987 "%s: HDD adapter is Null", __func__);
8988 return -ENODEV;
8989 }
8990
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308991 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308992
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308993 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308994 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8996 "%s: HDD context is not valid", __func__);
8997 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308998 }
8999
9000 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9001 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9002 if (NULL == hHal)
9003 {
9004 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9005 "%s: HAL context is Null!!!", __func__);
9006 return -EAGAIN;
9007 }
9008
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309009 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
9010 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
9011 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
9012 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309013 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309014 {
9015 /* changing from big to little endian since driver
9016 * works on little endian format
9017 */
9018 tANI_U8 *p =
9019 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
9020 int i;
9021
9022 for (i = 0; i < 8; i++)
9023 {
9024 p[7-i] = data->replay_ctr[i];
9025 }
9026 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309027
9028 if (TRUE == pHddCtx->hdd_wlan_suspended)
9029 {
9030 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309031 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
9032 sizeof (tSirGtkOffloadParams));
9033 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309034 pAdapter->sessionId);
9035
9036 if (eHAL_STATUS_SUCCESS != status)
9037 {
9038 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9039 "%s: sme_SetGTKOffload failed, returned %d",
9040 __func__, status);
9041 return status;
9042 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309043 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9044 "%s: sme_SetGTKOffload successfull", __func__);
9045 }
9046 else
9047 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309048 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9049 "%s: wlan not suspended GTKOffload request is stored",
9050 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309051 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309052
9053 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309054}
9055#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
9056
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309057/*
9058 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
9059 * This function is used to set access control policy
9060 */
9061static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
9062 struct net_device *dev, const struct cfg80211_acl_data *params)
9063{
9064 int i;
9065 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9066 hdd_hostapd_state_t *pHostapdState;
9067 tsap_Config_t *pConfig;
9068 v_CONTEXT_t pVosContext = NULL;
9069 hdd_context_t *pHddCtx;
9070 int status;
9071
9072 ENTER();
9073
9074 if (NULL == pAdapter)
9075 {
9076 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9077 "%s: HDD adapter is Null", __func__);
9078 return -ENODEV;
9079 }
9080
9081 if (NULL == params)
9082 {
9083 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9084 "%s: params is Null", __func__);
9085 return -EINVAL;
9086 }
9087
9088 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9089 status = wlan_hdd_validate_context(pHddCtx);
9090
9091 if (0 != status)
9092 {
9093 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9094 "%s: HDD context is not valid", __func__);
9095 return status;
9096 }
9097
9098 pVosContext = pHddCtx->pvosContext;
9099 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9100
9101 if (NULL == pHostapdState)
9102 {
9103 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9104 "%s: pHostapdState is Null", __func__);
9105 return -EINVAL;
9106 }
9107
9108 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
9109 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
9110
9111 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
9112 {
9113 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
9114
9115 /* default value */
9116 pConfig->num_accept_mac = 0;
9117 pConfig->num_deny_mac = 0;
9118
9119 /**
9120 * access control policy
9121 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
9122 * listed in hostapd.deny file.
9123 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
9124 * listed in hostapd.accept file.
9125 */
9126 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
9127 {
9128 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
9129 }
9130 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
9131 {
9132 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
9133 }
9134 else
9135 {
9136 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9137 "%s:Acl Policy : %d is not supported",
9138 __func__, params->acl_policy);
9139 return -ENOTSUPP;
9140 }
9141
9142 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
9143 {
9144 pConfig->num_accept_mac = params->n_acl_entries;
9145 for (i = 0; i < params->n_acl_entries; i++)
9146 {
9147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9148 "** Add ACL MAC entry %i in WhiletList :"
9149 MAC_ADDRESS_STR, i,
9150 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9151
9152 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
9153 sizeof(qcmacaddr));
9154 }
9155 }
9156 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
9157 {
9158 pConfig->num_deny_mac = params->n_acl_entries;
9159 for (i = 0; i < params->n_acl_entries; i++)
9160 {
9161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9162 "** Add ACL MAC entry %i in BlackList :"
9163 MAC_ADDRESS_STR, i,
9164 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9165
9166 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
9167 sizeof(qcmacaddr));
9168 }
9169 }
9170
9171 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
9172 {
9173 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9174 "%s: SAP Set Mac Acl fail", __func__);
9175 return -EINVAL;
9176 }
9177 }
9178 else
9179 {
9180 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9181 "%s: Invalid device_mode = %d",
9182 __func__, pAdapter->device_mode);
9183 return -EINVAL;
9184 }
9185
9186 return 0;
9187}
9188
Leo Chang9056f462013-08-01 19:21:11 -07009189#ifdef WLAN_NL80211_TESTMODE
9190#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07009191void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07009192(
9193 void *pAdapter,
9194 void *indCont
9195)
9196{
Leo Changd9df8aa2013-09-26 13:32:26 -07009197 tSirLPHBInd *lphbInd;
9198 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07009199
9200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009201 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07009202
9203 if (NULL == indCont)
9204 {
9205 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009206 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07009207 return;
9208 }
9209
Leo Changd9df8aa2013-09-26 13:32:26 -07009210 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07009211 skb = cfg80211_testmode_alloc_event_skb(
9212 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07009213 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07009214 GFP_ATOMIC);
9215 if (!skb)
9216 {
9217 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9218 "LPHB timeout, NL buffer alloc fail");
9219 return;
9220 }
9221
Leo Changac3ba772013-10-07 09:47:04 -07009222 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07009223 {
9224 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9225 "WLAN_HDD_TM_ATTR_CMD put fail");
9226 goto nla_put_failure;
9227 }
Leo Changac3ba772013-10-07 09:47:04 -07009228 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07009229 {
9230 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9231 "WLAN_HDD_TM_ATTR_TYPE put fail");
9232 goto nla_put_failure;
9233 }
Leo Changac3ba772013-10-07 09:47:04 -07009234 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07009235 sizeof(tSirLPHBInd), lphbInd))
9236 {
9237 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9238 "WLAN_HDD_TM_ATTR_DATA put fail");
9239 goto nla_put_failure;
9240 }
Leo Chang9056f462013-08-01 19:21:11 -07009241 cfg80211_testmode_event(skb, GFP_ATOMIC);
9242 return;
9243
9244nla_put_failure:
9245 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9246 "NLA Put fail");
9247 kfree_skb(skb);
9248
9249 return;
9250}
9251#endif /* FEATURE_WLAN_LPHB */
9252
9253static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9254{
9255 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9256 int err = 0;
9257#ifdef FEATURE_WLAN_LPHB
9258 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009259 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009260#endif /* FEATURE_WLAN_LPHB */
9261
9262 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9263 if (err)
9264 {
9265 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9266 "%s Testmode INV ATTR", __func__);
9267 return err;
9268 }
9269
9270 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9271 {
9272 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9273 "%s Testmode INV CMD", __func__);
9274 return -EINVAL;
9275 }
9276
9277 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9278 {
9279#ifdef FEATURE_WLAN_LPHB
9280 /* Low Power Heartbeat configuration request */
9281 case WLAN_HDD_TM_CMD_WLAN_HB:
9282 {
9283 int buf_len;
9284 void *buf;
9285 tSirLPHBReq *hb_params = NULL;
9286
9287 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9288 {
9289 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9290 "%s Testmode INV DATA", __func__);
9291 return -EINVAL;
9292 }
9293
9294 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9295 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
9296 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9297 if (NULL == hb_params)
9298 {
9299 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9300 "%s Request Buffer Alloc Fail", __func__);
9301 return -EINVAL;
9302 }
9303
9304 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009305 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9306 hb_params,
9307 wlan_hdd_cfg80211_lphb_ind_handler);
9308 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009309 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9311 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009312 vos_mem_free(hb_params);
9313 }
Leo Chang9056f462013-08-01 19:21:11 -07009314 return 0;
9315 }
9316#endif /* FEATURE_WLAN_LPHB */
9317 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309318 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9319 "%s: unsupported event",__func__);
Leo Chang9056f462013-08-01 19:21:11 -07009320 return -EOPNOTSUPP;
9321 }
9322
9323 return err;
9324}
9325#endif /* CONFIG_NL80211_TESTMODE */
9326
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309327static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9328 struct net_device *dev,
9329 int idx, struct survey_info *survey)
9330{
9331 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9332 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309333 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309334 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309335 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309336 v_S7_t snr,rssi;
9337 int status, i, j, filled = 0;
9338
9339 ENTER();
9340
9341
9342 if (NULL == pAdapter)
9343 {
9344 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9345 "%s: HDD adapter is Null", __func__);
9346 return -ENODEV;
9347 }
9348
9349 if (NULL == wiphy)
9350 {
9351 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9352 "%s: wiphy is Null", __func__);
9353 return -ENODEV;
9354 }
9355
9356 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9357 status = wlan_hdd_validate_context(pHddCtx);
9358
9359 if (0 != status)
9360 {
9361 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9362 "%s: HDD context is not valid", __func__);
9363 return status;
9364 }
9365
Mihir Sheted9072e02013-08-21 17:02:29 +05309366 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9367
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309368 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309369 0 != pAdapter->survey_idx ||
9370 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309371 {
9372 /* The survey dump ops when implemented completely is expected to
9373 * return a survey of all channels and the ops is called by the
9374 * kernel with incremental values of the argument 'idx' till it
9375 * returns -ENONET. But we can only support the survey for the
9376 * operating channel for now. survey_idx is used to track
9377 * that the ops is called only once and then return -ENONET for
9378 * the next iteration
9379 */
9380 pAdapter->survey_idx = 0;
9381 return -ENONET;
9382 }
9383
9384 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9385
9386 wlan_hdd_get_snr(pAdapter, &snr);
9387 wlan_hdd_get_rssi(pAdapter, &rssi);
9388
9389 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9390 hdd_wlan_get_freq(channel, &freq);
9391
9392
9393 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9394 {
9395 if (NULL == wiphy->bands[i])
9396 {
9397 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9398 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9399 continue;
9400 }
9401
9402 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9403 {
9404 struct ieee80211_supported_band *band = wiphy->bands[i];
9405
9406 if (band->channels[j].center_freq == (v_U16_t)freq)
9407 {
9408 survey->channel = &band->channels[j];
9409 /* The Rx BDs contain SNR values in dB for the received frames
9410 * while the supplicant expects noise. So we calculate and
9411 * return the value of noise (dBm)
9412 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9413 */
9414 survey->noise = rssi - snr;
9415 survey->filled = SURVEY_INFO_NOISE_DBM;
9416 filled = 1;
9417 }
9418 }
9419 }
9420
9421 if (filled)
9422 pAdapter->survey_idx = 1;
9423 else
9424 {
9425 pAdapter->survey_idx = 0;
9426 return -ENONET;
9427 }
9428
9429 return 0;
9430}
9431
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309432/*
9433 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9434 * this is called when cfg80211 driver resume
9435 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9436 */
9437int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9438{
9439 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9440 hdd_adapter_t *pAdapter;
9441 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9442 VOS_STATUS status = VOS_STATUS_SUCCESS;
9443
9444 ENTER();
9445
9446 if ( NULL == pHddCtx )
9447 {
9448 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9449 "%s: HddCtx validation failed", __func__);
9450 return 0;
9451 }
9452
9453 if (pHddCtx->isLogpInProgress)
9454 {
9455 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9456 "%s: LOGP in Progress. Ignore!!!", __func__);
9457 return 0;
9458 }
9459
9460 if (pHddCtx->isLoadUnloadInProgress)
9461 {
9462 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9463 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9464 return 0;
9465 }
9466
9467 spin_lock(&pHddCtx->schedScan_lock);
9468 pHddCtx->isWiphySuspended = FALSE;
9469 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9470 {
9471 spin_unlock(&pHddCtx->schedScan_lock);
9472 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9473 "%s: Return resume is not due to PNO indication", __func__);
9474 return 0;
9475 }
9476 // Reset flag to avoid updatating cfg80211 data old results again
9477 pHddCtx->isSchedScanUpdatePending = FALSE;
9478 spin_unlock(&pHddCtx->schedScan_lock);
9479
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309480
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309481 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9482
9483 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9484 {
9485 pAdapter = pAdapterNode->pAdapter;
9486 if ( (NULL != pAdapter) &&
9487 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9488 {
9489 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309490 {
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309491 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9492 "%s: NO SCAN result", __func__);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309493 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309494 else
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309495 {
9496 /* Acquire wakelock to handle the case where APP's tries to
9497 * suspend immediately after updating the scan results. Whis
9498 * results in app's is in suspended state and not able to
9499 * process the connect request to AP
9500 */
9501 hdd_prevent_suspend_timeout(2000);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309502 cfg80211_sched_scan_results(pHddCtx->wiphy);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309503 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309504
9505 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9506 "%s : cfg80211 scan result database updated", __func__);
9507
9508 return 0;
9509
9510 }
9511 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9512 pAdapterNode = pNext;
9513 }
9514
9515 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9516 "%s: Failed to find Adapter", __func__);
9517 return 0;
9518}
9519
9520/*
9521 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9522 * this is called when cfg80211 driver suspends
9523 */
9524int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9525 struct cfg80211_wowlan *wow)
9526{
9527 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9528
9529 ENTER();
9530 if (NULL == pHddCtx)
9531 {
9532 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9533 "%s: HddCtx validation failed", __func__);
9534 return 0;
9535 }
9536
9537 pHddCtx->isWiphySuspended = TRUE;
9538
9539 EXIT();
9540
9541 return 0;
9542}
9543
Jeff Johnson295189b2012-06-20 16:38:30 -07009544/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309545static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009546{
9547 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9548 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9549 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9550 .change_station = wlan_hdd_change_station,
9551#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9552 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9553 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9554 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009555#else
9556 .start_ap = wlan_hdd_cfg80211_start_ap,
9557 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9558 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009559#endif
9560 .change_bss = wlan_hdd_cfg80211_change_bss,
9561 .add_key = wlan_hdd_cfg80211_add_key,
9562 .get_key = wlan_hdd_cfg80211_get_key,
9563 .del_key = wlan_hdd_cfg80211_del_key,
9564 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009565#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009566 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009567#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009568 .scan = wlan_hdd_cfg80211_scan,
9569 .connect = wlan_hdd_cfg80211_connect,
9570 .disconnect = wlan_hdd_cfg80211_disconnect,
9571 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9572 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9573 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9574 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9575 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009576 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9577 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9578 .mgmt_tx = wlan_hdd_action,
9579#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9580 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9581 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9582 .set_txq_params = wlan_hdd_set_txq_params,
9583#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009584 .get_station = wlan_hdd_cfg80211_get_station,
9585 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9586 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009587 .add_station = wlan_hdd_cfg80211_add_station,
9588#ifdef FEATURE_WLAN_LFR
9589 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9590 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9591 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9592#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009593#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9594 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9595#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009596#ifdef FEATURE_WLAN_TDLS
9597 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9598 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9599#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309600#ifdef WLAN_FEATURE_GTK_OFFLOAD
9601 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9602#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309603#ifdef FEATURE_WLAN_SCAN_PNO
9604 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9605 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9606#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309607 .resume = wlan_hdd_cfg80211_resume_wlan,
9608 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309609 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009610#ifdef WLAN_NL80211_TESTMODE
9611 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9612#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309613 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009614};
9615