blob: bdcc128bc630a8bfd6e51ad69994070758baf50c [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 );
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002738 hdd_context_t *pHddCtx;
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
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002749 if (!pAdapter)
2750 {
2751 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2752 "%s: Adapter context is null", __func__);
2753 return VOS_STATUS_E_FAILURE;
2754 }
2755
2756 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2757 if (!pHddCtx)
2758 {
2759 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2760 "%s: HDD context is null", __func__);
2761 return VOS_STATUS_E_FAILURE;
2762 }
2763
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302764 status = wlan_hdd_validate_context(pHddCtx);
2765
2766 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002767 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302768 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2769 "%s: HDD context is not valid", __func__);
2770 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002771 }
2772
2773 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2774 __func__, pAdapter->device_mode);
2775
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302776 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002777 wdev = ndev->ieee80211_ptr;
2778
2779#ifdef WLAN_BTAMP_FEATURE
2780 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2781 (NL80211_IFTYPE_ADHOC == type)||
2782 (NL80211_IFTYPE_AP == type)||
2783 (NL80211_IFTYPE_P2P_GO == type))
2784 {
2785 pHddCtx->isAmpAllowed = VOS_FALSE;
2786 // stop AMP traffic
2787 status = WLANBAP_StopAmp();
2788 if(VOS_STATUS_SUCCESS != status )
2789 {
2790 pHddCtx->isAmpAllowed = VOS_TRUE;
2791 hddLog(VOS_TRACE_LEVEL_FATAL,
2792 "%s: Failed to stop AMP", __func__);
2793 return -EINVAL;
2794 }
2795 }
2796#endif //WLAN_BTAMP_FEATURE
2797 /* Reset the current device mode bit mask*/
2798 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2799
2800 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002801 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002802 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002803 )
2804 {
2805 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08002806 if (!pWextState)
2807 {
2808 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2809 "%s: pWextState is null", __func__);
2810 return VOS_STATUS_E_FAILURE;
2811 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002812 pRoamProfile = &pWextState->roamProfile;
2813 LastBSSType = pRoamProfile->BSSType;
2814
2815 switch (type)
2816 {
2817 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002818 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002819 hddLog(VOS_TRACE_LEVEL_INFO,
2820 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2821 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002822#ifdef WLAN_FEATURE_11AC
2823 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2824 {
2825 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2826 }
2827#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302828 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002829 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002830 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002831 //Check for sub-string p2p to confirm its a p2p interface
2832 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302833 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002834 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2835 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2836 }
2837 else
2838 {
2839 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002840 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002841 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302842#ifdef FEATURE_WLAN_TDLS
2843 /* The open adapter for the p2p shall skip initializations in
2844 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2845 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2846 * tdls_init when the change_iface sets the device mode to
2847 * WLAN_HDD_P2P_CLIENT.
2848 */
2849
2850 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2851 {
2852 if (0 != wlan_hdd_tdls_init (pAdapter))
2853 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302854 hddLog(VOS_TRACE_LEVEL_ERROR,
2855 "%s: tdls initialization failed", __func__);
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302856 return -EINVAL;
2857 }
2858 }
2859#endif
2860
Jeff Johnson295189b2012-06-20 16:38:30 -07002861 break;
2862 case NL80211_IFTYPE_ADHOC:
2863 hddLog(VOS_TRACE_LEVEL_INFO,
2864 "%s: setting interface Type to ADHOC", __func__);
2865 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2866 pRoamProfile->phyMode =
2867 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002868 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002869 wdev->iftype = type;
2870 break;
2871
2872 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002873 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002874 {
2875 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2876 "%s: setting interface Type to %s", __func__,
2877 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2878
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002879 //Cancel any remain on channel for GO mode
2880 if (NL80211_IFTYPE_P2P_GO == type)
2881 {
2882 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2883 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002884 if (NL80211_IFTYPE_AP == type)
2885 {
2886 /* As Loading WLAN Driver one interface being created for p2p device
2887 * address. This will take one HW STA and the max number of clients
2888 * that can connect to softAP will be reduced by one. so while changing
2889 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2890 * interface as it is not required in SoftAP mode.
2891 */
2892
2893 // Get P2P Adapter
2894 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2895
2896 if (pP2pAdapter)
2897 {
2898 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2899 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2900 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2901 }
2902 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302903#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002904
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302905 /* A Mutex Lock is introduced while changing the mode to
2906 * protect the concurrent access for the Adapters by TDLS
2907 * module.
2908 */
2909 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2910 {
2911 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2912 "%s: unable to lock list", __func__);
2913 return -EINVAL;
2914 }
2915#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002916 //De-init the adapter.
2917 hdd_stop_adapter( pHddCtx, pAdapter );
2918 hdd_deinit_adapter( pHddCtx, pAdapter );
2919 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002920 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2921 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302922#ifdef FEATURE_WLAN_TDLS
2923 mutex_unlock(&pHddCtx->tdls_lock);
2924#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002925
2926 //Disable BMPS and IMPS if enabled
2927 //before starting Go
2928 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2929 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302930 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002931 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2932 {
2933 //Fail to Exit BMPS
2934 VOS_ASSERT(0);
2935 }
2936 }
2937
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002938 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2939 (pConfig->apRandomBssidEnabled))
2940 {
2941 /* To meet Android requirements create a randomized
2942 MAC address of the form 02:1A:11:Fx:xx:xx */
2943 get_random_bytes(&ndev->dev_addr[3], 3);
2944 ndev->dev_addr[0] = 0x02;
2945 ndev->dev_addr[1] = 0x1A;
2946 ndev->dev_addr[2] = 0x11;
2947 ndev->dev_addr[3] |= 0xF0;
2948 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2949 VOS_MAC_ADDR_SIZE);
Arif Hussain24bafea2013-11-15 15:10:03 -08002950 pr_info("wlan: Generated HotSpot BSSID " MAC_ADDRESS_STR"\n",
2951 MAC_ADDR_ARRAY(ndev->dev_addr));
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002952 }
2953
Jeff Johnson295189b2012-06-20 16:38:30 -07002954 hdd_set_ap_ops( pAdapter->dev );
2955
Kiet Lam10841362013-11-01 11:36:50 +05302956 /* This is for only SAP mode where users can
2957 * control country through ini.
2958 * P2P GO follows station country code
2959 * acquired during the STA scanning. */
2960 if((NL80211_IFTYPE_AP == type) &&
2961 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2962 {
2963 int status = 0;
2964 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2965 "%s: setting country code from INI ", __func__);
2966 init_completion(&pAdapter->change_country_code);
2967 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2968 (void *)(tSmeChangeCountryCallback)
2969 wlan_hdd_change_country_code_cb,
2970 pConfig->apCntryCode, pAdapter,
2971 pHddCtx->pvosContext,
Abhishek Singha306a442013-11-07 18:39:01 +05302972 eSIR_FALSE,
2973 eSIR_TRUE);
Kiet Lam10841362013-11-01 11:36:50 +05302974 if (eHAL_STATUS_SUCCESS == status)
2975 {
2976 /* Wait for completion */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302977 ret = wait_for_completion_interruptible_timeout(
Kiet Lam10841362013-11-01 11:36:50 +05302978 &pAdapter->change_country_code,
2979 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302980 if (ret <= 0)
Kiet Lam10841362013-11-01 11:36:50 +05302981 {
2982 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05302983 FL("SME Timed out while setting country code %ld"),
2984 ret);
Yue Ma4f55ef32014-01-23 16:45:33 -08002985
2986 if (pHddCtx->isLogpInProgress)
2987 {
2988 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2989 "%s: LOGP in Progress. Ignore!!!", __func__);
2990 return -EAGAIN;
2991 }
Kiet Lam10841362013-11-01 11:36:50 +05302992 }
2993 }
2994 else
2995 {
2996 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08002997 "%s: SME Change Country code failed",__func__);
Kiet Lam10841362013-11-01 11:36:50 +05302998 return -EINVAL;
2999 }
3000 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003001 status = hdd_init_ap_mode(pAdapter);
3002 if(status != VOS_STATUS_SUCCESS)
3003 {
3004 hddLog(VOS_TRACE_LEVEL_FATAL,
3005 "%s: Error initializing the ap mode", __func__);
3006 return -EINVAL;
3007 }
3008 hdd_set_conparam(1);
3009
Jeff Johnson295189b2012-06-20 16:38:30 -07003010 /*interface type changed update in wiphy structure*/
3011 if(wdev)
3012 {
3013 wdev->iftype = type;
3014 pHddCtx->change_iface = type;
3015 }
3016 else
3017 {
3018 hddLog(VOS_TRACE_LEVEL_ERROR,
3019 "%s: ERROR !!!! Wireless dev is NULL", __func__);
3020 return -EINVAL;
3021 }
3022 goto done;
3023 }
3024
3025 default:
3026 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3027 __func__);
3028 return -EOPNOTSUPP;
3029 }
3030 }
3031 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003032 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003033 )
3034 {
3035 switch(type)
3036 {
3037 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07003038 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07003039 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303040#ifdef FEATURE_WLAN_TDLS
3041
3042 /* A Mutex Lock is introduced while changing the mode to
3043 * protect the concurrent access for the Adapters by TDLS
3044 * module.
3045 */
3046 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
3047 {
3048 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3049 "%s: unable to lock list", __func__);
3050 return -EINVAL;
3051 }
3052#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07003053 hdd_stop_adapter( pHddCtx, pAdapter );
3054 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003055 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08003056 //Check for sub-string p2p to confirm its a p2p interface
3057 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003058 {
3059 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
3060 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
3061 }
3062 else
3063 {
3064 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07003065 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08003066 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003067 hdd_set_conparam(0);
3068 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003069 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
3070 hdd_set_station_ops( pAdapter->dev );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303071#ifdef FEATURE_WLAN_TDLS
3072 mutex_unlock(&pHddCtx->tdls_lock);
3073#endif
Sunil Dutt66485cb2013-12-19 19:05:03 +05303074 status = hdd_init_station_mode( pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07003075 if( VOS_STATUS_SUCCESS != status )
3076 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07003077 /* In case of JB, for P2P-GO, only change interface will be called,
3078 * This is the right place to enable back bmps_imps()
3079 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05303080 if (pHddCtx->hdd_wlan_suspended)
3081 {
3082 hdd_set_pwrparams(pHddCtx);
3083 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003084 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07003085 goto done;
3086 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07003087 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07003089 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
3090 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07003091 goto done;
3092 default:
3093 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
3094 __func__);
3095 return -EOPNOTSUPP;
3096
3097 }
3098
3099 }
3100 else
3101 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303102 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: unsupported device mode(%d)",
3103 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 return -EOPNOTSUPP;
3105 }
3106
3107
3108 if(pRoamProfile)
3109 {
3110 if ( LastBSSType != pRoamProfile->BSSType )
3111 {
3112 /*interface type changed update in wiphy structure*/
3113 wdev->iftype = type;
3114
3115 /*the BSS mode changed, We need to issue disconnect
3116 if connected or in IBSS disconnect state*/
3117 if ( hdd_connGetConnectedBssType(
3118 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
3119 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
3120 {
3121 /*need to issue a disconnect to CSR.*/
3122 INIT_COMPLETION(pAdapter->disconnect_comp_var);
3123 if( eHAL_STATUS_SUCCESS ==
3124 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
3125 pAdapter->sessionId,
3126 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
3127 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303128 ret = wait_for_completion_interruptible_timeout(
3129 &pAdapter->disconnect_comp_var,
3130 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
3131 if (ret <= 0)
3132 {
3133 hddLog(VOS_TRACE_LEVEL_ERROR,
3134 FL("wait on disconnect_comp_var failed %ld"), ret);
3135 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003136 }
3137 }
3138 }
3139 }
3140
3141done:
3142 /*set bitmask based on updated value*/
3143 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07003144
3145 /* Only STA mode support TM now
3146 * all other mode, TM feature should be disabled */
3147 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
3148 (~VOS_STA & pHddCtx->concurrency_mode) )
3149 {
3150 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
3151 }
3152
Jeff Johnson295189b2012-06-20 16:38:30 -07003153#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303154 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003155 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
3156 {
3157 //we are ok to do AMP
3158 pHddCtx->isAmpAllowed = VOS_TRUE;
3159 }
3160#endif //WLAN_BTAMP_FEATURE
3161 EXIT();
3162 return 0;
3163}
3164
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003165#ifdef FEATURE_WLAN_TDLS
3166static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
3167 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
3168{
3169 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
3170 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
3171 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003172 hddTdlsPeer_t *pTdlsPeer;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303173 long ret;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003174
3175 ENTER();
3176
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303177 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003178 {
3179 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3180 "Invalid arguments");
3181 return -EINVAL;
3182 }
Hoonki Lee27511902013-03-14 18:19:06 -07003183
3184 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3185 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3186 {
3187 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3188 "%s: TDLS mode is disabled OR not enabled in FW."
3189 MAC_ADDRESS_STR " Request declined.",
3190 __func__, MAC_ADDR_ARRAY(mac));
3191 return -ENOTSUPP;
3192 }
3193
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003194 if (pHddCtx->isLogpInProgress)
3195 {
3196 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3197 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003198 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003199 return -EBUSY;
3200 }
3201
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303202 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003203
3204 if ( NULL == pTdlsPeer ) {
3205 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3206 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3207 __func__, MAC_ADDR_ARRAY(mac), update);
3208 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003209 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003210
3211 /* in add station, we accept existing valid staId if there is */
3212 if ((0 == update) &&
3213 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3214 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003215 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003216 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003217 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003218 " link_status %d. staId %d. add station ignored.",
3219 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3220 return 0;
3221 }
3222 /* in change station, we accept only when staId is valid */
3223 if ((1 == update) &&
3224 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3225 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3226 {
3227 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3228 "%s: " MAC_ADDRESS_STR
3229 " link status %d. staId %d. change station %s.",
3230 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3231 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3232 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003233 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003234
3235 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303236 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003237 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003238 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3239 "%s: " MAC_ADDRESS_STR
3240 " TDLS setup is ongoing. Request declined.",
3241 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003242 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003243 }
3244
3245 /* first to check if we reached to maximum supported TDLS peer.
3246 TODO: for now, return -EPERM looks working fine,
3247 but need to check if any other errno fit into this category.*/
3248 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3249 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003250 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3251 "%s: " MAC_ADDRESS_STR
3252 " TDLS Max peer already connected. Request declined.",
3253 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003254 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003255 }
3256 else
3257 {
3258 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303259 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003260 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003261 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003262 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3263 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3264 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003265 return -EPERM;
3266 }
3267 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003268 if (0 == update)
3269 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003270
Jeff Johnsond75fe012013-04-06 10:53:06 -07003271 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303272 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003273 {
3274 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3275 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003276 if(StaParams->htcap_present)
3277 {
3278 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3279 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3280 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3281 "ht_capa->extended_capabilities: %0x",
3282 StaParams->HTCap.extendedHtCapInfo);
3283 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003284 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3285 "params->capability: %0x",StaParams->capability);
3286 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003287 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003288 if(StaParams->vhtcap_present)
3289 {
3290 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3291 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3292 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3293 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3294 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003295 {
3296 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003297 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003298 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3299 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3300 "[%d]: %x ", i, StaParams->supported_rates[i]);
3301 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003302 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303303 else if ((1 == update) && (NULL == StaParams))
3304 {
3305 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3306 "%s : update is true, but staParams is NULL. Error!", __func__);
3307 return -EPERM;
3308 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003309
3310 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3311
3312 if (!update)
3313 {
3314 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3315 pAdapter->sessionId, mac);
3316 }
3317 else
3318 {
3319 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3320 pAdapter->sessionId, mac, StaParams);
3321 }
3322
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303323 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003324 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3325
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303326 if (ret <= 0)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003327 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003328 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303329 "%s: timeout waiting for tdls add station indication %ld",
3330 __func__, ret);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003331 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003332 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303333
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003334 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3335 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003337 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003338 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003339 }
3340
3341 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003342
3343error:
3344 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3345 return -EPERM;
3346
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003347}
3348#endif
3349
Jeff Johnson295189b2012-06-20 16:38:30 -07003350static int wlan_hdd_change_station(struct wiphy *wiphy,
3351 struct net_device *dev,
3352 u8 *mac,
3353 struct station_parameters *params)
3354{
3355 VOS_STATUS status = VOS_STATUS_SUCCESS;
3356 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303357 hdd_context_t *pHddCtx;
3358 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003359 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003360#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003361 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003362 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003363#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003364 ENTER();
3365
Gopichand Nakkala29149562013-05-10 21:43:41 +05303366 if ((NULL == pAdapter))
3367 {
3368 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3369 "invalid adapter ");
3370 return -EINVAL;
3371 }
3372
3373 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3374 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3375
3376 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3377 {
3378 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3379 "invalid HDD state or HDD station context");
3380 return -EINVAL;
3381 }
3382
3383 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003384 {
3385 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3386 "%s:LOGP in Progress. Ignore!!!", __func__);
3387 return -EAGAIN;
3388 }
3389
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3391
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003392 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3393 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003394 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003395 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303397 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003398 WLANTL_STA_AUTHENTICATED);
3399
Gopichand Nakkala29149562013-05-10 21:43:41 +05303400 if (status != VOS_STATUS_SUCCESS)
3401 {
3402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3403 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3404 return -EINVAL;
3405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003406 }
3407 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003408 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3409 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303410#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003411 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3412 StaParams.capability = params->capability;
3413 StaParams.uapsd_queues = params->uapsd_queues;
3414 StaParams.max_sp = params->max_sp;
3415
3416 if (0 != params->ext_capab_len)
3417 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3418 sizeof(StaParams.extn_capability));
3419
3420 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003421 {
3422 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003423 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003424 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003425
3426 StaParams.supported_rates_len = params->supported_rates_len;
3427
3428 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3429 * The supported_rates array , for all the structures propogating till Add Sta
3430 * to the firmware has to be modified , if the supplicant (ieee80211) is
3431 * modified to send more rates.
3432 */
3433
3434 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3435 */
3436 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3437 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3438
3439 if (0 != StaParams.supported_rates_len) {
3440 int i = 0;
3441 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3442 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003444 "Supported Rates with Length %d", StaParams.supported_rates_len);
3445 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003446 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003447 "[%d]: %0x", i, StaParams.supported_rates[i]);
3448 }
3449
3450 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003451 {
3452 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003453 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003454 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003455
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003456 if (0 != params->ext_capab_len ) {
3457 /*Define A Macro : TODO Sunil*/
3458 if ((1<<4) & StaParams.extn_capability[3]) {
3459 isBufSta = 1;
3460 }
3461 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303462 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3463 params->max_sp, isBufSta);
3464 if (VOS_STATUS_SUCCESS != status) {
3465 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3466 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3467 return -EINVAL;
3468 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003469 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3470
3471 if (VOS_STATUS_SUCCESS != status) {
3472 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3473 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3474 return -EINVAL;
3475 }
3476 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003477#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303478 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003479 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003480 return status;
3481}
3482
3483/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003484 * FUNCTION: wlan_hdd_cfg80211_add_key
3485 * This function is used to initialize the key information
3486 */
3487#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003488static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003489 struct net_device *ndev,
3490 u8 key_index, bool pairwise,
3491 const u8 *mac_addr,
3492 struct key_params *params
3493 )
3494#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003495static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003496 struct net_device *ndev,
3497 u8 key_index, const u8 *mac_addr,
3498 struct key_params *params
3499 )
3500#endif
3501{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003502 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003503 tCsrRoamSetKey setKey;
3504 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303505 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003506 v_U32_t roamId= 0xFF;
3507 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003508 hdd_hostapd_state_t *pHostapdState;
3509 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003510 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303511 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003512
3513 ENTER();
3514
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303515 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3516 status = wlan_hdd_validate_context(pHddCtx);
3517
3518 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003519 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303520 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3521 "%s: HDD context is not valid", __func__);
3522 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003523 }
3524
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003525 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3526 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003527
3528 if (CSR_MAX_NUM_KEY <= key_index)
3529 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003530 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003531 key_index);
3532
3533 return -EINVAL;
3534 }
3535
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003536 if (CSR_MAX_KEY_LEN < params->key_len)
3537 {
3538 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3539 params->key_len);
3540
3541 return -EINVAL;
3542 }
3543
3544 hddLog(VOS_TRACE_LEVEL_INFO,
3545 "%s: called with key index = %d & key length %d",
3546 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003547
3548 /*extract key idx, key len and key*/
3549 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3550 setKey.keyId = key_index;
3551 setKey.keyLength = params->key_len;
3552 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3553
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003554 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003555 {
3556 case WLAN_CIPHER_SUITE_WEP40:
3557 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3558 break;
3559
3560 case WLAN_CIPHER_SUITE_WEP104:
3561 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3562 break;
3563
3564 case WLAN_CIPHER_SUITE_TKIP:
3565 {
3566 u8 *pKey = &setKey.Key[0];
3567 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3568
3569 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3570
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003571 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003572
3573 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003574 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003575 |--------------|----------|----------|
3576 <---16bytes---><--8bytes--><--8bytes-->
3577
3578 */
3579 /*Sme expects the 32 bytes key to be in the below order
3580
3581 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003582 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003583 |--------------|----------|----------|
3584 <---16bytes---><--8bytes--><--8bytes-->
3585 */
3586 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003587 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003588
3589 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003590 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003591
3592 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003593 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003594
3595
3596 break;
3597 }
3598
3599 case WLAN_CIPHER_SUITE_CCMP:
3600 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3601 break;
3602
3603#ifdef FEATURE_WLAN_WAPI
3604 case WLAN_CIPHER_SUITE_SMS4:
3605 {
3606 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3607 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3608 params->key, params->key_len);
3609 return 0;
3610 }
3611#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003612
Jeff Johnson295189b2012-06-20 16:38:30 -07003613#ifdef FEATURE_WLAN_CCX
3614 case WLAN_CIPHER_SUITE_KRK:
3615 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3616 break;
3617#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003618
3619#ifdef WLAN_FEATURE_11W
3620 case WLAN_CIPHER_SUITE_AES_CMAC:
3621 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003622 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003623#endif
3624
Jeff Johnson295189b2012-06-20 16:38:30 -07003625 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003626 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 __func__, params->cipher);
3628 return -EOPNOTSUPP;
3629 }
3630
3631 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3632 __func__, setKey.encType);
3633
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003634 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003635#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3636 (!pairwise)
3637#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003638 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003639#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003640 )
3641 {
3642 /* set group key*/
3643 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3644 "%s- %d: setting Broadcast key",
3645 __func__, __LINE__);
3646 setKey.keyDirection = eSIR_RX_ONLY;
3647 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3648 }
3649 else
3650 {
3651 /* set pairwise key*/
3652 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3653 "%s- %d: setting pairwise key",
3654 __func__, __LINE__);
3655 setKey.keyDirection = eSIR_TX_RX;
3656 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3657 }
3658 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3659 {
3660 setKey.keyDirection = eSIR_TX_RX;
3661 /*Set the group key*/
3662 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3663 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003664
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003665 if ( 0 != status )
3666 {
3667 hddLog(VOS_TRACE_LEVEL_ERROR,
3668 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3669 return -EINVAL;
3670 }
3671 /*Save the keys here and call sme_RoamSetKey for setting
3672 the PTK after peer joins the IBSS network*/
3673 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3674 &setKey, sizeof(tCsrRoamSetKey));
3675 return status;
3676 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303677 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3678 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3679 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003681 if( pHostapdState->bssState == BSS_START )
3682 {
c_hpothu7c55da62014-01-23 18:34:02 +05303683 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3684 vos_status = wlan_hdd_check_ula_done(pAdapter);
3685
3686 if ( vos_status != VOS_STATUS_SUCCESS )
3687 {
3688 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3689 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3690 __LINE__, vos_status );
3691
3692 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3693
3694 return -EINVAL;
3695 }
3696
Jeff Johnson295189b2012-06-20 16:38:30 -07003697 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3698
3699 if ( status != eHAL_STATUS_SUCCESS )
3700 {
3701 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3702 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3703 __LINE__, status );
3704 }
3705 }
3706
3707 /* Saving WEP keys */
3708 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3709 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3710 {
3711 //Save the wep key in ap context. Issue setkey after the BSS is started.
3712 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3713 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3714 }
3715 else
3716 {
3717 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003718 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003719 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3720 }
3721 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003722 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3723 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003724 {
3725 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3726 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3727
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303728#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3729 if (!pairwise)
3730#else
3731 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3732#endif
3733 {
3734 /* set group key*/
3735 if (pHddStaCtx->roam_info.deferKeyComplete)
3736 {
3737 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3738 "%s- %d: Perform Set key Complete",
3739 __func__, __LINE__);
3740 hdd_PerformRoamSetKeyComplete(pAdapter);
3741 }
3742 }
3743
Jeff Johnson295189b2012-06-20 16:38:30 -07003744 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3745
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003746 pWextState->roamProfile.Keys.defaultIndex = key_index;
3747
3748
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003749 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003750 params->key, params->key_len);
3751
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303752
Jeff Johnson295189b2012-06-20 16:38:30 -07003753 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3754
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303755 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303757 __func__, setKey.peerMac[0], setKey.peerMac[1],
3758 setKey.peerMac[2], setKey.peerMac[3],
3759 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003760 setKey.keyDirection);
3761
3762 vos_status = wlan_hdd_check_ula_done(pAdapter);
3763
3764 if ( vos_status != VOS_STATUS_SUCCESS )
3765 {
3766 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3767 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3768 __LINE__, vos_status );
3769
3770 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3771
3772 return -EINVAL;
3773
3774 }
3775
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003776#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303777 /* The supplicant may attempt to set the PTK once pre-authentication
3778 is done. Save the key in the UMAC and include it in the ADD BSS
3779 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003780 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303781 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003782 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303783 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3784 "%s: Update PreAuth Key success", __func__);
3785 return 0;
3786 }
3787 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3788 {
3789 hddLog(VOS_TRACE_LEVEL_ERROR,
3790 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303791 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003792 }
3793#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003794
3795 /* issue set key request to SME*/
3796 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3797 pAdapter->sessionId, &setKey, &roamId );
3798
3799 if ( 0 != status )
3800 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303801 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003802 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3803 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3804 return -EINVAL;
3805 }
3806
3807
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303808 /* in case of IBSS as there was no information available about WEP keys during
3809 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003810 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303811 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3812 !( ( IW_AUTH_KEY_MGMT_802_1X
3813 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003814 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3815 )
3816 &&
3817 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3818 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3819 )
3820 )
3821 {
3822 setKey.keyDirection = eSIR_RX_ONLY;
3823 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3824
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303825 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003826 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303827 __func__, setKey.peerMac[0], setKey.peerMac[1],
3828 setKey.peerMac[2], setKey.peerMac[3],
3829 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003830 setKey.keyDirection);
3831
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303832 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003833 pAdapter->sessionId, &setKey, &roamId );
3834
3835 if ( 0 != status )
3836 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303837 hddLog(VOS_TRACE_LEVEL_ERROR,
3838 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003839 __func__, status);
3840 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3841 return -EINVAL;
3842 }
3843 }
3844 }
3845
3846 return 0;
3847}
3848
3849/*
3850 * FUNCTION: wlan_hdd_cfg80211_get_key
3851 * This function is used to get the key information
3852 */
3853#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303854static int wlan_hdd_cfg80211_get_key(
3855 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003856 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303857 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003858 const u8 *mac_addr, void *cookie,
3859 void (*callback)(void *cookie, struct key_params*)
3860 )
3861#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303862static int wlan_hdd_cfg80211_get_key(
3863 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003864 struct net_device *ndev,
3865 u8 key_index, const u8 *mac_addr, void *cookie,
3866 void (*callback)(void *cookie, struct key_params*)
3867 )
3868#endif
3869{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303870 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003871 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3872 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3873 struct key_params params;
3874
3875 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303876
Arif Hussain6d2a3322013-11-17 19:50:10 -08003877 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003878 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303879
Jeff Johnson295189b2012-06-20 16:38:30 -07003880 memset(&params, 0, sizeof(params));
3881
3882 if (CSR_MAX_NUM_KEY <= key_index)
3883 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05303884 hddLog(VOS_TRACE_LEVEL_ERROR, FL("invalid key index %d"), key_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07003885 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303886 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003887
3888 switch(pRoamProfile->EncryptionType.encryptionType[0])
3889 {
3890 case eCSR_ENCRYPT_TYPE_NONE:
3891 params.cipher = IW_AUTH_CIPHER_NONE;
3892 break;
3893
3894 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3895 case eCSR_ENCRYPT_TYPE_WEP40:
3896 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3897 break;
3898
3899 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3900 case eCSR_ENCRYPT_TYPE_WEP104:
3901 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3902 break;
3903
3904 case eCSR_ENCRYPT_TYPE_TKIP:
3905 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3906 break;
3907
3908 case eCSR_ENCRYPT_TYPE_AES:
3909 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3910 break;
3911
3912 default:
3913 params.cipher = IW_AUTH_CIPHER_NONE;
3914 break;
3915 }
3916
3917 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3918 params.seq_len = 0;
3919 params.seq = NULL;
3920 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3921 callback(cookie, &params);
3922 return 0;
3923}
3924
3925/*
3926 * FUNCTION: wlan_hdd_cfg80211_del_key
3927 * This function is used to delete the key information
3928 */
3929#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303930static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003931 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303932 u8 key_index,
3933 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003934 const u8 *mac_addr
3935 )
3936#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303937static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003938 struct net_device *ndev,
3939 u8 key_index,
3940 const u8 *mac_addr
3941 )
3942#endif
3943{
3944 int status = 0;
3945
3946 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303947 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 //it is observed that this is invalidating peer
3949 //key index whenever re-key is done. This is affecting data link.
3950 //It should be ok to ignore del_key.
3951#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303952 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3953 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3955 tCsrRoamSetKey setKey;
3956 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303957
Jeff Johnson295189b2012-06-20 16:38:30 -07003958 ENTER();
3959
3960 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3961 __func__,pAdapter->device_mode);
3962
3963 if (CSR_MAX_NUM_KEY <= key_index)
3964 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303965 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003966 key_index);
3967
3968 return -EINVAL;
3969 }
3970
3971 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3972 setKey.keyId = key_index;
3973
3974 if (mac_addr)
3975 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3976 else
3977 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3978
3979 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3980
3981 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303983 )
3984 {
3985
3986 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003987 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3988 if( pHostapdState->bssState == BSS_START)
3989 {
3990 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303991
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 if ( status != eHAL_STATUS_SUCCESS )
3993 {
3994 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3995 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3996 __LINE__, status );
3997 }
3998 }
3999 }
4000 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304001 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07004002 )
4003 {
4004 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4005
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304006 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
4007
4008 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07004009 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304010 __func__, setKey.peerMac[0], setKey.peerMac[1],
4011 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07004012 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304013 if(pAdapter->sessionCtx.station.conn_info.connState ==
4014 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07004015 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304016 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004017 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304018
Jeff Johnson295189b2012-06-20 16:38:30 -07004019 if ( 0 != status )
4020 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304021 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004022 "%s: sme_RoamSetKey failure, returned %d",
4023 __func__, status);
4024 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
4025 return -EINVAL;
4026 }
4027 }
4028 }
4029#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07004030 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004031 return status;
4032}
4033
4034/*
4035 * FUNCTION: wlan_hdd_cfg80211_set_default_key
4036 * This function is used to set the default tx key index
4037 */
4038#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
4039static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4040 struct net_device *ndev,
4041 u8 key_index,
4042 bool unicast, bool multicast)
4043#else
4044static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
4045 struct net_device *ndev,
4046 u8 key_index)
4047#endif
4048{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304049 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304050 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05304051 hdd_wext_state_t *pWextState;
4052 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304053 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004054
4055 ENTER();
4056
Gopichand Nakkala29149562013-05-10 21:43:41 +05304057 if ((NULL == pAdapter))
4058 {
4059 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4060 "invalid adapter");
4061 return -EINVAL;
4062 }
4063
4064 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4065 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4066
4067 if ((NULL == pWextState) || (NULL == pHddStaCtx))
4068 {
4069 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4070 "invalid Wext state or HDD context");
4071 return -EINVAL;
4072 }
4073
Arif Hussain6d2a3322013-11-17 19:50:10 -08004074 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004075 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304076
Jeff Johnson295189b2012-06-20 16:38:30 -07004077 if (CSR_MAX_NUM_KEY <= key_index)
4078 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304079 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004080 key_index);
4081
4082 return -EINVAL;
4083 }
4084
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304085 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4086 status = wlan_hdd_validate_context(pHddCtx);
4087
4088 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004089 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304090 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4091 "%s: HDD context is not valid", __func__);
4092 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004093 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304094
Jeff Johnson295189b2012-06-20 16:38:30 -07004095 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07004096 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304097 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004098 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05304099 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08004100 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304101 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08004102 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07004103 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304104 {
4105 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07004106 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304107
Jeff Johnson295189b2012-06-20 16:38:30 -07004108 tCsrRoamSetKey setKey;
4109 v_U32_t roamId= 0xFF;
4110 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304111
4112 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004113 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304114
Jeff Johnson295189b2012-06-20 16:38:30 -07004115 Keys->defaultIndex = (u8)key_index;
4116 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
4117 setKey.keyId = key_index;
4118 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304119
4120 vos_mem_copy(&setKey.Key[0],
4121 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07004122 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304123
Gopichand Nakkala29149562013-05-10 21:43:41 +05304124 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304125
4126 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07004127 &pHddStaCtx->conn_info.bssId[0],
4128 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304129
Gopichand Nakkala29149562013-05-10 21:43:41 +05304130 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
4131 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4132 eCSR_ENCRYPT_TYPE_WEP104)
4133 {
4134 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
4135 even though ap is configured for WEP-40 encryption. In this canse the key length
4136 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
4137 type(104) and switching encryption type to 40*/
4138 pWextState->roamProfile.EncryptionType.encryptionType[0] =
4139 eCSR_ENCRYPT_TYPE_WEP40;
4140 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
4141 eCSR_ENCRYPT_TYPE_WEP40;
4142 }
4143
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304144 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07004145 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304146
Jeff Johnson295189b2012-06-20 16:38:30 -07004147 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304148 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004149 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304150
Jeff Johnson295189b2012-06-20 16:38:30 -07004151 if ( 0 != status )
4152 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304153 hddLog(VOS_TRACE_LEVEL_ERROR,
4154 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004155 status);
4156 return -EINVAL;
4157 }
4158 }
4159 }
4160
4161 /* In SoftAp mode setting key direction for default mode */
4162 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
4163 {
4164 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
4165 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
4166 (eCSR_ENCRYPT_TYPE_AES !=
4167 pWextState->roamProfile.EncryptionType.encryptionType[0])
4168 )
4169 {
4170 /* Saving key direction for default key index to TX default */
4171 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
4172 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
4173 }
4174 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304175
Jeff Johnson295189b2012-06-20 16:38:30 -07004176 return status;
4177}
4178
Jeff Johnson295189b2012-06-20 16:38:30 -07004179/*
4180 * FUNCTION: wlan_hdd_cfg80211_inform_bss
4181 * This function is used to inform the BSS details to nl80211 interface.
4182 */
4183static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
4184 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
4185{
4186 struct net_device *dev = pAdapter->dev;
4187 struct wireless_dev *wdev = dev->ieee80211_ptr;
4188 struct wiphy *wiphy = wdev->wiphy;
4189 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
4190 int chan_no;
4191 int ie_length;
4192 const char *ie;
4193 unsigned int freq;
4194 struct ieee80211_channel *chan;
4195 int rssi = 0;
4196 struct cfg80211_bss *bss = NULL;
4197
4198 ENTER();
4199
4200 if( NULL == pBssDesc )
4201 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004202 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004203 return bss;
4204 }
4205
4206 chan_no = pBssDesc->channelId;
4207 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4208 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4209
4210 if( NULL == ie )
4211 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004212 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004213 return bss;
4214 }
4215
4216#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4217 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4218 {
4219 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4220 }
4221 else
4222 {
4223 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4224 }
4225#else
4226 freq = ieee80211_channel_to_frequency(chan_no);
4227#endif
4228
4229 chan = __ieee80211_get_channel(wiphy, freq);
4230
4231 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4232 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4233 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4234 if (bss == NULL)
4235 {
4236 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4237
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304238 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4239 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004240 pBssDesc->capabilityInfo,
4241 pBssDesc->beaconInterval, ie, ie_length,
4242 rssi, GFP_KERNEL ));
4243}
4244 else
4245 {
4246 return bss;
4247 }
4248}
4249
4250
4251
4252/*
4253 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4254 * This function is used to inform the BSS details to nl80211 interface.
4255 */
4256struct cfg80211_bss*
4257wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4258 tSirBssDescription *bss_desc
4259 )
4260{
4261 /*
4262 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4263 already exists in bss data base of cfg80211 for that particular BSS ID.
4264 Using cfg80211_inform_bss_frame to update the bss entry instead of
4265 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4266 now there is no possibility to get the mgmt(probe response) frame from PE,
4267 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4268 cfg80211_inform_bss_frame.
4269 */
4270 struct net_device *dev = pAdapter->dev;
4271 struct wireless_dev *wdev = dev->ieee80211_ptr;
4272 struct wiphy *wiphy = wdev->wiphy;
4273 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004274#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4275 qcom_ie_age *qie_age = NULL;
4276 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4277#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004278 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004279#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004280 const char *ie =
4281 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4282 unsigned int freq;
4283 struct ieee80211_channel *chan;
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304284 struct ieee80211_mgmt *mgmt = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004285 struct cfg80211_bss *bss_status = NULL;
4286 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4287 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004288 hdd_context_t *pHddCtx;
4289 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004290#ifdef WLAN_OPEN_SOURCE
4291 struct timespec ts;
4292#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004293
Wilson Yangf80a0542013-10-07 13:02:37 -07004294 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4295 status = wlan_hdd_validate_context(pHddCtx);
4296
4297 /*bss_update is not allowed during wlan driver loading or unloading*/
4298 if (pHddCtx->isLoadUnloadInProgress)
4299 {
4300 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4301 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4302 return NULL;
4303 }
4304
4305
4306 if (0 != status)
4307 {
4308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4309 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004310 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004311 }
4312
Abhishek Singh1e2bfa32014-01-02 15:44:15 +05304313 mgmt = kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
Wilson Yangf80a0542013-10-07 13:02:37 -07004314 if (!mgmt)
4315 {
4316 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4317 "%s: memory allocation failed ", __func__);
4318 return NULL;
4319 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004320
Jeff Johnson295189b2012-06-20 16:38:30 -07004321 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004322
4323#ifdef WLAN_OPEN_SOURCE
4324 /* Android does not want the timestamp from the frame.
4325 Instead it wants a monotonic increasing value */
4326 get_monotonic_boottime(&ts);
4327 mgmt->u.probe_resp.timestamp =
4328 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4329#else
4330 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004331 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4332 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004333
4334#endif
4335
Jeff Johnson295189b2012-06-20 16:38:30 -07004336 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4337 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004338
4339#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4340 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4341 /* Assuming this is the last IE, copy at the end */
4342 ie_length -=sizeof(qcom_ie_age);
4343 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4344 qie_age->element_id = QCOM_VENDOR_IE_ID;
4345 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4346 qie_age->oui_1 = QCOM_OUI1;
4347 qie_age->oui_2 = QCOM_OUI2;
4348 qie_age->oui_3 = QCOM_OUI3;
4349 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4350 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4351#endif
4352
Jeff Johnson295189b2012-06-20 16:38:30 -07004353 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304354 if (bss_desc->fProbeRsp)
4355 {
4356 mgmt->frame_control |=
4357 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4358 }
4359 else
4360 {
4361 mgmt->frame_control |=
4362 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4363 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004364
4365#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304366 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004367 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4368 {
4369 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4370 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304371 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004372 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4373
4374 {
4375 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4376 }
4377 else
4378 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304379 hddLog(VOS_TRACE_LEVEL_ERROR, "%s Invalid chan_no:%d",
4380 __func__, chan_no);
Jeff Johnson295189b2012-06-20 16:38:30 -07004381 kfree(mgmt);
4382 return NULL;
4383 }
4384#else
4385 freq = ieee80211_channel_to_frequency(chan_no);
4386#endif
4387 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004388 /*when the band is changed on the fly using the GUI, three things are done
4389 * 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)
4390 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4391 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4392 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4393 * and discards the channels correponding to previous band and calls back with zero bss results.
4394 * 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
4395 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4396 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4397 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4398 * So drop the bss and continue to next bss.
4399 */
4400 if(chan == NULL)
4401 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304402 hddLog(VOS_TRACE_LEVEL_ERROR, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004403 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004404 return NULL;
4405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004406 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304407 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004408 * */
4409 if (( eConnectionState_Associated ==
4410 pAdapter->sessionCtx.station.conn_info.connState ) &&
4411 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4412 pAdapter->sessionCtx.station.conn_info.bssId,
4413 WNI_CFG_BSSID_LEN)))
4414 {
4415 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4416 rssi = (pAdapter->rssi * 100);
4417 }
4418 else
4419 {
4420 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4421 }
4422
Nirav Shah20ac06f2013-12-12 18:14:06 +05304423 hddLog(VOS_TRACE_LEVEL_INFO, "%s: BSSID:" MAC_ADDRESS_STR " Channel:%d"
4424 "RSSI:%d", __func__, MAC_ADDR_ARRAY(mgmt->bssid),
4425 chan->center_freq, (int)(rssi/100));
4426
Jeff Johnson295189b2012-06-20 16:38:30 -07004427 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4428 frame_len, rssi, GFP_KERNEL);
4429 kfree(mgmt);
4430 return bss_status;
4431}
4432
4433/*
4434 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4435 * This function is used to update the BSS data base of CFG8011
4436 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304437struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004438 tCsrRoamInfo *pRoamInfo
4439 )
4440{
4441 tCsrRoamConnectedProfile roamProfile;
4442 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4443 struct cfg80211_bss *bss = NULL;
4444
4445 ENTER();
4446
4447 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4448 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4449
4450 if (NULL != roamProfile.pBssDesc)
4451 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304452 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004453 &roamProfile);
4454
4455 if (NULL == bss)
4456 {
4457 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4458 __func__);
4459 }
4460
4461 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4462 }
4463 else
4464 {
4465 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4466 __func__);
4467 }
4468 return bss;
4469}
4470
4471/*
4472 * FUNCTION: wlan_hdd_cfg80211_update_bss
4473 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304474static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4475 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004476 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304477{
Jeff Johnson295189b2012-06-20 16:38:30 -07004478 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4479 tCsrScanResultInfo *pScanResult;
4480 eHalStatus status = 0;
4481 tScanResultHandle pResult;
4482 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004483 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004484
4485 ENTER();
4486
Wilson Yangf80a0542013-10-07 13:02:37 -07004487 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4488
4489 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004490 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004491 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4492 "%s:LOGP in Progress. Ignore!!!",__func__);
4493 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004494 }
4495
Wilson Yangf80a0542013-10-07 13:02:37 -07004496
4497 /*bss_update is not allowed during wlan driver loading or unloading*/
4498 if (pHddCtx->isLoadUnloadInProgress)
4499 {
4500 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4501 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4502 return VOS_STATUS_E_PERM;
4503 }
4504
4505
Jeff Johnson295189b2012-06-20 16:38:30 -07004506 /*
4507 * start getting scan results and populate cgf80211 BSS database
4508 */
4509 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4510
4511 /* no scan results */
4512 if (NULL == pResult)
4513 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05304514 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result Status %d",
4515 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004516 return status;
4517 }
4518
4519 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4520
4521 while (pScanResult)
4522 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304523 /*
4524 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4525 * entry already exists in bss data base of cfg80211 for that
4526 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4527 * bss entry instead of cfg80211_inform_bss, But this call expects
4528 * mgmt packet as input. As of now there is no possibility to get
4529 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004530 * ieee80211_mgmt(probe response) and passing to c
4531 * fg80211_inform_bss_frame.
4532 * */
4533
4534 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4535 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304536
Jeff Johnson295189b2012-06-20 16:38:30 -07004537
4538 if (NULL == bss_status)
4539 {
4540 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004541 "%s: NULL returned by cfg80211_inform_bss", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004542 }
4543 else
4544 {
Yue Maf49ba872013-08-19 12:04:25 -07004545 cfg80211_put_bss(
4546#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4547 wiphy,
4548#endif
4549 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004550 }
4551
4552 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4553 }
4554
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304555 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004556
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304557 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004558}
4559
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004560void
4561hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4562{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304563 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussaina7c8e412013-11-20 11:06:42 -08004564 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004565} /****** end hddPrintMacAddr() ******/
4566
4567void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004568hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004569{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304570 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Arif Hussain6d2a3322013-11-17 19:50:10 -08004571 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004572 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4573 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4574 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004575} /****** end hddPrintPmkId() ******/
4576
4577//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4578//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4579
4580//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4581//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4582
4583#define dump_bssid(bssid) \
4584 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004585 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4586 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004587 }
4588
4589#define dump_pmkid(pMac, pmkid) \
4590 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004591 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4592 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004593 }
4594
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004595#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004596/*
4597 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4598 * This function is used to notify the supplicant of a new PMKSA candidate.
4599 */
4600int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304601 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004602 int index, bool preauth )
4603{
Jeff Johnsone7245742012-09-05 17:12:55 -07004604#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004605 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004606 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004607
4608 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004609 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004610
4611 if( NULL == pRoamInfo )
4612 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004613 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004614 return -EINVAL;
4615 }
4616
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004617 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4618 {
4619 dump_bssid(pRoamInfo->bssid);
4620 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004621 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004622 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004623#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304624 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004625}
4626#endif //FEATURE_WLAN_LFR
4627
Yue Maef608272013-04-08 23:09:17 -07004628#ifdef FEATURE_WLAN_LFR_METRICS
4629/*
4630 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4631 * 802.11r/LFR metrics reporting function to report preauth initiation
4632 *
4633 */
4634#define MAX_LFR_METRICS_EVENT_LENGTH 100
4635VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4636 tCsrRoamInfo *pRoamInfo)
4637{
4638 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4639 union iwreq_data wrqu;
4640
4641 ENTER();
4642
4643 if (NULL == pAdapter)
4644 {
4645 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4646 return VOS_STATUS_E_FAILURE;
4647 }
4648
4649 /* create the event */
4650 memset(&wrqu, 0, sizeof(wrqu));
4651 memset(metrics_notification, 0, sizeof(metrics_notification));
4652
4653 wrqu.data.pointer = metrics_notification;
4654 wrqu.data.length = scnprintf(metrics_notification,
4655 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4656 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4657
4658 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4659
4660 EXIT();
4661
4662 return VOS_STATUS_SUCCESS;
4663}
4664
4665/*
4666 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4667 * 802.11r/LFR metrics reporting function to report preauth completion
4668 * or failure
4669 */
4670VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4671 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4672{
4673 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4674 union iwreq_data wrqu;
4675
4676 ENTER();
4677
4678 if (NULL == pAdapter)
4679 {
4680 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4681 return VOS_STATUS_E_FAILURE;
4682 }
4683
4684 /* create the event */
4685 memset(&wrqu, 0, sizeof(wrqu));
4686 memset(metrics_notification, 0, sizeof(metrics_notification));
4687
4688 scnprintf(metrics_notification, sizeof(metrics_notification),
4689 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4690 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4691
4692 if (1 == preauth_status)
4693 strncat(metrics_notification, " TRUE", 5);
4694 else
4695 strncat(metrics_notification, " FALSE", 6);
4696
4697 wrqu.data.pointer = metrics_notification;
4698 wrqu.data.length = strlen(metrics_notification);
4699
4700 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4701
4702 EXIT();
4703
4704 return VOS_STATUS_SUCCESS;
4705}
4706
4707/*
4708 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4709 * 802.11r/LFR metrics reporting function to report handover initiation
4710 *
4711 */
4712VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4713 tCsrRoamInfo *pRoamInfo)
4714{
4715 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4716 union iwreq_data wrqu;
4717
4718 ENTER();
4719
4720 if (NULL == pAdapter)
4721 {
4722 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4723 return VOS_STATUS_E_FAILURE;
4724 }
4725
4726 /* create the event */
4727 memset(&wrqu, 0, sizeof(wrqu));
4728 memset(metrics_notification, 0, sizeof(metrics_notification));
4729
4730 wrqu.data.pointer = metrics_notification;
4731 wrqu.data.length = scnprintf(metrics_notification,
4732 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4733 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4734
4735 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4736
4737 EXIT();
4738
4739 return VOS_STATUS_SUCCESS;
4740}
4741#endif
4742
Jeff Johnson295189b2012-06-20 16:38:30 -07004743/*
4744 * FUNCTION: hdd_cfg80211_scan_done_callback
4745 * scanning callback function, called after finishing scan
4746 *
4747 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304748static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004749 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4750{
4751 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304752 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004754 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4755 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004756 struct cfg80211_scan_request *req = NULL;
4757 int ret = 0;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304758 long waitRet = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004759
4760 ENTER();
4761
4762 hddLog(VOS_TRACE_LEVEL_INFO,
4763 "%s called with halHandle = %p, pContext = %p,"
Arif Hussain6d2a3322013-11-17 19:50:10 -08004764 "scanID = %d, returned status = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004765 __func__, halHandle, pContext, (int) scanId, (int) status);
4766
Kiet Lamac06e2c2013-10-23 16:25:07 +05304767 pScanInfo->mScanPendingCounter = 0;
4768
Jeff Johnson295189b2012-06-20 16:38:30 -07004769 //Block on scan req completion variable. Can't wait forever though.
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304770 waitRet = wait_for_completion_interruptible_timeout(
Jeff Johnson295189b2012-06-20 16:38:30 -07004771 &pScanInfo->scan_req_completion_event,
4772 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304773 if (waitRet <= 0)
Jeff Johnson295189b2012-06-20 16:38:30 -07004774 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05304775 hddLog(VOS_TRACE_LEVEL_ERROR,
4776 "%s wait on scan_req_completion_event failed %ld",__func__, waitRet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004777 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004778 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004779 }
4780
Yue Maef608272013-04-08 23:09:17 -07004781 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004782 {
4783 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004784 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004785 }
4786
4787 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304788 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004789 {
4790 hddLog(VOS_TRACE_LEVEL_INFO,
4791 "%s called with mismatched scanId pScanInfo->scanId = %d "
Arif Hussain6d2a3322013-11-17 19:50:10 -08004792 "scanId = %d", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004793 (int) scanId);
4794 }
4795
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304796 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004797 pAdapter);
4798
4799 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304800 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004801
4802
4803 /* If any client wait scan result through WEXT
4804 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004805 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004806 {
4807 /* The other scan request waiting for current scan finish
4808 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004809 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004810 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004811 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004812 }
4813 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004814 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004815 {
4816 struct net_device *dev = pAdapter->dev;
4817 union iwreq_data wrqu;
4818 int we_event;
4819 char *msg;
4820
4821 memset(&wrqu, '\0', sizeof(wrqu));
4822 we_event = SIOCGIWSCAN;
4823 msg = NULL;
4824 wireless_send_event(dev, we_event, &wrqu, msg);
4825 }
4826 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004827 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004828
4829 /* Get the Scan Req */
4830 req = pAdapter->request;
4831
4832 if (!req)
4833 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08004834 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004835 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004836 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004837 }
4838
4839 /*
4840 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304841 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004842 req->n_ssids = 0;
4843 req->n_channels = 0;
4844 req->ie = 0;
4845
Jeff Johnson295189b2012-06-20 16:38:30 -07004846 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004847 /* Scan is no longer pending */
4848 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004849
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004850 /*
4851 * cfg80211_scan_done informing NL80211 about completion
4852 * of scanning
4853 */
4854 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004855 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004856
Jeff Johnsone7245742012-09-05 17:12:55 -07004857allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004858 /* release the wake lock at the end of the scan*/
4859 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004860
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004861 /* Acquire wakelock to handle the case where APP's tries to suspend
4862 * immediatly after the driver gets connect request(i.e after scan)
4863 * from supplicant, this result in app's is suspending and not able
4864 * to process the connect request to AP */
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05304865 hdd_prevent_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004866
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004867#ifdef FEATURE_WLAN_TDLS
4868 wlan_hdd_tdls_scan_done_callback(pAdapter);
4869#endif
4870
Jeff Johnson295189b2012-06-20 16:38:30 -07004871 EXIT();
4872 return 0;
4873}
4874
4875/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004876 * FUNCTION: hdd_isScanAllowed
4877 * Go through each adapter and check if scan allowed
4878 *
4879 */
4880v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4881{
4882 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4883 hdd_station_ctx_t *pHddStaCtx = NULL;
4884 hdd_adapter_t *pAdapter = NULL;
4885 VOS_STATUS status = 0;
4886 v_U8_t staId = 0;
4887 v_U8_t *staMac = NULL;
4888
c_hpothu9b781ba2013-12-30 20:57:45 +05304889 if (TRUE == pHddCtx->btCoexModeSet)
4890 {
4891 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
4892 FL("BTCoex Mode operation in progress, Do not allow scan"));
4893 return VOS_FALSE;
4894 }
4895
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004896 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4897
4898 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4899 {
4900 pAdapter = pAdapterNode->pAdapter;
4901
4902 if( pAdapter )
4903 {
4904 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304905 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004906 __func__, pAdapter->device_mode);
4907 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4908 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4909 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4910 {
4911 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4912 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4913 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4914 {
4915 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4916 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004917 "%s: client " MAC_ADDRESS_STR
4918 " is in the middle of WPS/EAPOL exchange.", __func__,
4919 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004920 return VOS_FALSE;
4921 }
4922 }
4923 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4924 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4925 {
4926 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4927 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304928 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004929 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4930 {
4931 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4932
4933 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain24bafea2013-11-15 15:10:03 -08004934 "%s: client " MAC_ADDRESS_STR " of SoftAP/P2P-GO is in the "
4935 "middle of WPS/EAPOL exchange.", __func__,
4936 MAC_ADDR_ARRAY(staMac));
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004937 return VOS_FALSE;
4938 }
4939 }
4940 }
4941 }
4942 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4943 pAdapterNode = pNext;
4944 }
4945 hddLog(VOS_TRACE_LEVEL_INFO,
4946 "%s: Scan allowed", __func__);
4947 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304948}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004949
4950/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004951 * FUNCTION: wlan_hdd_cfg80211_scan
4952 * this scan respond to scan trigger and update cfg80211 scan database
4953 * later, scan dump command can be used to recieve scan results
4954 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004955int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4956#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4957 struct net_device *dev,
4958#endif
4959 struct cfg80211_scan_request *request)
4960{
4961#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4962 struct net_device *dev = request->wdev->netdev;
4963#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304964 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004965 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4966 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304967 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004968 tCsrScanRequest scanRequest;
4969 tANI_U8 *channelList = NULL, i;
4970 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304971 int status;
4972 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004973 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004974
4975 ENTER();
4976
Arif Hussain6d2a3322013-11-17 19:50:10 -08004977 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004979
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304980 status = wlan_hdd_validate_context(pHddCtx);
4981
4982 if (0 != status)
4983 {
4984 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4985 "%s: HDD context is not valid", __func__);
4986 return status;
4987 }
4988
4989 cfg_param = pHddCtx->cfg_ini;
4990 pScanInfo = &pHddCtx->scan_info;
4991
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004992 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004993 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004994 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004995 {
4996 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004997 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4998 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004999 return -EBUSY;
5000 }
5001
Jeff Johnson295189b2012-06-20 16:38:30 -07005002#ifdef WLAN_BTAMP_FEATURE
5003 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005004 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005006 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005007 "%s: No scanning when AMP is on", __func__);
5008 return -EOPNOTSUPP;
5009 }
5010#endif
5011 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005012 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07005013 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005014 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005015 "%s: Not scanning on device_mode = %d",
5016 __func__, pAdapter->device_mode);
5017 return -EOPNOTSUPP;
5018 }
5019
5020 if (TRUE == pScanInfo->mScanPending)
5021 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305022 if ( MAX_PENDING_LOG > pScanInfo->mScanPendingCounter++ )
5023 {
5024 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: mScanPending is TRUE", __func__);
5025 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005026 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005027 }
5028
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305029 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07005030 //Channel and action frame is pending
5031 //Otherwise Cancel Remain On Channel and allow Scan
5032 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005033 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07005034 {
Kiet Lamac06e2c2013-10-23 16:25:07 +05305035 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Remain On Channel Pending", __func__);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005036 return -EBUSY;
5037 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005038#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005039 /* if tdls disagree scan right now, return immediately.
5040 tdls will schedule the scan when scan is allowed. (return SUCCESS)
5041 or will reject the scan if any TDLS is in progress. (return -EBUSY)
5042 */
5043 status = wlan_hdd_tdls_scan_callback (pAdapter,
5044 wiphy,
5045#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
5046 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07005047#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005048 request);
5049 if(status <= 0)
5050 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305051 if(!status)
5052 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS in progress."
5053 "scan rejected %d", __func__, status);
5054 else
5055 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: TDLS teardown is ongoing %d",
5056 __func__, status);
5057
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07005058 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08005059 }
5060#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07005061
Jeff Johnson295189b2012-06-20 16:38:30 -07005062 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
5063 {
5064 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08005065 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305067 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005068 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
5069 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305070 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005071 "%s: MAX TM Level Scan not allowed", __func__);
5072 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305073 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07005074 }
5075 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
5076
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08005077 /* Check if scan is allowed at this point of time.
5078 */
5079 if (!hdd_isScanAllowed(pHddCtx))
5080 {
5081 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
5082 return -EBUSY;
5083 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305084
Jeff Johnson295189b2012-06-20 16:38:30 -07005085 vos_mem_zero( &scanRequest, sizeof(scanRequest));
5086
5087 if (NULL != request)
5088 {
5089 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305090 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07005091
5092 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
5093 * Becasue of this, driver is assuming that this is not wildcard scan and so
5094 * is not aging out the scan results.
5095 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07005096 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07005097 {
5098 request->n_ssids = 0;
5099 }
5100
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07005101 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07005102 {
5103 tCsrSSIDInfo *SsidInfo;
5104 int j;
5105 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
5106 /* Allocate num_ssid tCsrSSIDInfo structure */
5107 SsidInfo = scanRequest.SSIDs.SSIDList =
5108 ( tCsrSSIDInfo *)vos_mem_malloc(
5109 request->n_ssids*sizeof(tCsrSSIDInfo));
5110
5111 if(NULL == scanRequest.SSIDs.SSIDList)
5112 {
5113 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305114 "%s: memory alloc failed SSIDInfo buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005115 return -ENOMEM;
5116 }
5117
5118 /* copy all the ssid's and their length */
5119 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
5120 {
5121 /* get the ssid length */
5122 SsidInfo->SSID.length = request->ssids[j].ssid_len;
5123 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
5124 SsidInfo->SSID.length);
5125 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
Nirav Shah20ac06f2013-12-12 18:14:06 +05305126 hddLog(VOS_TRACE_LEVEL_INFO, "SSID number %d: %s",
Jeff Johnson295189b2012-06-20 16:38:30 -07005127 j, SsidInfo->SSID.ssId);
5128 }
5129 /* set the scan type to active */
5130 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5131 }
5132 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
5133 {
5134 /* set the scan type to active */
5135 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5136 }
5137 else
5138 {
5139 /*Set the scan type to default type, in this case it is ACTIVE*/
5140 scanRequest.scanType = pScanInfo->scan_mode;
5141 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305142 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07005143 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
5144 }
5145 else
5146 {
5147 /* set the scan type to active */
5148 scanRequest.scanType = eSIR_ACTIVE_SCAN;
5149 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
5150
5151 /* set min and max channel time to zero */
5152 scanRequest.minChnTime = 0;
5153 scanRequest.maxChnTime = 0;
5154 }
5155
5156 /* set BSSType to default type */
5157 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
5158
5159 /*TODO: scan the requested channels only*/
5160
5161 /*Right now scanning all the channels */
5162 if( request )
5163 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305164 hddLog(VOS_TRACE_LEVEL_INFO,
5165 "No of Scan Channels: %d", request->n_channels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005166 if( request->n_channels )
5167 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305168 char chList [(request->n_channels*5)+1];
5169 int len;
Jeff Johnson295189b2012-06-20 16:38:30 -07005170 channelList = vos_mem_malloc( request->n_channels );
5171 if( NULL == channelList )
5172 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05305173 hddLog(VOS_TRACE_LEVEL_ERROR,
Nirav Shah20ac06f2013-12-12 18:14:06 +05305174 "%s: memory alloc failed channelList", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005175 status = -ENOMEM;
5176 goto free_mem;
5177 }
5178
Nirav Shah20ac06f2013-12-12 18:14:06 +05305179 for( i = 0, len = 0; i < request->n_channels ; i++ )
5180 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005181 channelList[i] = request->channels[i]->hw_value;
Nirav Shah20ac06f2013-12-12 18:14:06 +05305182 len += snprintf(chList+len, 5, "%d ", channelList[i]);
5183 }
5184
5185 hddLog(VOS_TRACE_LEVEL_INFO,
5186 "Channel-List: %s ", chList);
Jeff Johnson295189b2012-06-20 16:38:30 -07005187 }
5188
5189 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
5190 scanRequest.ChannelInfo.ChannelList = channelList;
5191
5192 /* set requestType to full scan */
5193 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305194
5195 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005196 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305197 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005198 */
5199
5200 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305201 * and in that case driver shoudnt flush scan results. If
5202 * driver flushes the scan results here and unfortunately if
5203 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005204 * fails which is not desired
5205 */
5206
5207 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
5208 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305209 hddLog(VOS_TRACE_LEVEL_DEBUG, "Flushing P2P Results");
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08005210 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
5211 pAdapter->sessionId );
5212 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005213
5214 if( request->ie_len )
5215 {
5216 /* save this for future association (join requires this) */
Agarwal Ashish4f616132013-12-30 23:32:50 +05305217 /*TODO: Array needs to be converted to dynamic allocation,
5218 * as multiple ie.s can be sent in cfg80211_scan_request structure
5219 * CR 597966
5220 */
Jeff Johnson295189b2012-06-20 16:38:30 -07005221 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
5222 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
5223 pScanInfo->scanAddIE.length = request->ie_len;
5224
Agarwal Ashish4f616132013-12-30 23:32:50 +05305225 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07005226 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
Agarwal Ashish4f616132013-12-30 23:32:50 +05305227 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
Jeff Johnson295189b2012-06-20 16:38:30 -07005228 {
Agarwal Ashish4f616132013-12-30 23:32:50 +05305229 if ( request->ie_len <= SIR_MAC_MAX_IE_LENGTH)
5230 {
5231 pwextBuf->roamProfile.nAddIEScanLength = request->ie_len;
5232 memcpy( pwextBuf->roamProfile.addIEScan,
5233 request->ie, request->ie_len);
5234 }
5235 else
5236 {
5237 hddLog(VOS_TRACE_LEVEL_ERROR, "Scan Ie length is invalid:"
5238 "%d", request->ie_len);
5239 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005240
Agarwal Ashish4f616132013-12-30 23:32:50 +05305241 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005242 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5243 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5244
Jeff Johnson295189b2012-06-20 16:38:30 -07005245 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5246 request->ie_len);
5247 if (pP2pIe != NULL)
5248 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005249#ifdef WLAN_FEATURE_P2P_DEBUG
5250 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5251 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5252 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5253 {
5254 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5255 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5256 "Go nego completed to Connection is started");
5257 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5258 "for 8way Handshake");
5259 }
5260 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5261 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5262 {
5263 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5264 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5265 "Disconnected state to Connection is started");
5266 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5267 "for 4way Handshake");
5268 }
5269#endif
5270
Jeff Johnsone7245742012-09-05 17:12:55 -07005271 /* no_cck will be set during p2p find to disable 11b rates */
5272 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005273 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 hddLog(VOS_TRACE_LEVEL_INFO,
5275 "%s: This is a P2P Search", __func__);
5276 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005277
Jeff Johnsone7245742012-09-05 17:12:55 -07005278 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5279 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005280 /* set requestType to P2P Discovery */
5281 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005282 }
5283
5284 /*
5285 Skip Dfs Channel in case of P2P Search
5286 if it is set in ini file
5287 */
5288 if(cfg_param->skipDfsChnlInP2pSearch)
5289 {
5290 scanRequest.skipDfsChnlInP2pSearch = 1;
5291 }
5292 else
5293 {
5294 scanRequest.skipDfsChnlInP2pSearch = 0;
5295 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005296
Jeff Johnson295189b2012-06-20 16:38:30 -07005297 }
5298 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005299 }
5300 }
5301
5302 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5303
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005304 /* acquire the wakelock to avoid the apps suspend during the scan. To
5305 * address the following issues.
5306 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5307 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5308 * for long time, this result in apps running at full power for long time.
5309 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5310 * be stuck in full power because of resume BMPS
5311 */
5312 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005313
Nirav Shah20ac06f2013-12-12 18:14:06 +05305314 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
5315 "requestType %d, scanType %d, minChnTime %d, maxChnTime %d,"
5316 "p2pSearch %d, skipDfsChnlInP2pSearch %d", scanRequest.requestType,
5317 scanRequest.scanType, scanRequest.minChnTime, scanRequest.maxChnTime,
5318 scanRequest.p2pSearch, scanRequest.skipDfsChnlInP2pSearch);
5319
Jeff Johnsone7245742012-09-05 17:12:55 -07005320 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 pAdapter->sessionId, &scanRequest, &scanId,
5322 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005323
Jeff Johnson295189b2012-06-20 16:38:30 -07005324 if (eHAL_STATUS_SUCCESS != status)
5325 {
5326 hddLog(VOS_TRACE_LEVEL_ERROR,
5327 "%s: sme_ScanRequest returned error %d", __func__, status);
5328 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005329 if(eHAL_STATUS_RESOURCES == status)
5330 {
Nirav Shah20ac06f2013-12-12 18:14:06 +05305331 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: HO is in progress."
5332 "So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005333 status = -EBUSY;
5334 } else {
5335 status = -EIO;
5336 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005337 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005338 goto free_mem;
5339 }
5340
5341 pScanInfo->mScanPending = TRUE;
5342 pAdapter->request = request;
5343 pScanInfo->scanId = scanId;
5344
5345 complete(&pScanInfo->scan_req_completion_event);
5346
5347free_mem:
5348 if( scanRequest.SSIDs.SSIDList )
5349 {
5350 vos_mem_free(scanRequest.SSIDs.SSIDList);
5351 }
5352
5353 if( channelList )
5354 vos_mem_free( channelList );
5355
5356 EXIT();
5357
5358 return status;
5359}
5360
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005361
5362void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5363{
5364 v_U8_t iniDot11Mode =
5365 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5366 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5367
5368 switch ( iniDot11Mode )
5369 {
5370 case eHDD_DOT11_MODE_AUTO:
5371 case eHDD_DOT11_MODE_11ac:
5372 case eHDD_DOT11_MODE_11ac_ONLY:
5373#ifdef WLAN_FEATURE_11AC
5374 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5375#else
5376 hddDot11Mode = eHDD_DOT11_MODE_11n;
5377#endif
5378 break;
5379 case eHDD_DOT11_MODE_11n:
5380 case eHDD_DOT11_MODE_11n_ONLY:
5381 hddDot11Mode = eHDD_DOT11_MODE_11n;
5382 break;
5383 default:
5384 hddDot11Mode = iniDot11Mode;
5385 break;
5386 }
5387 /* This call decides required channel bonding mode */
5388 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5389 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5390 operationChannel);
5391}
5392
Jeff Johnson295189b2012-06-20 16:38:30 -07005393/*
5394 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305395 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005396 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305397int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005398 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005399{
5400 int status = 0;
5401 hdd_wext_state_t *pWextState;
5402 v_U32_t roamId;
5403 tCsrRoamProfile *pRoamProfile;
Jeff Johnson295189b2012-06-20 16:38:30 -07005404 eCsrAuthType RSNAuthType;
5405
5406 ENTER();
5407
5408 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305409
Jeff Johnson295189b2012-06-20 16:38:30 -07005410 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5411 {
5412 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5413 return -EINVAL;
5414 }
5415
5416 pRoamProfile = &pWextState->roamProfile;
5417
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305418 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005419 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005420 hdd_station_ctx_t *pHddStaCtx;
5421 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005422
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305423 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005424 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5425 {
5426 /*QoS not enabled in cfg file*/
5427 pRoamProfile->uapsd_mask = 0;
5428 }
5429 else
5430 {
5431 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305432 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005433 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5434 }
5435
5436 pRoamProfile->SSIDs.numOfSSIDs = 1;
5437 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5438 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305439 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005440 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5441 ssid, ssid_len);
5442
5443 if (bssid)
5444 {
5445 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5446 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5447 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305448 /* Save BSSID in seperate variable as well, as RoamProfile
5449 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 case of join failure we should send valid BSSID to supplicant
5451 */
5452 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5453 WNI_CFG_BSSID_LEN);
5454 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005455 else
5456 {
5457 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5458 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005459
5460 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5461 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305462 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005463 /*set gen ie*/
5464 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5465 /*set auth*/
5466 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5467 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005468#ifdef FEATURE_WLAN_WAPI
5469 if (pAdapter->wapi_info.nWapiMode)
5470 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005471 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005472 switch (pAdapter->wapi_info.wapiAuthMode)
5473 {
5474 case WAPI_AUTH_MODE_PSK:
5475 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005476 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005477 pAdapter->wapi_info.wapiAuthMode);
5478 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5479 break;
5480 }
5481 case WAPI_AUTH_MODE_CERT:
5482 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005483 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005484 pAdapter->wapi_info.wapiAuthMode);
5485 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5486 break;
5487 }
5488 } // End of switch
5489 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5490 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5491 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005492 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005493 pRoamProfile->AuthType.numEntries = 1;
5494 pRoamProfile->EncryptionType.numEntries = 1;
5495 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5496 pRoamProfile->mcEncryptionType.numEntries = 1;
5497 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5498 }
5499 }
5500#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305501#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305502 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305503 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5504 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5505 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305506 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5507 sizeof (tSirGtkOffloadParams));
5508 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305509 }
5510#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005511 pRoamProfile->csrPersona = pAdapter->device_mode;
5512
Jeff Johnson32d95a32012-09-10 13:15:23 -07005513 if( operatingChannel )
5514 {
5515 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5516 pRoamProfile->ChannelInfo.numOfChannels = 1;
5517 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005518 else
5519 {
5520 pRoamProfile->ChannelInfo.ChannelList = NULL;
5521 pRoamProfile->ChannelInfo.numOfChannels = 0;
5522 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005523 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5524 {
5525 hdd_select_cbmode(pAdapter,operatingChannel);
5526 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005527 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5528 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305529 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005530 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005531 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5532 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305533 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5534 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005535 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5536 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305537
5538 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005539 pAdapter->sessionId, pRoamProfile, &roamId);
5540
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305541 if ((eHAL_STATUS_SUCCESS != status) &&
5542 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5543 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305544
5545 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005546 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5547 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5548 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305549 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005550 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305551 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005552
5553 pRoamProfile->ChannelInfo.ChannelList = NULL;
5554 pRoamProfile->ChannelInfo.numOfChannels = 0;
5555
Jeff Johnson295189b2012-06-20 16:38:30 -07005556 }
5557 else
5558 {
5559 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5560 return -EINVAL;
5561 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005562 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005563 return status;
5564}
5565
5566/*
5567 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5568 * This function is used to set the authentication type (OPEN/SHARED).
5569 *
5570 */
5571static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5572 enum nl80211_auth_type auth_type)
5573{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305574 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005575 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5576
5577 ENTER();
5578
5579 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305580 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005581 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305583 hddLog(VOS_TRACE_LEVEL_INFO,
5584 "%s: set authentication type to AUTOSWITCH", __func__);
5585 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5586 break;
5587
5588 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005589#ifdef WLAN_FEATURE_VOWIFI_11R
5590 case NL80211_AUTHTYPE_FT:
5591#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305592 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005593 "%s: set authentication type to OPEN", __func__);
5594 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5595 break;
5596
5597 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305598 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 "%s: set authentication type to SHARED", __func__);
5600 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5601 break;
5602#ifdef FEATURE_WLAN_CCX
5603 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305604 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005605 "%s: set authentication type to CCKM WPA", __func__);
5606 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5607 break;
5608#endif
5609
5610
5611 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305612 hddLog(VOS_TRACE_LEVEL_ERROR,
5613 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005614 auth_type);
5615 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5616 return -EINVAL;
5617 }
5618
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305619 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005620 pHddStaCtx->conn_info.authType;
5621 return 0;
5622}
5623
5624/*
5625 * FUNCTION: wlan_hdd_set_akm_suite
5626 * This function is used to set the key mgmt type(PSK/8021x).
5627 *
5628 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305629static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 u32 key_mgmt
5631 )
5632{
5633 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5634 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305635
Jeff Johnson295189b2012-06-20 16:38:30 -07005636 /*set key mgmt type*/
5637 switch(key_mgmt)
5638 {
5639 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305640#ifdef WLAN_FEATURE_VOWIFI_11R
5641 case WLAN_AKM_SUITE_FT_PSK:
5642#endif
5643 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 __func__);
5645 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5646 break;
5647
5648 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305649#ifdef WLAN_FEATURE_VOWIFI_11R
5650 case WLAN_AKM_SUITE_FT_8021X:
5651#endif
5652 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 __func__);
5654 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5655 break;
5656#ifdef FEATURE_WLAN_CCX
5657#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5658#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5659 case WLAN_AKM_SUITE_CCKM:
5660 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5661 __func__);
5662 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5663 break;
5664#endif
5665
5666 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305667 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005668 __func__, key_mgmt);
5669 return -EINVAL;
5670
5671 }
5672 return 0;
5673}
5674
5675/*
5676 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305677 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005678 * (NONE/WEP40/WEP104/TKIP/CCMP).
5679 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305680static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5681 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005682 bool ucast
5683 )
5684{
5685 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305686 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5688
5689 ENTER();
5690
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305691 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305693 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005694 __func__, cipher);
5695 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5696 }
5697 else
5698 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305699
Jeff Johnson295189b2012-06-20 16:38:30 -07005700 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305701 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 {
5703 case IW_AUTH_CIPHER_NONE:
5704 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5705 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305706
Jeff Johnson295189b2012-06-20 16:38:30 -07005707 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305708 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005709 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305710
Jeff Johnson295189b2012-06-20 16:38:30 -07005711 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305712 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005713 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305714
Jeff Johnson295189b2012-06-20 16:38:30 -07005715 case WLAN_CIPHER_SUITE_TKIP:
5716 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5717 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305718
Jeff Johnson295189b2012-06-20 16:38:30 -07005719 case WLAN_CIPHER_SUITE_CCMP:
5720 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5721 break;
5722#ifdef FEATURE_WLAN_WAPI
5723 case WLAN_CIPHER_SUITE_SMS4:
5724 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5725 break;
5726#endif
5727
5728#ifdef FEATURE_WLAN_CCX
5729 case WLAN_CIPHER_SUITE_KRK:
5730 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5731 break;
5732#endif
5733 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305734 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005735 __func__, cipher);
5736 return -EOPNOTSUPP;
5737 }
5738 }
5739
5740 if (ucast)
5741 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305742 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005743 __func__, encryptionType);
5744 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5745 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305746 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005747 encryptionType;
5748 }
5749 else
5750 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305751 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005752 __func__, encryptionType);
5753 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5754 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5755 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5756 }
5757
5758 return 0;
5759}
5760
5761
5762/*
5763 * FUNCTION: wlan_hdd_cfg80211_set_ie
5764 * This function is used to parse WPA/RSN IE's.
5765 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305766int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5767 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005768 size_t ie_len
5769 )
5770{
5771 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5772 u8 *genie = ie;
5773 v_U16_t remLen = ie_len;
5774#ifdef FEATURE_WLAN_WAPI
5775 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5776 u16 *tmp;
5777 v_U16_t akmsuiteCount;
5778 int *akmlist;
5779#endif
5780 ENTER();
5781
5782 /* clear previous assocAddIE */
5783 pWextState->assocAddIE.length = 0;
5784 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5785
5786 while (remLen >= 2)
5787 {
5788 v_U16_t eLen = 0;
5789 v_U8_t elementId;
5790 elementId = *genie++;
5791 eLen = *genie++;
5792 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305793
Arif Hussain6d2a3322013-11-17 19:50:10 -08005794 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]",
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305796
5797 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005798 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305799 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005800 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 -07005801 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305802 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005803 "%s: Invalid WPA IE", __func__);
5804 return -EINVAL;
5805 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305806 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005807 {
5808 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305809 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005810 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305811
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5813 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005814 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5815 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005816 VOS_ASSERT(0);
5817 return -ENOMEM;
5818 }
5819 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5820 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5821 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305822
Jeff Johnson295189b2012-06-20 16:38:30 -07005823 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5824 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5825 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5826 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305827 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5828 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005829 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5830 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5831 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5832 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5833 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5834 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305835 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
Kiet Lam8da98992013-11-21 15:59:07 +05305836 P2P_OUI_TYPE_SIZE)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005837 {
5838 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305839 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005840 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305841
Jeff Johnson295189b2012-06-20 16:38:30 -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");
Jeff Johnson295189b2012-06-20 16:38:30 -07005846 VOS_ASSERT(0);
5847 return -ENOMEM;
5848 }
5849 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5850 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5851 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305852
Jeff Johnson295189b2012-06-20 16:38:30 -07005853 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5854 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5855 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005856#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305857 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5858 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005859 /*Consider WFD IE, only for P2P Client */
5860 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5861 {
5862 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305863 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305865
Jeff Johnson295189b2012-06-20 16:38:30 -07005866 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5867 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005868 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5869 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005870 VOS_ASSERT(0);
5871 return -ENOMEM;
5872 }
5873 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5874 // WPS IE + P2P IE + WFD IE
5875 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5876 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305877
Jeff Johnson295189b2012-06-20 16:38:30 -07005878 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5879 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5880 }
5881#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005882 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305883 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005884 HS20_OUI_TYPE_SIZE)) )
5885 {
5886 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305887 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005888 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005889
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005890 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5891 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005892 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5893 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005894 VOS_ASSERT(0);
5895 return -ENOMEM;
5896 }
5897 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5898 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005899
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005900 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5901 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5902 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005903
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005904 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5905
5906 /* populating as ADDIE in beacon frames */
5907 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5908 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5909 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5910 {
5911 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5912 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5913 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5914 {
5915 hddLog(LOGE,
5916 "Coldn't pass "
5917 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5918 }
5919 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5920 else
5921 hddLog(LOGE,
5922 "Could not pass on "
5923 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5924
5925 /* IBSS mode doesn't contain params->proberesp_ies still
5926 beaconIE's need to be populated in probe response frames */
5927 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5928 {
5929 u16 rem_probe_resp_ie_len = eLen + 2;
5930 u8 probe_rsp_ie_len[3] = {0};
5931 u8 counter = 0;
5932
5933 /* Check Probe Resp Length if it is greater then 255 then
5934 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5935 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5936 not able Store More then 255 bytes into One Variable */
5937
5938 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5939 {
5940 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5941 {
5942 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5943 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5944 }
5945 else
5946 {
5947 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5948 rem_probe_resp_ie_len = 0;
5949 }
5950 }
5951
5952 rem_probe_resp_ie_len = 0;
5953
5954 if (probe_rsp_ie_len[0] > 0)
5955 {
5956 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5957 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5958 (tANI_U8*)(genie - 2),
5959 probe_rsp_ie_len[0], NULL,
5960 eANI_BOOLEAN_FALSE)
5961 == eHAL_STATUS_FAILURE)
5962 {
5963 hddLog(LOGE,
5964 "Could not pass"
5965 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5966 }
5967 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5968 }
5969
5970 if (probe_rsp_ie_len[1] > 0)
5971 {
5972 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5973 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5974 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5975 probe_rsp_ie_len[1], NULL,
5976 eANI_BOOLEAN_FALSE)
5977 == eHAL_STATUS_FAILURE)
5978 {
5979 hddLog(LOGE,
5980 "Could not pass"
5981 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5982 }
5983 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5984 }
5985
5986 if (probe_rsp_ie_len[2] > 0)
5987 {
5988 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5989 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5990 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5991 probe_rsp_ie_len[2], NULL,
5992 eANI_BOOLEAN_FALSE)
5993 == eHAL_STATUS_FAILURE)
5994 {
5995 hddLog(LOGE,
5996 "Could not pass"
5997 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5998 }
5999 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
6000 }
6001
6002 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
6003 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
6004 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
6005 {
6006 hddLog(LOGE,
6007 "Could not pass"
6008 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
6009 }
6010 }
6011 else
6012 {
6013 // Reset WNI_CFG_PROBE_RSP Flags
6014 wlan_hdd_reset_prob_rspies(pAdapter);
6015
6016 hddLog(VOS_TRACE_LEVEL_INFO,
6017 "%s: No Probe Response IE received in set beacon",
6018 __func__);
6019 }
6020 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07006021 break;
6022 case DOT11F_EID_RSN:
6023 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
6024 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
6025 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
6026 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
6027 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
6028 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006029 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
6030 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306031 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006032 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306033 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006034 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306035
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006036 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
6037 {
Jeff Johnson902c9832012-12-10 14:28:09 -08006038 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
6039 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006040 VOS_ASSERT(0);
6041 return -ENOMEM;
6042 }
6043 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
6044 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306045
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006046 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
6047 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
6048 break;
6049 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006050#ifdef FEATURE_WLAN_WAPI
6051 case WLAN_EID_WAPI:
6052 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07006053 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 pAdapter->wapi_info.nWapiMode);
6055 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306056 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07006057 akmsuiteCount = WPA_GET_LE16(tmp);
6058 tmp = tmp + 1;
6059 akmlist = (int *)(tmp);
6060 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
6061 {
6062 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
6063 }
6064 else
6065 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006066 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count");
Jeff Johnson295189b2012-06-20 16:38:30 -07006067 VOS_ASSERT(0);
6068 return -EINVAL;
6069 }
6070
6071 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
6072 {
6073 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006074 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006075 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306076 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006077 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306078 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006079 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006080 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
6082 }
6083 break;
6084#endif
6085 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306086 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006087 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07006088 /* when Unknown IE is received we should break and continue
6089 * to the next IE in the buffer instead we were returning
6090 * so changing this to break */
6091 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006092 }
6093 genie += eLen;
6094 remLen -= eLen;
6095 }
6096 EXIT();
6097 return 0;
6098}
6099
6100/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05306101 * FUNCTION: hdd_isWPAIEPresent
6102 * Parse the received IE to find the WPA IE
6103 *
6104 */
6105static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
6106{
6107 v_U8_t eLen = 0;
6108 v_U16_t remLen = ie_len;
6109 v_U8_t elementId = 0;
6110
6111 while (remLen >= 2)
6112 {
6113 elementId = *ie++;
6114 eLen = *ie++;
6115 remLen -= 2;
6116 if (eLen > remLen)
6117 {
6118 hddLog(VOS_TRACE_LEVEL_ERROR,
6119 "%s: IE length is wrong %d", __func__, eLen);
6120 return FALSE;
6121 }
6122 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
6123 {
6124 /* OUI - 0x00 0X50 0XF2
6125 WPA Information Element - 0x01
6126 WPA version - 0x01*/
6127 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
6128 return TRUE;
6129 }
6130 ie += eLen;
6131 remLen -= eLen;
6132 }
6133 return FALSE;
6134}
6135
6136/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006137 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306138 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006139 * parameters during connect operation.
6140 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306141int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006142 struct cfg80211_connect_params *req
6143 )
6144{
6145 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306146 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006147 ENTER();
6148
6149 /*set wpa version*/
6150 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6151
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306152 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006153 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05306154 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07006155 {
6156 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6157 }
6158 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
6159 {
6160 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6161 }
6162 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306163
6164 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006165 pWextState->wpaVersion);
6166
6167 /*set authentication type*/
6168 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
6169
6170 if (0 > status)
6171 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306172 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006173 "%s: failed to set authentication type ", __func__);
6174 return status;
6175 }
6176
6177 /*set key mgmt type*/
6178 if (req->crypto.n_akm_suites)
6179 {
6180 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
6181 if (0 > status)
6182 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306183 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07006184 __func__);
6185 return status;
6186 }
6187 }
6188
6189 /*set pairwise cipher type*/
6190 if (req->crypto.n_ciphers_pairwise)
6191 {
6192 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
6193 req->crypto.ciphers_pairwise[0], true);
6194 if (0 > status)
6195 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306196 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006197 "%s: failed to set unicast cipher type", __func__);
6198 return status;
6199 }
6200 }
6201 else
6202 {
6203 /*Reset previous cipher suite to none*/
6204 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
6205 if (0 > status)
6206 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306207 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006208 "%s: failed to set unicast cipher type", __func__);
6209 return status;
6210 }
6211 }
6212
6213 /*set group cipher type*/
6214 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6215 false);
6216
6217 if (0 > status)
6218 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306219 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 __func__);
6221 return status;
6222 }
6223
Chet Lanctot186b5732013-03-18 10:26:30 -07006224#ifdef WLAN_FEATURE_11W
6225 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6226#endif
6227
Jeff Johnson295189b2012-06-20 16:38:30 -07006228 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6229 if (req->ie_len)
6230 {
6231 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6232 if ( 0 > status)
6233 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306234 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 __func__);
6236 return status;
6237 }
6238 }
6239
6240 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306241 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006242 {
6243 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6244 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6245 )
6246 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306247 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006248 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6249 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306250 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006251 __func__);
6252 return -EOPNOTSUPP;
6253 }
6254 else
6255 {
6256 u8 key_len = req->key_len;
6257 u8 key_idx = req->key_idx;
6258
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306259 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006260 && (CSR_MAX_NUM_KEY > key_idx)
6261 )
6262 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306263 hddLog(VOS_TRACE_LEVEL_INFO,
6264 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006265 __func__, key_idx, key_len);
6266 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306267 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006268 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306269 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006270 (u8)key_len;
6271 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6272 }
6273 }
6274 }
6275 }
6276
6277 return status;
6278}
6279
6280/*
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306281 * FUNCTION: wlan_hdd_try_disconnect
6282 * This function is used to disconnect from previous
6283 * connection
6284 */
6285static int wlan_hdd_try_disconnect( hdd_adapter_t *pAdapter )
6286{
6287 long ret = 0;
6288 hdd_station_ctx_t *pHddStaCtx;
6289 eMib_dot11DesiredBssType connectedBssType;
6290
6291 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6292
6293 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
6294
6295 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
6296 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
6297 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
6298 {
6299 /* Issue disconnect to CSR */
6300 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6301 if( eHAL_STATUS_SUCCESS ==
6302 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6303 pAdapter->sessionId,
6304 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
6305 {
6306 ret = wait_for_completion_interruptible_timeout(
6307 &pAdapter->disconnect_comp_var,
6308 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6309 if (0 >= ret)
6310 {
6311 hddLog(LOGE, FL("Failed to receive disconnect event"));
6312 return -EALREADY;
6313 }
6314 }
6315 }
6316 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
6317 {
6318 ret = wait_for_completion_interruptible_timeout(
6319 &pAdapter->disconnect_comp_var,
6320 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6321 if (0 >= ret)
6322 {
6323 hddLog(LOGE, FL("Failed to receive disconnect event"));
6324 return -EALREADY;
6325 }
6326 }
6327
6328 return 0;
6329}
6330
6331/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006332 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306333 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006334 * parameters during connect operation.
6335 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306336static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006337 struct net_device *ndev,
6338 struct cfg80211_connect_params *req
6339 )
6340{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306341 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306342 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006343 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006344 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006345
6346 ENTER();
6347
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006348 if (!pAdapter)
6349 {
6350 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6351 "%s: Adapter context is null", __func__);
6352 return VOS_STATUS_E_FAILURE;
6353 }
6354
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306355 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006356 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006357
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306358 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Rajesh Chauhana0516c62014-01-30 16:11:18 -08006359 if (!pHddCtx)
6360 {
6361 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6362 "%s: HDD context is null", __func__);
6363 return VOS_STATUS_E_FAILURE;
6364 }
6365
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306366 status = wlan_hdd_validate_context(pHddCtx);
6367
6368 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006369 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306370 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6371 "%s: HDD context is not valid", __func__);
6372 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006373 }
6374
6375#ifdef WLAN_BTAMP_FEATURE
6376 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306377 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006378 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306379 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006381 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006382 }
6383#endif
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306384
6385 //If Device Mode is Station Concurrent Sessions Exit BMps
6386 //P2P Mode will be taken care in Open/close adapter
6387 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6388 (vos_concurrent_sessions_running()))
6389 {
6390 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
6391 }
6392
6393 /*Try disconnecting if already in connected state*/
6394 status = wlan_hdd_try_disconnect(pAdapter);
6395 if ( 0 > status)
6396 {
6397 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6398 " connection"));
6399 return -EALREADY;
6400 }
6401
Jeff Johnson295189b2012-06-20 16:38:30 -07006402 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306403 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006404
6405 if ( 0 > status)
6406 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306407 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006408 __func__);
6409 return status;
6410 }
6411
Mohit Khanna765234a2012-09-11 15:08:35 -07006412 if ( req->channel )
6413 {
6414 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6415 req->ssid_len, req->bssid,
6416 req->channel->hw_value);
6417 }
6418 else
6419 {
6420 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306421 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006422 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006423
6424 if (0 > status)
6425 {
6426 //ReEnable BMPS if disabled
6427 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6428 (NULL != pHddCtx))
6429 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306430 if (pHddCtx->hdd_wlan_suspended)
6431 {
6432 hdd_set_pwrparams(pHddCtx);
6433 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006434 //ReEnable Bmps and Imps back
6435 hdd_enable_bmps_imps(pHddCtx);
6436 }
6437
6438 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6439 return status;
6440 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306441 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006442 EXIT();
6443 return status;
6444}
6445
6446
6447/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306448 * FUNCTION: wlan_hdd_disconnect
6449 * This function is used to issue a disconnect request to SME
6450 */
6451int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6452{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306453 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306454 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306455 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306456 long ret;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306457
6458 status = wlan_hdd_validate_context(pHddCtx);
6459
6460 if (0 != status)
6461 {
6462 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6463 "%s: HDD context is not valid", __func__);
6464 return status;
6465 }
6466
6467 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306468 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306469 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306470
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306471 /*issue disconnect*/
6472 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6473 pAdapter->sessionId, reason);
6474
6475 if ( 0 != status )
6476 {
6477 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006478 "%s csrRoamDisconnect failure, returned %d",
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306479 __func__, (int)status );
6480 return -EINVAL;
6481 }
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306482 ret = wait_for_completion_interruptible_timeout(
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306483 &pAdapter->disconnect_comp_var,
6484 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
c_hpothu6ff1c3c2013-10-01 19:01:57 +05306485 if (ret <= 0)
6486 {
6487 hddLog(VOS_TRACE_LEVEL_ERROR,
6488 FL("wait on disconnect_comp_var failed %ld"), ret);
6489 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306490 /*stop tx queues*/
6491 netif_tx_disable(pAdapter->dev);
6492 netif_carrier_off(pAdapter->dev);
6493 return status;
6494}
6495
6496
6497/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006498 * FUNCTION: wlan_hdd_cfg80211_disconnect
6499 * This function is used to issue a disconnect request to SME
6500 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306501static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006502 struct net_device *dev,
6503 u16 reason
6504 )
6505{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306506 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6507 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006508 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306509 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006510 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006511 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306512#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006513 tANI_U8 staIdx;
6514#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306515
Jeff Johnson295189b2012-06-20 16:38:30 -07006516 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306517
Arif Hussain6d2a3322013-11-17 19:50:10 -08006518 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006519 __func__,pAdapter->device_mode);
6520
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306521 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6522 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006523
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306524 status = wlan_hdd_validate_context(pHddCtx);
6525
6526 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006527 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306528 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6529 "%s: HDD context is not valid", __func__);
6530 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306532
Jeff Johnson295189b2012-06-20 16:38:30 -07006533 if (NULL != pRoamProfile)
6534 {
6535 /*issue disconnect request to SME, if station is in connected state*/
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306536 if ((pHddStaCtx->conn_info.connState == eConnectionState_Associated) ||
6537 (pHddStaCtx->conn_info.connState == eConnectionState_Connecting))
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306539 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006540 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306541 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006542 switch(reason)
6543 {
6544 case WLAN_REASON_MIC_FAILURE:
6545 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6546 break;
6547
6548 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6549 case WLAN_REASON_DISASSOC_AP_BUSY:
6550 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6551 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6552 break;
6553
6554 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6555 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6556 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6557 break;
6558
6559 case WLAN_REASON_DEAUTH_LEAVING:
6560 default:
6561 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6562 break;
6563 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306564 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6565 pScanInfo = &pHddCtx->scan_info;
6566 if (pScanInfo->mScanPending)
6567 {
6568 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6569 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306570 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306571 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006572
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006573#ifdef FEATURE_WLAN_TDLS
6574 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006575 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006576 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006577 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6578 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006579 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006580 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006581 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006582 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006583 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006584 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006585 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006586 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006587 pAdapter->sessionId,
6588 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006589 }
6590 }
6591#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306592 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6593 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 {
6595 hddLog(VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006596 "%s wlan_hdd_disconnect failure, returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006597 __func__, (int)status );
6598 return -EINVAL;
6599 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006600 }
Mahesh A Saptasagar280fd5a2013-12-05 15:38:31 +05306601 else
6602 {
6603 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unexpected cfg disconnect API"
6604 "called while in %d state", __func__,
6605 pHddStaCtx->conn_info.connState);
6606 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006607 }
6608 else
6609 {
6610 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6611 }
6612
6613 return status;
6614}
6615
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306616
Jeff Johnson295189b2012-06-20 16:38:30 -07006617/*
6618 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306619 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006620 * settings in IBSS mode.
6621 */
6622static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306623 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006624 struct cfg80211_ibss_params *params
6625 )
6626{
6627 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306628 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006629 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6630 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306631
Jeff Johnson295189b2012-06-20 16:38:30 -07006632 ENTER();
6633
6634 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
Ravi Joshib58ca0d2013-10-29 09:50:23 -07006635 vos_mem_zero(&pHddStaCtx->ibss_enc_key, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -07006636
6637 if (params->ie_len && ( NULL != params->ie) )
6638 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006639 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6640 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006641 {
6642 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6643 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6644 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006645 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006646 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006647 tDot11fIEWPA dot11WPAIE;
6648 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006649 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006650
Wilson Yang00256342013-10-10 23:13:38 -07006651 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006652 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6653 params->ie_len, DOT11F_EID_WPA);
6654 if ( NULL != ie )
6655 {
6656 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6657 // Unpack the WPA IE
6658 //Skip past the EID byte and length byte - and four byte WiFi OUI
6659 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6660 &ie[2+4],
6661 ie[1] - 4,
6662 &dot11WPAIE);
6663 /*Extract the multicast cipher, the encType for unicast
6664 cipher for wpa-none is none*/
6665 encryptionType =
6666 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6667 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006668 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006669
Jeff Johnson295189b2012-06-20 16:38:30 -07006670 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6671
6672 if (0 > status)
6673 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306674 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006675 __func__);
6676 return status;
6677 }
6678 }
6679
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306680 pWextState->roamProfile.AuthType.authType[0] =
6681 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006682 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6683
6684 if (params->privacy)
6685 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306686 /* Security enabled IBSS, At this time there is no information available
6687 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006688 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306689 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006690 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306691 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006692 *enable privacy bit in beacons */
6693
6694 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6695 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006696 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6697 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006698 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6699 pWextState->roamProfile.EncryptionType.numEntries = 1;
6700 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006701 return status;
6702}
6703
6704/*
6705 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306706 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006707 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306708static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006709 struct net_device *dev,
6710 struct cfg80211_ibss_params *params
6711 )
6712{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306713 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006714 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6715 tCsrRoamProfile *pRoamProfile;
6716 int status;
krunal sonie9002db2013-11-25 14:24:17 -08006717 bool alloc_bssid = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006718 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306719 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006720
6721 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306722
6723 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006724 "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006725
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306726 status = wlan_hdd_validate_context(pHddCtx);
6727
6728 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006729 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306730 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6731 "%s: HDD context is not valid", __func__);
6732 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006733 }
6734
6735 if (NULL == pWextState)
6736 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006737 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006738 __func__);
6739 return -EIO;
6740 }
6741
Vinay Krishna Eranna21042322014-01-08 19:21:39 +05306742 /*Try disconnecting if already in connected state*/
6743 status = wlan_hdd_try_disconnect(pAdapter);
6744 if ( 0 > status)
6745 {
6746 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to disconnect the existing"
6747 " IBSS connection"));
6748 return -EALREADY;
6749 }
6750
Jeff Johnson295189b2012-06-20 16:38:30 -07006751 pRoamProfile = &pWextState->roamProfile;
6752
6753 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6754 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306755 hddLog (VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08006756 "%s Interface type is not set to IBSS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006757 return -EINVAL;
6758 }
6759
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006760 /* BSSID is provided by upper layers hence no need to AUTO generate */
6761 if (NULL != params->bssid) {
6762 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6763 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE) {
6764 hddLog (VOS_TRACE_LEVEL_ERROR,
6765 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6766 return -EIO;
6767 }
6768 }
krunal sonie9002db2013-11-25 14:24:17 -08006769 else if(pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0)
6770 {
6771 if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_IBSS_AUTO_BSSID, 0,
6772 NULL, eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
6773 {
6774 hddLog (VOS_TRACE_LEVEL_ERROR,
6775 "%s:ccmCfgStInt faild for WNI_CFG_IBSS_AUTO_BSSID", __func__);
6776 return -EIO;
6777 }
6778 params->bssid = vos_mem_malloc(sizeof(VOS_MAC_ADDR_SIZE));
6779 if (!params->bssid)
6780 {
6781 hddLog (VOS_TRACE_LEVEL_ERROR,
6782 "%s:Failed memory allocation", __func__);
6783 return -EIO;
6784 }
6785 vos_mem_copy((v_U8_t *)params->bssid,
6786 (v_U8_t *)&pHddCtx->cfg_ini->IbssBssid.bytes[0],
6787 VOS_MAC_ADDR_SIZE);
6788 alloc_bssid = VOS_TRUE;
6789 }
Praveen Kumar Sirisillad123d142013-09-24 16:50:13 -07006790
Jeff Johnson295189b2012-06-20 16:38:30 -07006791 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006792 if (NULL !=
6793#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6794 params->chandef.chan)
6795#else
6796 params->channel)
6797#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006798 {
6799 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006800 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6801 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6802 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6803 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006804
6805 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306806 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006807 ieee80211_frequency_to_channel(
6808#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6809 params->chandef.chan->center_freq);
6810#else
6811 params->channel->center_freq);
6812#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006813
6814 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6815 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006817 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6818 __func__);
6819 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006820 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006821
6822 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006823 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006824 if (channelNum == validChan[indx])
6825 {
6826 break;
6827 }
6828 }
6829 if (indx >= numChans)
6830 {
6831 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 __func__, channelNum);
6833 return -EINVAL;
6834 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006835 /* Set the Operational Channel */
6836 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6837 channelNum);
6838 pRoamProfile->ChannelInfo.numOfChannels = 1;
6839 pHddStaCtx->conn_info.operationChannel = channelNum;
6840 pRoamProfile->ChannelInfo.ChannelList =
6841 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006842 }
6843
6844 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306845 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006846 if (status < 0)
6847 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306848 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006849 __func__);
6850 return status;
6851 }
6852
6853 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306854 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006855 params->ssid_len, params->bssid,
6856 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006857
6858 if (0 > status)
6859 {
6860 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6861 return status;
6862 }
6863
krunal sonie9002db2013-11-25 14:24:17 -08006864 if (NULL != params->bssid &&
6865 pHddCtx->cfg_ini->isCoalesingInIBSSAllowed == 0 &&
6866 alloc_bssid == VOS_TRUE)
6867 {
6868 vos_mem_free(params->bssid);
6869 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006870 return 0;
6871}
6872
6873/*
6874 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306875 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306877static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 struct net_device *dev
6879 )
6880{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306881 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006882 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6883 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306884 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6885 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006886
6887 ENTER();
6888
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306889 status = wlan_hdd_validate_context(pHddCtx);
6890
6891 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006892 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306893 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6894 "%s: HDD context is not valid", __func__);
6895 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006896 }
6897
Arif Hussain6d2a3322013-11-17 19:50:10 -08006898 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",__func__,pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07006899 if (NULL == pWextState)
6900 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08006901 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption",
Jeff Johnson295189b2012-06-20 16:38:30 -07006902 __func__);
6903 return -EIO;
6904 }
6905
6906 pRoamProfile = &pWextState->roamProfile;
6907
6908 /* Issue disconnect only if interface type is set to IBSS */
6909 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6910 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306911 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006912 __func__);
6913 return -EINVAL;
6914 }
6915
6916 /* Issue Disconnect request */
6917 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6918 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6919 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6920
6921 return 0;
6922}
6923
6924/*
6925 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6926 * This function is used to set the phy parameters
6927 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6928 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306929static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006930 u32 changed)
6931{
6932 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6933 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306934 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006935
6936 ENTER();
6937
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306938 status = wlan_hdd_validate_context(pHddCtx);
6939
6940 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006941 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306942 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6943 "%s: HDD context is not valid", __func__);
6944 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006945 }
6946
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6948 {
6949 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6950 WNI_CFG_RTS_THRESHOLD_STAMAX :
6951 wiphy->rts_threshold;
6952
6953 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306954 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306956 hddLog(VOS_TRACE_LEVEL_ERROR,
6957 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006958 __func__, rts_threshold);
6959 return -EINVAL;
6960 }
6961
6962 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6963 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306964 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006965 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306966 hddLog(VOS_TRACE_LEVEL_ERROR,
6967 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006968 __func__, rts_threshold);
6969 return -EIO;
6970 }
6971
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306972 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006973 rts_threshold);
6974 }
6975
6976 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6977 {
6978 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6979 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6980 wiphy->frag_threshold;
6981
6982 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306983 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306985 hddLog(VOS_TRACE_LEVEL_ERROR,
6986 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006987 frag_threshold);
6988 return -EINVAL;
6989 }
6990
6991 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6992 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306993 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006994 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306995 hddLog(VOS_TRACE_LEVEL_ERROR,
6996 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006997 __func__, frag_threshold);
6998 return -EIO;
6999 }
7000
7001 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
7002 frag_threshold);
7003 }
7004
7005 if ((changed & WIPHY_PARAM_RETRY_SHORT)
7006 || (changed & WIPHY_PARAM_RETRY_LONG))
7007 {
7008 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
7009 wiphy->retry_short :
7010 wiphy->retry_long;
7011
7012 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
7013 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
7014 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307015 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007016 __func__, retry_value);
7017 return -EINVAL;
7018 }
7019
7020 if (changed & WIPHY_PARAM_RETRY_SHORT)
7021 {
7022 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
7023 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307024 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007025 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307026 hddLog(VOS_TRACE_LEVEL_ERROR,
7027 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007028 __func__, retry_value);
7029 return -EIO;
7030 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307031 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007032 __func__, retry_value);
7033 }
7034 else if (changed & WIPHY_PARAM_RETRY_SHORT)
7035 {
7036 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
7037 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307038 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007039 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307040 hddLog(VOS_TRACE_LEVEL_ERROR,
7041 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007042 __func__, retry_value);
7043 return -EIO;
7044 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307045 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07007046 __func__, retry_value);
7047 }
7048 }
7049
7050 return 0;
7051}
7052
7053/*
7054 * FUNCTION: wlan_hdd_cfg80211_set_txpower
7055 * This function is used to set the txpower
7056 */
7057static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07007058#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7059 struct wireless_dev *wdev,
7060#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007061#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307062 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007063#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307064 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07007065#endif
7066 int dbm)
7067{
7068 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307069 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007070 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
7071 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307072 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007073
7074 ENTER();
7075
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307076 status = wlan_hdd_validate_context(pHddCtx);
7077
7078 if (0 != status)
7079 {
7080 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7081 "%s: HDD context is not valid", __func__);
7082 return status;
7083 }
7084
7085 hHal = pHddCtx->hHal;
7086
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307087 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
7088 dbm, ccmCfgSetCallback,
7089 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307091 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
7093 return -EIO;
7094 }
7095
7096 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
7097 dbm);
7098
7099 switch(type)
7100 {
7101 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
7102 /* Fall through */
7103 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
7104 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
7105 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307106 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
7107 __func__);
7108 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07007109 }
7110 break;
7111 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307112 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07007113 __func__);
7114 return -EOPNOTSUPP;
7115 break;
7116 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307117 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
7118 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07007119 return -EIO;
7120 }
7121
7122 return 0;
7123}
7124
7125/*
7126 * FUNCTION: wlan_hdd_cfg80211_get_txpower
7127 * This function is used to read the txpower
7128 */
Yue Maf49ba872013-08-19 12:04:25 -07007129static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
7130#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
7131 struct wireless_dev *wdev,
7132#endif
7133 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07007134{
7135
7136 hdd_adapter_t *pAdapter;
7137 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307138 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007139
Jeff Johnsone7245742012-09-05 17:12:55 -07007140 ENTER();
7141
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307142 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007143
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307144 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007145 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307146 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7147 "%s: HDD context is not valid", __func__);
7148 *dbm = 0;
7149 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007150 }
7151
Jeff Johnson295189b2012-06-20 16:38:30 -07007152 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
7153 if (NULL == pAdapter)
7154 {
7155 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
7156 return -ENOENT;
7157 }
7158
7159 wlan_hdd_get_classAstats(pAdapter);
7160 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
7161
Jeff Johnsone7245742012-09-05 17:12:55 -07007162 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007163 return 0;
7164}
7165
7166static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
7167 u8* mac, struct station_info *sinfo)
7168{
7169 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
7170 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7171 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
7172 tANI_U8 rate_flags;
7173
7174 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
7175 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07007176
7177 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
7178 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
7179 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
7180 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
7181 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
7182 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
7183 tANI_U16 maxRate = 0;
7184 tANI_U16 myRate;
7185 tANI_U16 currentRate = 0;
7186 tANI_U8 maxSpeedMCS = 0;
7187 tANI_U8 maxMCSIdx = 0;
7188 tANI_U8 rateFlag = 1;
7189 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07007190 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307191 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007192
Leo Chang6f8870f2013-03-26 18:11:36 -07007193#ifdef WLAN_FEATURE_11AC
7194 tANI_U32 vht_mcs_map;
7195 eDataRate11ACMaxMcs vhtMaxMcs;
7196#endif /* WLAN_FEATURE_11AC */
7197
Jeff Johnsone7245742012-09-05 17:12:55 -07007198 ENTER();
7199
Jeff Johnson295189b2012-06-20 16:38:30 -07007200 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
7201 (0 == ssidlen))
7202 {
7203 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
7204 " Invalid ssidlen, %d", __func__, ssidlen);
7205 /*To keep GUI happy*/
7206 return 0;
7207 }
7208
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307209 status = wlan_hdd_validate_context(pHddCtx);
7210
7211 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007212 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307213 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7214 "%s: HDD context is not valid", __func__);
7215 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007216 }
7217
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007218 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007219 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
7220
Kiet Lam3b17fc82013-09-27 05:24:08 +05307221 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
7222 sinfo->filled |= STATION_INFO_SIGNAL;
7223
Jeff Johnson295189b2012-06-20 16:38:30 -07007224 //convert to the UI units of 100kbps
7225 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
7226
7227#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07007228 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 -07007229 sinfo->signal,
7230 pCfg->reportMaxLinkSpeed,
7231 myRate,
7232 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007233 (int) pCfg->linkSpeedRssiMid,
7234 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07007235 (int) rate_flags,
7236 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07007237#endif //LINKSPEED_DEBUG_ENABLED
7238
7239 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
7240 {
7241 // we do not want to necessarily report the current speed
7242 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
7243 {
7244 // report the max possible speed
7245 rssidx = 0;
7246 }
7247 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
7248 {
7249 // report the max possible speed with RSSI scaling
7250 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
7251 {
7252 // report the max possible speed
7253 rssidx = 0;
7254 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007255 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07007256 {
7257 // report middle speed
7258 rssidx = 1;
7259 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007260 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
7261 {
7262 // report middle speed
7263 rssidx = 2;
7264 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007265 else
7266 {
7267 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007268 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07007269 }
7270 }
7271 else
7272 {
7273 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
7274 hddLog(VOS_TRACE_LEVEL_ERROR,
7275 "%s: Invalid value for reportMaxLinkSpeed: %u",
7276 __func__, pCfg->reportMaxLinkSpeed);
7277 rssidx = 0;
7278 }
7279
7280 maxRate = 0;
7281
7282 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307283 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
7284 OperationalRates, &ORLeng))
7285 {
7286 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7287 /*To keep GUI happy*/
7288 return 0;
7289 }
7290
Jeff Johnson295189b2012-06-20 16:38:30 -07007291 for (i = 0; i < ORLeng; i++)
7292 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007293 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007294 {
7295 /* Validate Rate Set */
7296 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
7297 {
7298 currentRate = supported_data_rate[j].supported_rate[rssidx];
7299 break;
7300 }
7301 }
7302 /* Update MAX rate */
7303 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7304 }
7305
7306 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307307 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
7308 ExtendedRates, &ERLeng))
7309 {
7310 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7311 /*To keep GUI happy*/
7312 return 0;
7313 }
7314
Jeff Johnson295189b2012-06-20 16:38:30 -07007315 for (i = 0; i < ERLeng; i++)
7316 {
Jeff Johnsone7245742012-09-05 17:12:55 -07007317 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007318 {
7319 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
7320 {
7321 currentRate = supported_data_rate[j].supported_rate[rssidx];
7322 break;
7323 }
7324 }
7325 /* Update MAX rate */
7326 maxRate = (currentRate > maxRate)?currentRate:maxRate;
7327 }
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307328 /* Get MCS Rate Set --
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307329 Only if we are always reporting max speed (or)
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307330 if we have good rssi */
Kaushik, Sushantdc304d82014-01-22 10:58:37 +05307331 if ((0 == rssidx) ||
Kiet Lamb69f8dc2013-11-15 15:34:27 +05307332 (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed))
Jeff Johnson295189b2012-06-20 16:38:30 -07007333 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05307334 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
7335 MCSRates, &MCSLeng))
7336 {
7337 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
7338 /*To keep GUI happy*/
7339 return 0;
7340 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007341 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07007342#ifdef WLAN_FEATURE_11AC
7343 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307344 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007346 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307347 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007348 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007349 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007350 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007351 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007352 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007354 maxMCSIdx = 7;
7355 }
7356 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7357 {
7358 maxMCSIdx = 8;
7359 }
7360 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7361 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307362 //VHT20 is supporting 0~8
7363 if (rate_flags & eHAL_TX_RATE_VHT20)
7364 maxMCSIdx = 8;
7365 else
7366 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007367 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307368
7369 if (rate_flags & eHAL_TX_RATE_VHT80)
7370 {
7371 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7372 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7373 }
7374 else if (rate_flags & eHAL_TX_RATE_VHT40)
7375 {
7376 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7377 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7378 }
7379 else if (rate_flags & eHAL_TX_RATE_VHT20)
7380 {
7381 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7382 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7383 }
7384
Leo Chang6f8870f2013-03-26 18:11:36 -07007385 maxSpeedMCS = 1;
7386 if (currentRate > maxRate)
7387 {
7388 maxRate = currentRate;
7389 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307390
Leo Chang6f8870f2013-03-26 18:11:36 -07007391 }
7392 else
7393#endif /* WLAN_FEATURE_11AC */
7394 {
7395 if (rate_flags & eHAL_TX_RATE_HT40)
7396 {
7397 rateFlag |= 1;
7398 }
7399 if (rate_flags & eHAL_TX_RATE_SGI)
7400 {
7401 rateFlag |= 2;
7402 }
7403
7404 for (i = 0; i < MCSLeng; i++)
7405 {
7406 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7407 for (j = 0; j < temp; j++)
7408 {
7409 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7410 {
7411 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7412 break;
7413 }
7414 }
7415 if ((j < temp) && (currentRate > maxRate))
7416 {
7417 maxRate = currentRate;
7418 maxSpeedMCS = 1;
7419 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7420 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007421 }
7422 }
7423 }
7424
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307425 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7426 {
7427 maxRate = myRate;
7428 maxSpeedMCS = 1;
7429 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7430 }
7431
Jeff Johnson295189b2012-06-20 16:38:30 -07007432 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007433 if (((maxRate < myRate) && (0 == rssidx)) ||
7434 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007435 {
7436 maxRate = myRate;
7437 if (rate_flags & eHAL_TX_RATE_LEGACY)
7438 {
7439 maxSpeedMCS = 0;
7440 }
7441 else
7442 {
7443 maxSpeedMCS = 1;
7444 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7445 }
7446 }
7447
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307448 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007449 {
7450 sinfo->txrate.legacy = maxRate;
7451#ifdef LINKSPEED_DEBUG_ENABLED
7452 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7453#endif //LINKSPEED_DEBUG_ENABLED
7454 }
7455 else
7456 {
7457 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007458#ifdef WLAN_FEATURE_11AC
7459 sinfo->txrate.nss = 1;
7460 if (rate_flags & eHAL_TX_RATE_VHT80)
7461 {
7462 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307463 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007464 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307465 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007466 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307467 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7468 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7469 }
7470 else if (rate_flags & eHAL_TX_RATE_VHT20)
7471 {
7472 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7473 }
7474#endif /* WLAN_FEATURE_11AC */
7475 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7476 {
7477 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7478 if (rate_flags & eHAL_TX_RATE_HT40)
7479 {
7480 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7481 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007482 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007483 if (rate_flags & eHAL_TX_RATE_SGI)
7484 {
7485 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7486 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307487
Jeff Johnson295189b2012-06-20 16:38:30 -07007488#ifdef LINKSPEED_DEBUG_ENABLED
7489 pr_info("Reporting MCS rate %d flags %x\n",
7490 sinfo->txrate.mcs,
7491 sinfo->txrate.flags );
7492#endif //LINKSPEED_DEBUG_ENABLED
7493 }
7494 }
7495 else
7496 {
7497 // report current rate instead of max rate
7498
7499 if (rate_flags & eHAL_TX_RATE_LEGACY)
7500 {
7501 //provide to the UI in units of 100kbps
7502 sinfo->txrate.legacy = myRate;
7503#ifdef LINKSPEED_DEBUG_ENABLED
7504 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7505#endif //LINKSPEED_DEBUG_ENABLED
7506 }
7507 else
7508 {
7509 //must be MCS
7510 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007511#ifdef WLAN_FEATURE_11AC
7512 sinfo->txrate.nss = 1;
7513 if (rate_flags & eHAL_TX_RATE_VHT80)
7514 {
7515 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7516 }
7517 else
7518#endif /* WLAN_FEATURE_11AC */
7519 {
7520 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7521 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007522 if (rate_flags & eHAL_TX_RATE_SGI)
7523 {
7524 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7525 }
7526 if (rate_flags & eHAL_TX_RATE_HT40)
7527 {
7528 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7529 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007530#ifdef WLAN_FEATURE_11AC
7531 else if (rate_flags & eHAL_TX_RATE_VHT80)
7532 {
7533 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7534 }
7535#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007536#ifdef LINKSPEED_DEBUG_ENABLED
7537 pr_info("Reporting actual MCS rate %d flags %x\n",
7538 sinfo->txrate.mcs,
7539 sinfo->txrate.flags );
7540#endif //LINKSPEED_DEBUG_ENABLED
7541 }
7542 }
7543 sinfo->filled |= STATION_INFO_TX_BITRATE;
7544
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007545 sinfo->tx_packets =
7546 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7547 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7548 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7549 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7550
7551 sinfo->tx_retries =
7552 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7553 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7554 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7555 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7556
7557 sinfo->tx_failed =
7558 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7559 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7560 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7561 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7562
7563 sinfo->filled |=
7564 STATION_INFO_TX_PACKETS |
7565 STATION_INFO_TX_RETRIES |
7566 STATION_INFO_TX_FAILED;
7567
7568 EXIT();
7569 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007570}
7571
7572static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007573 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007574{
7575 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307576 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307578 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007579
Jeff Johnsone7245742012-09-05 17:12:55 -07007580 ENTER();
7581
Jeff Johnson295189b2012-06-20 16:38:30 -07007582 if (NULL == pAdapter)
7583 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08007584 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007585 return -ENODEV;
7586 }
7587
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307588 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307589 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307590
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307591 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307592 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7594 "%s: HDD context is not valid", __func__);
7595 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307596 }
7597
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307598 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7599 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7600 (pHddCtx->cfg_ini->fhostArpOffload) &&
7601 (eConnectionState_Associated ==
7602 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7603 {
Amar Singhald53568e2013-09-26 11:03:45 -07007604
7605 hddLog(VOS_TRACE_LEVEL_INFO,
7606 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307607 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307608 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7609 {
7610 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -08007611 "%s:Failed to enable ARPOFFLOAD Feature %d",
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307612 __func__, vos_status);
7613 }
7614 }
7615
Jeff Johnson295189b2012-06-20 16:38:30 -07007616 /**The get power cmd from the supplicant gets updated by the nl only
7617 *on successful execution of the function call
7618 *we are oppositely mapped w.r.t mode in the driver
7619 **/
7620 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7621
Jeff Johnsone7245742012-09-05 17:12:55 -07007622 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007623 if (VOS_STATUS_E_FAILURE == vos_status)
7624 {
c_hpothu6ff1c3c2013-10-01 19:01:57 +05307625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7626 "%s: failed to enter bmps mode", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007627 return -EINVAL;
7628 }
7629 return 0;
7630}
7631
7632
7633#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7634static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7635 struct net_device *netdev,
7636 u8 key_index)
7637{
Jeff Johnsone7245742012-09-05 17:12:55 -07007638 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007639 return 0;
7640}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307641#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007642
7643#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7644static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7645 struct net_device *dev,
7646 struct ieee80211_txq_params *params)
7647{
Jeff Johnsone7245742012-09-05 17:12:55 -07007648 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007649 return 0;
7650}
7651#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7652static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7653 struct ieee80211_txq_params *params)
7654{
Jeff Johnsone7245742012-09-05 17:12:55 -07007655 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007656 return 0;
7657}
7658#endif //LINUX_VERSION_CODE
7659
7660static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7661 struct net_device *dev, u8 *mac)
7662{
7663 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307664 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007665 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307666 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007667 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007668
Jeff Johnsone7245742012-09-05 17:12:55 -07007669 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307670 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007671 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307672 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007673 return -EINVAL;
7674 }
7675
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307676 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7677 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007678
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307679 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007680 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307681 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7682 "%s: HDD context is not valid", __func__);
7683 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007684 }
7685
Jeff Johnson295189b2012-06-20 16:38:30 -07007686 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007687 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007688 )
7689 {
7690 if( NULL == mac )
7691 {
7692 v_U16_t i;
7693 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7694 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007695 if ((pAdapter->aStaInfo[i].isUsed) &&
7696 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007697 {
7698 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7699 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007700 "%s: Delete STA with MAC::"
7701 MAC_ADDRESS_STR,
7702 __func__, MAC_ADDR_ARRAY(macAddr));
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007703 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7704 if (VOS_IS_STATUS_SUCCESS(vos_status))
7705 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007706 }
7707 }
7708 }
7709 else
7710 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007711
7712 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7713 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7714 {
7715 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007716 "%s: Skip this DEL STA as this is not used::"
7717 MAC_ADDRESS_STR,
7718 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007719 return -ENOENT;
7720 }
7721
7722 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7723 {
7724 hddLog(VOS_TRACE_LEVEL_INFO,
Arif Hussain24bafea2013-11-15 15:10:03 -08007725 "%s: Skip this DEL STA as deauth is in progress::"
7726 MAC_ADDRESS_STR,
7727 __func__, MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007728 return -ENOENT;
7729 }
7730
7731 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7732
Jeff Johnson295189b2012-06-20 16:38:30 -07007733 hddLog(VOS_TRACE_LEVEL_INFO,
7734 "%s: Delete STA with MAC::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007735 MAC_ADDRESS_STR,
Jeff Johnson295189b2012-06-20 16:38:30 -07007736 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007737 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007738
7739 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7740 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7741 {
7742 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7743 hddLog(VOS_TRACE_LEVEL_INFO,
7744 "%s: STA removal failed for ::"
Arif Hussain24bafea2013-11-15 15:10:03 -08007745 MAC_ADDRESS_STR,
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007746 __func__,
Arif Hussain24bafea2013-11-15 15:10:03 -08007747 MAC_ADDR_ARRAY(mac));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007748 return -ENOENT;
7749 }
7750
Jeff Johnson295189b2012-06-20 16:38:30 -07007751 }
7752 }
7753
7754 EXIT();
7755
7756 return 0;
7757}
7758
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007759static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7760 struct net_device *dev, u8 *mac, struct station_parameters *params)
7761{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007762 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007763#ifdef FEATURE_WLAN_TDLS
7764 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007765 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007766 mask = params->sta_flags_mask;
7767
7768 set = params->sta_flags_set;
7769
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007770#ifdef WLAN_FEATURE_TDLS_DEBUG
7771 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7772 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7773 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7774#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007775
7776 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7777 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007778 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007779 }
7780 }
7781#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007782 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007783}
7784
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007785
7786#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007787#define MAX_PMKSAIDS_IN_CACHE 8
7788
7789static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7790static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7791
7792
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007793static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007794 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007795{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307796 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007797 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7798 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307799 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307800 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007801 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307802 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307803
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007804 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
7805 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07007806
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307807 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307808 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007809 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307810 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007811 return -EINVAL;
7812 }
7813
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307814 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7815 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007816
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307817 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007818 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307819 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7820 "%s: HDD context is not valid", __func__);
7821 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007822 }
7823
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307824 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007825 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7826
Wilson Yang6507c4e2013-10-01 20:11:19 -07007827 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007828 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307829 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007830 pmksa->bssid, WNI_CFG_BSSID_LEN))
7831 {
7832 /* BSSID matched previous entry. Overwrite it. */
7833 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307834 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007835 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307836 vos_mem_copy(PMKIDCache[j].PMKID,
7837 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007838 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307839 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007840 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007841 dump_bssid(pmksa->bssid);
7842 dump_pmkid(halHandle, pmksa->pmkid);
7843 break;
7844 }
7845 }
7846
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007847 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007848 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007849
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007850 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307851 {
7852 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007853 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307854 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007855 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307856 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007857 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307858 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007859 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007860 dump_bssid(pmksa->bssid);
7861 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307862 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007863 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007864 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007865 }
7866
7867
7868 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307869 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007870 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307871 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007872 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007873 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307874 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7875 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007876 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007877 return 0;
7878}
7879
7880
Wilson Yang6507c4e2013-10-01 20:11:19 -07007881
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007882static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007883 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007884{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007885 tANI_U32 j=0;
7886 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7887 tHalHandle halHandle;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007888 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007889 hdd_context_t *pHddCtx;
Wilson Yangef657d32014-01-15 19:19:23 -08007890 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007891
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007892 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
7893 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007894
7895 /* Validate pAdapter */
7896 if (NULL == pAdapter)
7897 {
7898 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7899 return -EINVAL;
7900 }
7901
7902 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7903 status = wlan_hdd_validate_context(pHddCtx);
7904
7905 if (0 != status)
7906 {
7907 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7908 "%s: HDD context is not valid", __func__);
7909 return status;
7910 }
7911
7912 /*Retrieve halHandle*/
7913 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7914
7915 /*in case index is 0,no entry to delete*/
7916 if (0 == PMKIDCacheIndex)
7917 {
7918 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7919 __func__);
7920 return -EINVAL;
7921 }
7922
7923 /*find the matching PMKSA entry from j=0 to (index-1),
7924 * and delete the matched one
7925 */
7926 for (j = 0; j<PMKIDCacheIndex; j++)
7927 {
7928 if (vos_mem_compare(PMKIDCache[j].BSSID,
7929 pmksa->bssid,
7930 WNI_CFG_BSSID_LEN))
7931 {
7932 /* BSSID matched entry */
7933 BSSIDMatched = 1;
7934
7935 if (j<PMKIDCacheIndex-1)
7936 {
7937 /*replace the matching entry with the last entry in HDD local cache*/
7938 vos_mem_copy(PMKIDCache[j].BSSID,
7939 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7940 WNI_CFG_BSSID_LEN);
7941 vos_mem_copy(PMKIDCache[j].PMKID,
7942 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7943 CSR_RSN_PMKID_SIZE);
7944 }
7945
7946 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07007947 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7948 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7949
7950 /*reduce the PMKID array index*/
7951 PMKIDCacheIndex--;
7952
7953 /*delete the last PMKID cache in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08007954 if (eHAL_STATUS_SUCCESS !=
7955 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid))
Wilson Yang6507c4e2013-10-01 20:11:19 -07007956 {
7957 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7958 __func__,PMKIDCacheIndex);
Wilson Yangef657d32014-01-15 19:19:23 -08007959 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007960 }
7961
7962 dump_bssid(pmksa->bssid);
7963 dump_pmkid(halHandle,pmksa->pmkid);
7964
7965 break;
7966 }
7967 }
7968
7969 /* we compare all entries,but cannot find matching entry */
7970 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7971 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007972 hddLog(VOS_TRACE_LEVEL_FATAL,
7973 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
7974 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007975 dump_bssid(pmksa->bssid);
7976 dump_pmkid(halHandle, pmksa->pmkid);
7977 return -EINVAL;
7978 }
Wilson Yangef657d32014-01-15 19:19:23 -08007979 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007980}
7981
Wilson Yang6507c4e2013-10-01 20:11:19 -07007982
7983
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007984static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7985{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007986 tANI_U32 j=0;
7987 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7988 tHalHandle halHandle;
7989 hdd_context_t *pHddCtx;
7990 tANI_U8 *pBSSId;
Wilson Yangef657d32014-01-15 19:19:23 -08007991 int status = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007992
7993 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7994
7995 /* Validate pAdapter */
7996 if (NULL == pAdapter)
7997 {
7998 hddLog(VOS_TRACE_LEVEL_ERROR,
7999 "%s: Invalid Adapter" ,__func__);
8000 return -EINVAL;
8001 }
8002
8003 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8004 status = wlan_hdd_validate_context(pHddCtx);
8005
8006 if (0 != status)
8007 {
8008 hddLog(VOS_TRACE_LEVEL_ERROR,
8009 "%s: HDD context is not valid", __func__);
8010 return status;
8011 }
8012
8013 /*Retrieve halHandle*/
8014 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8015
8016 /*in case index is 0,no entry to delete*/
8017 if (0 == PMKIDCacheIndex)
8018 {
8019 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
8020 __func__);
8021 return -EINVAL;
8022 }
8023
8024 /*delete all the PMKSA one by one */
8025 for (j = 0; j<PMKIDCacheIndex; j++)
8026 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07008027 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008028
8029 /*delete the PMKID in CSR*/
Wilson Yangef657d32014-01-15 19:19:23 -08008030 if (eHAL_STATUS_SUCCESS !=
8031 sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId))
Wilson Yang6507c4e2013-10-01 20:11:19 -07008032 {
8033 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
8034 __func__,j);
Wilson Yangef657d32014-01-15 19:19:23 -08008035 status = -EINVAL;
Wilson Yang6507c4e2013-10-01 20:11:19 -07008036 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05308037 /*clear the entry in HDD cache 0--index-1 */
8038 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
8039 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07008040 }
8041
8042 PMKIDCacheIndex = 0;
Wilson Yangef657d32014-01-15 19:19:23 -08008043 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008044}
8045#endif
8046
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008047#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308048static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008049 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
8050{
8051 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8052 hdd_station_ctx_t *pHddStaCtx;
8053
8054 if (NULL == pAdapter)
8055 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008056 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL", __func__);
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008057 return -ENODEV;
8058 }
8059
8060 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8061
8062 // Added for debug on reception of Re-assoc Req.
8063 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
8064 {
Arif Hussain6d2a3322013-11-17 19:50:10 -08008065 hddLog(LOGE, FL("Called with Ie of length = %zu when not associated"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008066 ftie->ie_len);
Arif Hussain6d2a3322013-11-17 19:50:10 -08008067 hddLog(LOGE, FL("Should be Re-assoc Req IEs"));
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008068 }
8069
8070#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Arif Hussain6d2a3322013-11-17 19:50:10 -08008071 hddLog(LOGE, FL("%s called with Ie of length = %zu"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008072 ftie->ie_len);
8073#endif
8074
8075 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05308076 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
8077 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008078 ftie->ie_len);
8079 return 0;
8080}
8081#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008082
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308083#ifdef FEATURE_WLAN_SCAN_PNO
8084
8085void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
8086 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8087{
8088 int ret;
8089 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
8090 hdd_context_t *pHddCtx;
8091
Nirav Shah80830bf2013-12-31 16:35:12 +05308092 ENTER();
8093
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308094 if (NULL == pAdapter)
8095 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308096 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308097 "%s: HDD adapter is Null", __func__);
8098 return ;
8099 }
8100
8101 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8102 if (NULL == pHddCtx)
8103 {
8104 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8105 "%s: HDD context is Null!!!", __func__);
8106 return ;
8107 }
8108
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308109 spin_lock(&pHddCtx->schedScan_lock);
8110 if (TRUE == pHddCtx->isWiphySuspended)
8111 {
8112 pHddCtx->isSchedScanUpdatePending = TRUE;
8113 spin_unlock(&pHddCtx->schedScan_lock);
8114 hddLog(VOS_TRACE_LEVEL_INFO,
8115 "%s: Update cfg80211 scan database after it resume", __func__);
8116 return ;
8117 }
8118 spin_unlock(&pHddCtx->schedScan_lock);
8119
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308120 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
8121
8122 if (0 > ret)
8123 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
8124
8125 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308126 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8127 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308128}
8129
8130/*
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308131 * FUNCTION: wlan_hdd_is_pno_allowed
8132 * To check is there any P2P GO/SAP or P2P Client/STA
8133 * session is active
8134 */
8135static eHalStatus wlan_hdd_is_pno_allowed(hdd_adapter_t *pAdapter)
8136{
8137 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
8138 hdd_adapter_t *pTempAdapter = NULL;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308139 hdd_station_ctx_t *pStaCtx;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308140 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8141 int status = 0;
8142 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
8143
8144 while ((NULL != pAdapterNode) && (VOS_STATUS_SUCCESS == status))
8145 {
8146 pTempAdapter = pAdapterNode->pAdapter;
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308147 pStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pTempAdapter);
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308148
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308149 if (((WLAN_HDD_INFRA_STATION == pTempAdapter->device_mode)
8150 && (eConnectionState_NotConnected != pStaCtx->conn_info.connState))
8151 || (WLAN_HDD_P2P_CLIENT == pTempAdapter->device_mode)
8152 || (WLAN_HDD_P2P_GO == pTempAdapter->device_mode)
8153 || (WLAN_HDD_SOFTAP == pTempAdapter->device_mode)
8154 )
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308155 {
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308156 return eHAL_STATUS_FAILURE;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308157 }
8158 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8159 pAdapterNode = pNext;
8160 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308161 return eHAL_STATUS_SUCCESS;
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308162}
8163
8164/*
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308165 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
8166 * NL interface to enable PNO
8167 */
8168static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
8169 struct net_device *dev, struct cfg80211_sched_scan_request *request)
8170{
8171 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8172 tpSirPNOScanReq pPnoRequest = NULL;
8173 hdd_context_t *pHddCtx;
8174 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308175 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308176 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8177 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8178 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8179 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308180 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308181
8182 if (NULL == pAdapter)
8183 {
8184 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8185 "%s: HDD adapter is Null", __func__);
8186 return -ENODEV;
8187 }
8188
8189 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308190 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308191
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308192 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308193 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308194 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8195 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308196 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308197 }
8198
8199 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8200 if (NULL == hHal)
8201 {
8202 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8203 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308204 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308205 }
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308206
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308207 /* The current firmware design for PNO does not consider concurrent
8208 * active sessions.Hence , determine the concurrent active sessions
8209 * and return a failure to the framework on a request for schedule
8210 * scan.
8211 */
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308212 if (eHAL_STATUS_SUCCESS != wlan_hdd_is_pno_allowed(pAdapter))
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308213 {
8214 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Vinay Krishna Eranna23ffd182013-12-26 19:16:55 +05308215 FL("Cannot handle sched_scan"));
Mahesh A Saptasagar0f7b0372013-11-28 23:23:07 +05308216 return -EBUSY;
8217 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308218
8219 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8220 if (NULL == pPnoRequest)
8221 {
8222 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8223 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308224 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308225 }
8226
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05308227 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308228 pPnoRequest->enable = 1; /*Enable PNO */
8229 pPnoRequest->ucNetworksCount = request->n_match_sets;
8230
8231 if (( !pPnoRequest->ucNetworksCount ) ||
8232 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
8233 {
8234 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308235 "%s: Network input is not correct %d",
8236 __func__, pPnoRequest->ucNetworksCount);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308237 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308238 goto error;
8239 }
8240
8241 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
8242 {
8243 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308244 "%s: Incorrect number of channels %d",
8245 __func__, request->n_channels);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308246 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308247 goto error;
8248 }
8249
8250 /* Framework provides one set of channels(all)
8251 * common for all saved profile */
8252 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
8253 channels_allowed, &num_channels_allowed))
8254 {
8255 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8256 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308257 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308258 goto error;
8259 }
8260 /* Checking each channel against allowed channel list */
8261 num_ch = 0;
Nirav Shah80830bf2013-12-31 16:35:12 +05308262 if (request->n_channels)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308263 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308264 char chList [(request->n_channels*5)+1];
8265 int len;
8266 for (i = 0, len = 0; i < request->n_channels; i++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308267 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308268 for (indx = 0; indx < num_channels_allowed; indx++)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308269 {
Nirav Shah80830bf2013-12-31 16:35:12 +05308270 if (request->channels[i]->hw_value == channels_allowed[indx])
8271 {
8272 valid_ch[num_ch++] = request->channels[i]->hw_value;
8273 len += snprintf(chList+len, 5, "%d ",
8274 request->channels[i]->hw_value);
8275 break ;
8276 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308277 }
8278 }
Nirav Shah80830bf2013-12-31 16:35:12 +05308279 hddLog(VOS_TRACE_LEVEL_INFO,"Channel-List: %s ", chList);
8280 }
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308281
8282 /* Filling per profile params */
8283 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
8284 {
8285 pPnoRequest->aNetworks[i].ssId.length =
8286 request->match_sets[i].ssid.ssid_len;
8287
8288 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
8289 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
8290 {
8291 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308292 "%s: SSID Len %d is not correct for network %d",
8293 __func__, pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308294 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308295 goto error;
8296 }
8297
8298 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
8299 request->match_sets[i].ssid.ssid,
8300 request->match_sets[i].ssid.ssid_len);
8301 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
8302 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
8303 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
8304
8305 /*Copying list of valid channel into request */
8306 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
8307 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
8308
8309 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
8310 }
8311
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308312 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson59a121e2013-11-30 09:46:08 -08008313 "request->ie_len = %zu", request->ie_len);
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05308314 if ((0 < request->ie_len) && (NULL != request->ie))
8315 {
8316 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
8317 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
8318 pPnoRequest->us24GProbeTemplateLen);
8319
8320 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
8321 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
8322 pPnoRequest->us5GProbeTemplateLen);
8323 }
8324
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05308325 /* Driver gets only one time interval which is hardcoded in
8326 * supplicant for 10000ms. Taking power consumption into account 6 timers
8327 * will be used, Timervalue is increased exponentially i.e 10,20,40,
8328 * 80,160,320 secs. And number of scan cycle for each timer
8329 * is configurable through INI param gPNOScanTimerRepeatValue.
8330 * If it is set to 0 only one timer will be used and PNO scan cycle
8331 * will be repeated after each interval specified by supplicant
8332 * till PNO is disabled.
8333 */
8334 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
8335 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
8336 else
8337 pPnoRequest->scanTimers.ucScanTimersCount =
8338 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
8339
8340 tempInterval = (request->interval)/1000;
8341 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8342 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
8343 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
8344 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
8345 {
8346 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
8347 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
8348 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
8349 tempInterval *= 2;
8350 }
8351 //Repeat last timer until pno disabled.
8352 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
8353
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05308354 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308355
Nirav Shah80830bf2013-12-31 16:35:12 +05308356 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8357 "SessionId %d, enable %d, modePNO %d, ucScanTimersCount %d",
8358 pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO,
8359 pPnoRequest->scanTimers.ucScanTimersCount);
8360
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308361 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
8362 pPnoRequest, pAdapter->sessionId,
8363 hdd_cfg80211_sched_scan_done_callback, pAdapter);
8364 if (eHAL_STATUS_SUCCESS != status)
8365 {
8366 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Nirav Shah80830bf2013-12-31 16:35:12 +05308367 "%s: Failed to enable PNO", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308368 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308369 goto error;
8370 }
8371
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308372 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8373 "PNO scanRequest offloaded");
8374
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308375error:
8376 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308377 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308378}
8379
8380/*
8381 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
8382 * NL interface to disable PNO
8383 */
8384static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
8385 struct net_device *dev)
8386{
8387 eHalStatus status = eHAL_STATUS_FAILURE;
8388 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8389 hdd_context_t *pHddCtx;
8390 tHalHandle hHal;
8391 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308392 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308393
8394 ENTER();
8395
8396 if (NULL == pAdapter)
8397 {
8398 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8399 "%s: HDD adapter is Null", __func__);
8400 return -ENODEV;
8401 }
8402
8403 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308404
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308405 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308406 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308407 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308408 "%s: HDD context is Null", __func__);
8409 return -ENODEV;
8410 }
8411
8412 /* The return 0 is intentional when isLogpInProgress and
8413 * isLoadUnloadInProgress. We did observe a crash due to a return of
8414 * failure in sched_scan_stop , especially for a case where the unload
8415 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8416 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8417 * success. If it returns a failure , then its next invocation due to the
8418 * clean up of the second interface will have the dev pointer corresponding
8419 * to the first one leading to a crash.
8420 */
8421 if (pHddCtx->isLogpInProgress)
8422 {
8423 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8424 "%s: LOGP in Progress. Ignore!!!", __func__);
8425 return ret;
8426 }
8427
8428 if (pHddCtx->isLoadUnloadInProgress)
8429 {
8430 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8431 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8432 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308433 }
8434
8435 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8436 if (NULL == hHal)
8437 {
8438 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8439 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308440 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308441 }
8442
8443 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8444 if (NULL == pPnoRequest)
8445 {
8446 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8447 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308448 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308449 }
8450
8451 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8452 pPnoRequest->enable = 0; /* Disable PNO */
8453 pPnoRequest->ucNetworksCount = 0;
8454
8455 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8456 pAdapter->sessionId,
8457 NULL, pAdapter);
8458 if (eHAL_STATUS_SUCCESS != status)
8459 {
8460 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8461 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308462 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308463 }
8464
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308465 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8466 "%s: PNO scan disabled", __func__);
8467
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308468 vos_mem_free(pPnoRequest);
8469
8470 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308471 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308472}
8473
8474#endif /*FEATURE_WLAN_SCAN_PNO*/
8475
8476
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008477#ifdef FEATURE_WLAN_TDLS
8478static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8479 u8 *peer, u8 action_code, u8 dialog_token,
8480 u16 status_code, const u8 *buf, size_t len)
8481{
8482
8483 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8484 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008485 u8 peerMac[6];
8486 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008487 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008488 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008489 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008490
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008491 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008492 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308493 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008494 "Invalid arguments");
8495 return -EINVAL;
8496 }
8497
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008498 if (pHddCtx->isLogpInProgress)
8499 {
8500 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8501 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008502 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008503 return -EBUSY;
8504 }
8505
Hoonki Lee27511902013-03-14 18:19:06 -07008506 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008507 {
Hoonki Lee27511902013-03-14 18:19:06 -07008508 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8509 "%s: TDLS mode is disabled OR not enabled in FW."
8510 MAC_ADDRESS_STR " action %d declined.",
8511 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008512 return -ENOTSUPP;
8513 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008514
Hoonki Lee27511902013-03-14 18:19:06 -07008515 /* other than teardown frame, other mgmt frames are not sent if disabled */
8516 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8517 {
8518 /* if tdls_mode is disabled to respond to peer's request */
8519 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8520 {
8521 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8522 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008523 " TDLS mode is disabled. action %d declined.",
8524 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008525
8526 return -ENOTSUPP;
8527 }
8528 }
8529
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008530 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8531 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308532 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008533 {
8534 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008535 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008536 " TDLS setup is ongoing. action %d declined.",
8537 __func__, MAC_ADDR_ARRAY(peer), action_code);
8538 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008539 }
8540 }
8541
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008542 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8543 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008544 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008545 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008546 {
8547 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8548 we return error code at 'add_station()'. Hence we have this
8549 check again in addtion to add_station().
8550 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008551 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008552 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008553 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8554 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008555 " TDLS Max peer already connected. action %d declined.",
8556 __func__, MAC_ADDR_ARRAY(peer), action_code);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308557 return -EINVAL;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008558 }
8559 else
8560 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008561 /* maximum reached. tweak to send error code to peer and return
8562 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008563 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008564 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8565 "%s: " MAC_ADDRESS_STR
8566 " TDLS Max peer already connected send response status %d",
8567 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008568 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008569 /* fall through to send setup resp with failure status
8570 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008571 }
8572 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008573 else
8574 {
8575 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308576 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008577 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008578 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008579 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008580 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8581 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008582 return -EPERM;
8583 }
8584 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008585 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008586 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008587
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008588#ifdef WLAN_FEATURE_TDLS_DEBUG
8589 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008590 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8591 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8592 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008593#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008594
Hoonki Leea34dd892013-02-05 22:56:02 -08008595 /*Except teardown responder will not be used so just make 0*/
8596 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008597 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008598 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008599
8600 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308601 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008602
8603 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8604 responder = pTdlsPeer->is_responder;
8605 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008606 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008607 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8608 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8609 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8610 dialog_token, status_code, len);
8611 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008612 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008613 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008614
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308615 /* For explicit trigger of DIS_REQ come out of BMPS for
8616 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008617 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308618 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8619 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008620 {
8621 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8622 {
8623 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308624 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008625 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8626 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308627 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8628 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008629 }
8630
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008631 /* make sure doesn't call send_mgmt() while it is pending */
8632 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8633 {
8634 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Arif Hussain6d2a3322013-11-17 19:50:10 -08008635 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY",
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008636 __func__, MAC_ADDR_ARRAY(peer), action_code);
8637 return -EBUSY;
8638 }
8639
8640 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008641 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8642
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008643 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008644 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008645
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008646 if (VOS_STATUS_SUCCESS != status)
8647 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008648 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8649 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008650 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008651 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308652 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008653 }
8654
Hoonki Leed37cbb32013-04-20 00:31:14 -07008655 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8656 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8657
8658 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008659 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008660 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008661 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008662 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008663 pAdapter->mgmtTxCompletionStatus = FALSE;
Yue Ma4f55ef32014-01-23 16:45:33 -08008664
8665 if (pHddCtx->isLogpInProgress)
8666 {
8667 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8668 "%s: LOGP in Progress. Ignore!!!", __func__);
8669 return -EAGAIN;
8670 }
8671
Hoonki Leed37cbb32013-04-20 00:31:14 -07008672 wlan_hdd_tdls_check_bmps(pAdapter);
Sunil Dutt388ac8f2013-11-28 18:06:52 +05308673 return -EINVAL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008674 }
8675
Gopichand Nakkala05922802013-03-14 12:23:19 -07008676 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008677 {
8678 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008679 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008680 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008681
Hoonki Leea34dd892013-02-05 22:56:02 -08008682 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8683 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008684 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008685 }
8686 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8687 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008688 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008689 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008690
8691 return 0;
8692}
8693
8694static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8695 u8 *peer, enum nl80211_tdls_operation oper)
8696{
8697 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8698 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308699 int status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008700 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008701
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308702 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008703 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008704 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008705 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008706 return -EINVAL;
8707 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008708
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308709 status = wlan_hdd_validate_context(pHddCtx);
8710
8711 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008712 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308713 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8714 "%s: HDD context is not valid", __func__);
8715 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008716 }
8717
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008718
8719 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008720 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008721 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008722 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008723 "TDLS Disabled in INI OR not enabled in FW. "
8724 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008725 return -ENOTSUPP;
8726 }
8727
8728 switch (oper) {
8729 case NL80211_TDLS_ENABLE_LINK:
8730 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008731 VOS_STATUS status;
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308732 long ret;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308733 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008734
Sunil Dutt41de4e22013-11-14 18:09:02 +05308735 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8736
8737 if ( NULL == pTdlsPeer ) {
8738 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8739 " (oper %d) not exsting. ignored",
8740 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8741 return -EINVAL;
8742 }
8743
8744 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8745 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8746 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8747 "NL80211_TDLS_ENABLE_LINK");
8748
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008749 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8750 {
8751 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8752 MAC_ADDRESS_STR " failed",
8753 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8754 return -EINVAL;
8755 }
8756
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008757 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008758 {
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308759 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308760
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308761 if (0 != wlan_hdd_tdls_get_link_establish_params(
8762 pAdapter, peer,&tdlsLinkEstablishParams)) {
8763 return -EINVAL;
8764 }
8765 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308766
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308767 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8768 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8769 /* Send TDLS peer UAPSD capabilities to the firmware and
8770 * register with the TL on after the response for this operation
8771 * is received .
8772 */
8773 ret = wait_for_completion_interruptible_timeout(
8774 &pAdapter->tdls_link_establish_req_comp,
8775 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8776 if (ret <= 0)
8777 {
8778 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8779 "%s: Link Establish Request Faled Status %ld",
8780 __func__, ret);
8781 return -EINVAL;
8782 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308783 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008784 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308785 /* Mark TDLS client Authenticated .*/
8786 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8787 pTdlsPeer->staId,
8788 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008789 if (VOS_STATUS_SUCCESS == status)
8790 {
Hoonki Lee14621352013-04-16 17:51:19 -07008791 if (pTdlsPeer->is_responder == 0)
8792 {
8793 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8794
8795 wlan_hdd_tdls_timer_restart(pAdapter,
8796 &pTdlsPeer->initiatorWaitTimeoutTimer,
8797 WAIT_TIME_TDLS_INITIATOR);
8798 /* suspend initiator TX until it receives direct packet from the
8799 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8800 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8801 &staId, NULL);
8802 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008803 wlan_hdd_tdls_increment_peer_count(pAdapter);
8804 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008805 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308806
8807 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308808 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8809 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308810 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308811 int ac;
8812 uint8 ucAc[4] = { WLANTL_AC_VO,
8813 WLANTL_AC_VI,
8814 WLANTL_AC_BK,
8815 WLANTL_AC_BE };
8816 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8817 for(ac=0; ac < 4; ac++)
8818 {
8819 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8820 pTdlsPeer->staId, ucAc[ac],
8821 tlTid[ac], tlTid[ac], 0, 0,
8822 WLANTL_BI_DIR );
8823 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308824 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008825 }
8826
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008827 }
8828 break;
8829 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008830 {
Sunil Dutt41de4e22013-11-14 18:09:02 +05308831 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8832
8833 if ( NULL == pTdlsPeer ) {
8834 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR
8835 " (oper %d) not exsting. ignored",
8836 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8837 return -EINVAL;
8838 }
8839
8840 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8841 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8842 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
8843 "NL80211_TDLS_DISABLE_LINK");
8844
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008845 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008846 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008847 long status;
8848
8849 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8850
Lee Hoonkic1262f22013-01-24 21:59:00 -08008851 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8852 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008853
8854 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8855 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8856 if (status <= 0)
8857 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008858 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008859 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8860 "%s: Del station failed status %ld",
8861 __func__, status);
8862 return -EPERM;
8863 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008864 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008865 }
8866 else
8867 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008868 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8869 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008870 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008871 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008872 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008873 case NL80211_TDLS_TEARDOWN:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308874 {
8875 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8876 " %s : NL80211_TDLS_TEARDOWN for " MAC_ADDRESS_STR,
8877 __func__, MAC_ADDR_ARRAY(peer));
8878
8879 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8880 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8881
8882 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8883 " %s TDLS External control and Implicit Trigger not enabled ",
8884 __func__);
8885 return -ENOTSUPP;
8886 }
8887
Sunil Dutt41de4e22013-11-14 18:09:02 +05308888
8889 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
8890
8891 if ( NULL == pTdlsPeer ) {
8892 hddLog(VOS_TRACE_LEVEL_INFO, "%s: " MAC_ADDRESS_STR
8893 " peer not exsting",
8894 __func__, MAC_ADDR_ARRAY(peer));
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308895 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308896 }
8897 else {
8898 wlan_hdd_tdls_indicate_teardown(pAdapter, pTdlsPeer,
8899 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
8900 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308901
8902 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, FALSE) )
8903 return -EINVAL;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308904 break;
8905 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008906 case NL80211_TDLS_SETUP:
Sunil Dutt41de4e22013-11-14 18:09:02 +05308907 {
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308908 hddTdlsPeer_t *pTdlsPeer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308909 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8910 " %s : NL80211_TDLS_SETUP for " MAC_ADDRESS_STR,
8911 __func__, MAC_ADDR_ARRAY(peer));
8912
8913 if ( (FALSE == pHddCtx->cfg_ini->fTDLSExternalControl) ||
8914 (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) ) {
8915
8916 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8917 " %s TDLS External control and Implicit Trigger not enabled ",
8918 __func__);
8919 return -ENOTSUPP;
8920 }
8921
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308922 /* To cater the requirement of establishing the TDLS link
8923 * irrespective of the data traffic , get an entry of TDLS peer.
8924 */
8925 pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
8926 if (pTdlsPeer == NULL) {
8927 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8928 "%s: peer " MAC_ADDRESS_STR " not existing",
8929 __func__, MAC_ADDR_ARRAY(peer));
8930 return -EINVAL;
8931 }
Naresh Jayaram937abdf2013-11-26 19:50:25 +05308932
8933 if ( 0 != wlan_hdd_tdls_set_force_peer(pAdapter, peer, TRUE) ) {
8934
8935 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8936 " %s TDLS Add Force Peer Failed",
8937 __func__);
8938 return -EINVAL;
8939 }
Naresh Jayaramdb4514b2013-11-25 18:08:10 +05308940 break;
Sunil Dutt41de4e22013-11-14 18:09:02 +05308941 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008942 case NL80211_TDLS_DISCOVERY_REQ:
8943 /* We don't support in-driver setup/teardown/discovery */
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308944 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8945 "%s: We don't support in-driver setup/teardown/discovery "
8946 ,__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008947 return -ENOTSUPP;
8948 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05308949 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8950 "%s: unsupported event",__func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008951 return -ENOTSUPP;
8952 }
8953 return 0;
8954}
Chilam NG571c65a2013-01-19 12:27:36 +05308955
8956int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8957 struct net_device *dev, u8 *peer)
8958{
Arif Hussaina7c8e412013-11-20 11:06:42 -08008959 hddLog(VOS_TRACE_LEVEL_INFO,
8960 "tdls send discover req: "MAC_ADDRESS_STR,
8961 MAC_ADDR_ARRAY(peer));
Chilam NG571c65a2013-01-19 12:27:36 +05308962
8963 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8964 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8965}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008966#endif
8967
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308968#ifdef WLAN_FEATURE_GTK_OFFLOAD
8969/*
8970 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8971 * Callback rountine called upon receiving response for
8972 * get offload info
8973 */
8974void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8975 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8976{
8977
8978 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308979 tANI_U8 tempReplayCounter[8];
8980 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308981
8982 ENTER();
8983
8984 if (NULL == pAdapter)
8985 {
Agarwal Ashish971c2882013-10-30 20:11:12 +05308986 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308987 "%s: HDD adapter is Null", __func__);
8988 return ;
8989 }
8990
8991 if (NULL == pGtkOffloadGetInfoRsp)
8992 {
8993 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8994 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8995 return ;
8996 }
8997
8998 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8999 {
9000 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9001 "%s: wlan Failed to get replay counter value",
9002 __func__);
9003 return ;
9004 }
9005
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309006 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9007 /* Update replay counter */
9008 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
9009 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9010
9011 {
9012 /* changing from little to big endian since supplicant
9013 * works on big endian format
9014 */
9015 int i;
9016 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
9017
9018 for (i = 0; i < 8; i++)
9019 {
9020 tempReplayCounter[7-i] = (tANI_U8)p[i];
9021 }
9022 }
9023
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309024 /* Update replay counter to NL */
9025 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309026 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309027}
9028
9029/*
9030 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
9031 * This function is used to offload GTK rekeying job to the firmware.
9032 */
9033int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
9034 struct cfg80211_gtk_rekey_data *data)
9035{
9036 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9037 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9038 hdd_station_ctx_t *pHddStaCtx;
9039 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309040 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309041 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309042 eHalStatus status = eHAL_STATUS_FAILURE;
9043
9044 ENTER();
9045
9046 if (NULL == pAdapter)
9047 {
9048 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9049 "%s: HDD adapter is Null", __func__);
9050 return -ENODEV;
9051 }
9052
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309053 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309054
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309055 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309056 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05309057 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9058 "%s: HDD context is not valid", __func__);
9059 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309060 }
9061
9062 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9063 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
9064 if (NULL == hHal)
9065 {
9066 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9067 "%s: HAL context is Null!!!", __func__);
9068 return -EAGAIN;
9069 }
9070
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309071 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
9072 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
9073 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
9074 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309075 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309076 {
9077 /* changing from big to little endian since driver
9078 * works on little endian format
9079 */
9080 tANI_U8 *p =
9081 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
9082 int i;
9083
9084 for (i = 0; i < 8; i++)
9085 {
9086 p[7-i] = data->replay_ctr[i];
9087 }
9088 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309089
9090 if (TRUE == pHddCtx->hdd_wlan_suspended)
9091 {
9092 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309093 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
9094 sizeof (tSirGtkOffloadParams));
9095 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309096 pAdapter->sessionId);
9097
9098 if (eHAL_STATUS_SUCCESS != status)
9099 {
9100 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9101 "%s: sme_SetGTKOffload failed, returned %d",
9102 __func__, status);
9103 return status;
9104 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309105 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9106 "%s: sme_SetGTKOffload successfull", __func__);
9107 }
9108 else
9109 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309110 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9111 "%s: wlan not suspended GTKOffload request is stored",
9112 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309113 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05309114
9115 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309116}
9117#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
9118
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309119/*
9120 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
9121 * This function is used to set access control policy
9122 */
9123static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
9124 struct net_device *dev, const struct cfg80211_acl_data *params)
9125{
9126 int i;
9127 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9128 hdd_hostapd_state_t *pHostapdState;
9129 tsap_Config_t *pConfig;
9130 v_CONTEXT_t pVosContext = NULL;
9131 hdd_context_t *pHddCtx;
9132 int status;
9133
9134 ENTER();
9135
9136 if (NULL == pAdapter)
9137 {
9138 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9139 "%s: HDD adapter is Null", __func__);
9140 return -ENODEV;
9141 }
9142
9143 if (NULL == params)
9144 {
9145 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9146 "%s: params is Null", __func__);
9147 return -EINVAL;
9148 }
9149
9150 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9151 status = wlan_hdd_validate_context(pHddCtx);
9152
9153 if (0 != status)
9154 {
9155 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9156 "%s: HDD context is not valid", __func__);
9157 return status;
9158 }
9159
9160 pVosContext = pHddCtx->pvosContext;
9161 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
9162
9163 if (NULL == pHostapdState)
9164 {
9165 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9166 "%s: pHostapdState is Null", __func__);
9167 return -EINVAL;
9168 }
9169
9170 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
9171 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
9172
9173 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
9174 {
9175 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
9176
9177 /* default value */
9178 pConfig->num_accept_mac = 0;
9179 pConfig->num_deny_mac = 0;
9180
9181 /**
9182 * access control policy
9183 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
9184 * listed in hostapd.deny file.
9185 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
9186 * listed in hostapd.accept file.
9187 */
9188 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
9189 {
9190 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
9191 }
9192 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
9193 {
9194 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
9195 }
9196 else
9197 {
9198 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9199 "%s:Acl Policy : %d is not supported",
9200 __func__, params->acl_policy);
9201 return -ENOTSUPP;
9202 }
9203
9204 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
9205 {
9206 pConfig->num_accept_mac = params->n_acl_entries;
9207 for (i = 0; i < params->n_acl_entries; i++)
9208 {
9209 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9210 "** Add ACL MAC entry %i in WhiletList :"
9211 MAC_ADDRESS_STR, i,
9212 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9213
9214 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
9215 sizeof(qcmacaddr));
9216 }
9217 }
9218 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
9219 {
9220 pConfig->num_deny_mac = params->n_acl_entries;
9221 for (i = 0; i < params->n_acl_entries; i++)
9222 {
9223 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9224 "** Add ACL MAC entry %i in BlackList :"
9225 MAC_ADDRESS_STR, i,
9226 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
9227
9228 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
9229 sizeof(qcmacaddr));
9230 }
9231 }
9232
9233 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
9234 {
9235 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9236 "%s: SAP Set Mac Acl fail", __func__);
9237 return -EINVAL;
9238 }
9239 }
9240 else
9241 {
9242 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9243 "%s: Invalid device_mode = %d",
9244 __func__, pAdapter->device_mode);
9245 return -EINVAL;
9246 }
9247
9248 return 0;
9249}
9250
Leo Chang9056f462013-08-01 19:21:11 -07009251#ifdef WLAN_NL80211_TESTMODE
9252#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07009253void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07009254(
9255 void *pAdapter,
9256 void *indCont
9257)
9258{
Leo Changd9df8aa2013-09-26 13:32:26 -07009259 tSirLPHBInd *lphbInd;
9260 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07009261
9262 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009263 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07009264
9265 if (NULL == indCont)
9266 {
9267 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07009268 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07009269 return;
9270 }
9271
Leo Changd9df8aa2013-09-26 13:32:26 -07009272 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07009273 skb = cfg80211_testmode_alloc_event_skb(
9274 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07009275 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07009276 GFP_ATOMIC);
9277 if (!skb)
9278 {
9279 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9280 "LPHB timeout, NL buffer alloc fail");
9281 return;
9282 }
9283
Leo Changac3ba772013-10-07 09:47:04 -07009284 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07009285 {
9286 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9287 "WLAN_HDD_TM_ATTR_CMD put fail");
9288 goto nla_put_failure;
9289 }
Leo Changac3ba772013-10-07 09:47:04 -07009290 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07009291 {
9292 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9293 "WLAN_HDD_TM_ATTR_TYPE put fail");
9294 goto nla_put_failure;
9295 }
Leo Changac3ba772013-10-07 09:47:04 -07009296 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07009297 sizeof(tSirLPHBInd), lphbInd))
9298 {
9299 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9300 "WLAN_HDD_TM_ATTR_DATA put fail");
9301 goto nla_put_failure;
9302 }
Leo Chang9056f462013-08-01 19:21:11 -07009303 cfg80211_testmode_event(skb, GFP_ATOMIC);
9304 return;
9305
9306nla_put_failure:
9307 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9308 "NLA Put fail");
9309 kfree_skb(skb);
9310
9311 return;
9312}
9313#endif /* FEATURE_WLAN_LPHB */
9314
9315static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
9316{
9317 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
9318 int err = 0;
9319#ifdef FEATURE_WLAN_LPHB
9320 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07009321 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07009322#endif /* FEATURE_WLAN_LPHB */
9323
9324 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
9325 if (err)
9326 {
9327 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9328 "%s Testmode INV ATTR", __func__);
9329 return err;
9330 }
9331
9332 if (!tb[WLAN_HDD_TM_ATTR_CMD])
9333 {
9334 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9335 "%s Testmode INV CMD", __func__);
9336 return -EINVAL;
9337 }
9338
9339 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
9340 {
9341#ifdef FEATURE_WLAN_LPHB
9342 /* Low Power Heartbeat configuration request */
9343 case WLAN_HDD_TM_CMD_WLAN_HB:
9344 {
9345 int buf_len;
9346 void *buf;
9347 tSirLPHBReq *hb_params = NULL;
9348
9349 if (!tb[WLAN_HDD_TM_ATTR_DATA])
9350 {
9351 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9352 "%s Testmode INV DATA", __func__);
9353 return -EINVAL;
9354 }
9355
9356 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
9357 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
9358 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
9359 if (NULL == hb_params)
9360 {
9361 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9362 "%s Request Buffer Alloc Fail", __func__);
9363 return -EINVAL;
9364 }
9365
9366 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07009367 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
9368 hb_params,
9369 wlan_hdd_cfg80211_lphb_ind_handler);
9370 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07009371 {
Leo Changd9df8aa2013-09-26 13:32:26 -07009372 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9373 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07009374 vos_mem_free(hb_params);
9375 }
Leo Chang9056f462013-08-01 19:21:11 -07009376 return 0;
9377 }
9378#endif /* FEATURE_WLAN_LPHB */
9379 default:
c_hpothu6ff1c3c2013-10-01 19:01:57 +05309380 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9381 "%s: unsupported event",__func__);
Leo Chang9056f462013-08-01 19:21:11 -07009382 return -EOPNOTSUPP;
9383 }
9384
9385 return err;
9386}
9387#endif /* CONFIG_NL80211_TESTMODE */
9388
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309389static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
9390 struct net_device *dev,
9391 int idx, struct survey_info *survey)
9392{
9393 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
9394 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05309395 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309396 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05309397 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309398 v_S7_t snr,rssi;
9399 int status, i, j, filled = 0;
9400
9401 ENTER();
9402
9403
9404 if (NULL == pAdapter)
9405 {
9406 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9407 "%s: HDD adapter is Null", __func__);
9408 return -ENODEV;
9409 }
9410
9411 if (NULL == wiphy)
9412 {
9413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9414 "%s: wiphy is Null", __func__);
9415 return -ENODEV;
9416 }
9417
9418 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
9419 status = wlan_hdd_validate_context(pHddCtx);
9420
9421 if (0 != status)
9422 {
9423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9424 "%s: HDD context is not valid", __func__);
9425 return status;
9426 }
9427
Mihir Sheted9072e02013-08-21 17:02:29 +05309428 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
9429
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309430 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05309431 0 != pAdapter->survey_idx ||
9432 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309433 {
9434 /* The survey dump ops when implemented completely is expected to
9435 * return a survey of all channels and the ops is called by the
9436 * kernel with incremental values of the argument 'idx' till it
9437 * returns -ENONET. But we can only support the survey for the
9438 * operating channel for now. survey_idx is used to track
9439 * that the ops is called only once and then return -ENONET for
9440 * the next iteration
9441 */
9442 pAdapter->survey_idx = 0;
9443 return -ENONET;
9444 }
9445
9446 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
9447
9448 wlan_hdd_get_snr(pAdapter, &snr);
9449 wlan_hdd_get_rssi(pAdapter, &rssi);
9450
9451 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
9452 hdd_wlan_get_freq(channel, &freq);
9453
9454
9455 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
9456 {
9457 if (NULL == wiphy->bands[i])
9458 {
9459 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
9460 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
9461 continue;
9462 }
9463
9464 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
9465 {
9466 struct ieee80211_supported_band *band = wiphy->bands[i];
9467
9468 if (band->channels[j].center_freq == (v_U16_t)freq)
9469 {
9470 survey->channel = &band->channels[j];
9471 /* The Rx BDs contain SNR values in dB for the received frames
9472 * while the supplicant expects noise. So we calculate and
9473 * return the value of noise (dBm)
9474 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
9475 */
9476 survey->noise = rssi - snr;
9477 survey->filled = SURVEY_INFO_NOISE_DBM;
9478 filled = 1;
9479 }
9480 }
9481 }
9482
9483 if (filled)
9484 pAdapter->survey_idx = 1;
9485 else
9486 {
9487 pAdapter->survey_idx = 0;
9488 return -ENONET;
9489 }
9490
9491 return 0;
9492}
9493
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309494/*
9495 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9496 * this is called when cfg80211 driver resume
9497 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9498 */
9499int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9500{
9501 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9502 hdd_adapter_t *pAdapter;
9503 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9504 VOS_STATUS status = VOS_STATUS_SUCCESS;
9505
9506 ENTER();
9507
9508 if ( NULL == pHddCtx )
9509 {
9510 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9511 "%s: HddCtx validation failed", __func__);
9512 return 0;
9513 }
9514
9515 if (pHddCtx->isLogpInProgress)
9516 {
9517 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9518 "%s: LOGP in Progress. Ignore!!!", __func__);
9519 return 0;
9520 }
9521
9522 if (pHddCtx->isLoadUnloadInProgress)
9523 {
9524 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9525 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9526 return 0;
9527 }
9528
9529 spin_lock(&pHddCtx->schedScan_lock);
9530 pHddCtx->isWiphySuspended = FALSE;
9531 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9532 {
9533 spin_unlock(&pHddCtx->schedScan_lock);
9534 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9535 "%s: Return resume is not due to PNO indication", __func__);
9536 return 0;
9537 }
9538 // Reset flag to avoid updatating cfg80211 data old results again
9539 pHddCtx->isSchedScanUpdatePending = FALSE;
9540 spin_unlock(&pHddCtx->schedScan_lock);
9541
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309542
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309543 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9544
9545 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9546 {
9547 pAdapter = pAdapterNode->pAdapter;
9548 if ( (NULL != pAdapter) &&
9549 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9550 {
9551 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309552 {
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309553 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9554 "%s: NO SCAN result", __func__);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309555 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309556 else
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309557 {
9558 /* Acquire wakelock to handle the case where APP's tries to
9559 * suspend immediately after updating the scan results. Whis
9560 * results in app's is in suspended state and not able to
9561 * process the connect request to AP
9562 */
9563 hdd_prevent_suspend_timeout(2000);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309564 cfg80211_sched_scan_results(pHddCtx->wiphy);
Mahesh A Saptasagarb9c50402014-01-16 15:49:22 +05309565 }
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309566
9567 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9568 "%s : cfg80211 scan result database updated", __func__);
9569
9570 return 0;
9571
9572 }
9573 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9574 pAdapterNode = pNext;
9575 }
9576
9577 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9578 "%s: Failed to find Adapter", __func__);
9579 return 0;
9580}
9581
9582/*
9583 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9584 * this is called when cfg80211 driver suspends
9585 */
9586int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9587 struct cfg80211_wowlan *wow)
9588{
9589 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9590
9591 ENTER();
9592 if (NULL == pHddCtx)
9593 {
9594 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9595 "%s: HddCtx validation failed", __func__);
9596 return 0;
9597 }
9598
9599 pHddCtx->isWiphySuspended = TRUE;
9600
9601 EXIT();
9602
9603 return 0;
9604}
9605
Jeff Johnson295189b2012-06-20 16:38:30 -07009606/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309607static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009608{
9609 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9610 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9611 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9612 .change_station = wlan_hdd_change_station,
9613#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9614 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9615 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9616 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009617#else
9618 .start_ap = wlan_hdd_cfg80211_start_ap,
9619 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9620 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009621#endif
9622 .change_bss = wlan_hdd_cfg80211_change_bss,
9623 .add_key = wlan_hdd_cfg80211_add_key,
9624 .get_key = wlan_hdd_cfg80211_get_key,
9625 .del_key = wlan_hdd_cfg80211_del_key,
9626 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009627#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009628 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009629#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009630 .scan = wlan_hdd_cfg80211_scan,
9631 .connect = wlan_hdd_cfg80211_connect,
9632 .disconnect = wlan_hdd_cfg80211_disconnect,
9633 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9634 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9635 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9636 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9637 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009638 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9639 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9640 .mgmt_tx = wlan_hdd_action,
9641#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9642 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9643 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9644 .set_txq_params = wlan_hdd_set_txq_params,
9645#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009646 .get_station = wlan_hdd_cfg80211_get_station,
9647 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9648 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009649 .add_station = wlan_hdd_cfg80211_add_station,
9650#ifdef FEATURE_WLAN_LFR
9651 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9652 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9653 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9654#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009655#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9656 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9657#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009658#ifdef FEATURE_WLAN_TDLS
9659 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9660 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9661#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309662#ifdef WLAN_FEATURE_GTK_OFFLOAD
9663 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9664#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309665#ifdef FEATURE_WLAN_SCAN_PNO
9666 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9667 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9668#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309669 .resume = wlan_hdd_cfg80211_resume_wlan,
9670 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309671 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009672#ifdef WLAN_NL80211_TESTMODE
9673 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9674#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309675 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009676};
9677